root/include/asm-alpha/byteorder.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. __ntohl
  2. __ntohs

   1 #ifndef _ALPHA_BYTEORDER_H
   2 #define _ALPHA_BYTEORDER_H
   3 
   4 #undef ntohl
   5 #undef ntohs
   6 #undef htonl
   7 #undef htons
   8 
   9 #ifndef __LITTLE_ENDIAN
  10 #define __LITTLE_ENDIAN
  11 #endif
  12 
  13 #ifndef __LITTLE_ENDIAN_BITFIELD
  14 #define __LITTLE_ENDIAN_BITFIELD
  15 #endif
  16 
  17 extern unsigned long int        ntohl(unsigned long int);
  18 extern unsigned short int       ntohs(unsigned short int);
  19 extern unsigned long int        htonl(unsigned long int);
  20 extern unsigned short int       htons(unsigned short int);
  21 
  22 extern unsigned long int        __ntohl(unsigned long int);
  23 extern unsigned short int       __ntohs(unsigned short int);
  24 extern unsigned long int        __constant_ntohl(unsigned long int);
  25 extern unsigned short int       __constant_ntohs(unsigned short int);
  26 
  27 /*
  28  * The constant and non-constant versions here are the same.
  29  * Maybe I'll come up with an alpha-optimized routine for the
  30  * non-constant ones (the constant ones don't need it: gcc
  31  * will optimize it to the correct constant)
  32  */
  33 
  34 extern __inline__ unsigned long int
  35 __ntohl(unsigned long int x)
     /* [previous][next][first][last][top][bottom][index][help] */
  36 {
  37         unsigned long int res, t1, t2;
  38 
  39         __asm__
  40             ("bis       %3,%3,%0        # %0 is result; %0=aabbccdd
  41               extlh     %0,5,%1         # %1 = dd000000
  42               zap       %0,0xfd,%2      # %2 = 0000cc00
  43               sll       %2,5,%2         # %2 = 00198000
  44               s8addl    %2,%1,%1        # %1 = ddcc0000
  45               zap       %0,0xfb,%2      # %2 = 00bb0000
  46               srl       %2,8,%2         # %2 = 0000bb00
  47               extbl     %0,3,%0         # %0 = 000000aa
  48               or        %1,%0,%0        # %0 = ddcc00aa
  49               or        %2,%0,%0        # %0 = ddccbbaa"
  50              : "r="(res), "r="(t1), "r="(t2) : "r"(x));
  51         return res;
  52 }
  53 
  54 #define __constant_ntohl(x) \
  55 ((unsigned int)((((unsigned int)(x) & 0x000000ffU) << 24) | \
  56                 (((unsigned int)(x) & 0x0000ff00U) <<  8) | \
  57                 (((unsigned int)(x) & 0x00ff0000U) >>  8) | \
  58                 (((unsigned int)(x) & 0xff000000U) >> 24)))
  59 
  60 extern __inline__ unsigned short int
  61 __ntohs(unsigned short int x)
     /* [previous][next][first][last][top][bottom][index][help] */
  62 {
  63         unsigned long int res, t1;
  64         
  65         __asm__
  66             ("bis       %2,%2,%0        # v0 is result; swap in-place.  v0=aabb
  67               extwh     %0,7,%1         # t1 = bb00
  68               extbl     %0,1,%0         # v0 = 00aa
  69               bis       %0,%1,%0        # v0 = bbaa"
  70              : "r="(res), "r="(t1) : "r"(x));
  71         return res;
  72 }
  73 
  74 #define __constant_ntohs(x) \
  75 ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
  76                       (((unsigned short int)(x) & 0xff00) >> 8)))
  77 
  78 #define __htonl(x) __ntohl(x)
  79 #define __htons(x) __ntohs(x)
  80 #define __constant_htonl(x) __constant_ntohl(x)
  81 #define __constant_htons(x) __constant_ntohs(x)
  82 
  83 #ifdef  __OPTIMIZE__
  84 #  define ntohl(x) \
  85 (__builtin_constant_p((long)(x)) ? \
  86  __constant_ntohl((x)) : \
  87  __ntohl((x)))
  88 #  define ntohs(x) \
  89 (__builtin_constant_p((short)(x)) ? \
  90  __constant_ntohs((x)) : \
  91  __ntohs((x)))
  92 #  define htonl(x) \
  93 (__builtin_constant_p((long)(x)) ? \
  94  __constant_htonl((x)) : \
  95  __htonl((x)))
  96 #  define htons(x) \
  97 (__builtin_constant_p((short)(x)) ? \
  98  __constant_htons((x)) : \
  99  __htons((x)))
 100 #endif
 101 
 102 #endif

/* [previous][next][first][last][top][bottom][index][help] */