diff options
author | Olivier Houchard <cognet@FreeBSD.org> | 2004-10-01 16:55:59 +0000 |
---|---|---|
committer | Olivier Houchard <cognet@FreeBSD.org> | 2004-10-01 16:55:59 +0000 |
commit | 74e9b5ed3b6c99d879eacafdd1e5ab8d887b5dc8 (patch) | |
tree | 5b0531dd054ba7cd1f2953c80e9f0451076de209 /sys/arm/include/endian.h | |
parent | d60ea0a81630e86773bdeaf24a5ff9a56853b57c (diff) |
Add optimized version of the bswap macroes for constants if __OPTIMIZED__ is
defined.
Notes
Notes:
svn path=/head/; revision=136033
Diffstat (limited to 'sys/arm/include/endian.h')
-rw-r--r-- | sys/arm/include/endian.h | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/sys/arm/include/endian.h b/sys/arm/include/endian.h index 56d5d868db36..135392acac21 100644 --- a/sys/arm/include/endian.h +++ b/sys/arm/include/endian.h @@ -70,7 +70,7 @@ __bswap64(__uint64_t _x) } static __inline __uint32_t -__bswap32(__uint32_t v) +__bswap32_var(__uint32_t v) { __uint32_t t1; @@ -83,7 +83,7 @@ __bswap32(__uint32_t v) } static __inline __uint16_t -__bswap16(__uint32_t v) +__bswap16_var(__uint32_t v) { __asm __volatile( "mov %0, %1, ror #8\n" @@ -94,4 +94,32 @@ __bswap16(__uint32_t v) return (v); } + +#ifdef __OPTIMIZE__ + +#define __bswap32_constant(x) \ + ((((x) & 0xff000000U) >> 24) | \ + (((x) & 0x00ff0000U) >> 8) | \ + (((x) & 0x0000ff00U) << 8) | \ + (((x) & 0x000000ffU) << 24)) + +#define __bswap16_constant(x) \ + ((((x) & 0xff00) >> 8) | \ + (((x) & 0x00ff) << 8)) + +#define __bswap16(x) \ + (__builtin_constant_p(x) ? \ + __bswap16_constant(x) : \ + __bswap16_var(x)) + +#define __bswap32(x) \ + (__builtin_constant_p(x) ? \ + __bswap32_constant(x) : \ + __bswap32_var(x)) + +#else +#define __bswap16(x) __bswap16_var(x) +#define __bswap32(x) __bswap32_var(x) + +#endif /* __OPTIMIZE__ */ #endif /* !_ENDIAN_H_ */ |