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         __asm__("xchgb %b0,%h0\n\t"     /* swap lower bytes     */
  31                 "rorl $16,%0\n\t"       /* swap words           */
  32                 "xchgb %b0,%h0"         /* swap higher bytes    */
  33                 :"=q" (x)
  34                 : "0" (x));
  35         return x;
  36 }
  37 
  38 #define __constant_ntohl(x) \
  39         ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
  40                              (((unsigned long int)(x) & 0x0000ff00U) <<  8) | \
  41                              (((unsigned long int)(x) & 0x00ff0000U) >>  8) | \
  42                              (((unsigned long int)(x) & 0xff000000U) >> 24)))
  43 
  44 extern __inline__ unsigned short int
  45 __ntohs(unsigned short int x)
     /* [previous][next][first][last][top][bottom][index][help] */
  46 {
  47         __asm__("xchgb %b0,%h0"         /* swap bytes           */
  48                 : "=q" (x)
  49                 :  "0" (x));
  50         return x;
  51 }
  52 
  53 #define __constant_ntohs(x) \
  54         ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
  55                               (((unsigned short int)(x) & 0xff00) >> 8))) \
  56 
  57 #define __htonl(x) __ntohl(x)
  58 #define __htons(x) __ntohs(x)
  59 #define __constant_htonl(x) __constant_ntohl(x)
  60 #define __constant_htons(x) __constant_ntohs(x)
  61 
  62 #ifdef  __OPTIMIZE__
  63 #  define ntohl(x) \
  64 (__builtin_constant_p((long)(x)) ? \
  65  __constant_ntohl((x)) : \
  66  __ntohl((x)))
  67 #  define ntohs(x) \
  68 (__builtin_constant_p((short)(x)) ? \
  69  __constant_ntohs((x)) : \
  70  __ntohs((x)))
  71 #  define htonl(x) \
  72 (__builtin_constant_p((long)(x)) ? \
  73  __constant_htonl((x)) : \
  74  __htonl((x)))
  75 #  define htons(x) \
  76 (__builtin_constant_p((short)(x)) ? \
  77  __constant_htons((x)) : \
  78  __htons((x)))
  79 #endif
  80 
  81 #endif

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