From 36eb3a3ac83793748e9e5b644a848e6fa23c84cb Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 20 Sep 2017 08:18:49 +0200 Subject: [PATCH] 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. --- include/common/standard.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/common/standard.h b/include/common/standard.h index 74dc04129d..2645c44dd5 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -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 from network byte order to host byte order. */ -- 2.39.5