root/include/asm-i386/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 _I386_BYTEORDER_H
   2 #define _I386_BYTEORDER_H
   3 
   4 #undef ntohl
   5 #undef ntohs
   6 #undef htonl
   7 #undef htons
   8 
   9 #ifndef __LITTLE_ENDIAN
  10 #define __LITTLE_ENDIAN 1234
  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 __inline__ unsigned long int     __ntohl(unsigned long int);
  23 extern __inline__ unsigned short int    __ntohs(unsigned short int);
  24 extern __inline__ unsigned long int     __constant_ntohl(unsigned long int);
  25 extern __inline__ unsigned short int    __constant_ntohs(unsigned short int);
  26 
  27 extern __inline__ unsigned long int
  28 __ntohl(unsigned long int x)
     /* [previous][next][first][last][top][bottom][index][help] */
  29 {
  30 #if defined(__KERNEL__) && !defined(CONFIG_M386)
  31         __asm__("bswap %0" : "=r" (x) : "0" (x));
  32 #else
  33         __asm__("xchgb %b0,%h0\n\t"     /* swap lower bytes     */
  34                 "rorl $16,%0\n\t"       /* swap words           */
  35                 "xchgb %b0,%h0"         /* swap higher bytes    */
  36                 :"=q" (x)
  37                 : "0" (x));
  38 #endif  
  39         return x;
  40 }
  41 
  42 #define __constant_ntohl(x) \
  43         ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
  44                              (((unsigned long int)(x) & 0x0000ff00U) <<  8) | \
  45                              (((unsigned long int)(x) & 0x00ff0000U) >>  8) | \
  46                              (((unsigned long int)(x) & 0xff000000U) >> 24)))
  47 
  48 extern __inline__ unsigned short int
  49 __ntohs(unsigned short int x)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51         __asm__("xchgb %b0,%h0"         /* swap bytes           */
  52                 : "=q" (x)
  53                 :  "0" (x));
  54         return x;
  55 }
  56 
  57 #define __constant_ntohs(x) \
  58         ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
  59                               (((unsigned short int)(x) & 0xff00) >> 8))) \
  60 
  61 #define __htonl(x) __ntohl(x)
  62 #define __htons(x) __ntohs(x)
  63 #define __constant_htonl(x) __constant_ntohl(x)
  64 #define __constant_htons(x) __constant_ntohs(x)
  65 
  66 #ifdef  __OPTIMIZE__
  67 #  define ntohl(x) \
  68 (__builtin_constant_p((long)(x)) ? \
  69  __constant_ntohl((x)) : \
  70  __ntohl((x)))
  71 #  define ntohs(x) \
  72 (__builtin_constant_p((short)(x)) ? \
  73  __constant_ntohs((x)) : \
  74  __ntohs((x)))
  75 #  define htonl(x) \
  76 (__builtin_constant_p((long)(x)) ? \
  77  __constant_htonl((x)) : \
  78  __htonl((x)))
  79 #  define htons(x) \
  80 (__builtin_constant_p((short)(x)) ? \
  81  __constant_htons((x)) : \
  82  __htons((x)))
  83 #endif
  84 
  85 #endif

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