]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: tools: make my_htonll() more efficient on x86_64
authorWilly Tarreau <w@1wt.eu>
Wed, 20 Sep 2017 06:18:49 +0000 (08:18 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 20 Sep 2017 09:27:31 +0000 (11:27 +0200)
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

index 74dc04129dd81a96a06b0eda83b0953e8a55f271..2645c44dd582efb013258537283fa7cbbffd66e9 100644 (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. */