Skip to contentSkip to conversation

target-aarch64 fix and improvments

PATCH In review Richard Henderson 4 participants 23 messages Feb 19, 2015 – Mar 10, 2015

lore
Share & tools
lore
#0 lore raw

cover target-aarch64 fix and improvments

While doing the mechanics of a previous patch set converting translators to use to TCGLabel pointers, I was reminded of several outstanding OPTME comments in the aarch64 translator.

I had started with the csel change, which at first failed and took quite some time to debug. See the comment for patch 1.

Since this depends on the outstanding TCGLabel patch set, the full tree is available at

git://github.com/rth7680/qemu.git arm-movcond

r~

Richard Henderson (11):
target-arm: Introduce DisasCompare
target-arm: Extend NZCF to 64 bits
target-arm: Handle always condition codes within arm_test_cc
target-arm: Recognize SXTB, SXTH, SXTW, ASR
target-arm: Recognize UXTB, UXTH, LSR, LSL
target-arm: Eliminate unnecessary zero-extend in disas_bitfield
target-arm: Recognize ROR
target-arm: Use setcond and movcond for csel
target-arm: Implement ccmp branchless
target-arm: Implement fccmp branchless
target-arm: Implement fcsel with movcond

 target-arm/cpu.h           |  21 +-
 target-arm/helper.c        |  18 +-
 target-arm/translate-a64.c | 688 ++++++++++++++++++++++++++-------------------
 target-arm/translate.c     | 151 ++++++----
 target-arm/translate.h     |   2 -
 5 files changed, 524 insertions(+), 356 deletions(-)
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/11 target-arm: Introduce DisasCompare

Splitting arm_gen_test_cc into 3 functions, so that it can be reused for non-branch TCG comparisons.

Note that this is also a bug fix for aarch64. At present, we have branches using the 32-bit (translate.c) versions of cpu_[NZCV]F, but we set the flags using the 64-bit (translate-a64.c) versions of cpu_[NZCV]F. From the view of the TCG code generator, these are unrelated variables.

The bug is hard to see because we currently only read these variables from branches, and upon reaching a branch TCG will first spill live variables and then reload the arguments of the branch. Since the 32-bit versions were never live until reaching the branch, we'd re-read the data that had just been spilled from the 64-bit versions.

Accept the code duplication for now, as the 64-bit functions will diverge.

---
 target-arm/translate-a64.c | 102 +++++++++++++++++++++++++++++++++++++++
 target-arm/translate.c     | 116 +++++++++++++++++++++++++++------------------
 target-arm/translate.h     |   2 -
 3 files changed, 172 insertions(+), 48 deletions(-)
target-arm/translate-a64.c +102 -0
index 0b192a1..dbca12a 100644
@@ -1036,6 +1036,108 @@ static inline void gen_check_sp_alignment(DisasContext *s)
      */
 }
 
+typedef struct DisasCompare {
+    TCGCond cond;
+    TCGv_i32 value;
+    bool value_global;
+} DisasCompare;
+
+/*
+ * generate a conditional based on ARM condition code cc.
+ * This is common between ARM and Aarch64 targets.
+ */
+static void arm_test_cc(DisasCompare *cmp, int cc)
+{
+    TCGv_i32 value;
+    TCGCond cond;
+    bool global = true;
+
+    switch (cc) {
+    case 0: /* eq: Z */
+    case 1: /* ne: !Z */
+        cond = TCG_COND_EQ;
+        value = cpu_ZF;
+        break;
+
+    case 2: /* cs: C */
+    case 3: /* cc: !C */
+        cond = TCG_COND_NE;
+        value = cpu_CF;
+        break;
+
+    case 4: /* mi: N */
+    case 5: /* pl: !N */
+        cond = TCG_COND_LT;
+        value = cpu_NF;
+        break;
+
+    case 6: /* vs: V */
+    case 7: /* vc: !V */
+        cond = TCG_COND_LT;
+        value = cpu_VF;
+        break;
+
+    case 8: /* hi: C && !Z */
+    case 9: /* ls: !C || Z */
+        cond = TCG_COND_NE;
+        value = tcg_temp_new_i32();
+        global = false;
+        tcg_gen_neg_i32(value, cpu_CF);
+        tcg_gen_and_i32(value, value, cpu_ZF);
+        break;
+
+    case 10: /* ge: N == V -> N ^ V == 0 */
+    case 11: /* lt: N != V -> N ^ V != 0 */
+        cond = TCG_COND_GE;
+        value = tcg_temp_new_i32();
+        global = false;
+        tcg_gen_xor_i32(value, cpu_VF, cpu_NF);
+        break;
+
+    case 12: /* gt: !Z && N == V */
+    case 13: /* le: Z || N != V */
+        cond = TCG_COND_NE;
+        value = tcg_temp_new_i32();
+        global = false;
+        tcg_gen_xor_i32(value, cpu_VF, cpu_NF);
+        tcg_gen_sari_i32(value, value, 31);
+        tcg_gen_andc_i32(value, cpu_ZF, value);
+        break;
+
+    default:
+        fprintf(stderr, "Bad condition code 0x%x\n", cc);
+        abort();
+    }
+
+    if (cc & 1) {
+        cond = tcg_invert_cond(cond);
+    }
+
+    cmp->cond = cond;
+    cmp->value = value;
+    cmp->value_global = global;
+}
+
+static void arm_free_cc(DisasCompare *cmp)
+{
+    if (!cmp->value_global) {
+        tcg_temp_free_i32(cmp->value);
+    }
+}
+
+static void arm_jump_cc(DisasCompare *cmp, TCGLabel *label)
+{
+    tcg_gen_brcondi_i32(cmp->cond, cmp->value, 0, label);
+}
+
+static void arm_gen_test_cc(int cc, TCGLabel *label)
+{
+    DisasCompare cmp;
+    arm_test_cc(&cmp, cc);
+    arm_jump_cc(&cmp, label);
+    arm_free_cc(&cmp);
+}
+
 /*
  * This provides a simple table based table lookup decoder. It is
  * intended to be used when the relevant bits for decode are too
target-arm/translate.c +70 -46

152 lines not on this page · raw message

target-arm/translate.h +0 -2
index 9829576..e6c7048 100644
@@ -119,6 +119,4 @@ static inline void aarch64_cpu_dump_state(CPUState *cs, FILE *f,
 }
 #endif
 
-void arm_gen_test_cc(int cc, TCGLabel *label);
-
 #endif /* TARGET_ARM_TRANSLATE_H */
Signature · 1 line
2.1.0
#2 lore raw

PATCH 2/11 target-arm: Extend NZCF to 64 bits

In reply to Richard Henderson

The resulting aarch64 translation is a bit cleaner. Sign-extending from 32-bits is simpler than having to use setcond to narrow from 64-bits.

---
 target-arm/cpu.h           |  21 ++--
 target-arm/helper.c        |  18 ++-
 target-arm/translate-a64.c | 297 ++++++++++++++++++---------------------------
 target-arm/translate.c     |  26 +++-
 4 files changed, 163 insertions(+), 199 deletions(-)
target-arm/cpu.h +11 -10
index 11845a6..74835f4 100644
@@ -167,10 +167,10 @@ typedef struct CPUARMState {
     uint32_t fiq_regs[5];
 
     /* cpsr flag cache for faster execution */
-    uint32_t CF; /* 0 or 1 */
-    uint32_t VF; /* V is the bit 31. All other bits are undefined */
-    uint32_t NF; /* N is bit 31. All other bits are undefined.  */
-    uint32_t ZF; /* Z set if zero.  */
+    uint64_t CF; /* 0 or 1 */
+    uint64_t VF; /* V is the bit 63. All other bits are undefined */
+    uint64_t NF; /* N is bit 63. All other bits are undefined.  */
+    uint64_t ZF; /* Z set if zero.  */
     uint32_t QF; /* 0 or 1 */
     uint32_t GE; /* cpsr[19:16] */
     uint32_t thumb; /* cpsr[5]. 0 = arm mode, 1 = thumb mode. */
@@ -666,20 +666,21 @@ static inline unsigned int aarch64_pstate_mode(unsigned int el, bool handler)
  */
 static inline uint32_t pstate_read(CPUARMState *env)
 {
-    int ZF;
+    unsigned ZF = (env->ZF == 0);
+    unsigned NF = ((int64_t)env->NF < 0);
+    unsigned VF = ((int64_t)env->VF < 0);
+    unsigned CF = env->CF;
 
-    ZF = (env->ZF == 0);
-    return (env->NF & 0x80000000) | (ZF << 30)
-        | (env->CF << 29) | ((env->VF & 0x80000000) >> 3)
+    return (NF << 31) | (ZF << 30) | (CF << 29) | (VF << 28)
         | env->pstate | env->daif;
 }
 
 static inline void pstate_write(CPUARMState *env, uint32_t val)
 {
+    env->NF = (uint64_t)val << 32;
     env->ZF = (~val) & PSTATE_Z;
-    env->NF = val;
     env->CF = (val >> 29) & 1;
-    env->VF = (val << 3) & 0x80000000;
+    env->VF = (uint64_t)val << (32 + (31 - 28));
     env->daif = val & PSTATE_DAIF;
     env->pstate = val & ~CACHED_PSTATE_BITS;
 }
target-arm/helper.c +12 -6
index 3bc20af..1b28108 100644
@@ -3876,10 +3876,13 @@ static int bad_mode_switch(CPUARMState *env, int mode)
 
 uint32_t cpsr_read(CPUARMState *env)
 {
-    int ZF;
-    ZF = (env->ZF == 0);
-    return env->uncached_cpsr | (env->NF & 0x80000000) | (ZF << 30) |
-        (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27)
+    unsigned ZF = (env->ZF == 0);
+    unsigned NF = ((int64_t)env->NF < 0);
+    unsigned VF = ((int64_t)env->VF < 0);
+    unsigned CF = env->CF;
+
+    return env->uncached_cpsr | (NF << 31) | (ZF << 30)
+        | (CF << 29) | (VF << 28) | (env->QF << 27)
         | (env->thumb << 5) | ((env->condexec_bits & 3) << 25)
         | ((env->condexec_bits & 0xfc) << 8)
         | (env->GE << 16) | (env->daif & CPSR_AIF);
@@ -3890,10 +3893,10 @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask)
     uint32_t changed_daif;
 
     if (mask & CPSR_NZCV) {
+        env->NF = (uint64_t)val << 32;
         env->ZF = (~val) & CPSR_Z;
-        env->NF = val;
         env->CF = (val >> 29) & 1;
-        env->VF = (val << 3) & 0x80000000;
+        env->VF = (uint64_t)val << (32 + (31 - 28));
     }
     if (mask & CPSR_Q)
         env->QF = ((val & CPSR_Q) != 0);
@@ -4545,6 +4548,9 @@ void aarch64_sync_64_to_32(CPUARMState *env)
         env->regs[i] = env->xregs[i];
     }
 
+    /* Need to compress Z into the low bits.  */
+    env->ZF = (env->ZF != 0);
+
     /* Unless we are in FIQ mode, r8-r12 come from the user registers x8-x12.
      * Otherwise, we copy x8-x12 into the banked user regs.
      */
target-arm/translate-a64.c +119 -178

423 lines not on this page · raw message

target-arm/translate.c +21 -5
index dd4d80f..0d0a4d1 100644
@@ -85,7 +85,7 @@ static const char *regnames[] =
 /* initialize TCG globals.  */
 void arm_translate_init(void)
 {
-    int i;
+    int i, be, le;
 
     cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
 
@@ -94,10 +94,26 @@ void arm_translate_init(void)
                                           offsetof(CPUARMState, regs[i]),
                                           regnames[i]);
     }
-    cpu_CF = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUARMState, CF), "CF");
-    cpu_NF = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUARMState, NF), "NF");
-    cpu_VF = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUARMState, VF), "VF");
-    cpu_ZF = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUARMState, ZF), "ZF");
+
+#ifdef HOST_WORDS_BIGENDIAN
+    be = 0;
+    le = 4;
+#else
+    le = 0;
+    be = 4;
+#endif
+
+    /* Place CF and ZF at the low end of the 64-bit variable, and NF
+       and VF at the high end.  The other halves are ignore(able) in
+       32-bit mode and synced during mode transition.  */
+    cpu_CF = tcg_global_mem_new_i32(TCG_AREG0,
+                                    offsetof(CPUARMState, CF) + le, "CF");
+    cpu_ZF = tcg_global_mem_new_i32(TCG_AREG0,
+                                    offsetof(CPUARMState, ZF) + le, "ZF");
+    cpu_NF = tcg_global_mem_new_i32(TCG_AREG0,
+                                    offsetof(CPUARMState, NF) + be, "NF");
+    cpu_VF = tcg_global_mem_new_i32(TCG_AREG0,
+                                    offsetof(CPUARMState, VF) + be, "VF");
 
     cpu_exclusive_addr = tcg_global_mem_new_i64(TCG_AREG0,
         offsetof(CPUARMState, exclusive_addr), "exclusive_addr");
Signature · 1 line
2.1.0
#3 lore raw

Re: [Qemu-devel] [PATCH 02/11] target-arm: Extend NZCF to 64 bits

Quoted 8 lines · Richard Henderson

The resulting aarch64 translation is a bit cleaner. Sign-extending from 32-bits is simpler than having to use setcond to narrow from 64-bits.

target-arm/helper.c void aarch64_sync_64_to_32(CPUARMState *env) · line 4553

Quoted 6 lines
target-arm/helper.c +3 -0
@@ -4545,6 +4548,9 @@ void aarch64_sync_64_to_32(CPUARMState *env)
         env->regs[i] = env->xregs[i];
     }
 
+    /* Need to compress Z into the low bits.  */
+    env->ZF = (env->ZF != 0);
+

I really don't like this. Having state with a different format in 32-bit and 64-bit modes is asking for trouble -- the bits we already have to convert are already awkward enough.

I'd much rather we stuck with a format where env->ZF is the same regardless of register width, as we have now.

-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH 02/11] target-arm: Extend NZCF to 64 bits

Quoted 20 lines · Peter Maydell
Quoted 8 lines · Richard Henderson

The resulting aarch64 translation is a bit cleaner. Sign-extending from 32-bits is simpler than having to use setcond to narrow from 64-bits.

target-arm/helper.c void aarch64_sync_64_to_32(CPUARMState *env) · line 4553

Quoted 6 lines
target-arm/helper.c +3 -0
@@ -4545,6 +4548,9 @@ void aarch64_sync_64_to_32(CPUARMState *env)
         env->regs[i] = env->xregs[i];
     }
 
+    /* Need to compress Z into the low bits.  */
+    env->ZF = (env->ZF != 0);
+

I really don't like this. Having state with a different format in 32-bit and 64-bit modes is asking for trouble -- the bits we already have to convert are already awkward enough.

Quoted 2 lines

I'd much rather we stuck with a format where env->ZF is the same regardless of register width, as we have now.

Err.. it is the same format, from the viewpoint of outside TCG generated code.

Quoted 1 line

From the viewpoint inside TCG generated code, for AArch32, ZF is only 32-bits

wide. For AArch64, ZF is 64-bits wide. So when we transition from AArch64 to AArch32, we must make sure that if ZF != 0, then ZF <= 0xffffffff.

It's a similar concept for NF and VF, except there I can arrange for the sign bit of the 32-bit AArch32 NF/VF to line up with the 64-bit AArch64 NF/VF in memory.

If that's not what you mean... then I don't know what you mean.

r~

#5 lore raw

PATCH 3/11 target-arm: Handle always condition codes within arm_test_cc

In reply to Richard Henderson

Handling this with TCG_COND_ALWAYS will allow these unlikely cases to be handled without special cases in the rest of the translator. The TCG optimizer ought to be able to reduce these ALWAYS conditions completely.

---
 target-arm/translate-a64.c | 9 +++++++++
 target-arm/translate.c     | 9 +++++++++
 2 files changed, 18 insertions(+)
target-arm/translate-a64.c +9 -0
index 763bf35..219e257 100644
@@ -1056,6 +1056,14 @@ static void arm_test_cc(DisasCompare *cmp, int cc)
         tcg_gen_andc_i64(value, cpu_ZF, value);
         break;
 
+    case 14: /* always */
+    case 15: /* always */
+        /* Use the ALWAYS condition, which will fold early.
+           It doesn't matter what we use for the value.  */
+        cond = TCG_COND_ALWAYS;
+        value = cpu_ZF;
+        goto no_invert;
+
     default:
         fprintf(stderr, "Bad condition code 0x%x\n", cc);
         abort();
@@ -1065,6 +1073,7 @@ static void arm_test_cc(DisasCompare *cmp, int cc)
         cond = tcg_invert_cond(cond);
     }
 
+ no_invert:
     cmp->cond = cond;
     cmp->value = value;
     cmp->value_global = global;
target-arm/translate.c +9 -0
index 0d0a4d1..54edc33 100644
@@ -816,6 +816,14 @@ static void arm_test_cc(DisasCompare *cmp, int cc)
         tcg_gen_andc_i32(value, cpu_ZF, value);
         break;
 
+    case 14: /* always */
+    case 15: /* always */
+        /* Use the ALWAYS condition, which will fold early.
+           It doesn't matter what we use for the value.  */
+        cond = TCG_COND_ALWAYS;
+        value = cpu_ZF;
+        goto no_invert;
+
     default:
         fprintf(stderr, "Bad condition code 0x%x\n", cc);
         abort();
@@ -825,6 +833,7 @@ static void arm_test_cc(DisasCompare *cmp, int cc)
         cond = tcg_invert_cond(cond);
     }
 
+ no_invert:
     cmp->cond = cond;
     cmp->value = value;
     cmp->value_global = global;
Signature · 1 line
2.1.0
#6 lore raw

PATCH 4/11 target-arm: Recognize SXTB, SXTH, SXTW, ASR

In reply to Richard Henderson

... as aliases of SBFM, and special-case them.

---
 target-arm/translate-a64.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
target-arm/translate-a64.c +23 -1
index 219e257..0cb60a2 100644
@@ -3036,7 +3036,28 @@ static void disas_bitfield(DisasContext *s, uint32_t insn)
     tcg_rd = cpu_reg(s, rd);
     tcg_tmp = read_cpu_reg(s, rn, sf);
 
-    /* OPTME: probably worth recognizing common cases of ext{8,16,32}{u,s} */
+    /* Recognize the common aliases.  */
+    if (opc == 0) { /* SBFM */
+        if (ri == 0) {
+            if (si == 7) { /* SXTB */
+                tcg_gen_ext8s_i64(tcg_rd, tcg_tmp);
+                goto done;
+            } else if (si == 15) { /* SXTH */
+                tcg_gen_ext16s_i64(tcg_rd, tcg_tmp);
+                goto done;
+            } else if (si == 31) { /* SXTW */
+                tcg_gen_ext32s_i64(tcg_rd, tcg_tmp);
+                goto done;
+            }
+        }
+        if (si == 63 || (si == 31 && ri <= si)) { /* ASR */
+            if (si == 31) {
+                tcg_gen_ext32s_i64(tcg_tmp, tcg_tmp);
+            }
+            tcg_gen_sari_i64(tcg_rd, tcg_tmp, ri);
+            goto done;
+        }
+    }
 
     if (opc != 1) { /* SBFM or UBFM */
         tcg_gen_movi_i64(tcg_rd, 0);
@@ -3061,6 +3082,7 @@ static void disas_bitfield(DisasContext *s, uint32_t insn)
         tcg_gen_sari_i64(tcg_rd, tcg_rd, 64 - (pos + len));
     }
 
+ done:
     if (!sf) { /* zero extend final result */
         tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
     }
Signature · 1 line
2.1.0
#7 lore raw

PATCH 5/11 target-arm: Recognize UXTB, UXTH, LSR, LSL

In reply to Richard Henderson
---
 target-arm/translate-a64.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
target-arm/translate-a64.c +17 -0
index 0cb60a2..54290ad 100644
@@ -3057,6 +3057,23 @@ static void disas_bitfield(DisasContext *s, uint32_t insn)
             tcg_gen_sari_i64(tcg_rd, tcg_tmp, ri);
             goto done;
         }
