5755981 [rkeene@sledge /home/rkeene/devel/cygwin-stuff/cyg-root/usr/include/asm]$ cat -n byteorder.h
 1 #ifndef _I386_BYTEORDER_H
 2 #define _I386_BYTEORDER_H
 3 
 4 #ifdef __cplusplus
 5 extern "C" {
 6 #endif
 7 
 8 #if 0
 9 #undef ntohl
10 #undef ntohs
11 #undef htonl
12 #undef htons
13 #endif
14 
15 #ifndef __LITTLE_ENDIAN
16 #define __LITTLE_ENDIAN 1234
17 #endif
18 
19 #ifndef __LITTLE_ENDIAN_BITFIELD
20 #define __LITTLE_ENDIAN_BITFIELD
21 #endif
22 
23 #if 1
24 extern unsigned long int    ntohl(unsigned long int);
25 extern unsigned short int   ntohs(unsigned short int);
26 extern unsigned long int    htonl(unsigned long int);
27 extern unsigned short int   htons(unsigned short int);
28 
29 extern __inline__ unsigned long int __ntohl(unsigned long int);
30 extern __inline__ unsigned short int    __ntohs(unsigned short int);
31 extern __inline__ unsigned long int __constant_ntohl(unsigned long int);
32 extern __inline__ unsigned short int    __constant_ntohs(unsigned short int);
33 
34 extern __inline__ unsigned long int
35 __ntohl(unsigned long int x)
36 {
37     __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */
38         "rorl $16,%0\n\t"   /* swap words       */
39         "xchgb %b0,%h0"     /* swap higher bytes    */
40         :"=q" (x)
41         : "0" (x));
42     return x;
43 }
44 
45 #define __constant_ntohl(x) \
46     ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
47                  (((unsigned long int)(x) & 0x0000ff00U) <<  8) | \
48                  (((unsigned long int)(x) & 0x00ff0000U) >>  8) | \
49                  (((unsigned long int)(x) & 0xff000000U) >> 24)))
50 
51 extern __inline__ unsigned short int
52 __ntohs(unsigned short int x)
53 {
54     __asm__("xchgb %b0,%h0"     /* swap bytes       */
55         : "=q" (x)
56         :  "0" (x));
57     return x;
58 }
59 
60 #define __constant_ntohs(x) \
61     ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
62                   (((unsigned short int)(x) & 0xff00) >> 8))) \
63 
64 #define __htonl(x) __ntohl(x)
65 #define __htons(x) __ntohs(x)
66 #define __constant_htonl(x) __constant_ntohl(x)
67 #define __constant_htons(x) __constant_ntohs(x)
68 
69 #ifdef  __OPTIMIZE__
70 #  define ntohl(x) \
71 (__builtin_constant_p((long)(x)) ? \
72  __constant_ntohl((x)) : \
73  __ntohl((x)))
74 #  define ntohs(x) \
75 (__builtin_constant_p((short)(x)) ? \
76  __constant_ntohs((x)) : \
77  __ntohs((x)))
78 #  define htonl(x) \
79 (__builtin_constant_p((long)(x)) ? \
80  __constant_htonl((x)) : \
81  __htonl((x)))
82 #  define htons(x) \
83 (__builtin_constant_p((short)(x)) ? \
84  __constant_htons((x)) : \
85  __htons((x)))
86 #endif
87 #endif
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif
5755982 [rkeene@sledge /home/rkeene/devel/cygwin-stuff/cyg-root/usr/include/asm]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2001-01-31 15:09:09