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         "# bswap input: %0 (aabbccdd)
  41         # output: %0, used %1 %2
  42         extlh   %0,5,%1         # %1 = dd000000
  43         zap     %0,0xfd,%2      # %2 = 0000cc00
  44         sll     %2,5,%2         # %2 = 00198000
  45         s8addq  %2,%1,%1        # %1 = ddcc0000
  46         zap     %0,0xfb,%2      # %2 = 00bb0000
  47         srl     %2,8,%2         # %2 = 0000bb00
  48         extbl   %0,3,%0         # %0 = 000000aa
  49         or      %1,%0,%0        # %0 = ddcc00aa
  50         or      %2,%0,%0        # %0 = ddccbbaa"
  51         : "r="(res), "r="(t1), "r="(t2)
  52         : "0" (x & 0xffffffffUL));
  53         return res;
  54 }
  55 
  56 #define __constant_ntohl(x) \
  57    ((unsigned long int)((((x) & 0x000000ffUL) << 24) | \
  58                         (((x) & 0x0000ff00UL) <<  8) | \
  59                         (((x) & 0x00ff0000UL) >>  8) | \
  60                         (((x) & 0xff000000UL) >> 24)))
  61 
  62 extern __inline__ unsigned short int
  63 __ntohs(unsigned short int x)
     /* [previous][next][first][last][top][bottom][index][help] */
  64 {
  65         unsigned long int res, t1;
  66         
  67         __asm__
  68             ("bis       %2,%2,%0        # v0 is result; swap in-place.  v0=aabb
  69               extwh     %0,7,%1         # t1 = bb00
  70               extbl     %0,1,%0         # v0 = 00aa
  71               bis       %0,%1,%0        # v0 = bbaa"
  72              : "r="(res), "r="(t1) : "r"(x));
  73         return res;
  74 }
  75 
  76 #define __constant_ntohs(x) \
  77 ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
  78                       (((unsigned short int)(x) & 0xff00) >> 8)))
  79 
  80 #define __htonl(x) __ntohl(x)
  81 #define __htons(x) __ntohs(x)
  82 #define __constant_htonl(x) __constant_ntohl(x)
  83 #define __constant_htons(x) __constant_ntohs(x)
  84 
  85 #ifdef  __OPTIMIZE__
  86 #  define ntohl(x) \
  87 (__builtin_constant_p((long)(x)) ? \
  88  __constant_ntohl((x)) : \
  89  __ntohl((x)))
  90 #  define ntohs(x) \
  91 (__builtin_constant_p((short)(x)) ? \
  92  __constant_ntohs((x)) : \
  93  __ntohs((x)))
  94 #  define htonl(x) \
  95 (__builtin_constant_p((long)(x)) ? \
  96  __constant_htonl((x)) : \
  97  __htonl((x)))
  98 #  define htons(x) \
  99 (__builtin_constant_p((short)(x)) ? \
 100  __constant_htons((x)) : \
 101  __htons((x)))
 102 #endif
 103 
 104 #endif

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