diff options
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 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_ */ |