Commit c648c9c
bpf, arm: Optimize ALU ARSH K using asr immediate instruction
This patch adds an optimization that uses the asr immediate instruction
for BPF_ALU BPF_ARSH BPF_K, rather than loading the immediate to
a temporary register. This is similar to existing code for handling
BPF_ALU BPF_{LSH,RSH} BPF_K. This optimization saves two instructions
and is more consistent with LSH and RSH.
Example of the code generated for BPF_ALU32_IMM(BPF_ARSH, BPF_REG_0, 5)
before the optimization:
2c: mov r8, #5
30: mov r9, #0
34: asr r0, r0, r8
and after optimization:
2c: asr r0, r0, #5
Tested on QEMU using lib/test_bpf and test_verifier.
Co-developed-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Signed-off-by: Luke Nelson <luke.r.nels@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200501020210.32294-3-luke.r.nels@gmail.com1 parent cf48db6 commit c648c9c
2 files changed
+10
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
795 | 795 | | |
796 | 796 | | |
797 | 797 | | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
798 | 801 | | |
799 | 802 | | |
800 | 803 | | |
| |||
1408 | 1411 | | |
1409 | 1412 | | |
1410 | 1413 | | |
1411 | | - | |
1412 | 1414 | | |
1413 | 1415 | | |
1414 | 1416 | | |
| |||
1465 | 1467 | | |
1466 | 1468 | | |
1467 | 1469 | | |
1468 | | - | |
1469 | 1470 | | |
1470 | | - | |
| 1471 | + | |
| 1472 | + | |
1471 | 1473 | | |
| 1474 | + | |
| 1475 | + | |
1472 | 1476 | | |
1473 | 1477 | | |
1474 | 1478 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
| |||
0 commit comments