4 /* COM32 will be running on an i386 platform */
7 #include <klibc/compiler.h>
9 #define __bswap_16_macro(v) ((uint16_t) \
10 (((uint16_t)(v) << 8) | \
11 ((uint16_t)(v) >> 8)))
13 static inline __constfunc
uint16_t __bswap_16(uint16_t v
)
15 return __bswap_16_macro(v
);
18 #define bswap_16(x) (__builtin_constant_p(x) ? \
19 __bswap_16_macro(x) : __bswap_16(x))
21 #define __bswap_32_macro(v) ((uint32_t) \
22 ((((uint32_t)(v) & 0x000000ff) << 24) | \
23 (((uint32_t)(v) & 0x0000ff00) << 8) | \
24 (((uint32_t)(v) & 0x00ff0000) >> 8) | \
25 (((uint32_t)(v) & 0xff000000) >> 24)))
27 static inline __constfunc
uint32_t __bswap_32(uint32_t v
)
29 #if __SIZEOF_POINTER__ == 4
30 asm("xchgb %h0,%b0 ; roll $16,%0 ; xchgb %h0,%b0"
32 #elif __SIZEOF_POINTER__ == 8
37 #error "unable to build for architecture"
42 #define bswap_32(x) (__builtin_constant_p(x) ? \
43 __bswap_32_macro(x) : __bswap_32(x))
46 #define __bswap_64_macro(v) ((uint64_t) \
47 (((uint64_t)__bswap_32_macro((uint32_t)(v)) << 32) | \
48 (__bswap_32_macro((uint32_t)((uint64_t)(v) >> 32)))))
50 static inline __constfunc
uint64_t __bswap_64(uint64_t v
)
52 return ((uint64_t)__bswap_32(v
) << 32) | __bswap_32(v
>> 32);
55 #define bswap_64(x) (__builtin_constant_p(x) ? \
56 __bswap_64_macro(x) : __bswap_64(x))
58 #endif /* byteswap.h */