Skip to contentSkip to conversation

tcg patch queue 20261030

GIT PULL Applied Richard Henderson 2 participants 25 messages Oct 30 – Nov 2 RISC-V

lore
Share & tools
lore
#0 lore raw

The following changes since commit 61436f5ff1c4e5ee8f60fa1a37962a60f73ea7a4:

Merge tag 'pbouvier/pr/dockerfiles-20261029' of https://gitlab.com/p-b-o/qemu into staging (2026-10-29 17:09:01 -0500)

are available in the Git repository at:

https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20261030

for you to fetch changes up to 0e68878f962a2117fc5de8a0025f3064bf5cbe9a:

tcg/s390x: Implement INDEX_op_lea (2026-10-30 07:06:16 -0500)

----------------------------------------------------------------
accel/tcg: Fix false awakening of gdb
accel/tcg: Do not flush and retry in place in tb_gen_code
tcg: Adjust NONNULL annotation on *_diff functions
tcg: Add tcg_gen_lea_{i32,i64,tl}
target/alpha: Use tcg_gen_lea_i64 for S{4,8}ADD{L,Q} target/loongarch: Use tcg_gen_lea_tl for ALSL target/riscv: Use tcg_gen_lea_tl for SH*ADD target/s390x: Use tcg_gen_lea_i64 in get_address target/i386: Use tcg_gen_lea_tl in gen_lea_modrm_1 target/mips: Use tcg_gen_lea() for [D]LSA and MXU S32LD*V opcodes

----------------------------------------------------------------
Aleksandr Sergeev (1):
accel/tcg: Fix false awakening of gdb

Philippe Mathieu-Daudé (1):
target/mips: Use tcg_gen_lea() for [D]LSA and MXU S32LD*V opcodes

Richard Henderson (16):
tcg: Adjust NONNULL annotation on *_diff functions
tcg: Add INDEX_op_lea
tcg: Add tcg_gen_lea_{i32,i64,tl} tcg/optimize: Handle INDEX_op_lea target/alpha: Use tcg_gen_lea_i64 for S{4,8}ADD{L,Q} target/loongarch: Use tcg_gen_lea_tl for ALSL target/riscv: Use tcg_gen_lea_tl for SH*ADD target/s390x: Use tcg_gen_lea_i64 in get_address target/i386: Use tcg_gen_lea_tl in gen_lea_modrm_1 tcg/x86_64: Introduce TCG_REG_NONE tcg/x86_64: Implement INDEX_op_lea tcg/loongarch64: Import SLADD insns tcg/loongarch64: Implement INDEX_op_lea tcg/aarch64: Implement INDEX_op_lea tcg/riscv64: Implement INDEX_op_lea tcg/s390x: Implement INDEX_op_lea

Stian Halseth (1):
accel/tcg: Do not flush and retry in place in tb_gen_code

 docs/devel/tcg-ops.rst                            |  4 ++
 include/tcg/tcg-op.h                              |  2 +
 include/tcg/tcg-opc.h                             |  1 +
 include/tcg/tcg.h                                 |  5 +-
 tcg/aarch64/tcg-target-has.h                      |  3 +
 tcg/loongarch64/tcg-target-has.h                  |  3 +
 tcg/ppc64/tcg-target-has.h                        |  3 +
 tcg/riscv64/tcg-target-has.h                      | 11 ++++
 tcg/s390x/tcg-target-has.h                        |  4 ++
 tcg/sparc64/tcg-target-has.h                      |  3 +
 tcg/tci/tcg-target-has.h                          |  3 +
 tcg/x86_64/tcg-target-con-set.h                   |  1 +
 tcg/x86_64/tcg-target-has.h                       |  3 +
 tcg/x86_64/tcg-target.h                           |  3 +
 include/tcg/tcg-op-def.h.inc                      |  1 +
 accel/tcg/cpu-exec.c                              | 20 +++---
 accel/tcg/translate-all.c                         | 11 ++--
 target/alpha/translate.c                          | 20 ++----
 target/i386/tcg/translate.c                       | 27 ++++----
 target/mips/tcg/mxu_translate.c                   |  3 +-
 target/mips/tcg/translate_addr_const.c            |  6 +-
 target/s390x/tcg/translate.c                      |  4 +-
 tcg/optimize.c                                    | 66 ++++++++++++++++++-
 tcg/tcg-op.c                                      | 43 ++++++++++++
 tcg/tcg.c                                         | 22 +++++++
 target/loongarch/tcg/insn_trans/trans_arith.c.inc |  4 +-
 target/riscv/tcg/insn_trans/trans_rvb.c.inc       |  5 +-
 tcg/aarch64/tcg-target.c.inc                      | 11 ++++
 tcg/loongarch64/tcg-insn-defs.c.inc               | 30 ++++++++-
 tcg/loongarch64/tcg-target.c.inc                  | 15 +++++
 tcg/ppc64/tcg-target.c.inc                        |  3 +
 tcg/riscv64/tcg-target.c.inc                      | 17 +++++
 tcg/s390x/tcg-target.c.inc                        | 14 ++++
 tcg/sparc64/tcg-target.c.inc                      |  3 +
 tcg/tci/tcg-target.c.inc                          |  4 ++
 tcg/x86_64/tcg-target.c.inc                       | 79 ++++++++++++++---------
 36 files changed, 363 insertions(+), 94 deletions(-)
#1 lore raw

[PULL 09/19] target/mips: Use tcg_gen_lea() for [D]LSA and MXU S32LD*V opcodes

From: Philippe Mathieu-Daudé <[email protected]>

Message-ID: <[email protected]>

---
 target/mips/tcg/mxu_translate.c        | 3 +--
 target/mips/tcg/translate_addr_const.c | 6 ++----
 2 files changed, 3 insertions(+), 6 deletions(-)
target/mips/tcg/mxu_translate.c +1 -2
index a38f4da12b..5361c94b34 100644
@@ -1596,8 +1596,7 @@ static void gen_mxu_s32ldxvx(DisasContext *ctx, bool reversed,
 
     gen_load_gpr(t0, Rb);
     gen_load_gpr(t1, Rc);
-    tcg_gen_shli_i32(t1, t1, strd2);
-    tcg_gen_add_i32(t0, t0, t1);
+    tcg_gen_lea_i32(t0, t0, t1, strd2, 0);
 
     tcg_gen_qemu_ld_i32(t1, t0, ctx->mem_idx,
                        MO_SL | mo_endian_rev(ctx, reversed) |
target/mips/tcg/translate_addr_const.c +2 -4
index 1d140e918d..910177e43b 100644
@@ -26,8 +26,7 @@ bool gen_lsa(DisasContext *ctx, int rd, int rt, int rs, int sa)
     t1 = tcg_temp_new();
     gen_load_gpr(t0, rs);
     gen_load_gpr(t1, rt);
-    tcg_gen_shli_tl(t0, t0, sa);
-    tcg_gen_add_tl(cpu_gpr[rd], t0, t1);
+    tcg_gen_lea_tl(cpu_gpr[rd], t1, t0, sa, 0);
     tcg_gen_ext32s_tl(cpu_gpr[rd], cpu_gpr[rd]);
     return true;
 }
@@ -47,7 +46,6 @@ bool gen_dlsa(DisasContext *ctx, int rd, int rt, int rs, int sa)
     t1 = tcg_temp_new();
     gen_load_gpr(t0, rs);
     gen_load_gpr(t1, rt);
-    tcg_gen_shli_tl(t0, t0, sa);
-    tcg_gen_add_tl(cpu_gpr[rd], t0, t1);
+    tcg_gen_lea_tl(cpu_gpr[rd], t1, t0, sa, 0);
     return true;
 }
Signature · 1 line
2.53.0
#2 lore raw

