diff options
author | cognet <cognet@FreeBSD.org> | 2004-10-01 16:55:59 +0000 |
---|---|---|
committer | cognet <cognet@FreeBSD.org> | 2004-10-01 16:55:59 +0000 |
commit | d3c9c2ab1a405cf5971fb9dc8779f36a9035eec6 (patch) | |
tree | 5b0531dd054ba7cd1f2953c80e9f0451076de209 /sys/arm/include | |
parent | 898ea0c22612f50332855f8258214d5ab77a90be (diff) | |
download | FreeBSD-src-d3c9c2ab1a405cf5971fb9dc8779f36a9035eec6.zip FreeBSD-src-d3c9c2ab1a405cf5971fb9dc8779f36a9035eec6.tar.gz |
Add optimized version of the bswap macroes for constants if __OPTIMIZED__ is
defined.
Diffstat (limited to 'sys/arm/include')
-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 56d5d86..135392a 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_ */ |