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