[PULL 10/19] target/riscv: Use tcg_gen_lea_tl for SH*ADD

In reply to Richard Henderson
---
 target/riscv/tcg/insn_trans/trans_rvb.c.inc | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
target/riscv/tcg/insn_trans/trans_rvb.c.inc +1 -4
index 3e74be223b..82e715c7b7 100644
@@ -336,10 +336,7 @@ static bool trans_orc_b(DisasContext *ctx, arg_orc_b *a)
 #define GEN_SHADD(SHAMT)                                       \
 static void gen_sh##SHAMT##add(TCGv ret, TCGv arg1, TCGv arg2) \
 {                                                              \
-    TCGv t = tcg_temp_new();                                   \
-                                                               \
-    tcg_gen_shli_tl(t, arg1, SHAMT);                           \
-    tcg_gen_add_tl(ret, t, arg2);                              \
+    tcg_gen_lea_tl(ret, arg2, arg1, SHAMT, 0);                 \
 }
 
 GEN_SHADD(1)
Signature · 1 line
2.53.0
#3 lore raw

[PULL 03/19] accel/tcg: Do not flush and retry in place in tb_gen_code

In reply to Richard Henderson

From: Stian Halseth <[email protected]>

When the code buffer is full in a serial context, tb_gen_code() flushes it and retries in place. cpu_exec_loop() then chains its last_tb, now freed, into the new TB. When that TB is invalidated, tb_jmp_unlink() follows the stale entry and qemu crashes inside its SIGSEGV handler.

Always queue the flush and leave through cpu_loop_exit(), as before commit ebf7a5d294a3. This also brings back the cleanup in cpu_loop_exit() and cpu_exec_longjmp_cleanup() that the retry skipped.

Since commit 25e5c6a320db ("accel/tcg: Allow cross-page goto_tb chaining in user-only builds"), user-only builds hit this easily, e.g. qemu-sparc64 -tb-size 1 on a program writing next to its PLT.

Fixes ebf7a5d294a3 ("accel/tcg: Improve buffer overflow in tb_gen_code")
---
 accel/tcg/translate-all.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
accel/tcg/translate-all.c +5 -6
index 328d96aba3..ea8257935e 100644
@@ -288,12 +288,11 @@ TranslationBlock *tb_gen_code(CPUState *cpu, TCGTBCPUState s)
     assert_no_pages_locked();
     tb = tcg_tb_alloc(tcg_ctx);
     if (unlikely(!tb)) {
-        /* flush must be done */
-        if (cpu_in_serial_context(cpu)) {
-            trace_tb_gen_code_buffer_overflow("tcg_tb_alloc");
-            tb_flush__exclusive_or_serial();
-            goto buffer_overflow;
-        }
+        /*
+         * Flush must be done.  Always exit the cpu loop so that the
+         * last_tb linkage within the inner cpu loop does not apply.
+         */
+        trace_tb_gen_code_buffer_overflow("tcg_tb_alloc");
         queue_tb_flush(cpu);
         mmap_unlock();
         /* Make the execution loop process the flush as soon as possible.  */
Signature · 1 line
2.53.0
#4 lore raw

[PULL 12/19] target/i386: Use tcg_gen_lea_tl in gen_lea_modrm_1

In reply to Richard Henderson
---
 target/i386/tcg/translate.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
target/i386/tcg/translate.c +14 -13
index dd417cb534..5199c330ac 100644
@@ -1698,31 +1698,32 @@ static TCGv gen_shiftd_rm_T1(DisasContext *s, MemOp ot,
 /* Compute the address, with a minimum number of TCG ops.  */
 static TCGv gen_lea_modrm_1(DisasContext *s, AddressParts a, bool is_vsib)
 {
-    TCGv ea = NULL;
+    TCGv ea = (a.base >= 0 ? cpu_regs[a.base] : NULL);
 
     if (a.index >= 0 && !is_vsib) {
+        TCGv index = cpu_regs[a.index];
+
+        if (ea) {
+            tcg_gen_lea_tl(s->A0, ea, index, a.scale, a.disp);
+            return s->A0;
+        }
         if (a.scale == 0) {
-            ea = cpu_regs[a.index];
+            ea = index;
         } else {
-            tcg_gen_shli_tl(s->A0, cpu_regs[a.index], a.scale);
+            tcg_gen_shli_tl(s->A0, index, a.scale);
             ea = s->A0;
         }
-        if (a.base >= 0) {
-            tcg_gen_add_tl(s->A0, ea, cpu_regs[a.base]);
-            ea = s->A0;
-        }
-    } else if (a.base >= 0) {
-        ea = cpu_regs[a.base];
-    }
-    if (!ea) {
+    } else if (!ea) {
         if (tb_cflags(s->base.tb) & CF_PCREL && a.base == -2) {
             /* With cpu_eip ~= pc_save, the expression is pc-relative. */
             tcg_gen_addi_tl(s->A0, cpu_eip, a.disp - s->pc_save);
         } else {
             tcg_gen_movi_tl(s->A0, a.disp);
         }
-        ea = s->A0;
-    } else if (a.disp != 0) {
+        return s->A0;
+    }
+
+    if (a.disp != 0) {
         tcg_gen_addi_tl(s->A0, ea, a.disp);
         ea = s->A0;
     }
Signature · 1 line
2.53.0
#5 lore raw

[PULL 02/19] accel/tcg: Fix false awakening of gdb

In reply to Richard Henderson

From: Aleksandr Sergeev <[email protected]>

In qemu there is a mechanism to cancel execution of tb. If cpu->neg.icount_decr is <0, translation block will exit in prolog.
E.g. such may happen when RCU thread kicks out vCPU.

If tb is not executed, we shall not raise EXCP_DEBUG, because no step actually happened.

Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4766

Message-ID: <[email protected]>

---
 accel/tcg/cpu-exec.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
accel/tcg/cpu-exec.c +10 -10
index 9ead35418d..4497701486 100644
@@ -478,16 +478,16 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
                          last_tb->tc.ptr, pc, lookup_symbol(pc));
             }
         }
-    }
-
-    /*
-     * If gdb single-step, and we haven't raised another exception,
-     * raise a debug exception.  Single-step with another exception
-     * is handled in cpu_handle_exception.
-     */
-    if (unlikely(cpu_single_stepping(cpu)) && cpu->exception_index == -1) {
-        cpu->exception_index = EXCP_DEBUG;
-        cpu_loop_exit(cpu);
+    } else {
+        /*
+         * If gdb single-step, and we haven't raised another exception,
+         * raise a debug exception.  Single-step with another exception
+         * is handled in cpu_handle_exception.
+         */
+        if (unlikely(cpu_single_stepping(cpu)) && cpu->exception_index == -1) {
+            cpu->exception_index = EXCP_DEBUG;
+            cpu_loop_exit(cpu);
+        }
     }
 
     return last_tb;
Signature · 1 line
2.53.0
#6 lore raw

[PULL 07/19] target/alpha: Use tcg_gen_lea_i64 for S{4,8}ADD{L,Q}

In reply to Richard Henderson
---
 target/alpha/translate.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)
target/alpha/translate.c +6 -14
index c66e3f9c14..6f18b8d1af 100644
@@ -1474,10 +1474,8 @@ static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)
             break;
         case 0x02:
             /* S4ADDL */
-            tmp = tcg_temp_new_i64();
-            tcg_gen_shli_i64(tmp, va, 2);
-            tcg_gen_add_i64(tmp, tmp, vb);
-            tcg_gen_ext32s_i64(vc, tmp);
+            tcg_gen_lea_i64(vc, vb, va, 2, 0);
+            tcg_gen_ext32s_i64(vc, vc);
             break;
         case 0x09:
             /* SUBL */
@@ -1502,10 +1500,8 @@ static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)
             break;
         case 0x12:
             /* S8ADDL */
-            tmp = tcg_temp_new_i64();
-            tcg_gen_shli_i64(tmp, va, 3);
-            tcg_gen_add_i64(tmp, tmp, vb);
-            tcg_gen_ext32s_i64(vc, tmp);
+            tcg_gen_lea_i64(vc, vb, va, 3, 0);
+            tcg_gen_ext32s_i64(vc, vc);
             break;
         case 0x1B:
             /* S8SUBL */
@@ -1524,9 +1520,7 @@ static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)
             break;
         case 0x22:
             /* S4ADDQ */
-            tmp = tcg_temp_new_i64();
-            tcg_gen_shli_i64(tmp, va, 2);
-            tcg_gen_add_i64(vc, tmp, vb);
+            tcg_gen_lea_i64(vc, vb, va, 2, 0);
             break;
         case 0x29:
             /* SUBQ */
@@ -1544,9 +1538,7 @@ static DisasJumpType translate_one(DisasContext *ctx, uint32_t insn)
             break;
         case 0x32:
             /* S8ADDQ */
-            tmp = tcg_temp_new_i64();
-            tcg_gen_shli_i64(tmp, va, 3);
-            tcg_gen_add_i64(vc, tmp, vb);
+            tcg_gen_lea_i64(vc, vb, va, 3, 0);
             break;
         case 0x3B:
             /* S8SUBQ */
Signature · 1 line
2.53.0
#7 lore raw

[PULL 05/19] tcg: Add tcg_gen_lea_{i32,i64,tl}

In reply to Richard Henderson
---
 include/tcg/tcg-op.h         |  2 ++
 include/tcg/tcg-op-def.h.inc |  1 +
 tcg/tcg-op.c                 | 43 ++++++++++++++++++++++++++++++++++++
 3 files changed, 46 insertions(+)
include/tcg/tcg-op.h +2 -0
index 3721164236..a7d001c959 100644
@@ -83,6 +83,7 @@ typedef TCGv_i64 TCGv;
 #define tcg_gen_shri_tl tcg_gen_shri_i64
 #define tcg_gen_sar_tl tcg_gen_sar_i64
 #define tcg_gen_sari_tl tcg_gen_sari_i64
+#define tcg_gen_lea_tl tcg_gen_lea_i64
 #define tcg_gen_brcond_tl tcg_gen_brcond_i64
 #define tcg_gen_brcondi_tl tcg_gen_brcondi_i64
 #define tcg_gen_setcond_tl tcg_gen_setcond_i64
@@ -209,6 +210,7 @@ typedef TCGv_i64 TCGv;
 #define tcg_gen_shri_tl tcg_gen_shri_i32
 #define tcg_gen_sar_tl tcg_gen_sar_i32
 #define tcg_gen_sari_tl tcg_gen_sari_i32
+#define tcg_gen_lea_tl tcg_gen_lea_i32
 #define tcg_gen_brcond_tl tcg_gen_brcond_i32
 #define tcg_gen_brcondi_tl tcg_gen_brcondi_i32
 #define tcg_gen_setcond_tl tcg_gen_setcond_i32
include/tcg/tcg-op-def.h.inc +1 -0
index e694f0e38c..c9caab2138 100644
@@ -37,6 +37,7 @@ DEF3(ld8s, TCGV, TCGv_ptr, tcg_target_long)
 DEF3(ld8u, TCGV, TCGv_ptr, tcg_target_long)
 DEF3(ld16s, TCGV, TCGv_ptr, tcg_target_long)
 DEF3(ld16u, TCGV, TCGv_ptr, tcg_target_long)
+DEF5(lea, TCGV, TCGV, TCGV, unsigned, TINT)
 DEF2(mov, TCGV, TCGV)
 DEF2(movi, TCGV, TINT)
 DEF6(movcond, TCGCond, TCGV, TCGV, TCGV, TCGV, TCGV)
tcg/tcg-op.c +43 -0

49 lines not on this page · raw message

Signature · 1 line
2.53.0
#8 lore raw

[PULL 06/19] tcg/optimize: Handle INDEX_op_lea

In reply to Richard Henderson
---
 tcg/optimize.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)
tcg/optimize.c +65 -1
index 294eb5ed29..a518707887 100644
@@ -2106,6 +2106,68 @@ static bool fold_extu(OptContext *ctx, TCGOp *op)
     return fold_masks_zo(ctx, op, z_mask, o_mask);
 }
 
+static bool fold_shift(OptContext *ctx, TCGOp *op);
+static bool fold_lea(OptContext *ctx, TCGOp *op)
+{
+    TCGArg sh = op->args[3];
+    TCGArg imm = op->args[4];
+    int var_mask = 0;
+
+    if (arg_is_const(op->args[1])) {
+        imm += arg_const_val(op->args[1]);
+    } else {
+        var_mask |= 1;
+    }
+    if (arg_is_const(op->args[2])) {
+        imm += arg_const_val(op->args[2]) << sh;
+    } else {
+        var_mask |= 2;
+    }
+
+    switch (var_mask) {
+    case 0:
+        return tcg_opt_gen_movi(ctx, op, op->args[0], imm);
+
+    case 1:
+        if (imm == 0) {
+            return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[1]);
+        }
+        op->opc = INDEX_op_add;
+        op->args[2] = arg_new_constant(ctx, imm);
+        break;
+
+    case 2:
+        if (sh == 0) {
+            if (imm == 0) {
+                return tcg_opt_gen_mov(ctx, op, op->args[0], op->args[2]);
+            }
+            op->opc = INDEX_op_add;
+            op->args[1] = op->args[2];
+            op->args[2] = arg_new_constant(ctx, imm);
+            break;
+        }
+        if (imm == 0) {
+            op->opc = INDEX_op_shl;
+            op->args[1] = op->args[2];
+            op->args[2] = arg_new_constant(ctx, sh);
+            return fold_shift(ctx, op);
+        }
+
+        /* If arg1 was not already 0, fold the immediates. */
+        if (arg_const_val(op->args[1]) != 0) {
+            if (TCG_TARGET_lea_imm_valid(ctx->type, imm)) {
+                op->args[1] = arg_new_constant(ctx, 0);
+                op->args[4] = imm;
+            } else {
+                op->args[1] = arg_new_constant(ctx, imm);
+                op->args[4] = 0;
+            }
+        }
+        break;
+    }
+    return finish_folding(ctx, op);
+}
+
 static bool fold_mb(OptContext *ctx, TCGOp *op)
 {
     /* Eliminate duplicate and redundant fence instructions.  */
@@ -2218,7 +2280,6 @@ static bool fold_mul_highpart(OptContext *ctx, TCGOp *op)
     return finish_folding(ctx, op);
 }
 
