[PATCH] arm: bpf_jit: support MOD operation

Subsystems: arm port, bpf jit for arm, bpf [general] (safe dynamic programs and tools), the rest

STALE4716d

2 messages, 1 author, 2013-09-02 · open the first message on its own page

[PATCH] arm: bpf_jit: support MOD operation

From: Vladimir Murzin <hidden>
Date: 2013-08-27 22:52:32

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 <redacted>
---
 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

[PATCH] arm: bpf_jit: support MOD operation

From: Vladimir Murzin <hidden>
Date: 2013-09-02 17:49:32

Ping

On Wed, Aug 28, 2013 at 02:52:32AM +0400, Vladimir Murzin wrote:
quoted hunk
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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help