Skip to content

Commit

Permalink
bpf, x64: save one byte per shl/shr/sar when imm is 1
Browse files Browse the repository at this point in the history
When we shift by one, we can use a different encoding where imm
is not explicitly needed, which saves 1 byte per such op.

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
  • Loading branch information
borkmann authored and Alexei Starovoitov committed Feb 24, 2018
1 parent ee07862 commit 88e69a1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion arch/x86/net/bpf_jit_comp.c
Expand Up @@ -640,7 +640,11 @@ static int do_jit(struct bpf_prog *bpf_prog, int *addrs, u8 *image,
case BPF_RSH: b3 = 0xE8; break;
case BPF_ARSH: b3 = 0xF8; break;
}
EMIT3(0xC1, add_1reg(b3, dst_reg), imm32);

if (imm32 == 1)
EMIT2(0xD1, add_1reg(b3, dst_reg));
else
EMIT3(0xC1, add_1reg(b3, dst_reg), imm32);
break;

case BPF_ALU | BPF_LSH | BPF_X:
Expand Down

0 comments on commit 88e69a1

Please sign in to comment.