-static bool fold_shift(OptContext *ctx, TCGOp *op);
 static bool fold_multiply2(OptContext *ctx, TCGOp *op)
 {
     swap_commutative(op->args[0], &op->args[2], &op->args[3]);
@@ -3220,6 +3281,9 @@ void tcg_optimize(TCGContext *s)
         case INDEX_op_st_vec:
             done = fold_tcg_st_memcopy(&ctx, op);
             break;
+        case INDEX_op_lea:
+            done = fold_lea(&ctx, op);
+            break;
         case INDEX_op_mb:
             done = fold_mb(&ctx, op);
             break;
Signature · 1 line
2.53.0
#9 lore raw

[PULL 01/19] tcg: Adjust NONNULL annotation on *_diff functions

In reply to Richard Henderson

In tcg/sparc64 we use tcg_tbrel_diff with NULL as a negative addend in a relocation.

Fixes b0b6701a4018 ("tcg: Annotate functions in tcg.h with QEMU_*_NONNULL")
---
 include/tcg/tcg.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
include/tcg/tcg.h +2 -3
index 8f409b23b7..3dc26b919d 100644
@@ -881,7 +881,6 @@ static inline TCGLabel *arg_label(TCGArg i)
  * This version relies on GCC's void pointer arithmetic to get the
  * correct result.
  */
-QEMU_ARG_NONNULL
 static inline ptrdiff_t tcg_ptr_byte_diff(const void *a, const void *b)
 {
     return a - b;
@@ -895,7 +894,7 @@ static inline ptrdiff_t tcg_ptr_byte_diff(const void *a, const void *b)
  * Produce a pc-relative difference, from the current code_ptr
  * to the destination address.
  */
-QEMU_ARG_NONNULL
+QEMU_ARG_LIST_NONNULL(1)
 static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, const void *target)
 {
     return tcg_ptr_byte_diff(target, tcg_splitwx_to_rx(s->code_ptr));
@@ -909,7 +908,7 @@ static inline ptrdiff_t tcg_pcrel_diff(TCGContext *s, const void *target)
  * Produce a difference, from the beginning of the current TB code
  * to the destination address.
  */
-QEMU_ARG_NONNULL
+QEMU_ARG_LIST_NONNULL(1)
 static inline ptrdiff_t tcg_tbrel_diff(TCGContext *s, const void *target)
 {
     return tcg_ptr_byte_diff(target, tcg_splitwx_to_rx(s->code_buf));
Signature · 1 line
2.53.0
#10 lore raw

[PULL 19/19] tcg/s390x: Implement INDEX_op_lea

In reply to Richard Henderson
---
 tcg/s390x/tcg-target-has.h |  5 +++--
 tcg/s390x/tcg-target.c.inc | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 3 deletions(-)
tcg/s390x/tcg-target-has.h +3 -2
index 58e3afe526..33a3b72318 100644
@@ -77,7 +77,8 @@ tcg_target_sextract_valid(TCGType type, unsigned ofs, unsigned len)
 }
 #define TCG_TARGET_sextract_valid  tcg_target_sextract_valid
 
-#define TCG_TARGET_lea_sh_valid(type, sh)          0
-#define TCG_TARGET_lea_imm_valid(type, imm)        0
+#define TCG_TARGET_lea_sh_valid(type, sh)          ((sh) == 0)
+#define TCG_TARGET_lea_imm_valid(type, imm)        \
+    ((imm) >= -0x80000 && (imm) < 0x80000)
 
 #endif
tcg/s390x/tcg-target.c.inc +12 -1
index 2fd7012d04..db3b2fc3c9 100644
@@ -3187,8 +3187,19 @@ static const TCGOutOpStore outop_st = {
     .out_r = tcg_out_st,
 };
 
+static void tgen_lea(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1,
+                     TCGReg a2, unsigned sh, tcg_target_long imm)
+{
+    if (imm >= 0 && imm < 0x1000) {
+        tcg_out_insn(s, RX, LA, a0, a1, a2, imm);
+    } else {
+        tcg_out_insn(s, RXY, LAY, a0, a1, a2, imm);
+    }
+}
+
 static const TCGOutOpLea outop_lea = {
-    .base.static_constraint = C_NotImplemented,
+    .base.static_constraint = C_O1_I2(r, r, r),
+    .out = tgen_lea,
 };
 
 static bool tcg_out_dup_vec(TCGContext *s, TCGType type, unsigned vece,
Signature · 1 line
2.53.0
#11 lore raw

[PULL 04/19] tcg: Add INDEX_op_lea

In reply to Richard Henderson

Add an opcode for compound address formation.

---
 docs/devel/tcg-ops.rst           |  4 ++++
 include/tcg/tcg-opc.h            |  1 +
 tcg/aarch64/tcg-target-has.h     |  3 +++
 tcg/loongarch64/tcg-target-has.h |  3 +++
 tcg/ppc64/tcg-target-has.h       |  3 +++
 tcg/riscv64/tcg-target-has.h     |  3 +++
 tcg/s390x/tcg-target-has.h       |  3 +++
 tcg/sparc64/tcg-target-has.h     |  3 +++
 tcg/tci/tcg-target-has.h         |  3 +++
 tcg/x86_64/tcg-target-has.h      |  3 +++
 tcg/tcg.c                        | 22 ++++++++++++++++++++++
 tcg/aarch64/tcg-target.c.inc     |  4 ++++
 tcg/loongarch64/tcg-target.c.inc |  4 ++++
 tcg/ppc64/tcg-target.c.inc       |  3 +++
 tcg/riscv64/tcg-target.c.inc     |  3 +++
 tcg/s390x/tcg-target.c.inc       |  3 +++
 tcg/sparc64/tcg-target.c.inc     |  3 +++
 tcg/tci/tcg-target.c.inc         |  4 ++++
 tcg/x86_64/tcg-target.c.inc      |  4 ++++
 19 files changed, 79 insertions(+)
docs/devel/tcg-ops.rst +4 -0
index 88d48a1f99..51fa183e91 100644
@@ -524,6 +524,10 @@ Misc
 
      - | Reverse the 64 bits of input *t1* with output in *dest*.
 
+   * - lea *dest*, *t1*, *t2*, *sh*, *imm*
+
+     - | *dest* = *t1* + (*t2* << *sh*) + *imm*.
+
 Conditional moves
 -----------------
 
include/tcg/tcg-opc.h +1 -0
index f3a81d5d7f..884345afe5 100644
@@ -64,6 +64,7 @@ DEF(ld16s, 1, 1, 1, TCG_OPF_INT)
 DEF(ld32u, 1, 1, 1, TCG_OPF_INT)
 DEF(ld32s, 1, 1, 1, TCG_OPF_INT)
 DEF(ld, 1, 1, 1, TCG_OPF_INT)
+DEF(lea, 1, 2, 2, TCG_OPF_INT)
 DEF(movcond, 1, 4, 1, TCG_OPF_INT)
 DEF(mul, 1, 2, 0, TCG_OPF_INT)
 DEF(muls2, 2, 2, 0, TCG_OPF_INT)
tcg/aarch64/tcg-target-has.h +3 -0
index 69e83efb69..86672b2eab 100644
@@ -57,4 +57,7 @@
 #define TCG_TARGET_sextract_valid(type, ofs, len)  1
 #define TCG_TARGET_deposit_valid(type, ofs, len)   1
 
+#define TCG_TARGET_lea_sh_valid(type, sh)          0
+#define TCG_TARGET_lea_imm_valid(type, imm)        0
+
 #endif
tcg/loongarch64/tcg-target-has.h +3 -0
index 32abc6f457..31e6ea9632 100644
@@ -54,4 +54,7 @@ tcg_target_sextract_valid(TCGType type, unsigned ofs, unsigned len)
 }
 #define TCG_TARGET_sextract_valid  tcg_target_sextract_valid
 
+#define TCG_TARGET_lea_sh_valid(type, sh)          0
+#define TCG_TARGET_lea_imm_valid(type, imm)        0
+
 #endif
tcg/ppc64/tcg-target-has.h +3 -0
index a3711feeae..d11d82f184 100644
@@ -66,4 +66,7 @@ tcg_target_sextract_valid(TCGType type, unsigned ofs, unsigned len)
 }
 #define TCG_TARGET_sextract_valid  tcg_target_sextract_valid
 
+#define TCG_TARGET_lea_sh_valid(type, sh)          0
+#define TCG_TARGET_lea_imm_valid(type, imm)        0
+
 #endif
tcg/riscv64/tcg-target-has.h +3 -0
index aef10c2d9d..93f8baad09 100644
@@ -69,4 +69,7 @@ tcg_target_sextract_valid(TCGType type, unsigned ofs, unsigned len)
 
 #define TCG_TARGET_deposit_valid(type, ofs, len)  0
 
+#define TCG_TARGET_lea_sh_valid(type, sh)         0
+#define TCG_TARGET_lea_imm_valid(type, imm)       0
+
 #endif
tcg/s390x/tcg-target-has.h +3 -0
index 0aeb5ba01a..58e3afe526 100644
@@ -77,4 +77,7 @@ tcg_target_sextract_valid(TCGType type, unsigned ofs, unsigned len)
 }
 #define TCG_TARGET_sextract_valid  tcg_target_sextract_valid
 