+    } else if (opc == 2) { /* UBFM */
+        if (ri == 0) { /* UXTB, UXTH, plus non-canonical AND */
+            tcg_gen_andi_i64(tcg_rd, tcg_tmp, bitmask64(si + 1));
+            return;
+        }
+        if (si == 63 || (si == 31 && ri <= si)) { /* LSR */
+            if (si == 31) {
+                tcg_gen_ext32u_i64(tcg_tmp, tcg_tmp);
+            }
+            tcg_gen_shri_i64(tcg_rd, tcg_tmp, ri);
+            return;
+        }
+        if (si + 1 == ri && si != bitsize - 1) { /* LSL */
+            int shift = bitsize - 1 - si;
+            tcg_gen_shli_i64(tcg_rd, tcg_tmp, shift);
+            goto done;
+        }
     }
 
     if (opc != 1) { /* SBFM or UBFM */
Signature · 1 line
2.1.0
#8 lore raw

PATCH 6/11 target-arm: Eliminate unnecessary zero-extend in disas_bitfield

In reply to Richard Henderson

For !SF, this initial ext32u can't be optimized away by the current TCG code generator. (It would require backward bit liveness propagation.)

But since the range of bits for !SF are already constrained by unallocated_encoding, we'll never reference the high bits anyway.

---
 target-arm/translate-a64.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
target-arm/translate-a64.c +5 -1
index 54290ad..ed97ed6 100644
@@ -3034,7 +3034,11 @@ static void disas_bitfield(DisasContext *s, uint32_t insn)
     }
 
     tcg_rd = cpu_reg(s, rd);
-    tcg_tmp = read_cpu_reg(s, rn, sf);
+
+    /* Suppress the zero-extend for !sf.  Since RI and SI are constrained
+       to be smaller than bitsize, we'll never reference data outside the
+       low 32-bits anyway.  */
+    tcg_tmp = read_cpu_reg(s, rn, 1);
 
     /* Recognize the common aliases.  */
     if (opc == 0) { /* SBFM */
Signature · 1 line
2.1.0
#9 lore raw

PATCH 7/11 target-arm: Recognize ROR

In reply to Richard Henderson
---
 target-arm/translate-a64.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)
target-arm/translate-a64.c +21 -12
index ed97ed6..d139b2d 100644
@@ -3136,17 +3136,7 @@ static void disas_extract(DisasContext *s, uint32_t insn)
 
         tcg_rd = cpu_reg(s, rd);
 
-        if (imm) {
-            /* OPTME: we can special case rm==rn as a rotate */
-            tcg_rm = read_cpu_reg(s, rm, sf);
-            tcg_rn = read_cpu_reg(s, rn, sf);
-            tcg_gen_shri_i64(tcg_rm, tcg_rm, imm);
-            tcg_gen_shli_i64(tcg_rn, tcg_rn, bitsize - imm);
-            tcg_gen_or_i64(tcg_rd, tcg_rm, tcg_rn);
-            if (!sf) {
-                tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
-            }
-        } else {
+        if (unlikely(imm == 0)) {
             /* tcg shl_i32/shl_i64 is undefined for 32/64 bit shifts,
              * so an extract from bit 0 is a special case.
              */
@@ -3155,8 +3145,27 @@ static void disas_extract(DisasContext *s, uint32_t insn)
             } else {
                 tcg_gen_ext32u_i64(tcg_rd, cpu_reg(s, rm));
             }
+        } else if (rm == rn) { /* ROR */
+            tcg_rm = cpu_reg(s, rm);
+            if (sf) {
+                tcg_gen_rotri_i64(tcg_rd, tcg_rm, imm);
+            } else {
+                TCGv_i32 tmp = tcg_temp_new_i32();
+                tcg_gen_trunc_i64_i32(tmp, tcg_rm);
+                tcg_gen_rotri_i32(tmp, tmp, imm);
+                tcg_gen_extu_i32_i64(tcg_rd, tmp);
+                tcg_temp_free_i32(tmp);
+            }
+        } else {
+            tcg_rm = read_cpu_reg(s, rm, sf);
+            tcg_rn = read_cpu_reg(s, rn, sf);
+            tcg_gen_shri_i64(tcg_rm, tcg_rm, imm);
+            tcg_gen_shli_i64(tcg_rn, tcg_rn, bitsize - imm);
+            tcg_gen_or_i64(tcg_rd, tcg_rm, tcg_rn);
+            if (!sf) {
+                tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
+            }
         }
-
     }
 }
 
Signature · 1 line
2.1.0
#10 lore raw

PATCH 8/11 target-arm: Use setcond and movcond for csel

In reply to Richard Henderson
---
 target-arm/translate-a64.c | 60 +++++++++++++++++++---------------------------
 1 file changed, 24 insertions(+), 36 deletions(-)
