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

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