Add optimized version of the bswap macroes for constants if __OPTIMIZED__ is
defined.
This commit is contained in:
parent
d60ea0a816
commit
74e9b5ed3b
@ -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_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user