This source file includes following definitions.
- __ntohl
- __ntohs
1 #ifndef _ALPHA_BYTEORDER_H
2 #define _ALPHA_BYTEORDER_H
3
4 #undef ntohl
5 #undef ntohs
6 #undef htonl
7 #undef htons
8
9 #ifndef __LITTLE_ENDIAN
10 #define __LITTLE_ENDIAN
11 #endif
12
13 #ifndef __LITTLE_ENDIAN_BITFIELD
14 #define __LITTLE_ENDIAN_BITFIELD
15 #endif
16
17 extern unsigned long int ntohl(unsigned long int);
18 extern unsigned short int ntohs(unsigned short int);
19 extern unsigned long int htonl(unsigned long int);
20 extern unsigned short int htons(unsigned short int);
21
22 extern unsigned long int __ntohl(unsigned long int);
23 extern unsigned short int __ntohs(unsigned short int);
24 extern unsigned long int __constant_ntohl(unsigned long int);
25 extern unsigned short int __constant_ntohs(unsigned short int);
26
27
28
29
30
31
32
33
34 extern __inline__ unsigned long int
35 __ntohl(unsigned long int x)
36 {
37 unsigned long int res, t1, t2;
38
39 __asm__(
40 "# bswap input: %0 (aabbccdd)\n\t"
41 "# output: %0, used %1 %2\n\t"
42 "extlh %0,5,%1 # %1 = dd000000\n\t"
43 "zap %0,0xfd,%2 # %2 = 0000cc00\n\t"
44 "sll %2,5,%2 # %2 = 00198000\n\t"
45 "s8addq %2,%1,%1 # %1 = ddcc0000\n\t"
46 "zap %0,0xfb,%2 # %2 = 00bb0000\n\t"
47 "srl %2,8,%2 # %2 = 0000bb00\n\t"
48 "extbl %0,3,%0 # %0 = 000000aa\n\t"
49 "or %1,%0,%0 # %0 = ddcc00aa\n\t"
50 "or %2,%0,%0 # %0 = ddccbbaa\n"
51 : "r="(res), "r="(t1), "r="(t2)
52 : "0" (x & 0xffffffffUL));
53 return res;
54 }
55
56 #define __constant_ntohl(x) \
57 ((unsigned long int)((((x) & 0x000000ffUL) << 24) | \
58 (((x) & 0x0000ff00UL) << 8) | \
59 (((x) & 0x00ff0000UL) >> 8) | \
60 (((x) & 0xff000000UL) >> 24)))
61
62 extern __inline__ unsigned short int
63 __ntohs(unsigned short int x)
64 {
65 unsigned long int res, t1;
66
67 __asm__(
68 "# v0 is result; swap in-place.\n\t"
69 "bis %2,%2,%0 # v0 = aabb\n\t"
70 "extwh %0,7,%1 # t1 = bb00\n\t"
71 "extbl %0,1,%0 # v0 = 00aa\n\t"
72 "bis %0,%1,%0 # v0 = bbaa\n"
73 : "r="(res), "r="(t1) : "r"(x));
74 return res;
75 }
76
77 #define __constant_ntohs(x) \
78 ((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
79 (((unsigned short int)(x) & 0xff00) >> 8)))
80
81 #define __htonl(x) __ntohl(x)
82 #define __htons(x) __ntohs(x)
83 #define __constant_htonl(x) __constant_ntohl(x)
84 #define __constant_htons(x) __constant_ntohs(x)
85
86 #ifdef __OPTIMIZE__
87 # define ntohl(x) \
88 (__builtin_constant_p((long)(x)) ? \
89 __constant_ntohl((x)) : \
90 __ntohl((x)))
91 # define ntohs(x) \
92 (__builtin_constant_p((short)(x)) ? \
93 __constant_ntohs((x)) : \
94 __ntohs((x)))
95 # define htonl(x) \
96 (__builtin_constant_p((long)(x)) ? \
97 __constant_htonl((x)) : \
98 __htonl((x)))
99 # define htons(x) \
100 (__builtin_constant_p((short)(x)) ? \
101 __constant_htons((x)) : \
102 __htons((x)))
103 #endif
104
105 #endif