Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: ak@linux.intel.com, gbakos@alpinista.org, netdev@vger.kernel.org
Subject: [PATCH net-next] x86 bpf_jit: support MOD operation
Date: Mon, 10 Sep 2012 22:48:33 +0200	[thread overview]
Message-ID: <1347310113.13103.8.camel@edumazet-glaptop> (raw)
In-Reply-To: <20120910.154537.639794042526369471.davem@davemloft.net>

From: Eric Dumazet <edumazet@google.com>

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>
---
 arch/x86/net/bpf_jit_comp.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 33643a8..106c578 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)
 				}
 				EMIT4(0x31, 0xd2, 0xf7, 0xf3); /* xor %edx,%edx; div %ebx */
 				break;
+			case BPF_S_ALU_MOD_X: /* A %= X; */
+				seen |= SEEN_XREG;
+				EMIT2(0x85, 0xdb);	/* test %ebx,%ebx */
+				if (pc_ret0 > 0) {
+					/* addrs[pc_ret0 - 1] is start address of target
+					 * (addrs[i] - 6) is the address following this jmp
+					 * ("xor %edx,%edx; div %ebx;mov %edx,%eax" being 6 bytes long)
+					 */
+					EMIT_COND_JMP(X86_JE, addrs[pc_ret0 - 1] -
+								(addrs[i] - 6));
+				} else {
+					EMIT_COND_JMP(X86_JNE, 2 + 5);
+					CLEAR_A();
+					EMIT1_off32(0xe9, cleanup_addr - (addrs[i] - 6)); /* jmp .+off32 */
+				}
+				EMIT2(0x31, 0xd2);	/* xor %edx,%edx */
+				EMIT2(0xf7, 0xf3);	/* div %ebx */
+				EMIT2(0x89, 0xd0);	/* mov %edx,%eax */
+				break;
+			case BPF_S_ALU_MOD_K: /* A %= K; */
+				EMIT2(0x31, 0xd2);	/* xor %edx,%edx */
+				EMIT1(0xb9);EMIT(K, 4);	/* mov imm32,%ecx */
+				EMIT2(0xf7, 0xf1);	/* div %ecx */
+				EMIT2(0x89, 0xd0);	/* mov %edx,%eax */
+				break;
 			case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
 				EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
 				EMIT(K, 4);

  reply	other threads:[~2012-09-10 20:48 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20120905213941.03c85968@arrowsmith>
     [not found] ` <C71A36A8-08D2-4D3D-AF2B-EF89FEECE1A6@alum.mit.edu>
     [not found]   ` <20120906073615.693d14e0@arrowsmith>
     [not found]     ` <46AB14E3-73F4-41FA-8086-F1D663AF4549@alum.mit.edu>
     [not found]       ` <20120907074910.2df46817@arrowsmith>
2012-09-08  3:03         ` [tcpdump-workers] Modular arithmetic Andi Kleen
2012-09-08  8:03           ` [PATCH net-next] filter: add MOD operation Eric Dumazet
2012-09-08 20:31             ` George Bakos
2012-09-10 19:45             ` David Miller
2012-09-10 20:48               ` Eric Dumazet [this message]
2012-09-10 21:09                 ` [PATCH net-next] x86 bpf_jit: support " David Miller
2012-09-10  8:41           ` [tcpdump-workers] Modular arithmetic David Laight
2012-09-10  9:25             ` Eric Dumazet
2012-09-10 10:41               ` David Laight
2012-09-10 11:49                 ` [tcpdump-workers] " Daniel Borkmann
2012-09-10 17:50                 ` Guy Harris
2014-05-18 18:26                   ` Guy Harris
2012-09-10 14:49             ` [tcpdump-workers] " Andi Kleen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1347310113.13103.8.camel@edumazet-glaptop \
    --to=eric.dumazet@gmail.com \
    --cc=ak@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=gbakos@alpinista.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox