diff options
author | Eric Dumazet <edumazet@google.com> | 2012-09-10 16:48:33 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-09-10 17:08:48 -0400 |
commit | 280050cc81ccb2e06e4061228ee34c0cc86b1560 (patch) | |
tree | 37c47086c4b1eb4b0ab6a471243274f61d7bcb8f /arch/x86 | |
parent | 26964bb72afd0310c17750c002eebbf022db3b19 (diff) |
x86 bpf_jit: support MOD operation
commit b6069a9570 (filter: add MOD operation) added generic
support for modulus operation in BPF.
This patch brings JIT support for x86_64
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: George Bakos <gbakos@alpinista.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/x86')
-rw-r--r-- | arch/x86/net/bpf_jit_comp.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 33643a8bcbbb..106c57829120 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c | |||
@@ -280,6 +280,31 @@ void bpf_jit_compile(struct sk_filter *fp) | |||
280 | } | 280 | } |
281 | EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */ | 281 | EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */ |
282 | break; | 282 | break; |
283 | case BPF_S_ALU_MOD_X: /* A %= X; */ | ||
284 | seen |= SEEN_XREG; | ||
285 | EMIT2(0x85, 0xdb); /* test %ebx,%ebx */ | ||
286 | if (pc_ret0 > 0) { | ||
287 | /* addrs[pc_ret0 - 1] is start address of target | ||
288 | * (addrs[i] - 6) is the address following this jmp | ||
289 | * ("xor %edx,%edx; div %ebx;mov %edx,%eax" being 6 bytes long) | ||
290 | */ | ||
291 | EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] - | ||
292 | (addrs[i] - 6)); | ||
293 | } else { | ||
294 | EMIT_COND_JMP(X86_JNE, 2 + 5); | ||
295 | CLEAR_A(); | ||
296 | EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 6)); /* jmp .+off32 */ | ||
297 | } | ||
298 | EMIT2(0x31, 0xd2); /* xor %edx,%edx */ | ||
299 | EMIT2(0xf7, 0xf3); /* div %ebx */ | ||
300 | EMIT2(0x89, 0xd0); /* mov %edx,%eax */ | ||
301 | break; | ||
302 | case BPF_S_ALU_MOD_K: /* A %= K; */ | ||
303 | EMIT2(0x31, 0xd2); /* xor %edx,%edx */ | ||
304 | EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */ | ||
305 | EMIT2(0xf7, 0xf1); /* div %ecx */ | ||
306 | EMIT2(0x89, 0xd0); /* mov %edx,%eax */ | ||
307 | break; | ||
283 | case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */ | 308 | case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */ |
284 | EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */ | 309 | EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */ |
285 | EMIT(K, 4); | 310 | EMIT(K, 4); |