This source file includes following definitions.
- __ntohl
- __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 #define LITTLE_ENDIAN 1234
10 #define LITTLE_ENDIAN_BITFIELD
11
12 extern unsigned long int ntohl(unsigned long int);
13 extern unsigned short int ntohs(unsigned short int);
14 extern unsigned long int htonl(unsigned long int);
15 extern unsigned short int htons(unsigned short int);
16
17 extern unsigned long int __ntohl(unsigned long int);
18 extern unsigned short int __ntohs(unsigned short int);
19 extern unsigned long int __constant_ntohl(unsigned long int);
20 extern unsigned short int __constant_ntohs(unsigned short int);
21
22 extern __inline__ unsigned long int
23 __ntohl(unsigned long int x)
24 {
25 __asm__("xchgb %b0,%h0\n\t"
26 "rorl $16,%0\n\t"
27 "xchgb %b0,%h0"
28 :"=q" (x)
29 : "0" (x));
30 return x;
31 }
32
33 #define __constant_ntohl(x) \
34 ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
35 (((unsigned long int)(x) & 0x0000ff00U) << 8) | \
36 (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \
37 (((unsigned long int)(x) & 0xff000000U) >> 24)))
38
39 extern __inline__ unsigned short int
40 __ntohs(unsigned short int x)
41 {
42 __asm__("xchgb %b0,%h0"
43 : "=q" (x)
44 : "0" (x));
45 return x;
46 }
47
48 #define __constant_ntohs(x) \
49 ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
50 (((unsigned short int)(x) & 0xff00) >> 8))) \
51
52 #define __htonl(x) __ntohl(x)
53 #define __htons(x) __ntohs(x)
54 #define __constant_htonl(x) __constant_ntohl(x)
55 #define __constant_htons(x) __constant_ntohs(x)
56
57 #ifdef __OPTIMIZE__
58 # define ntohl(x) \
59 (__builtin_constant_p((long)(x)) ? \
60 __constant_ntohl((x)) : \
61 __ntohl((x)))
62 # define ntohs(x) \
63 (__builtin_constant_p((short)(x)) ? \
64 __constant_ntohs((x)) : \
65 __ntohs((x)))
66 # define htonl(x) \
67 (__builtin_constant_p((long)(x)) ? \
68 __constant_htonl((x)) : \
69 __htonl((x)))
70 # define htons(x) \
71 (__builtin_constant_p((short)(x)) ? \
72 __constant_htons((x)) : \
73 __htons((x)))
74 #endif
75
76 #endif