target-arm/translate-a64.c +24 -36
index d139b2d..7549267 100644
@@ -3703,7 +3703,8 @@ static void disas_cc(DisasContext *s, uint32_t insn)
 static void disas_cond_select(DisasContext *s, uint32_t insn)
 {
     unsigned int sf, else_inv, rm, cond, else_inc, rn, rd;
-    TCGv_i64 tcg_rd, tcg_src;
+    TCGv_i64 tcg_rd, zero;
+    DisasCompare c;
 
     if (extract32(insn, 29, 1) || extract32(insn, 11, 1)) {
         /* S == 1 or op2<1> == 1 */
@@ -3718,48 +3719,35 @@ static void disas_cond_select(DisasContext *s, uint32_t insn)
     rn = extract32(insn, 5, 5);
     rd = extract32(insn, 0, 5);
 
-    if (rd == 31) {
-        /* silly no-op write; until we use movcond we must special-case
-         * this to avoid a dead temporary across basic blocks.
-         */
-        return;
-    }
-
     tcg_rd = cpu_reg(s, rd);
 
-    if (cond >= 0x0e) { /* condition "always" */
-        tcg_src = read_cpu_reg(s, rn, sf);
-        tcg_gen_mov_i64(tcg_rd, tcg_src);
-    } else {
-        /* OPTME: we could use movcond here, at the cost of duplicating
-         * a lot of the arm_gen_test_cc() logic.
-         */
-        TCGLabel *label_match = gen_new_label();
-        TCGLabel *label_continue = gen_new_label();
-
-        arm_gen_test_cc(cond, label_match);
-        /* nomatch: */
-        tcg_src = cpu_reg(s, rm);
+    arm_test_cc(&c, cond);
+    zero = tcg_const_i64(0);
 
+    if (rn == 31 && rm == 31 && (else_inc ^ else_inv)) {
+        /* CSET & CSETM.  */
+        tcg_gen_setcond_i64(tcg_invert_cond(c.cond), tcg_rd, c.value, zero);
+        if (else_inv) {
+            tcg_gen_neg_i64(tcg_rd, tcg_rd);
+        }
+    } else {
+        TCGv_i64 t_true = cpu_reg(s, rn);
+        TCGv_i64 t_false = read_cpu_reg(s, rm, 1);
         if (else_inv && else_inc) {
-            tcg_gen_neg_i64(tcg_rd, tcg_src);
+            tcg_gen_neg_i64(t_false, t_false);
         } else if (else_inv) {
-            tcg_gen_not_i64(tcg_rd, tcg_src);
+            tcg_gen_not_i64(t_false, t_false);
         } else if (else_inc) {
-            tcg_gen_addi_i64(tcg_rd, tcg_src, 1);
-        } else {
-            tcg_gen_mov_i64(tcg_rd, tcg_src);
-        }
-        if (!sf) {
-            tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
+            tcg_gen_addi_i64(t_false, t_false, 1);
         }
-        tcg_gen_br(label_continue);
-        /* match: */
-        gen_set_label(label_match);
-        tcg_src = read_cpu_reg(s, rn, sf);
-        tcg_gen_mov_i64(tcg_rd, tcg_src);
-        /* continue: */
-        gen_set_label(label_continue);
+        tcg_gen_movcond_i64(c.cond, tcg_rd, c.value, zero, t_true, t_false);
+    }
+
+    tcg_temp_free_i64(zero);
+    arm_free_cc(&c);
+
+    if (!sf) {
+        tcg_gen_ext32u_i64(tcg_rd, tcg_rd);
     }
 }
 
Signature · 1 line
2.1.0
#11 lore raw

PATCH 9/11 target-arm: Implement ccmp branchless

In reply to Richard Henderson

This can allow much of a ccmp to be elided when particular flags are subsequently dead.

---
 target-arm/translate-a64.c | 62 ++++++++++++++++++++++++++++++----------------
 1 file changed, 41 insertions(+), 21 deletions(-)
target-arm/translate-a64.c +41 -21
index 7549267..8171a1f 100644
@@ -3641,8 +3641,8 @@ static void disas_adc_sbc(DisasContext *s, uint32_t insn)
 static void disas_cc(DisasContext *s, uint32_t insn)
 {
     unsigned int sf, op, y, cond, rn, nzcv, is_imm;
-    TCGLabel *label_continue = NULL;
-    TCGv_i64 tcg_tmp, tcg_y, tcg_rn;
+    TCGv_i64 tcg_t0, tcg_t1, tcg_t2, tcg_y, tcg_rn;
+    DisasCompare c;
 
     if (!extract32(insn, 29, 1)) {
         unallocated_encoding(s);
@@ -3660,19 +3660,13 @@ static void disas_cc(DisasContext *s, uint32_t insn)
     rn = extract32(insn, 5, 5);
     nzcv = extract32(insn, 0, 4);
 
-    if (cond < 0x0e) { /* not always */
-        TCGLabel *label_match = gen_new_label();
-        label_continue = gen_new_label();
-        arm_gen_test_cc(cond, label_match);
-        /* nomatch: */
-        tcg_tmp = tcg_temp_new_i64();
-        tcg_gen_movi_i64(tcg_tmp, nzcv << 28);
-        gen_set_nzcv(tcg_tmp);
-        tcg_temp_free_i64(tcg_tmp);
-        tcg_gen_br(label_continue);
-        gen_set_label(label_match);
-    }
-    /* match, or condition is always */
+    /* Set T0 = !COND.  */
+    tcg_t0 = tcg_temp_new_i64();
+    arm_test_cc(&c, cond);
+    tcg_gen_setcondi_i64(tcg_invert_cond(c.cond), tcg_t0, c.value, 0);
+    arm_free_cc(&c);
+
+    /* Load the arguments for the new comparison.  */
     if (is_imm) {
         tcg_y = new_tmp_a64(s);
         tcg_gen_movi_i64(tcg_y, y);
@@ -3681,17 +3675,43 @@ static void disas_cc(DisasContext *s, uint32_t insn)
     }
     tcg_rn = cpu_reg(s, rn);
 
-    tcg_tmp = tcg_temp_new_i64();
+    /* Set the flags for the new comparison.  */
+    tcg_t1 = tcg_temp_new_i64();
     if (op) {
-        gen_sub_CC(sf, tcg_tmp, tcg_rn, tcg_y);
+        gen_sub_CC(sf, tcg_t1, tcg_rn, tcg_y);
     } else {
-        gen_add_CC(sf, tcg_tmp, tcg_rn, tcg_y);
+        gen_add_CC(sf, tcg_t1, tcg_rn, tcg_y);
     }
-    tcg_temp_free_i64(tcg_tmp);
 
-    if (cond < 0x0e) { /* continue */
-        gen_set_label(label_continue);
+    /* If COND was false, force the flags to #nzcv.
+       Note that T1 = (COND ? 0 : -1), T2 = (COND ? -1 : 0).  */
+    tcg_t2 = tcg_temp_new_i64();
+    tcg_gen_neg_i64(tcg_t1, tcg_t0);
+    tcg_gen_subi_i64(tcg_t2, tcg_t0, 1);
+
+    if (nzcv & 8) { /* N */
+        tcg_gen_or_i64(cpu_NF, cpu_NF, tcg_t1);
+    } else {
+        tcg_gen_and_i64(cpu_NF, cpu_NF, tcg_t2);
+    }
+    if (nzcv & 4) { /* Z */
+        tcg_gen_and_i64(cpu_ZF, cpu_ZF, tcg_t2);
+    } else {
+        tcg_gen_or_i64(cpu_ZF, cpu_ZF, tcg_t0);
+    }
+    if (nzcv & 2) { /* C */
+        tcg_gen_or_i64(cpu_CF, cpu_CF, tcg_t0);
+    } else {
+        tcg_gen_and_i64(cpu_CF, cpu_CF, tcg_t2);
+    }
+    if (nzcv & 1) { /* V */
+        tcg_gen_or_i64(cpu_VF, cpu_VF, tcg_t1);
+    } else {
+        tcg_gen_and_i64(cpu_VF, cpu_VF, tcg_t2);
     }
+    tcg_temp_free_i64(tcg_t0);
+    tcg_temp_free_i64(tcg_t1);
+    tcg_temp_free_i64(tcg_t2);
 }
 
 /* C3.5.6 Conditional select
Signature · 1 line
2.1.0
#12 lore raw

PATCH 10/11 target-arm: Implement fccmp branchless

In reply to Richard Henderson
---
 target-arm/translate-a64.c | 50 +++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 21 deletions(-)
target-arm/translate-a64.c +29 -21
index 8171a1f..5539ae3 100644
@@ -4128,11 +4128,11 @@ static void disas_data_proc_reg(DisasContext *s, uint32_t insn)
     }
 }
 
-static void handle_fp_compare(DisasContext *s, bool is_double,
-                              unsigned int rn, unsigned int rm,
-                              bool cmp_with_zero, bool signal_all_nans)
+static void handle_fp_compare_1(DisasContext *s, TCGv_i64 tcg_flags,
+                                bool is_double, unsigned int rn,
+                                unsigned int rm, bool cmp_with_zero,
+                                bool signal_all_nans)
 {
-    TCGv_i64 tcg_flags = tcg_temp_new_i64();
     TCGv_ptr fpst = get_fpstatus_ptr();
 
     if (is_double) {
@@ -4170,7 +4170,16 @@ static void handle_fp_compare(DisasContext *s, bool is_double,
     }
 
     tcg_temp_free_ptr(fpst);
+}
 
+static void handle_fp_compare(DisasContext *s, bool is_double,
+                              unsigned int rn, unsigned int rm,
+                              bool cmp_with_zero, bool signal_all_nans)
+{
+    TCGv_i64 tcg_flags = tcg_temp_new_i64();
+
+    handle_fp_compare_1(s, tcg_flags, is_double, rn, rm,
+                        cmp_with_zero, signal_all_nans);
     gen_set_nzcv(tcg_flags);
 
     tcg_temp_free_i64(tcg_flags);
@@ -4215,8 +4224,8 @@ static void disas_fp_compare(DisasContext *s, uint32_t insn)
 static void disas_fp_ccomp(DisasContext *s, uint32_t insn)
 {
     unsigned int mos, type, rm, cond, rn, op, nzcv;
-    TCGv_i64 tcg_flags;
-    TCGLabel *label_continue = NULL;
+    TCGv_i64 t_flags, t_zero, t_nzcv;
+    DisasCompare c;
 
     mos = extract32(insn, 29, 3);
     type = extract32(insn, 22, 2); /* 0 = single, 1 = double */
@@ -4235,23 +4244,22 @@ static void disas_fp_ccomp(DisasContext *s, uint32_t insn)
         return;
     }
 
-    if (cond < 0x0e) { /* not always */
-        TCGLabel *label_match = gen_new_label();
-        label_continue = gen_new_label();
-        arm_gen_test_cc(cond, label_match);
-        /* nomatch: */
-        tcg_flags = tcg_const_i64(nzcv << 28);
-        gen_set_nzcv(tcg_flags);
-        tcg_temp_free_i64(tcg_flags);
-        tcg_gen_br(label_continue);
-        gen_set_label(label_match);
-    }
+    /* Perform the new compare, but don't write the result back to flags. */
+    t_flags = tcg_temp_new_i64();
+    handle_fp_compare_1(s, t_flags, type, rn, rm, false, op);
 
-    handle_fp_compare(s, type, rn, rm, false, op);
+    /* If the condition is false, force the flags to #nzcv.  */
+    arm_test_cc(&c, cond);
+    t_zero = tcg_const_i64(0);
+    t_nzcv = tcg_const_i64(nzcv << 28);
+    tcg_gen_movcond_i64(c.cond, t_flags, c.value, t_zero, t_flags, t_nzcv);
+    tcg_temp_free_i64(t_zero);
+    tcg_temp_free_i64(t_nzcv);
+    arm_free_cc(&c);
 
-    if (cond < 0x0e) {
-        gen_set_label(label_continue);
-    }
+    /* Write back the new flags.  */
+    gen_set_nzcv(t_flags);
+    tcg_temp_free_i64(t_flags);
 }
 
 /* copy src FP register to dst FP register; type specifies single or double */
Signature · 1 line
2.1.0
#13 lore raw

Re: [Qemu-devel] [PATCH 10/11] target-arm: Implement fccmp branchless

Hi Richard,

Quoted 61 lines · Richard Henderson
---
 target-arm/translate-a64.c | 50 +++++++++++++++++++++++++++-------------------
 1 file changed, 29 insertions(+), 21 deletions(-)
target-arm/translate-a64.c +15 -10
index 8171a1f..5539ae3 100644
@@ -4128,11 +4128,11 @@ static void disas_data_proc_reg(DisasContext *s, uint32_t insn)
     }
 }
 
