qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PULL 12/23] tcg/aarch64: Use constant pool for movi
Date: Thu,  7 Sep 2017 15:40:40 -0700	[thread overview]
Message-ID: <20170907224051.21518-13-richard.henderson@linaro.org> (raw)
In-Reply-To: <20170907224051.21518-1-richard.henderson@linaro.org>

From: Richard Henderson <rth@twiddle.net>

Signed-off-by: Richard Henderson <rth@twiddle.net>
---
 tcg/aarch64/tcg-target.h     |  1 +
 tcg/aarch64/tcg-target.inc.c | 62 +++++++++++++++++++++++---------------------
 2 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h
index 1bdbd7058b..c2525066ab 100644
--- a/tcg/aarch64/tcg-target.h
+++ b/tcg/aarch64/tcg-target.h
@@ -125,5 +125,6 @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t);
 #ifdef CONFIG_SOFTMMU
 #define TCG_TARGET_NEED_LDST_LABELS
 #endif
+#define TCG_TARGET_NEED_POOL_LABELS
 
 #endif /* AARCH64_TCG_TARGET_H */
diff --git a/tcg/aarch64/tcg-target.inc.c b/tcg/aarch64/tcg-target.inc.c
index c7c751bafc..c2f3812214 100644
--- a/tcg/aarch64/tcg-target.inc.c
+++ b/tcg/aarch64/tcg-target.inc.c
@@ -10,6 +10,7 @@
  * See the COPYING file in the top-level directory for details.
  */
 
+#include "tcg-pool.inc.c"
 #include "qemu/bitops.h"
 
 /* We're going to re-use TCGType in setting of the SF bit, which controls
@@ -587,9 +588,11 @@ static void tcg_out_logicali(TCGContext *s, AArch64Insn insn, TCGType ext,
 static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd,
                          tcg_target_long value)
 {
-    int i, wantinv, shift;
     tcg_target_long svalue = value;
     tcg_target_long ivalue = ~value;
+    tcg_target_long t0, t1, t2;
+    int s0, s1;
+    AArch64Insn opc;
 
     /* For 32-bit values, discard potential garbage in value.  For 64-bit
        values within [2**31, 2**32-1], we can create smaller sequences by
@@ -638,38 +641,29 @@ static void tcg_out_movi(TCGContext *s, TCGType type, TCGReg rd,
         }
     }
 
-    /* Would it take fewer insns to begin with MOVN?  For the value and its
-       inverse, count the number of 16-bit lanes that are 0.  */
-    for (i = wantinv = 0; i < 64; i += 16) {
-        tcg_target_long mask = 0xffffull << i;
-        wantinv -= ((value & mask) == 0);
-        wantinv += ((ivalue & mask) == 0);
-    }
-
-    if (wantinv <= 0) {
-        /* Find the lowest lane that is not 0x0000.  */
-        shift = ctz64(value) & (63 & -16);
-        tcg_out_insn(s, 3405, MOVZ, type, rd, value >> shift, shift);
-        /* Clear out the lane that we just set.  */
-        value &= ~(0xffffUL << shift);
-        /* Iterate until all non-zero lanes have been processed.  */
-        while (value) {
-            shift = ctz64(value) & (63 & -16);
-            tcg_out_insn(s, 3405, MOVK, type, rd, value >> shift, shift);
-            value &= ~(0xffffUL << shift);
-        }
+    /* Would it take fewer insns to begin with MOVN?  */
+    if (ctpop64(value) >= 32) {
+        t0 = ivalue;
+        opc = I3405_MOVN;
     } else {
-        /* Like above, but with the inverted value and MOVN to start.  */
-        shift = ctz64(ivalue) & (63 & -16);
-        tcg_out_insn(s, 3405, MOVN, type, rd, ivalue >> shift, shift);
-        ivalue &= ~(0xffffUL << shift);
-        while (ivalue) {
-            shift = ctz64(ivalue) & (63 & -16);
-            /* Provide MOVK with the non-inverted value.  */
-            tcg_out_insn(s, 3405, MOVK, type, rd, ~(ivalue >> shift), shift);
-            ivalue &= ~(0xffffUL << shift);
+        t0 = value;
+        opc = I3405_MOVZ;
+    }
+    s0 = ctz64(t0) & (63 & -16);
+    t1 = t0 & ~(0xffffUL << s0);
+    s1 = ctz64(t1) & (63 & -16);
+    t2 = t1 & ~(0xffffUL << s1);
+    if (t2 == 0) {
+        tcg_out_insn_3405(s, opc, type, rd, t0 >> s0, s0);
+        if (t1 != 0) {
+            tcg_out_insn(s, 3405, MOVK, type, rd, value >> s1, s1);
         }
+        return;
     }
+
+    /* For more than 2 insns, dump it into the constant pool.  */
+    new_pool_label(s, value, R_AARCH64_CONDBR19, s->code_ptr, 0);
+    tcg_out_insn(s, 3305, LDR, 0, rd);
 }
 
 /* Define something more legible for general use.  */
@@ -2030,6 +2024,14 @@ static void tcg_target_qemu_prologue(TCGContext *s)
     tcg_out_insn(s, 3207, RET, TCG_REG_LR);
 }
 
+static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
+{
+    int i;
+    for (i = 0; i < count; ++i) {
+        p[i] = NOP;
+    }
+}
+
 typedef struct {
     DebugFrameHeader h;
     uint8_t fde_def_cfa[4];
-- 
2.13.5

  parent reply	other threads:[~2017-09-07 22:41 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-07 22:40 [Qemu-devel] [PULL 00/23] tcg constant pools and USE_DIRECT_JUMP cleanup Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 01/23] tcg: Move USE_DIRECT_JUMP discriminator to tcg/cpu/tcg-target.h Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 02/23] tcg: Rearrange ldst label tracking Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 03/23] tcg: Infrastructure for managing constant pools Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 04/23] tcg/i386: Store out-of-range call targets in constant pool Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 05/23] tcg/s390: Introduce TCG_REG_TB Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 06/23] tcg/s390: Fix sign of patch_reloc addend Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 07/23] tcg/s390: Use constant pool for movi Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 08/23] tcg/s390: Use constant pool for andi Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 09/23] tcg/s390: Use constant pool for ori Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 10/23] tcg/s390: Use constant pool for xori Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 11/23] tcg/s390: Use constant pool for cmpi Richard Henderson
2017-09-07 22:40 ` Richard Henderson [this message]
2017-09-07 22:40 ` [Qemu-devel] [PULL 13/23] tcg/sparc: Introduce TCG_REG_TB Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 14/23] tcg/sparc: Use constant pool for movi Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 15/23] tcg/arm: Improve tlb load for armv7 Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 16/23] tcg/arm: Tighten tlb indexing offset test Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 17/23] tcg/arm: Code rearrangement Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 18/23] tcg/arm: Extract INSN_NOP Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 19/23] tcg/arm: Use constant pool for movi Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 20/23] tcg/arm: Use constant pool for call Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 21/23] tcg/ppc: Change TCG_REG_RA to TCG_REG_TB Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 22/23] tcg/ppc: Look for shifted constants Richard Henderson
2017-09-07 22:40 ` [Qemu-devel] [PULL 23/23] tcg/ppc: Use constant pool for movi Richard Henderson
2017-09-08 11:56 ` [Qemu-devel] [PULL 00/23] tcg constant pools and USE_DIRECT_JUMP cleanup Peter Maydell

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=20170907224051.21518-13-richard.henderson@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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;
as well as URLs for NNTP newsgroup(s).