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 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 #define __constant_ntohl(x) \
31 ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
32 (((unsigned long int)(x) & 0x0000ff00U) << 8) | \
33 (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \
34 (((unsigned long int)(x) & 0xff000000U) >> 24)))
35
36 extern __inline__ unsigned short int
37 __ntohs(unsigned short int x)
38 {
39 __asm__("xchgb %b0,%h0"
40 : "=q" (x)
41 : "0" (x));
42 return x;
43 }
44
45 #define __constant_ntohs(x) \
46 ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
47 (((unsigned short int)(x) & 0xff00) >> 8))) \
48
49 #define __htonl(x) __ntohl(x)
50 #define __htons(x) __ntohs(x)
51 #define __constant_htonl(x) __constant_ntohl(x)
52 #define __constant_htons(x) __constant_ntohs(x)
53
54 #ifdef __OPTIMIZE__
55 # define ntohl(x) \
56 (__builtin_constant_p((long)(x)) ? \
57 __constant_ntohl((x)) : \
58 __ntohl((x)))
59 # define ntohs(x) \
60 (__builtin_constant_p((short)(x)) ? \
61 __constant_ntohs((x)) : \
62 __ntohs((x)))
63 # define htonl(x) \
64 (__builtin_constant_p((long)(x)) ? \
65 __constant_htonl((x)) : \
66 __htonl((x)))
67 # define htons(x) \
68 (__builtin_constant_p((short)(x)) ? \
69 __constant_htons((x)) : \
70 __htons((x)))
71 #endif
72
73 #endif