-static void handle_fp_compare(DisasContext *s, bool is_double,
-                              unsigned int rn, unsigned int rm,
-                              bool cmp_with_zero, bool signal_all_nans)
+static void handle_fp_compare_1(DisasContext *s, TCGv_i64 tcg_flags,
+                                bool is_double, unsigned int rn,
+                                unsigned int rm, bool cmp_with_zero,
+                                bool signal_all_nans)
 {
-    TCGv_i64 tcg_flags = tcg_temp_new_i64();
     TCGv_ptr fpst = get_fpstatus_ptr();
 
     if (is_double) {
@@ -4170,7 +4170,16 @@ static void handle_fp_compare(DisasContext *s, bool is_double,
     }
 
     tcg_temp_free_ptr(fpst);
+}
 
+static void handle_fp_compare(DisasContext *s, bool is_double,
+                              unsigned int rn, unsigned int rm,
+                              bool cmp_with_zero, bool signal_all_nans)
+{
+    TCGv_i64 tcg_flags = tcg_temp_new_i64();
+
+    handle_fp_compare_1(s, tcg_flags, is_double, rn, rm,
+                        cmp_with_zero, signal_all_nans);
     gen_set_nzcv(tcg_flags);
 
     tcg_temp_free_i64(tcg_flags);
@@ -4215,8 +4224,8 @@ static void disas_fp_compare(DisasContext *s, uint32_t insn)
 static void disas_fp_ccomp(DisasContext *s, uint32_t insn)
 {
     unsigned int mos, type, rm, cond, rn, op, nzcv;
-    TCGv_i64 tcg_flags;
-    TCGLabel *label_continue = NULL;
+    TCGv_i64 t_flags, t_zero, t_nzcv;
+    DisasCompare c;
 
     mos = extract32(insn, 29, 3);
     type = extract32(insn, 22, 2); /* 0 = single, 1 = double */
@@ -4235,23 +4244,22 @@ static void disas_fp_ccomp(DisasContext *s, uint32_t insn)
         return;
     }
 
-    if (cond < 0x0e) { /* not always */
-        TCGLabel *label_match = gen_new_label();
-        label_continue = gen_new_label();
-        arm_gen_test_cc(cond, label_match);

target-arm/translate-a64.c static void disas_fp_ccomp(DisasContext *s, uint32_t insn) · line 4249

Quoted 10 lines
target-arm/translate-a64.c +3 -7
-        /* nomatch: */
-        tcg_flags = tcg_const_i64(nzcv << 28);
-        gen_set_nzcv(tcg_flags);
-        tcg_temp_free_i64(tcg_flags);
-        tcg_gen_br(label_continue);
-        gen_set_label(label_match);
-    }
+    /* Perform the new compare, but don't write the result back to flags. */
+    t_flags = tcg_temp_new_i64();
+    handle_fp_compare_1(s, t_flags, type, rn, rm, false, op);

The problem with this approach is that you'll always call the FP compare which might result in FP flags corruption.

The ARMv8 manual clearly states that the FP compare should only be called if the condition holds.

Thanks,

Laurent

Quoted 23 lines
target-arm/translate-a64.c +11 -5
-    handle_fp_compare(s, type, rn, rm, false, op);
+    /* If the condition is false, force the flags to #nzcv.  */
+    arm_test_cc(&c, cond);
+    t_zero = tcg_const_i64(0);
+    t_nzcv = tcg_const_i64(nzcv << 28);
+    tcg_gen_movcond_i64(c.cond, t_flags, c.value, t_zero, t_flags, t_nzcv);
+    tcg_temp_free_i64(t_zero);
+    tcg_temp_free_i64(t_nzcv);
+    arm_free_cc(&c);
 
-    if (cond < 0x0e) {
-        gen_set_label(label_continue);
-    }
+    /* Write back the new flags.  */
+    gen_set_nzcv(t_flags);
+    tcg_temp_free_i64(t_flags);
 }
 
 /* copy src FP register to dst FP register; type specifies single or double */
--

2.1.0

#14 lore raw

Re: [Qemu-devel] [PATCH 10/11] target-arm: Implement fccmp branchless

Quoted 5 lines · Laurent Desnogues

The problem with this approach is that you'll always call the FP compare which might result in FP flags corruption.

The ARMv8 manual clearly states that the FP compare should only be called if the condition holds.

Ah, I hadn't considered that. Consider this patch dropped.

Thanks,

r~

#15 lore raw

Re: [Qemu-devel] [PATCH 10/11] target-arm: Implement fccmp branchless

Hi Richard,

Quoted 8 lines · Richard Henderson
Quoted 5 lines · Laurent Desnogues

The problem with this approach is that you'll always call the FP compare which might result in FP flags corruption.

The ARMv8 manual clearly states that the FP compare should only be called if the condition holds.

Ah, I hadn't considered that. Consider this patch dropped.

With this patch removed, all the FP tests pass as on master.

Thanks,

Laurent

Quoted 4 lines

Thanks,

r~

#16 lore raw

PATCH 11/11 target-arm: Implement fcsel with movcond

In reply to Richard Henderson
---
 target-arm/translate-a64.c | 48 ++++++++++++++++++++--------------------------
 1 file changed, 21 insertions(+), 27 deletions(-)
target-arm/translate-a64.c +21 -27
index 5539ae3..1302cec 100644
@@ -4262,20 +4262,6 @@ static void disas_fp_ccomp(DisasContext *s, uint32_t insn)
     tcg_temp_free_i64(t_flags);
 }
 
