PPC: bpf_jit_comp: Unify BPF_MOD | BPF_X and BPF_DIV | BPF_X
Subsystems (5)
PATCH 1/1 PPC: bpf_jit_comp: Unify BPF_MOD | BPF_X and BPF_DIV | BPF_X
Reduce duplicated code by unifyingBPF_ALU | BPF_MOD | BPF_X and BPF_ALU | BPF_DIV | BPF_X
--- arch/powerpc/net/bpf_jit_comp.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-)
arch/powerpc/net/bpf_jit_comp.c +8 -19
@@ -181,6 +181,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image, }break ;case BPF_ALU |BPF_MOD |BPF_X :/* A %= X; */ +case BPF_ALU |BPF_DIV |BPF_X :/* A /= X; */ ctx->seen |=SEEN_XREG ;PPC_CMPWI (r_X,0 );if (ctx->pc_ret0 !=-1 ) {
@@ -190,9 +191,13 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,PPC_LI (r_ret,0 );PPC_JMP (exit_addr); } -PPC_DIVWU (r_scratch1, r_A, r_X); -PPC_MUL (r_scratch1, r_X, r_scratch1); -PPC_SUB (r_A, r_A, r_scratch1); +if (code == (BPF_ALU |BPF_MOD |BPF_X )) { +PPC_DIVWU (r_scratch1, r_A, r_X); +PPC_MUL (r_scratch1, r_X, r_scratch1); +PPC_SUB (r_A, r_A, r_scratch1); + }else { +PPC_DIVWU (r_A, r_A, r_X); + }break ;case BPF_ALU |BPF_MOD |BPF_K :/* A %= K; */ PPC_LI32 (r_scratch2,K );
@@ -200,22 +205,6 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,PPC_MUL (r_scratch1, r_scratch2, r_scratch1);PPC_SUB (r_A, r_A, r_scratch1);break ; -case BPF_ALU |BPF_DIV |BPF_X :/* A /= X; */ - ctx->seen |=SEEN_XREG ; -PPC_CMPWI (r_X,0 ); -if (ctx->pc_ret0 !=-1 ) { -PPC_BCC (COND_EQ , addrs[ctx->pc_ret0]); - }else { -/* -* Exit, returning 0; first pass hits here -* (longer worst-case code size). -*/ -PPC_BCC_SHORT (COND_NE , (ctx->idx*4 )+12 ); -PPC_LI (r_ret,0 ); -PPC_JMP (exit_addr); - } -PPC_DIVWU (r_A, r_A, r_X); -break ;case BPF_ALU |BPF_DIV |BPF_K :/* A /= K */ if (K ==1 )break ;
Signature · 1 line
2.1.0
Michael Ellerman
reviewerQuoted 7 lines · Denis Kirjanov
Reduce duplicated code by unifying
BPF_ALU|BPF_MOD|BPF_XandBPF_ALU|BPF_DIV|BPF_XCC Alexei Starovoitov<[email protected]>CC Daniel Borkmann<[email protected]>CC Philippe Bergheaud<[email protected]>Signed-off-by Denis Kirjanov <[email protected]>
Please include the output of the test suite.
Assuming that's OK I'm happy for it to go in.
cheers
Hi Michael,
This patch added no new functionality so I haven't put the test results (of course I ran the test suite to check the patch).
The output :
[ 650.198958] test_bpf: Summary: 60 PASSED, 0 FAILED
Quoted 18 lines · Michael Ellerman
Quoted 7 lines · Denis Kirjanov
Reduce duplicated code by unifying
BPF_ALU|BPF_MOD|BPF_XandBPF_ALU|BPF_DIV|BPF_XCC Alexei Starovoitov<[email protected]>CC Daniel Borkmann<[email protected]>CC Philippe Bergheaud<[email protected]>Signed-off-by Denis Kirjanov <[email protected]>Please include the output of the test suite.
Assuming that's OK I'm happy for it to go in.
cheers
Alexei Starovoitov
Acked-byQuoted 7 lines · Denis Kirjanov
Hi Michael,
This patch added no new functionality so I haven't put the test results (of course I ran the test suite to check the patch).
The output :
[ 650.198958] test_bpf: Summary: 60 PASSED, 0 FAILED
btw, please don't top post.
From: Alexei Starovoitov <[email protected]>
Date: Tue, 18 Nov 2014 07:37:21 -0800
Quoted 10 lines · Denis Kirjanov
Quoted 7 lines
Hi Michael,
This patch added no new functionality so I haven't put the test results (of course I ran the test suite to check the patch).
The output :
[ 650.198958] test_bpf: Summary: 60 PASSED, 0 FAILED
Applied, thanks everyone.
Quoted 1 line
btw, please don't top post.
Seriously, it's my biggest pet peeve. It's like going to a dinner party and eating with your feet.