+#define TCG_TARGET_lea_sh_valid(type, sh)          0
+#define TCG_TARGET_lea_imm_valid(type, imm)        0
+
 #endif
tcg/sparc64/tcg-target-has.h +3 -0
index b29fd177f6..4182a7c1aa 100644
@@ -19,4 +19,7 @@
 
 #define TCG_TARGET_deposit_valid(type, ofs, len) 0
 
+#define TCG_TARGET_lea_sh_valid(type, sh)          0
+#define TCG_TARGET_lea_imm_valid(type, imm)        0
+
 #endif
tcg/tci/tcg-target-has.h +3 -0
index 64742cf0b7..f4f9ddf595 100644
@@ -17,4 +17,7 @@
 #define TCG_TARGET_sextract_valid(type, ofs, len)  1
 #define TCG_TARGET_deposit_valid(type, ofs, len)   1
 
+#define TCG_TARGET_lea_sh_valid(type, sh)          0
+#define TCG_TARGET_lea_imm_valid(type, imm)        0
+
 #endif
tcg/x86_64/tcg-target-has.h +3 -0
index d249c1b3e7..6ffae51f92 100644
@@ -105,4 +105,7 @@ tcg_target_extract_valid(TCGType type, unsigned ofs, unsigned len)
 }
 #define TCG_TARGET_extract_valid  tcg_target_extract_valid
 
+#define TCG_TARGET_lea_sh_valid(type, sh)          0
+#define TCG_TARGET_lea_imm_valid(type, imm)        0
+
 #endif
tcg/tcg.c +22 -0
index 1cd6d41d31..d19c3fb857 100644
@@ -1095,6 +1095,12 @@ typedef struct TCGOutOpSubtract {
                     TCGReg a0, tcg_target_long a1, TCGReg a2);
 } TCGOutOpSubtract;
 
+typedef struct TCGOutOpLea {
+    TCGOutOp base;
+    void (*out)(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1,
+                TCGReg a2, unsigned sh, tcg_target_long imm);
+} TCGOutOpLea;
+
 #include "tcg-target.c.inc"
 
 #ifndef CONFIG_TCG_INTERPRETER
@@ -1191,6 +1197,7 @@ static const TCGOutOp * const all_outop[NB_OPS] = {
     OUTOP(INDEX_op_ld16u, TCGOutOpLoad, outop_ld16u),
     OUTOP(INDEX_op_ld32s, TCGOutOpLoad, outop_ld32s),
     OUTOP(INDEX_op_ld32u, TCGOutOpLoad, outop_ld32u),
+    OUTOP(INDEX_op_lea, TCGOutOpLea, outop_lea),
     OUTOP(INDEX_op_movcond, TCGOutOpMovcond, outop_movcond),
     OUTOP(INDEX_op_mul, TCGOutOpBinary, outop_mul),
     OUTOP(INDEX_op_muls2, TCGOutOpMul2, outop_muls2),
@@ -5796,6 +5803,21 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp *op)
         }
         break;
 
+    case INDEX_op_lea:
+        {
+            const TCGOutOpLea *out = &outop_lea;
+            int sh = new_args[3];
+            tcg_target_long imm = new_args[4];
+
+            tcg_debug_assert(!const_args[1]);
+            tcg_debug_assert(!const_args[2]);
+            tcg_debug_assert(TCG_TARGET_lea_sh_valid(type, sh));
+            tcg_debug_assert(TCG_TARGET_lea_imm_valid(type, imm));
+
+            out->out(s, type, new_args[0], new_args[1], new_args[2], sh, imm);
+        }
+        break;
+
     case INDEX_op_goto_ptr:
         tcg_debug_assert(!const_args[0]);
         tcg_out_goto_ptr(s, new_args[0]);
tcg/aarch64/tcg-target.c.inc +4 -0
index 273462ca61..b601b19c7f 100644
@@ -3081,6 +3081,10 @@ static const TCGOutOpStore outop_st = {
     .out_r = tcg_out_st,
 };
 
+static const TCGOutOpLea outop_lea = {
+    .base.static_constraint = C_NotImplemented,
+};
+
 static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
                            unsigned vecl, unsigned vece,
                            const TCGArg args[TCG_MAX_OP_ARGS],
tcg/loongarch64/tcg-target.c.inc +4 -0
index 69e76807d6..17784d8bbe 100644
@@ -2098,6 +2098,10 @@ static const TCGOutOpStore outop_st = {
     .out_r = tcg_out_st,
 };
 