-/* copy src FP register to dst FP register; type specifies single or double */
-static void gen_mov_fp2fp(DisasContext *s, int type, int dst, int src)
-{
-    if (type) {
-        TCGv_i64 v = read_fp_dreg(s, src);
-        write_fp_dreg(s, dst, v);
-        tcg_temp_free_i64(v);
-    } else {
-        TCGv_i32 v = read_fp_sreg(s, src);
-        write_fp_sreg(s, dst, v);
-        tcg_temp_free_i32(v);
-    }
-}
-
 /* C3.6.24 Floating point conditional select
  *   31  30  29 28       24 23  22  21 20  16 15  12 11 10 9    5 4    0
  * +---+---+---+-----------+------+---+------+------+-----+------+------+
@@ -4285,7 +4271,8 @@ static void gen_mov_fp2fp(DisasContext *s, int type, int dst, int src)
 static void disas_fp_csel(DisasContext *s, uint32_t insn)
 {
     unsigned int mos, type, rm, cond, rn, rd;
-    TCGLabel *label_continue = NULL;
+    TCGv_i64 t_true, t_false, t_zero;
+    DisasCompare c;
 
     mos = extract32(insn, 29, 3);
     type = extract32(insn, 22, 2); /* 0 = single, 1 = double */
@@ -4303,21 +4290,28 @@ static void disas_fp_csel(DisasContext *s, uint32_t insn)
         return;
     }
 
-    if (cond < 0x0e) { /* not always */
-        TCGLabel *label_match = gen_new_label();
-        label_continue = gen_new_label();
-        arm_gen_test_cc(cond, label_match);
-        /* nomatch: */
-        gen_mov_fp2fp(s, type, rd, rm);
-        tcg_gen_br(label_continue);
-        gen_set_label(label_match);
+    if (type) {
+        t_true = read_fp_dreg(s, rn);
+        t_false = read_fp_dreg(s, rm);
+    } else {
+        /* Zero-extend sreg inputs to 64-bits now.  */
+        t_true = tcg_temp_new_i64();
+        t_false = tcg_temp_new_i64();
+        tcg_gen_ld32u_i64(t_true, cpu_env, fp_reg_offset(s, rn, MO_32));
+        tcg_gen_ld32u_i64(t_false, cpu_env, fp_reg_offset(s, rm, MO_32));
     }
 
-    gen_mov_fp2fp(s, type, rd, rn);
+    arm_test_cc(&c, cond);
+    t_zero = tcg_const_i64(0);
+    tcg_gen_movcond_i64(c.cond, t_true, c.value, t_zero, t_true, t_false);
+    tcg_temp_free_i64(t_zero);
+    tcg_temp_free_i64(t_false);
+    arm_free_cc(&c);
 
-    if (cond < 0x0e) { /* continue */
-        gen_set_label(label_continue);
-    }
+    /* Note that sregs write back zeros to the high bits,
+       and we've already done the zero-extension.  */
+    write_fp_dreg(s, rd, t_true);
+    tcg_temp_free_i64(t_true);
 }
 
 /* C3.6.25 Floating-point data-processing (1 source) - single precision */
Signature · 1 line
2.1.0
#17 lore raw
In reply to Richard Henderson
Quoted 11 lines · Richard Henderson

While doing the mechanics of a previous patch set converting translators to use to TCGLabel pointers, I was reminded of several outstanding OPTME comments in the aarch64 translator.

I had started with the csel change, which at first failed and took quite some time to debug. See the comment for patch 1.

Since this depends on the outstanding TCGLabel patch set, the full tree is available at

git://github.com/rth7680/qemu.git arm-movcond

Alex, could you run this lot through the A64 risu testsuite, please?

thanks
-- PMM

#18 lore raw

It's running through LAVA now:

https://validation.linaro.org/scheduler/job/268253

Quoted 18 lines · Peter Maydell
Quoted 11 lines · Richard Henderson

While doing the mechanics of a previous patch set converting translators to use to TCGLabel pointers, I was reminded of several outstanding OPTME comments in the aarch64 translator.

I had started with the csel change, which at first failed and took quite some time to debug. See the comment for patch 1.

Since this depends on the outstanding TCGLabel patch set, the full tree is available at

