diff options
| author | Daniel Borkmann <daniel@iogearbox.net> | 2026-10-13 19:12:21 +0200 |
|---|---|---|
| committer | Kumar Kartikeya Dwivedi <memxor@gmail.com> | 2026-10-15 02:40:09 +0200 |
| commit | 0847f6cb2e6aec22e5a7bf4e3000e9a080bf9878 (patch) | |
| tree | 3e982004d39d1ee2f94d2b2786102e6777b05e17 /scripts/Makefile.thinlto | |
| parent | d59f47e031aecdb6d8e03d4d4d8880613339f086 (diff) | |
bpf, x86: Swap 16-bit values with bswap and shr, not ror and movzx
The 16-bit byte swap was emitted as a 16-bit rotate followed by a zero
extending move. bswap of the 32-bit register followed by a right shift
by 16 has the same result, is two bytes shorter, and avoids the operand
size prefix and the 16-bit partial register write. Both sequences are
two single cycle uops on Intel and AMD. LLVM emits be16 for bpf_htons()
and bpf_ntohs() with cpu v3 and bswap16 with cpu v4, both of which
take this path.
Before, for r1 = be16 r1:
66 c1 cf 08 rorw $0x8,%di
0f b7 ff movzwl %di,%edi
After:
0f cf bswap %edi
c1 ef 10 shrl $0x10,%edi
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20261013171230.523677-10-daniel@iogearbox.net
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Diffstat (limited to 'scripts/Makefile.thinlto')
0 files changed, 0 insertions, 0 deletions
