Skip to content

Commit cef1e8c

Browse files
rnavmpe
authored andcommitted
powerpc/bpf/jit: A few cleanups
1. Per the ISA, ADDIS actually uses RT, rather than RS. Though the result is the same, make the usage clear. 2. The multiply instruction used is a 32-bit multiply. Rename PPC_MUL() to PPC_MULW() to make the same clear. 3. PPC_STW[U] take the entire 16-bit immediate value and do not require word-alignment, per the ISA. Change the macros to use IMM_L(). 4. A few white-space cleanups to satisfy checkpatch.pl. Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: Naveen N. Rao <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent 277285b commit cef1e8c

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

arch/powerpc/net/bpf_jit.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
8383
*/
8484
#define IMM_H(i) ((uintptr_t)(i)>>16)
8585
#define IMM_HA(i) (((uintptr_t)(i)>>16) + \
86-
(((uintptr_t)(i) & 0x8000) >> 15))
86+
(((uintptr_t)(i) & 0x8000) >> 15))
8787
#define IMM_L(i) ((uintptr_t)(i) & 0xffff)
8888

8989
#define PLANT_INSTR(d, idx, instr) \
@@ -99,16 +99,16 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
9999
#define PPC_MR(d, a) PPC_OR(d, a, a)
100100
#define PPC_LI(r, i) PPC_ADDI(r, 0, i)
101101
#define PPC_ADDIS(d, a, i) EMIT(PPC_INST_ADDIS | \
102-
___PPC_RS(d) | ___PPC_RA(a) | IMM_L(i))
102+
___PPC_RT(d) | ___PPC_RA(a) | IMM_L(i))
103103
#define PPC_LIS(r, i) PPC_ADDIS(r, 0, i)
104104
#define PPC_STD(r, base, i) EMIT(PPC_INST_STD | ___PPC_RS(r) | \
105105
___PPC_RA(base) | ((i) & 0xfffc))
106106
#define PPC_STDU(r, base, i) EMIT(PPC_INST_STDU | ___PPC_RS(r) | \
107107
___PPC_RA(base) | ((i) & 0xfffc))
108108
#define PPC_STW(r, base, i) EMIT(PPC_INST_STW | ___PPC_RS(r) | \
109-
___PPC_RA(base) | ((i) & 0xfffc))
109+
___PPC_RA(base) | IMM_L(i))
110110
#define PPC_STWU(r, base, i) EMIT(PPC_INST_STWU | ___PPC_RS(r) | \
111-
___PPC_RA(base) | ((i) & 0xfffc))
111+
___PPC_RA(base) | IMM_L(i))
112112

113113
#define PPC_LBZ(r, base, i) EMIT(PPC_INST_LBZ | ___PPC_RT(r) | \
114114
___PPC_RA(base) | IMM_L(i))
@@ -174,13 +174,14 @@ DECLARE_LOAD_FUNC(sk_load_byte_msh);
174174
#define PPC_CMPWI(a, i) EMIT(PPC_INST_CMPWI | ___PPC_RA(a) | IMM_L(i))
175175
#define PPC_CMPDI(a, i) EMIT(PPC_INST_CMPDI | ___PPC_RA(a) | IMM_L(i))
176176
#define PPC_CMPLWI(a, i) EMIT(PPC_INST_CMPLWI | ___PPC_RA(a) | IMM_L(i))
177-
#define PPC_CMPLW(a, b) EMIT(PPC_INST_CMPLW | ___PPC_RA(a) | ___PPC_RB(b))
177+
#define PPC_CMPLW(a, b) EMIT(PPC_INST_CMPLW | ___PPC_RA(a) | \
178+
___PPC_RB(b))
178179

179180
#define PPC_SUB(d, a, b) EMIT(PPC_INST_SUB | ___PPC_RT(d) | \
180181
___PPC_RB(a) | ___PPC_RA(b))
181182
#define PPC_ADD(d, a, b) EMIT(PPC_INST_ADD | ___PPC_RT(d) | \
182183
___PPC_RA(a) | ___PPC_RB(b))
183-
#define PPC_MUL(d, a, b) EMIT(PPC_INST_MULLW | ___PPC_RT(d) | \
184+
#define PPC_MULW(d, a, b) EMIT(PPC_INST_MULLW | ___PPC_RT(d) | \
184185
___PPC_RA(a) | ___PPC_RB(b))
185186
#define PPC_MULHWU(d, a, b) EMIT(PPC_INST_MULHWU | ___PPC_RT(d) | \
186187
___PPC_RA(a) | ___PPC_RB(b))

arch/powerpc/net/bpf_jit_comp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,14 +161,14 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
161161
break;
162162
case BPF_ALU | BPF_MUL | BPF_X: /* A *= X; */
163163
ctx->seen |= SEEN_XREG;
164-
PPC_MUL(r_A, r_A, r_X);
164+
PPC_MULW(r_A, r_A, r_X);
165165
break;
166166
case BPF_ALU | BPF_MUL | BPF_K: /* A *= K */
167167
if (K < 32768)
168168
PPC_MULI(r_A, r_A, K);
169169
else {
170170
PPC_LI32(r_scratch1, K);
171-
PPC_MUL(r_A, r_A, r_scratch1);
171+
PPC_MULW(r_A, r_A, r_scratch1);
172172
}
173173
break;
174174
case BPF_ALU | BPF_MOD | BPF_X: /* A %= X; */
@@ -184,7 +184,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
184184
}
185185
if (code == (BPF_ALU | BPF_MOD | BPF_X)) {
186186
PPC_DIVWU(r_scratch1, r_A, r_X);
187-
PPC_MUL(r_scratch1, r_X, r_scratch1);
187+
PPC_MULW(r_scratch1, r_X, r_scratch1);
188188
PPC_SUB(r_A, r_A, r_scratch1);
189189
} else {
190190
PPC_DIVWU(r_A, r_A, r_X);
@@ -193,7 +193,7 @@ static int bpf_jit_build_body(struct bpf_prog *fp, u32 *image,
193193
case BPF_ALU | BPF_MOD | BPF_K: /* A %= K; */
194194
PPC_LI32(r_scratch2, K);
195195
PPC_DIVWU(r_scratch1, r_A, r_scratch2);
196-
PPC_MUL(r_scratch1, r_scratch2, r_scratch1);
196+
PPC_MULW(r_scratch1, r_scratch2, r_scratch1);
197197
PPC_SUB(r_A, r_A, r_scratch1);
198198
break;
199199
case BPF_ALU | BPF_DIV | BPF_K: /* A /= K */

0 commit comments

Comments
 (0)