diff options
author | Markos Chandras <markos.chandras@imgtec.com> | 2014-07-23 05:00:09 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2014-09-22 07:35:51 -0400 |
commit | 39bcb7969a84aab3dcdb857b261a87d5d888f5a7 (patch) | |
tree | a8b6a4f1e4fd765cc9c904c5b3baf53f50d8b65a /arch/mips/net | |
parent | 011eeece0bb2e1b65b2d2fd618067425e8ccdbb4 (diff) |
MIPS: BPF: Add new emit_long_instr macro
This macro uses the capitalized UASM_* macros to emit 32 or 64-bit
instructions depending on the kernel configurations. This allows
us to remove a few CONFIG_64BIT ifdefs from the code.
Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/7446/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
Diffstat (limited to 'arch/mips/net')
-rw-r--r-- | arch/mips/net/bpf_jit.c | 51 |
1 files changed, 19 insertions, 32 deletions
diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c index ae8cc8477389..b14e2148bee4 100644 --- a/arch/mips/net/bpf_jit.c +++ b/arch/mips/net/bpf_jit.c | |||
@@ -163,6 +163,19 @@ do { \ | |||
163 | (ctx)->idx++; \ | 163 | (ctx)->idx++; \ |
164 | } while (0) | 164 | } while (0) |
165 | 165 | ||
166 | /* | ||
167 | * Similar to emit_instr but it must be used when we need to emit | ||
168 | * 32-bit or 64-bit instructions | ||
169 | */ | ||
170 | #define emit_long_instr(ctx, func, ...) \ | ||
171 | do { \ | ||
172 | if ((ctx)->target != NULL) { \ | ||
173 | u32 *p = &(ctx)->target[ctx->idx]; \ | ||
174 | UASM_i_##func(&p, ##__VA_ARGS__); \ | ||
175 | } \ | ||
176 | (ctx)->idx++; \ | ||
177 | } while (0) | ||
178 | |||
166 | /* Determine if immediate is within the 16-bit signed range */ | 179 | /* Determine if immediate is within the 16-bit signed range */ |
167 | static inline bool is_range16(s32 imm) | 180 | static inline bool is_range16(s32 imm) |
168 | { | 181 | { |
@@ -218,13 +231,6 @@ static inline void emit_ori(unsigned int dst, unsigned src, u32 imm, | |||
218 | } | 231 | } |
219 | } | 232 | } |
220 | 233 | ||
221 | |||
222 | static inline void emit_daddu(unsigned int dst, unsigned int src1, | ||
223 | unsigned int src2, struct jit_ctx *ctx) | ||
224 | { | ||
225 | emit_instr(ctx, daddu, dst, src1, src2); | ||
226 | } | ||
227 | |||
228 | static inline void emit_daddiu(unsigned int dst, unsigned int src, | 234 | static inline void emit_daddiu(unsigned int dst, unsigned int src, |
229 | int imm, struct jit_ctx *ctx) | 235 | int imm, struct jit_ctx *ctx) |
230 | { | 236 | { |
@@ -283,11 +289,7 @@ static inline void emit_xori(ptr dst, ptr src, u32 imm, struct jit_ctx *ctx) | |||
283 | 289 | ||
284 | static inline void emit_stack_offset(int offset, struct jit_ctx *ctx) | 290 | static inline void emit_stack_offset(int offset, struct jit_ctx *ctx) |
285 | { | 291 | { |
286 | if (config_enabled(CONFIG_64BIT)) | 292 | emit_long_instr(ctx, ADDIU, r_sp, r_sp, offset); |
287 | emit_instr(ctx, daddiu, r_sp, r_sp, offset); | ||
288 | else | ||
289 | emit_instr(ctx, addiu, r_sp, r_sp, offset); | ||
290 | |||
291 | } | 293 | } |
292 | 294 | ||
293 | static inline void emit_subu(unsigned int dst, unsigned int src1, | 295 | static inline void emit_subu(unsigned int dst, unsigned int src1, |
@@ -365,10 +367,7 @@ static inline void emit_store_stack_reg(ptr reg, ptr base, | |||
365 | unsigned int offset, | 367 | unsigned int offset, |
366 | struct jit_ctx *ctx) | 368 | struct jit_ctx *ctx) |
367 | { | 369 | { |
368 | if (config_enabled(CONFIG_64BIT)) | 370 | emit_long_instr(ctx, SW, reg, offset, base); |
369 | emit_instr(ctx, sd, reg, offset, base); | ||
370 | else | ||
371 | emit_instr(ctx, sw, reg, offset, base); | ||
372 | } | 371 | } |
373 | 372 | ||
374 | static inline void emit_store(ptr reg, ptr base, unsigned int offset, | 373 | static inline void emit_store(ptr reg, ptr base, unsigned int offset, |
@@ -381,10 +380,7 @@ static inline void emit_load_stack_reg(ptr reg, ptr base, | |||
381 | unsigned int offset, | 380 | unsigned int offset, |
382 | struct jit_ctx *ctx) | 381 | struct jit_ctx *ctx) |
383 | { | 382 | { |
384 | if (config_enabled(CONFIG_64BIT)) | 383 | emit_long_instr(ctx, LW, reg, offset, base); |
385 | emit_instr(ctx, ld, reg, offset, base); | ||
386 | else | ||
387 | emit_instr(ctx, lw, reg, offset, base); | ||
388 | } | 384 | } |
389 | 385 | ||
390 | static inline void emit_load(unsigned int reg, unsigned int base, | 386 | static inline void emit_load(unsigned int reg, unsigned int base, |
@@ -458,10 +454,7 @@ static inline void emit_load_ptr(unsigned int dst, unsigned int src, | |||
458 | int imm, struct jit_ctx *ctx) | 454 | int imm, struct jit_ctx *ctx) |
459 | { | 455 | { |
460 | /* src contains the base addr of the 32/64-pointer */ | 456 | /* src contains the base addr of the 32/64-pointer */ |
461 | if (config_enabled(CONFIG_64BIT)) | 457 | emit_long_instr(ctx, LW, dst, imm, src); |
462 | emit_instr(ctx, ld, dst, imm, src); | ||
463 | else | ||
464 | emit_instr(ctx, lw, dst, imm, src); | ||
465 | } | 458 | } |
466 | 459 | ||
467 | /* load a function pointer to register */ | 460 | /* load a function pointer to register */ |
@@ -483,10 +476,7 @@ static inline void emit_load_func(unsigned int reg, ptr imm, | |||
483 | /* Move to real MIPS register */ | 476 | /* Move to real MIPS register */ |
484 | static inline void emit_reg_move(ptr dst, ptr src, struct jit_ctx *ctx) | 477 | static inline void emit_reg_move(ptr dst, ptr src, struct jit_ctx *ctx) |
485 | { | 478 | { |
486 | if (config_enabled(CONFIG_64BIT)) | 479 | emit_long_instr(ctx, ADDU, dst, src, r_zero); |
487 | emit_daddu(dst, src, r_zero, ctx); | ||
488 | else | ||
489 | emit_addu(dst, src, r_zero, ctx); | ||
490 | } | 480 | } |
491 | 481 | ||
492 | /* Move to JIT (32-bit) register */ | 482 | /* Move to JIT (32-bit) register */ |
@@ -623,10 +613,7 @@ static void save_bpf_jit_regs(struct jit_ctx *ctx, unsigned offset) | |||
623 | if (ctx->flags & SEEN_MEM) { | 613 | if (ctx->flags & SEEN_MEM) { |
624 | if (real_off % (RSIZE * 2)) | 614 | if (real_off % (RSIZE * 2)) |
625 | real_off += RSIZE; | 615 | real_off += RSIZE; |
626 | if (config_enabled(CONFIG_64BIT)) | 616 | emit_long_instr(ctx, ADDIU, r_M, r_sp, real_off); |
627 | emit_daddiu(r_M, r_sp, real_off, ctx); | ||
628 | else | ||
629 | emit_addiu(r_M, r_sp, real_off, ctx); | ||
630 | } | 617 | } |
631 | } | 618 | } |
632 | 619 | ||