dc26d51fff3b62169c820a6f4159d8098077fab6
2 * local version of endian.h - byte order defines
4 * Copyright 2007, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: bcmendian.h,v 1.1.1.11 2007/05/31 08:00:41 michael Exp $
20 /* Byte swap a 16 bit value */
21 #define BCMSWAP16(val) \
23 (((uint16)(val) & (uint16)0x00ffU) << 8) | \
24 (((uint16)(val) & (uint16)0xff00U) >> 8)))
26 /* Byte swap a 32 bit value */
27 #define BCMSWAP32(val) \
29 (((uint32)(val) & (uint32)0x000000ffUL) << 24) | \
30 (((uint32)(val) & (uint32)0x0000ff00UL) << 8) | \
31 (((uint32)(val) & (uint32)0x00ff0000UL) >> 8) | \
32 (((uint32)(val) & (uint32)0xff000000UL) >> 24)))
34 /* 2 Byte swap a 32 bit value */
35 #define BCMSWAP32BY16(val) \
37 (((uint32)(val) & (uint32)0x0000ffffUL) << 16) | \
38 (((uint32)(val) & (uint32)0xffff0000UL) >> 16)))
44 return BCMSWAP16(val
);
50 return BCMSWAP32(val
);
54 bcmswap32by16(uint32 val
)
56 return BCMSWAP32BY16(val
);
59 /* buf - start of buffer of shorts to swap */
60 /* len - byte length of buffer */
62 bcmswap16_buf(uint16
*buf
, uint len
)
67 *buf
= bcmswap16(*buf
);
74 #define HTON16(i) BCMSWAP16(i)
75 #define hton16(i) bcmswap16(i)
76 #define hton32(i) bcmswap32(i)
77 #define ntoh16(i) bcmswap16(i)
78 #define ntoh32(i) bcmswap32(i)
89 #define ltoh16(i) bcmswap16(i)
90 #define ltoh32(i) bcmswap32(i)
91 #define htol16(i) bcmswap16(i)
92 #define htol32(i) bcmswap32(i)
93 #endif /* IL_BIGENDIAN */
97 #define ltoh16_buf(buf, i)
98 #define htol16_buf(buf, i)
100 #define ltoh16_buf(buf, i) bcmswap16_buf((uint16*)buf, i)
101 #define htol16_buf(buf, i) bcmswap16_buf((uint16*)buf, i)
102 #endif /* IL_BIGENDIAN */
105 * store 16-bit value to unaligned little endian byte array.
108 htol16_ua_store(uint16 val
, uint8
*bytes
)
115 * store 32-bit value to unaligned little endian byte array.
118 htol32_ua_store(uint32 val
, uint8
*bytes
)
121 bytes
[1] = (val
>>8)&0xff;
122 bytes
[2] = (val
>>16)&0xff;
127 * store 16-bit value to unaligned network(big) endian byte array.
130 hton16_ua_store(uint16 val
, uint8
*bytes
)
137 * store 32-bit value to unaligned network(big) endian byte array.
140 hton32_ua_store(uint32 val
, uint8
*bytes
)
143 bytes
[2] = (val
>>8)&0xff;
144 bytes
[1] = (val
>>16)&0xff;
149 * load 16-bit value from unaligned little endian byte array.
152 ltoh16_ua(void *bytes
)
154 return (((uint8
*)bytes
)[1]<<8)+((uint8
*)bytes
)[0];
158 * load 32-bit value from unaligned little endian byte array.
161 ltoh32_ua(void *bytes
)
163 return (((uint8
*)bytes
)[3]<<24)+(((uint8
*)bytes
)[2]<<16)+
164 (((uint8
*)bytes
)[1]<<8)+((uint8
*)bytes
)[0];
168 * load 16-bit value from unaligned big(network) endian byte array.
171 ntoh16_ua(void *bytes
)
173 return (((uint8
*)bytes
)[0]<<8)+((uint8
*)bytes
)[1];
177 * load 32-bit value from unaligned big(network) endian byte array.
180 ntoh32_ua(void *bytes
)
182 return (((uint8
*)bytes
)[0]<<24)+(((uint8
*)bytes
)[1]<<16)+
183 (((uint8
*)bytes
)[2]<<8)+((uint8
*)bytes
)[3];
186 #define ltoh_ua(ptr) (\
187 sizeof(*(ptr)) == sizeof(uint8) ? *(uint8 *)ptr : \
188 sizeof(*(ptr)) == sizeof(uint16) ? (((uint8 *)ptr)[1]<<8)+((uint8 *)ptr)[0] : \
189 (((uint8 *)ptr)[3]<<24)+(((uint8 *)ptr)[2]<<16)+(((uint8 *)ptr)[1]<<8)+((uint8 *)ptr)[0] \
192 #define ntoh_ua(ptr) (\
193 sizeof(*(ptr)) == sizeof(uint8) ? *(uint8 *)ptr : \
194 sizeof(*(ptr)) == sizeof(uint16) ? (((uint8 *)ptr)[0]<<8)+((uint8 *)ptr)[1] : \
195 (((uint8 *)ptr)[0]<<24)+(((uint8 *)ptr)[1]<<16)+(((uint8 *)ptr)[2]<<8)+((uint8 *)ptr)[3] \
198 #endif /* _BCMENDIAN_H_ */
This page took 0.044544 seconds and 3 git commands to generate.