]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: standard: provide htonll() and ntohll()
authorWilly Tarreau <w@1wt.eu>
Tue, 21 Jul 2015 21:47:18 +0000 (23:47 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 21 Jul 2015 21:50:06 +0000 (23:50 +0200)
commit5b4dd683cbeb04729193f1409ac0d86947f1d165
tree0097d640b54584b7255c68963604c80c85c88b57
parent763a5d85f7226c22abda17f3b8cdf2ae2edc4f77
MINOR: standard: provide htonll() and ntohll()

These are the 64-bit equivalent of htonl() and ntohl(). They're a bit
tricky in order to avoid expensive operations.

The principle consists in letting the compiler detect we're playing
with a union and simplify most or all operations. The asm-optimized
htonl() version involving bswap (x86) / rev (arm) / other is a single
operation on little endian, or a NOP on big-endian. In both cases,
this lets the compiler "see" that we're rebuilding a 64-bit word from
two 32-bit quantities that fit into a 32-bit register. In big endian,
the whole code is optimized out. In little endian, with a decent compiler,
a few bswap and 2 shifts are left, which is the minimum acceptable.
include/common/standard.h