git://github.com/rth7680/qemu.git arm-movcond

Alex, could you run this lot through the A64 risu testsuite, please?

thanks
-- PMM

Signature · 2 lines
Alex Bennée
KVM/QEMU Hacker for Linaro
#19 lore raw

https://validation.linaro.org/dashboard/streams/anonymous/alex.bennee/bundles/52315b57f77238f924b5528ad16cc549d93a9d31/2a7f8984-0d1c-4268-8249-ba86c56dcbb7/?search=&length=100#table

All passing on the current test set. I've got more to add when I get a chance,

Quoted 30 lines · Alex Bennée

It's running through LAVA now:

https://validation.linaro.org/scheduler/job/268253

Quoted 11 lines · Peter Maydell
Quoted 10 lines · Richard Henderson

While doing the mechanics of a previous patch set converting translators to use to TCGLabel pointers, I was reminded of several outstanding OPTME comments in the aarch64 translator.

I had started with the csel change, which at first failed and took quite some time to debug. See the comment for patch 1.

Since this depends on the outstanding TCGLabel patch set, the full tree is available at

Quoted 7 lines
Quoted 1 line

git://github.com/rth7680/qemu.git arm-movcond

Alex, could you run this lot through the A64 risu testsuite, please?

thanks
-- PMM

--
Alex Bennée
KVM/QEMU Hacker for Linaro

Signature · 2 lines
Alex Bennée
KVM/QEMU Hacker for Linaro
#20 lore raw
In reply to Richard Henderson
Quoted 11 lines · Richard Henderson

While doing the mechanics of a previous patch set converting translators to use to TCGLabel pointers, I was reminded of several outstanding OPTME comments in the aarch64 translator.

I had started with the csel change, which at first failed and took quite some time to debug. See the comment for patch 1.

Since this depends on the outstanding TCGLabel patch set, the full tree is available at

git://github.com/rth7680/qemu.git arm-movcond

Tested on both integer and FP tests. No regression found.

On the other hand, aarch64-linux-user seems to be significantly slower on a linux-user test I ran:

176.gcc with 166.i
Host: CPU E5-2650 v2 iwth CentOS 6.6 64-bit
time for standard QEMU: ~29s
time for RTH QEMU: ~33s

Is this expected?

Thanks,

Laurent

Quoted 28 lines

r~

Richard Henderson (11):
target-arm: Introduce DisasCompare
target-arm: Extend NZCF to 64 bits
target-arm: Handle always condition codes within arm_test_cc
target-arm: Recognize SXTB, SXTH, SXTW, ASR
target-arm: Recognize UXTB, UXTH, LSR, LSL
target-arm: Eliminate unnecessary zero-extend in disas_bitfield
target-arm: Recognize ROR
target-arm: Use setcond and movcond for csel
target-arm: Implement ccmp branchless
target-arm: Implement fccmp branchless
target-arm: Implement fcsel with movcond

 target-arm/cpu.h           |  21 +-
 target-arm/helper.c        |  18 +-
 target-arm/translate-a64.c | 688 ++++++++++++++++++++++++++-------------------
 target-arm/translate.c     | 151 ++++++----
 target-arm/translate.h     |   2 -
 5 files changed, 524 insertions(+), 356 deletions(-)

--
2.1.0

#21 lore raw
Quoted 18 lines · Laurent Desnogues
Quoted 11 lines · Richard Henderson

While doing the mechanics of a previous patch set converting translators to use to TCGLabel pointers, I was reminded of several outstanding OPTME comments in the aarch64 translator.

I had started with the csel change, which at first failed and took quite some time to debug. See the comment for patch 1.

Since this depends on the outstanding TCGLabel patch set, the full tree is available at

git://github.com/rth7680/qemu.git arm-movcond

Tested on both integer and FP tests. No regression found.

On the other hand, aarch64-linux-user seems to be significantly slower on a linux-user test I ran:

Quoted 6 lines

176.gcc with 166.i
Host: CPU E5-2650 v2 iwth CentOS 6.6 64-bit
time for standard QEMU: ~29s
time for RTH QEMU: ~33s

Is this expected?

Forget this, I had forgotten to switch to the arm-movcond branch...

This patch set breaks fccmp and various integer tests. I'll take a look this afternoon.

Laurent

Quoted 32 lines

Thanks,

Laurent

Quoted 28 lines

r~

Richard Henderson (11):
target-arm: Introduce DisasCompare
target-arm: Extend NZCF to 64 bits
target-arm: Handle always condition codes within arm_test_cc
target-arm: Recognize SXTB, SXTH, SXTW, ASR
target-arm: Recognize UXTB, UXTH, LSR, LSL
target-arm: Eliminate unnecessary zero-extend in disas_bitfield
target-arm: Recognize ROR
target-arm: Use setcond and movcond for csel
target-arm: Implement ccmp branchless
target-arm: Implement fccmp branchless
target-arm: Implement fcsel with movcond

 target-arm/cpu.h           |  21 +-
 target-arm/helper.c        |  18 +-
 target-arm/translate-a64.c | 688 ++++++++++++++++++++++++++-------------------
 target-arm/translate.c     | 151 ++++++----
 target-arm/translate.h     |   2 -
 5 files changed, 524 insertions(+), 356 deletions(-)

--
2.1.0

#22 lore raw
In reply to Richard Henderson

Hi Richard,

Quoted 11 lines · Richard Henderson

While doing the mechanics of a previous patch set converting translators to use to TCGLabel pointers, I was reminded of several outstanding OPTME comments in the aarch64 translator.

I had started with the csel change, which at first failed and took quite some time to debug. See the comment for patch 1.

Since this depends on the outstanding TCGLabel patch set, the full tree is available at

git://github.com/rth7680/qemu.git arm-movcond

With patch 10 (fccmp) removed and the handling of ALWAYS and NEVER added to tcg-op.c, I get no failure any more (and no significant speed change).

Thanks,

Laurent

Quoted 28 lines

r~

Richard Henderson (11):
target-arm: Introduce DisasCompare
target-arm: Extend NZCF to 64 bits
target-arm: Handle always condition codes within arm_test_cc
target-arm: Recognize SXTB, SXTH, SXTW, ASR
target-arm: Recognize UXTB, UXTH, LSR, LSL
target-arm: Eliminate unnecessary zero-extend in disas_bitfield
target-arm: Recognize ROR
target-arm: Use setcond and movcond for csel
target-arm: Implement ccmp branchless
target-arm: Implement fccmp branchless
target-arm: Implement fcsel with movcond

 target-arm/cpu.h           |  21 +-
 target-arm/helper.c        |  18 +-
 target-arm/translate-a64.c | 688 ++++++++++++++++++++++++++-------------------
 target-arm/translate.c     | 151 ++++++----
 target-arm/translate.h     |   2 -
 5 files changed, 524 insertions(+), 356 deletions(-)

--
2.1.0