public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] arm: bpf_jit: support MOD operation
@ 2013-08-27 22:52 Vladimir Murzin
  2013-09-02 17:49 ` Vladimir Murzin
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Murzin @ 2013-08-27 22:52 UTC (permalink / raw)
  To: linux-arm-kernel

commit b6069a9570 (filter: add MOD operation) added generic
support for modulus operation in BPF.

This patch brings JIT support for ARM.

Signed-off-by: Vladimir Murzin <murzin.v@gmail.com>
---
 arch/arm/net/bpf_jit_32.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
index f50d223..0bfff55 100644
--- a/arch/arm/net/bpf_jit_32.c
+++ b/arch/arm/net/bpf_jit_32.c
@@ -636,6 +636,24 @@ load_ind:
 			update_on_xread(ctx);
 			emit(ARM_MUL(r_A, r_A, r_X), ctx);
 			break;
+		case BPF_S_ALU_MOD_X: /* A %= X; */
+			update_on_xread(ctx);
+			emit(ARM_CMP_I(r_X, 0), ctx);
+			emit_err_ret(ARM_COND_EQ, ctx);
+			emit_udiv(r_scratch, r_A, r_X, ctx);
+			emit(ARM_MUL(r_scratch, r_X, r_scratch), ctx);
+			emit(ARM_SUB_R(r_A, r_A, r_scratch), ctx);
+			break;
+		case BPF_S_ALU_MOD_K: /* A %= K; */
+			/*
+			 * reuse ARM_R1 as the temp register - it should be safe
+			 * as soon as udiv may touch it too.
+			 */
+			emit_mov_i(ARM_R1, k, ctx);
+			emit_udiv(r_scratch, r_A, ARM_R1, ctx);
+			emit(ARM_MUL(r_scratch, ARM_R1, r_scratch), ctx);
+			emit(ARM_SUB_R(r_A, r_A, r_scratch), ctx);
+			break;
 		case BPF_S_ALU_DIV_K:
 			/* current k == reciprocal_value(userspace k) */
 			emit_mov_i(r_scratch, k, ctx);
-- 
1.8.1.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-09-02 17:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-27 22:52 [PATCH] arm: bpf_jit: support MOD operation Vladimir Murzin
2013-09-02 17:49 ` Vladimir Murzin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox