6 /* Avoid namespace collisions with BSD <sys/endian.h>. */
7 #define be16dec libcperciva_be16dec
8 #define be16enc libcperciva_be16enc
9 #define be32dec libcperciva_be32dec
10 #define be32enc libcperciva_be32enc
11 #define be64dec libcperciva_be64dec
12 #define be64enc libcperciva_be64enc
13 #define le16dec libcperciva_le16dec
14 #define le16enc libcperciva_le16enc
15 #define le32dec libcperciva_le32dec
16 #define le32enc libcperciva_le32enc
17 #define le64dec libcperciva_le64dec
18 #define le64enc libcperciva_le64enc
20 static inline uint16_t
21 be16dec(const void * pp
)
23 const uint8_t * p
= (uint8_t const *)pp
;
25 return (uint16_t)((uint16_t)(p
[1]) + ((uint16_t)(p
[0]) << 8));
29 be16enc(void * pp
, uint16_t x
)
31 uint8_t * p
= (uint8_t *)pp
;
34 p
[0] = (x
>> 8) & 0xff;
37 static inline uint32_t
38 be32dec(const void * pp
)
40 const uint8_t * p
= (uint8_t const *)pp
;
42 return ((uint32_t)(p
[3]) + ((uint32_t)(p
[2]) << 8) +
43 ((uint32_t)(p
[1]) << 16) + ((uint32_t)(p
[0]) << 24));
47 be32enc(void * pp
, uint32_t x
)
49 uint8_t * p
= (uint8_t *)pp
;
52 p
[2] = (x
>> 8) & 0xff;
53 p
[1] = (x
>> 16) & 0xff;
54 p
[0] = (x
>> 24) & 0xff;
57 static inline uint64_t
58 be64dec(const void * pp
)
60 const uint8_t * p
= (uint8_t const *)pp
;
62 return ((uint64_t)(p
[7]) + ((uint64_t)(p
[6]) << 8) +
63 ((uint64_t)(p
[5]) << 16) + ((uint64_t)(p
[4]) << 24) +
64 ((uint64_t)(p
[3]) << 32) + ((uint64_t)(p
[2]) << 40) +
65 ((uint64_t)(p
[1]) << 48) + ((uint64_t)(p
[0]) << 56));
69 be64enc(void * pp
, uint64_t x
)
71 uint8_t * p
= (uint8_t *)pp
;
74 p
[6] = (x
>> 8) & 0xff;
75 p
[5] = (x
>> 16) & 0xff;
76 p
[4] = (x
>> 24) & 0xff;
77 p
[3] = (x
>> 32) & 0xff;
78 p
[2] = (x
>> 40) & 0xff;
79 p
[1] = (x
>> 48) & 0xff;
80 p
[0] = (x
>> 56) & 0xff;
83 static inline uint16_t
84 le16dec(const void * pp
)
86 const uint8_t * p
= (uint8_t const *)pp
;
88 return (uint16_t)((uint16_t)(p
[0]) + ((uint16_t)(p
[1]) << 8));
92 le16enc(void * pp
, uint16_t x
)
94 uint8_t * p
= (uint8_t *)pp
;
97 p
[1] = (x
>> 8) & 0xff;
100 static inline uint32_t
101 le32dec(const void * pp
)
103 const uint8_t * p
= (uint8_t const *)pp
;
105 return ((uint32_t)(p
[0]) + ((uint32_t)(p
[1]) << 8) +
106 ((uint32_t)(p
[2]) << 16) + ((uint32_t)(p
[3]) << 24));
110 le32enc(void * pp
, uint32_t x
)
112 uint8_t * p
= (uint8_t *)pp
;
115 p
[1] = (x
>> 8) & 0xff;
116 p
[2] = (x
>> 16) & 0xff;
117 p
[3] = (x
>> 24) & 0xff;
120 static inline uint64_t
121 le64dec(const void * pp
)
123 const uint8_t * p
= (uint8_t const *)pp
;
125 return ((uint64_t)(p
[0]) + ((uint64_t)(p
[1]) << 8) +
126 ((uint64_t)(p
[2]) << 16) + ((uint64_t)(p
[3]) << 24) +
127 ((uint64_t)(p
[4]) << 32) + ((uint64_t)(p
[5]) << 40) +
128 ((uint64_t)(p
[6]) << 48) + ((uint64_t)(p
[7]) << 56));
132 le64enc(void * pp
, uint64_t x
)
134 uint8_t * p
= (uint8_t *)pp
;
137 p
[1] = (x
>> 8) & 0xff;
138 p
[2] = (x
>> 16) & 0xff;
139 p
[3] = (x
>> 24) & 0xff;
140 p
[4] = (x
>> 32) & 0xff;
141 p
[5] = (x
>> 40) & 0xff;
142 p
[6] = (x
>> 48) & 0xff;
143 p
[7] = (x
>> 56) & 0xff;
146 #endif /* !_SYSENDIAN_H_ */
This page took 0.027281 seconds and 5 git commands to generate.