| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: bswap.h,v 1.16 2009/08/08 21:23:15 christos Exp $ */ | | 1 | /* $NetBSD: bswap.h,v 1.17 2014/12/03 18:33:02 joerg Exp $ */ |
2 | | | 2 | |
3 | /* Written by Manuel Bouyer. Public domain */ | | 3 | /* Written by Manuel Bouyer. Public domain */ |
4 | | | 4 | |
5 | #ifndef _SYS_BSWAP_H_ | | 5 | #ifndef _SYS_BSWAP_H_ |
6 | #define _SYS_BSWAP_H_ | | 6 | #define _SYS_BSWAP_H_ |
7 | | | 7 | |
8 | #ifndef _LOCORE | | 8 | #ifndef _LOCORE |
9 | #include <sys/cdefs.h> | | 9 | #include <sys/cdefs.h> |
10 | #include <sys/types.h> | | 10 | #include <sys/types.h> |
11 | | | 11 | |
12 | #include <machine/bswap.h> | | 12 | #include <machine/bswap.h> |
13 | | | 13 | |
14 | __BEGIN_DECLS | | 14 | __BEGIN_DECLS |
| @@ -52,28 +52,28 @@ __END_DECLS | | | @@ -52,28 +52,28 @@ __END_DECLS |
52 | #define __byte_swap_u32_constant(x) \ | | 52 | #define __byte_swap_u32_constant(x) \ |
53 | (__CAST(uint32_t, \ | | 53 | (__CAST(uint32_t, \ |
54 | ((((x) & 0xff000000) >> 24) | \ | | 54 | ((((x) & 0xff000000) >> 24) | \ |
55 | (((x) & 0x00ff0000) >> 8) | \ | | 55 | (((x) & 0x00ff0000) >> 8) | \ |
56 | (((x) & 0x0000ff00) << 8) | \ | | 56 | (((x) & 0x0000ff00) << 8) | \ |
57 | (((x) & 0x000000ff) << 24)))) | | 57 | (((x) & 0x000000ff) << 24)))) |
58 | | | 58 | |
59 | #define __byte_swap_u16_constant(x) \ | | 59 | #define __byte_swap_u16_constant(x) \ |
60 | (__CAST(uint16_t, \ | | 60 | (__CAST(uint16_t, \ |
61 | ((((x) & 0xff00) >> 8) | \ | | 61 | ((((x) & 0xff00) >> 8) | \ |
62 | (((x) & 0x00ff) << 8)))) | | 62 | (((x) & 0x00ff) << 8)))) |
63 | | | 63 | |
64 | #define bswap64(x) \ | | 64 | #define bswap64(x) \ |
65 | (__builtin_constant_p((x)) ? \ | | 65 | __CAST(uint64_t, __builtin_constant_p((x)) ? \ |
66 | __byte_swap_u64_constant(x) : __BYTE_SWAP_U64_VARIABLE(x)) | | 66 | __byte_swap_u64_constant(x) : __BYTE_SWAP_U64_VARIABLE(x)) |
67 | | | 67 | |
68 | #define bswap32(x) \ | | 68 | #define bswap32(x) \ |
69 | (__builtin_constant_p((x)) ? \ | | 69 | __CAST(uint32_t, __builtin_constant_p((x)) ? \ |
70 | __byte_swap_u32_constant(x) : __BYTE_SWAP_U32_VARIABLE(x)) | | 70 | __byte_swap_u32_constant(x) : __BYTE_SWAP_U32_VARIABLE(x)) |
71 | | | 71 | |
72 | #define bswap16(x) \ | | 72 | #define bswap16(x) \ |
73 | (__builtin_constant_p((x)) ? \ | | 73 | __CAST(uint16_t, __builtin_constant_p((x)) ? \ |
74 | __byte_swap_u16_constant(x) : __BYTE_SWAP_U16_VARIABLE(x)) | | 74 | __byte_swap_u16_constant(x) : __BYTE_SWAP_U16_VARIABLE(x)) |
75 | | | 75 | |
76 | #endif /* __GNUC__ && __OPTIMIZE__ */ | | 76 | #endif /* __GNUC__ && __OPTIMIZE__ */ |
77 | #endif /* !_LOCORE */ | | 77 | #endif /* !_LOCORE */ |
78 | | | 78 | |
79 | #endif /* !_SYS_BSWAP_H_ */ | | 79 | #endif /* !_SYS_BSWAP_H_ */ |