Microoptimization to allow the compiler to evaluate ntohl() etc on

known constants at compile time rather than at run time.  We have a number
of nasty hacks around the place to cache ntohl() of constants (eg: nfs).
This change allows the compiler to compile-time evaluate ntohl(1) as
0x01000000 rather than having to emit assembler code to do it.  This
has other smaller flow-on effects because the compiler can see that
ntohl(constant) itself has a constant value now and can propagate the
compile time evaluation.

Obtained from:  Ideas from NetBSD and Linux, and some code from NetBSD
This commit is contained in:
peter 2003-09-22 21:46:47 +00:00
parent b4cfe6d4c8
commit 9cd1883cc6

View File

@ -69,31 +69,76 @@
#ifdef __GNUC__
#define __word_swap_int(x) \
#define __word_swap_int_var(x) \
__extension__ ({ register __uint32_t __X = (x); \
__asm ("rorl $16, %0" : "+r" (__X)); \
__X; })
#ifdef __OPTIMIZE__
#define __word_swap_int_const(x) \
((((x) & 0xffff0000) >> 16) | \
(((x) & 0x0000ffff) << 16))
#define __word_swap_int(x) (__builtin_constant_p(x) ? \
__word_swap_int_const(x) : __word_swap_int_var(x))
#else /* __OPTIMIZE__ */
#define __word_swap_int(x) __word_swap_int_var(x)
#endif /* __OPTIMIZE__ */
#if defined(_KERNEL) && (defined(I486_CPU) || defined(I586_CPU) || defined(I686_CPU)) && !defined(I386_CPU)
#define __byte_swap_int(x) \
#define __byte_swap_int_var(x) \
__extension__ ({ register __uint32_t __X = (x); \
__asm ("bswap %0" : "+r" (__X)); \
__X; })
#else
#define __byte_swap_int(x) \
#define __byte_swap_int_var(x) \
__extension__ ({ register __uint32_t __X = (x); \
__asm ("xchgb %h0, %b0\n\trorl $16, %0\n\txchgb %h0, %b0" \
: "+q" (__X)); \
__X; })
#endif
#define __byte_swap_word(x) \
#ifdef __OPTIMIZE__
#define __byte_swap_int_const(x) \
((((x) & 0xff000000) >> 24) | \
(((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | \
(((x) & 0x000000ff) << 24))
#define __byte_swap_int(x) (__builtin_constant_p(x) ? \
__byte_swap_int_const(x) : __byte_swap_int_var(x))
#else /* __OPTIMIZE__ */
#define __byte_swap_int(x) __byte_swap_int_var(x)
#endif /* __OPTIMIZE__ */
#define __byte_swap_word_var(x) \
__extension__ ({ register __uint16_t __X = (x); \
__asm ("xchgb %h0, %b0" : "+q" (__X)); \
__X; })
#ifdef __OPTIMIZE__
#define __byte_swap_word_const(x) \
((((x) & 0xff00) >> 8) | \
(((x) & 0x00ff) << 8))
#define __byte_swap_word(x) (__builtin_constant_p(x) ? \
__byte_swap_word_const(x) : __byte_swap_word_var(x))
#else /* __OPTIMIZE__ */
#define __byte_swap_word(x) __byte_swap_word_var(x)
#endif /* __OPTIMIZE__ */
static __inline __uint64_t
__bswap64(__uint64_t _x)
{