MINOR: tools: make my_htonll() more efficient on x86_64

The current construct was made when developing on a 32-bit machine.
Having a simple bswap operation replaced with 2 bswap, 2 shift and
2 or is quite of a waste of precious cycles... Let's provide a trivial
asm-based implementation for x86_64.
This commit is contained in:
Willy Tarreau 2017-09-20 08:18:49 +02:00
parent 2f1cacb1aa
commit 36eb3a3ac8
1 changed files with 5 additions and 0 deletions

View File

@ -1201,6 +1201,10 @@ static inline unsigned char utf8_return_length(unsigned char code)
*/
static inline unsigned long long my_htonll(unsigned long long a)
{
#if defined(__x86_64__)
__asm__ volatile("bswap %0" : "=r"(a));
return a;
#else
union {
struct {
unsigned int w1;
@ -1209,6 +1213,7 @@ static inline unsigned long long my_htonll(unsigned long long a)
unsigned long long by64;
} w = { .by64 = a };
return ((unsigned long long)htonl(w.by32.w1) << 32) | htonl(w.by32.w2);
#endif
}
/* Turns 64-bit value <a> from network byte order to host byte order. */