+static const TCGOutOpLea outop_lea = {
+    .base.static_constraint = C_NotImplemented,
+};
+
 static bool tcg_out_dup_vec(TCGContext *s, TCGType type, unsigned vece,
                             TCGReg rd, TCGReg rs)
 {
tcg/ppc64/tcg-target.c.inc +3 -0
index cd1c234367..99f4469f4b 100644
@@ -3633,6 +3633,9 @@ static const TCGOutOpStore outop_st = {
     .out_r = tcg_out_st,
 };
 
+static const TCGOutOpLea outop_lea = {
+    .base.static_constraint = C_NotImplemented,
+};
 
 int tcg_can_emit_vec_op(TCGOpcode opc, TCGType type, unsigned vece)
 {
tcg/riscv64/tcg-target.c.inc +3 -0
index 03f32c5819..ec0c8e1af0 100644
@@ -2740,6 +2740,9 @@ static const TCGOutOpStore outop_st = {
     .out_r = tcg_out_st,
 };
 
+static const TCGOutOpLea outop_lea = {
+    .base.static_constraint = C_NotImplemented,
+};
 
 static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
                            unsigned vecl, unsigned vece,
tcg/s390x/tcg-target.c.inc +3 -0
index 4d1a779c47..2fd7012d04 100644
@@ -3187,6 +3187,9 @@ static const TCGOutOpStore outop_st = {
     .out_r = tcg_out_st,
 };
 
+static const TCGOutOpLea outop_lea = {
+    .base.static_constraint = C_NotImplemented,
+};
 
 static bool tcg_out_dup_vec(TCGContext *s, TCGType type, unsigned vece,
                             TCGReg dst, TCGReg src)
tcg/sparc64/tcg-target.c.inc +3 -0
index 35cd14a5b6..cb457453ff 100644
@@ -2120,6 +2120,9 @@ static const TCGOutOpStore outop_st = {
     .out_r = tcg_out_st,
 };
 
+static const TCGOutOpLea outop_lea = {
+    .base.static_constraint = C_NotImplemented,
+};
 
 static TCGConstraintSetIndex
 tcg_target_op_def(TCGOpcode op, TCGType type, unsigned flags)
tcg/tci/tcg-target.c.inc +4 -0
index 4cd1c1431c..6942fdbb4e 100644
@@ -1220,6 +1220,10 @@ static inline bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val,
     return false;
 }
 
+static const TCGOutOpLea outop_lea = {
+    .base.static_constraint = C_NotImplemented,
+};
+
 /* Test if a constant matches the constraint. */
 static bool tcg_target_const_match(int64_t val, int ct,
                                    TCGType type, TCGCond cond, int vece)
tcg/x86_64/tcg-target.c.inc +4 -0
index 590c9c2402..46efee87e6 100644
@@ -3357,6 +3357,10 @@ static const TCGOutOpStore outop_st = {
     .out_i = tgen_st_i,
 };
 
+static const TCGOutOpLea outop_lea = {
+    .base.static_constraint = C_NotImplemented,
+};
+
 static int const umin_insn[4] = {
     OPC_PMINUB, OPC_PMINUW, OPC_PMINUD, OPC_VPMINUQ
 };
Signature · 1 line
2.53.0
#12 lore raw

[PULL 11/19] target/s390x: Use tcg_gen_lea_i64 in get_address

In reply to Richard Henderson

While there's no actual shift, use the compound function to add two registers and an immediate in one step.

---
 target/s390x/tcg/translate.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
target/s390x/tcg/translate.c +2 -2
index 474d604ed1..ce55edb93a 100644
@@ -460,8 +460,8 @@ static TCGv_i64 get_address(DisasContext *s, int x2, int b2, int d2)
      * displacements early we create larger immediate addends.
      */
     if (b2 && x2) {
-        tcg_gen_add_i64(tmp, regs[b2], regs[x2]);
-        gen_addi_and_wrap_i64(s, tmp, tmp, d2);
+        tcg_gen_lea_i64(tmp, regs[b2], regs[x2], 0, d2);
+        gen_addi_and_wrap_i64(s, tmp, tmp, 0);
     } else if (b2) {
         gen_addi_and_wrap_i64(s, tmp, regs[b2], d2);
     } else if (x2) {
Signature · 1 line
2.53.0
#13 lore raw

[PULL 14/19] tcg/x86_64: Implement INDEX_op_lea

In reply to Richard Henderson
---
 tcg/x86_64/tcg-target-con-set.h |  1 +
 tcg/x86_64/tcg-target-has.h     |  4 ++--
 tcg/x86_64/tcg-target.h         |  2 ++
 tcg/x86_64/tcg-target.c.inc     | 11 ++++++++++-
 4 files changed, 15 insertions(+), 3 deletions(-)
tcg/x86_64/tcg-target-con-set.h +1 -0
index 7df9bf4917..2529539f89 100644
@@ -47,6 +47,7 @@ C_O1_I2(r, r, r)
 C_O1_I2(r, r, re)
 C_O1_I2(r, r, ri)
 C_O1_I2(r, rO, re)
+C_O1_I2(r, rz, r)
 C_O1_I2(x, x, x)
 C_N1_I2(r, r, r)
 C_N1_I2(r, r, rW)
tcg/x86_64/tcg-target-has.h +2 -2
index 6ffae51f92..f1d3d256ee 100644
@@ -105,7 +105,7 @@ tcg_target_extract_valid(TCGType type, unsigned ofs, unsigned len)
 }
 #define TCG_TARGET_extract_valid  tcg_target_extract_valid
 
-#define TCG_TARGET_lea_sh_valid(type, sh)          0
-#define TCG_TARGET_lea_imm_valid(type, imm)        0
+#define TCG_TARGET_lea_sh_valid(type, sh)          ((sh) <= 3)
+#define TCG_TARGET_lea_imm_valid(type, imm)        ((imm) == (int32_t)(imm))
 
 #endif
tcg/x86_64/tcg-target.h +2 -0
index 7109722f24..3444bcdca0 100644
@@ -80,4 +80,6 @@ typedef enum {
     TCG_REG_CALL_STACK = TCG_REG_ESP
 } TCGReg;
 
+#define TCG_REG_ZERO  TCG_REG_NONE
+
 #endif
tcg/x86_64/tcg-target.c.inc +10 -1
index d85e95a32b..3fca0693e2 100644
@@ -3361,8 +3361,17 @@ static const TCGOutOpStore outop_st = {
     .out_i = tgen_st_i,
 };
 
+static void tgen_lea(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1,
+                     TCGReg a2, unsigned sh, tcg_target_long imm)
+{
+    int rexw = type == TCG_TYPE_I32 ? 0 : P_REXW;
+    tcg_out_modrm_sib_offset(s, OPC_LEA + rexw, a0, a1, a2, sh, imm);
+}
+
 static const TCGOutOpLea outop_lea = {
-    .base.static_constraint = C_NotImplemented,
+    /* Allow "lea imm(, a2, sh), a0" via TCG_REG_ZERO constraint */
+    .base.static_constraint = C_O1_I2(r, rz, r),
+    .out = tgen_lea,
 };
 
 static int const umin_insn[4] = {
Signature · 1 line
2.53.0
#14 lore raw

[PULL 15/19] tcg/loongarch64: Import SLADD insns

In reply to Richard Henderson
---
 tcg/loongarch64/tcg-insn-defs.c.inc | 30 ++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
tcg/loongarch64/tcg-insn-defs.c.inc +29 -1
index e907fc755f..ececc6a3dd 100644
@@ -4,7 +4,7 @@
  *
  * This file is auto-generated by genqemutcgdefs from
  * https://github.com/loongson-community/loongarch-opcodes,
- * from commit 1b95bb8c443ad71e266120fd97bd227df2d8ecfc.
+ * from commit 2d84c975e8894afc8b3ee9b8559f10308a658440.
  * DO NOT EDIT.
  */
 
@@ -24,6 +24,7 @@ typedef enum {
     OPC_REVBIT_D = 0x00005400,
     OPC_SEXT_H = 0x00005800,
     OPC_SEXT_B = 0x00005c00,
+    OPC_SLADD_W = 0x00040000,
     OPC_ADD_W = 0x00100000,
     OPC_ADD_D = 0x00108000,
     OPC_SUB_W = 0x00110000,
@@ -62,6 +63,7 @@ typedef enum {
     OPC_MOD_D = 0x00228000,
     OPC_DIV_DU = 0x00230000,
     OPC_MOD_DU = 0x00238000,
+    OPC_SLADD_D = 0x002c0000,
     OPC_SLLI_W = 0x00408000,
     OPC_SLLI_D = 0x00410000,
     OPC_SRLI_W = 0x00448000,
@@ -619,6 +621,18 @@ encode_djk_insn(LoongArchInsn opc, TCGReg d, TCGReg j, TCGReg k)
     return encode_djk_slots(opc, d, j, k);
 }
 
+static int32_t __attribute__((unused)) encode_djkua2_insn(LoongArchInsn opc,
+                                                          TCGReg d, TCGReg j,
+                                                          TCGReg k,
+                                                          uint32_t ua2)
+{
+    tcg_debug_assert(d >= 0 && d <= 0x1f);
+    tcg_debug_assert(j >= 0 && j <= 0x1f);
+    tcg_debug_assert(k >= 0 && k <= 0x1f);
+    tcg_debug_assert(ua2 <= 0x3);
+    return encode_djka_slots(opc, d, j, k, ua2);
+}
+
 static int32_t __attribute__((unused))
 encode_djsk12_insn(LoongArchInsn opc, TCGReg d, TCGReg j, int32_t sk12)
 {
@@ -1426,6 +1440,13 @@ static void __attribute__((unused)) tcg_out_opc_sext_b(TCGContext *s, TCGReg d,
     tcg_out32(s, encode_dj_insn(OPC_SEXT_B, d, j));
 }
 
+/* Emits the `sladd.w d, j, k, ua2` instruction.  */
+static void __attribute__((unused))
+tcg_out_opc_sladd_w(TCGContext *s, TCGReg d, TCGReg j, TCGReg k, uint32_t ua2)
+{
+    tcg_out32(s, encode_djkua2_insn(OPC_SLADD_W, d, j, k, ua2));
+}
+
 /* Emits the `add.w d, j, k` instruction.  */
 static void __attribute__((unused)) tcg_out_opc_add_w(TCGContext *s, TCGReg d,
                                                       TCGReg j, TCGReg k)
@@ -1692,6 +1713,13 @@ static void __attribute__((unused)) tcg_out_opc_mod_du(TCGContext *s, TCGReg d,
     tcg_out32(s, encode_djk_insn(OPC_MOD_DU, d, j, k));
 }
 
+/* Emits the `sladd.d d, j, k, ua2` instruction.  */
+static void __attribute__((unused))
+tcg_out_opc_sladd_d(TCGContext *s, TCGReg d, TCGReg j, TCGReg k, uint32_t ua2)
+{
+    tcg_out32(s, encode_djkua2_insn(OPC_SLADD_D, d, j, k, ua2));
+}
+
 /* Emits the `slli.w d, j, uk5` instruction.  */
 static void __attribute__((unused)) tcg_out_opc_slli_w(TCGContext *s, TCGReg d,
                                                        TCGReg j, uint32_t uk5)
Signature · 1 line
2.53.0
#15 lore raw

[PULL 17/19] tcg/aarch64: Implement INDEX_op_lea

In reply to Richard Henderson
---
 tcg/aarch64/tcg-target-has.h | 4 ++--
 tcg/aarch64/tcg-target.c.inc | 9 ++++++++-
 2 files changed, 10 insertions(+), 3 deletions(-)
tcg/aarch64/tcg-target-has.h +2 -2
index 86672b2eab..b0868e5827 100644
@@ -57,7 +57,7 @@
 #define TCG_TARGET_sextract_valid(type, ofs, len)  1
 #define TCG_TARGET_deposit_valid(type, ofs, len)   1
 
-#define TCG_TARGET_lea_sh_valid(type, sh)          0
-#define TCG_TARGET_lea_imm_valid(type, imm)        0
+#define TCG_TARGET_lea_sh_valid(type, sh)          ((sh) < tcg_type_bits(type))
+#define TCG_TARGET_lea_imm_valid(type, imm)        ((imm) == 0)
 
 #endif
tcg/aarch64/tcg-target.c.inc +8 -1
index b601b19c7f..5c186156c0 100644
@@ -3081,8 +3081,15 @@ static const TCGOutOpStore outop_st = {
     .out_r = tcg_out_st,
 };
 
+static void tgen_lea(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1,
+                     TCGReg a2, unsigned sh, tcg_target_long imm)
+{
+    tcg_out_insn(s, addsub_realshift, ADD_LSL, type, a0, a1, a2, sh);
+}
+
 static const TCGOutOpLea outop_lea = {
-    .base.static_constraint = C_NotImplemented,
+    .base.static_constraint = C_O1_I2(r, r, r),
+    .out = tgen_lea,
 };
 
 static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
Signature · 1 line
2.53.0
#16 lore raw

[PULL 18/19] tcg/riscv64: Implement INDEX_op_lea

In reply to Richard Henderson
---
 tcg/riscv64/tcg-target-has.h | 12 ++++++++++--
 tcg/riscv64/tcg-target.c.inc | 16 +++++++++++++++-
 2 files changed, 25 insertions(+), 3 deletions(-)
tcg/riscv64/tcg-target-has.h +10 -2
index 93f8baad09..3cdeb5c390 100644
@@ -69,7 +69,15 @@ tcg_target_sextract_valid(TCGType type, unsigned ofs, unsigned len)
 
 #define TCG_TARGET_deposit_valid(type, ofs, len)  0
 
-#define TCG_TARGET_lea_sh_valid(type, sh)         0
-#define TCG_TARGET_lea_imm_valid(type, imm)       0
+/*
+ * The SH*ADD instructions only operate on full register width.
+ * To allow TCG_TYPE_I32, we'd need a subsequent extension,
+ * with the result no better than the separate shift+add insns.
+ */
+#define TCG_TARGET_lea_sh_valid(type, sh)         \
+    (cpuinfo & CPUINFO_ZBA &&                     \
+     (type) == TCG_TYPE_REG &&                    \
+     (sh) >= 1 && (sh) <= 3)
+#define TCG_TARGET_lea_imm_valid(type, imm)       ((imm) == 0)
 
 #endif
tcg/riscv64/tcg-target.c.inc +15 -1
index ec0c8e1af0..6da52929a4 100644
@@ -224,6 +224,7 @@ typedef enum {
 
     /* Zba: Bit manipulation extension, address generation */
     OPC_ADD_UW = 0x0800003b,
+    OPC_SHxADD = 0x20000033,  /* plus sh << 13 */
 
     /* Zbb: Bit manipulation extension, basic bit manipulation */
     OPC_ANDN   = 0x40007033,
@@ -2740,8 +2741,21 @@ static const TCGOutOpStore outop_st = {
     .out_r = tcg_out_st,
 };
 
+static void tgen_lea(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1,
+                     TCGReg a2, unsigned sh, tcg_target_long imm)
+{
+    tcg_out32(s, encode_r(OPC_SHxADD, a0, a2, a1) | (sh << 13));
+}
+
+static TCGConstraintSetIndex cset_zba_rrr(TCGType type, unsigned flags)
+{
+    return cpuinfo & CPUINFO_ZBA ? C_O1_I2(r, r, r) : C_NotImplemented;
+}
+
 static const TCGOutOpLea outop_lea = {
-    .base.static_constraint = C_NotImplemented,
+    .base.static_constraint = C_Dynamic,
+    .base.dynamic_constraint = cset_zba_rrr,
+    .out = tgen_lea,
 };
 
 static void tcg_out_vec_op(TCGContext *s, TCGOpcode opc,
Signature · 1 line
2.53.0
#17 lore raw

[PULL 13/19] tcg/x86_64: Introduce TCG_REG_NONE

In reply to Richard Henderson

Rather than hard-code -1, or compare < 0, use something more descriptive. This also allows more use of TCGReg.

---
 tcg/x86_64/tcg-target.h     |  1 +
 tcg/x86_64/tcg-target.c.inc | 66 ++++++++++++++++++++-----------------
 2 files changed, 36 insertions(+), 31 deletions(-)
tcg/x86_64/tcg-target.h +1 -0
index 7ebae56a7d..7109722f24 100644
@@ -31,6 +31,7 @@
 #define MAX_CODE_GEN_BUFFER_SIZE  (2 * GiB)
 
 typedef enum {
+    TCG_REG_NONE = -1,
     TCG_REG_EAX = 0,
     TCG_REG_ECX,
     TCG_REG_EDX,
tcg/x86_64/tcg-target.c.inc +35 -31

179 lines not on this page · raw message

Signature · 1 line
2.53.0
#18 lore raw

Re: [PULL 13/19] tcg/x86_64: Introduce TCG_REG_NONE

Quoted 4 lines · Richard Henderson

Rather than hard-code -1, or compare < 0, use something more descriptive. This also allows more use of TCGReg.

Quoted 8 lines

typedef enum {
+ TCG_REG_NONE = -1,

     TCG_REG_EAX = 0,
     TCG_REG_ECX,
     TCG_REG_EDX,

This has resulted in Coverity producing a set of new complaints (CID 1689946, 1689949, 1689951, 1689952, 1689953, 1689954, 1689955), because it now assumes that variables of type TCGReg can be -1, and that therefore code like:

                TCGReg reg = order[i];
                if (tcg_regset_test_reg(set, reg)) {

(from tcg_reg_alloc_pair(), but the others are similar)

might be buggy, because it hands a TCGReg to tcg_regset_test_reg(), which uses it as a shift count without checking for the -1 possibility (which would be UB if it happened).

Should we just mark all these as false-positives, or is it worth maybe having operations that work on a TCGReg but don't expect TCG_REG_NONE add assertions against that ?

thanks
-- PMM

#19 lore raw

Re: [PULL 13/19] tcg/x86_64: Introduce TCG_REG_NONE

Quoted 24 lines · Peter Maydell
Quoted 4 lines · Richard Henderson

Rather than hard-code -1, or compare < 0, use something more descriptive. This also allows more use of TCGReg.

Quoted 8 lines

typedef enum {
+ TCG_REG_NONE = -1,

      TCG_REG_EAX = 0,
      TCG_REG_ECX,
      TCG_REG_EDX,

This has resulted in Coverity producing a set of new complaints (CID 1689946, 1689949, 1689951, 1689952, 1689953, 1689954, 1689955), because it now assumes that variables of type TCGReg can be -1, and that therefore code like:

                 TCGReg reg = order[i];
                 if (tcg_regset_test_reg(set, reg)) {

(from tcg_reg_alloc_pair(), but the others are similar)

Quoted 7 lines

might be buggy, because it hands a TCGReg to tcg_regset_test_reg(), which uses it as a shift count without checking for the -1 possibility (which would be UB if it happened).

Should we just mark all these as false-positives, or is it worth maybe having operations that work on a TCGReg but don't expect TCG_REG_NONE add assertions against that ?

Ug. I didn't want to have to add that many assertions. Maybe I should revert the few places that require -1 to int. Maybe I should use something other than -1.

Perhaps all false positives for now? If I adjust anything later, it'll refresh itself anyway.

r~

#20 lore raw

Re: [PULL 13/19] tcg/x86_64: Introduce TCG_REG_NONE

Quoted 33 lines · Richard Henderson
Quoted 24 lines · Peter Maydell
Quoted 4 lines · Richard Henderson

Rather than hard-code -1, or compare < 0, use something more descriptive. This also allows more use of TCGReg.

Quoted 8 lines

typedef enum {
+ TCG_REG_NONE = -1,

      TCG_REG_EAX = 0,
      TCG_REG_ECX,
      TCG_REG_EDX,

This has resulted in Coverity producing a set of new complaints (CID 1689946, 1689949, 1689951, 1689952, 1689953, 1689954, 1689955), because it now assumes that variables of type TCGReg can be -1, and that therefore code like:

                 TCGReg reg = order[i];
                 if (tcg_regset_test_reg(set, reg)) {

(from tcg_reg_alloc_pair(), but the others are similar)

Quoted 7 lines

might be buggy, because it hands a TCGReg to tcg_regset_test_reg(), which uses it as a shift count without checking for the -1 possibility (which would be UB if it happened).

Should we just mark all these as false-positives, or is it worth maybe having operations that work on a TCGReg but don't expect TCG_REG_NONE add assertions against that ?

Quoted 6 lines

Ug. I didn't want to have to add that many assertions. Maybe I should revert the few places that require -1 to int. Maybe I should use something other than -1.

Perhaps all false positives for now? If I adjust anything later, it'll refresh itself anyway.

I've marked them as false positives for the moment.

Incidentally, s390x uses 0 for TCG_REG_NONE, but that seems to be because the instruction set really does have "0 in register field means no register" in some places.

-- PMM

#21 lore raw

Re: [PULL 13/19] tcg/x86_64: Introduce TCG_REG_NONE

Quoted 1 line · Peter Maydell

I've marked them as false positives for the moment.

Thanks.

Quoted 3 lines

Incidentally, s390x uses 0 for TCG_REG_NONE, but that seems to be because the instruction set really does have "0 in register field means no register" in some places.

Exactly.

r~

#22 lore raw

[PULL 16/19] tcg/loongarch64: Implement INDEX_op_lea

In reply to Richard Henderson
---
 tcg/loongarch64/tcg-target-has.h |  4 ++--
 tcg/loongarch64/tcg-target.c.inc | 13 ++++++++++++-
 2 files changed, 14 insertions(+), 3 deletions(-)
tcg/loongarch64/tcg-target-has.h +2 -2
index 31e6ea9632..53b7ca4057 100644
@@ -54,7 +54,7 @@ tcg_target_sextract_valid(TCGType type, unsigned ofs, unsigned len)
 }
 #define TCG_TARGET_sextract_valid  tcg_target_sextract_valid
 
-#define TCG_TARGET_lea_sh_valid(type, sh)          0
-#define TCG_TARGET_lea_imm_valid(type, imm)        0
+#define TCG_TARGET_lea_sh_valid(type, sh)          ((sh) >= 1 && (sh) <= 4)
+#define TCG_TARGET_lea_imm_valid(type, imm)        ((imm) == 0)
 
 #endif
tcg/loongarch64/tcg-target.c.inc +12 -1
index 17784d8bbe..377cd9ec08 100644
@@ -2098,8 +2098,19 @@ static const TCGOutOpStore outop_st = {
     .out_r = tcg_out_st,
 };
 
+static void tgen_lea(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1,
+                     TCGReg a2, unsigned sh, tcg_target_long imm)
+{
+    if (type == TCG_TYPE_I32) {
+        tcg_out_opc_sladd_w(s, a0, a2, a1, sh - 1);
+    } else {
+        tcg_out_opc_sladd_d(s, a0, a2, a1, sh - 1);
+    }
+}
+
 static const TCGOutOpLea outop_lea = {
-    .base.static_constraint = C_NotImplemented,
+    .base.static_constraint = C_O1_I2(r, r, r),
+    .out = tgen_lea,
 };
 
 static bool tcg_out_dup_vec(TCGContext *s, TCGType type, unsigned vece,
Signature · 1 line
2.53.0
#23 lore raw

[PULL 08/19] target/loongarch: Use tcg_gen_lea_tl for ALSL

In reply to Richard Henderson
---
 target/loongarch/tcg/insn_trans/trans_arith.c.inc | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
target/loongarch/tcg/insn_trans/trans_arith.c.inc +1 -3
index 2be057e932..c358e64264 100644
@@ -188,9 +188,7 @@ static void gen_rem_w(TCGv dest, TCGv src1, TCGv src2)
 
 static void gen_alsl(TCGv dest, TCGv src1, TCGv src2, target_long sa)
 {
-    TCGv t0 = tcg_temp_new();
-    tcg_gen_shli_tl(t0, src1, sa);
-    tcg_gen_add_tl(dest, t0, src2);
+    tcg_gen_lea_tl(dest, src2, src1, sa, 0);
 }
 
 static bool trans_lu32i_d(DisasContext *ctx, arg_lu32i_d *a)
Signature · 1 line
2.53.0
author Applied
#24 lore raw
In reply to Richard Henderson
Quoted 12 lines · Richard Henderson

The following changes since commit 61436f5ff1c4e5ee8f60fa1a37962a60f73ea7a4:

   Merge tag 'pbouvier/pr/dockerfiles-20261029' ofhttps://gitlab.com/p-b-o/qemu into staging (2026-10-29 17:09:01 -0500)

are available in the Git repository at:

   https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20261030

for you to fetch changes up to 0e68878f962a2117fc5de8a0025f3064bf5cbe9a:

   tcg/s390x: Implement INDEX_op_lea (2026-10-30 07:06:16 -0500)
Quoted 11 lines

----------------------------------------------------------------
accel/tcg: Fix false awakening of gdb
accel/tcg: Do not flush and retry in place in tb_gen_code
tcg: Adjust NONNULL annotation on *_diff functions
tcg: Add tcg_gen_lea_{i32,i64,tl}
target/alpha: Use tcg_gen_lea_i64 for S{4,8}ADD{L,Q} target/loongarch: Use tcg_gen_lea_tl for ALSL target/riscv: Use tcg_gen_lea_tl for SH*ADD target/s390x: Use tcg_gen_lea_i64 in get_address target/i386: Use tcg_gen_lea_tl in gen_lea_modrm_1 target/mips: Use tcg_gen_lea() for [D]LSA and MXU S32LD*V opcodes

Applied, thanks.

r~