Netdev List
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: netdev@vger.kernel.org
Cc: oss-drivers@netronome.com, Jakub Kicinski <jakub.kicinski@netronome.com>
Subject: [PATCH net-next 9/9] nfp: bpf: optimize mov64 a little
Date: Mon, 23 Oct 2017 11:58:14 -0700	[thread overview]
Message-ID: <20171023185814.4797-10-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <20171023185814.4797-1-jakub.kicinski@netronome.com>

Loading 64bit constants require up to 4 load immediates, since
we can only load 16 bits at a time.  If the 32bit halves of
the 64bit constant are the same, however, we can save a cycle
by doing a register move instead of two loads of 16 bits.

Note that we don't optimize the normal ALU64 load because even
though it's a 64 bit load the upper half of the register is
a coming from sign extension so we can load it in one cycle
anyway.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
---
 drivers/net/ethernet/netronome/nfp/bpf/jit.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/bpf/jit.c b/drivers/net/ethernet/netronome/nfp/bpf/jit.c
index d84f00b80aac..e7eeb7a07f81 100644
--- a/drivers/net/ethernet/netronome/nfp/bpf/jit.c
+++ b/drivers/net/ethernet/netronome/nfp/bpf/jit.c
@@ -1384,19 +1384,28 @@ static int end_reg32(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 
 static int imm_ld8_part2(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 {
-	wrp_immed(nfp_prog, reg_both(nfp_meta_prev(meta)->insn.dst_reg * 2 + 1),
-		  meta->insn.imm);
+	struct nfp_insn_meta *prev = nfp_meta_prev(meta);
+	u32 imm_lo, imm_hi;
+	u8 dst;
+
+	dst = prev->insn.dst_reg * 2;
+	imm_lo = prev->insn.imm;
+	imm_hi = meta->insn.imm;
+
+	wrp_immed(nfp_prog, reg_both(dst), imm_lo);
+
+	/* mov is always 1 insn, load imm may be two, so try to use mov */
+	if (imm_hi == imm_lo)
+		wrp_mov(nfp_prog, reg_both(dst + 1), reg_a(dst));
+	else
+		wrp_immed(nfp_prog, reg_both(dst + 1), imm_hi);
 
 	return 0;
 }
 
 static int imm_ld8(struct nfp_prog *nfp_prog, struct nfp_insn_meta *meta)
 {
-	const struct bpf_insn *insn = &meta->insn;
-
 	meta->double_cb = imm_ld8_part2;
-	wrp_immed(nfp_prog, reg_both(insn->dst_reg * 2), insn->imm);
-
 	return 0;
 }
 
-- 
2.14.1

  parent reply	other threads:[~2017-10-23 18:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-23 18:58 [PATCH net-next 0/9] nfp: bpf: stack support in offload Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 1/9] nfp: bpf: add helper for emitting nops Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 2/9] nfp: bpf: refactor nfp_bpf_check_ptr() Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 3/9] nfp: bpf: add stack write support Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 4/9] nfp: bpf: add stack read support Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 5/9] nfp: bpf: optimize the RMW for stack accesses Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 6/9] nfp: bpf: allow stack accesses via modified stack registers Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 7/9] nfp: bpf: support accessing the stack beyond 64 bytes Jakub Kicinski
2017-10-23 18:58 ` [PATCH net-next 8/9] nfp: bpf: support stack accesses via non-constant pointers Jakub Kicinski
2017-10-23 18:58 ` Jakub Kicinski [this message]
2017-10-24  8:39 ` [PATCH net-next 0/9] nfp: bpf: stack support in offload David Miller

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=20171023185814.4797-10-jakub.kicinski@netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    /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