]> asedeno.scripts.mit.edu Git - linux.git/commit
nfp: bpf: optimize add/sub of a negative constant
authorJakub Kicinski <jakub.kicinski@netronome.com>
Wed, 25 Apr 2018 04:22:37 +0000 (21:22 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 25 Apr 2018 07:56:10 +0000 (09:56 +0200)
commit6c59500c2dbfae0e3c90854ef443948d2889495d
tree0ad0b3cf7ace13bc02338e6408b4bd45013f5b86
parent9c9e53233c281ed6c00425b165c4dd7fd0881cd5
nfp: bpf: optimize add/sub of a negative constant

NFP instruction set can fit small immediates into the instruction.
Negative integers, however, will never fit because they will have
highest bit set.  If we swap the ALU op between ADD and SUB and
negate the constant we have a better chance of fitting small negative
integers into the instruction itself and saving one or two cycles.

immed[gprB_21, 0xfffffffc]
alu[gprA_4, gprA_4, +, gprB_21], gpr_wrboth
immed[gprB_21, 0xffffffff]
alu[gprA_5, gprA_5, +carry, gprB_21], gpr_wrboth

now becomes:

alu[gprA_4, gprA_4, -, 4], gpr_wrboth
alu[gprA_5, gprA_5, -carry, 0], gpr_wrboth

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
drivers/net/ethernet/netronome/nfp/bpf/jit.c