Re: [PATCH v4 095/163] tcg: Convert sextract to TCGOutOpExtract

2025-04-15 Thread Pierrick Bouvier

On 4/15/25 12:24, Richard Henderson wrote:

Signed-off-by: Richard Henderson 
---
  tcg/tcg.c|  4 ++
  tcg/aarch64/tcg-target.c.inc | 18 +
  tcg/arm/tcg-target.c.inc | 21 ++-
  tcg/i386/tcg-target.c.inc| 63 
  tcg/loongarch64/tcg-target.c.inc | 49 ++---
  tcg/mips/tcg-target.c.inc| 42 -
  tcg/ppc/tcg-target.c.inc | 49 ++---
  tcg/riscv/tcg-target.c.inc   | 49 ++---
  tcg/s390x/tcg-target.c.inc   | 15 
  tcg/sparc64/tcg-target.c.inc | 18 ++---
  tcg/tci/tcg-target.c.inc | 11 +++---
  11 files changed, 188 insertions(+), 151 deletions(-)

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 5f5b323c66..b86e3daed0 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -,6 +,8 @@ static const TCGOutOp * const all_outop[NB_OPS] = {
  OUTOP(INDEX_op_rotr, TCGOutOpBinary, outop_rotr),
  OUTOP(INDEX_op_sar, TCGOutOpBinary, outop_sar),
  OUTOP(INDEX_op_setcond, TCGOutOpSetcond, outop_setcond),
+OUTOP(INDEX_op_sextract_i32, TCGOutOpExtract, outop_sextract),
+OUTOP(INDEX_op_sextract_i64, TCGOutOpExtract, outop_sextract),
  OUTOP(INDEX_op_shl, TCGOutOpBinary, outop_shl),
  OUTOP(INDEX_op_shr, TCGOutOpBinary, outop_shr),
  OUTOP(INDEX_op_sub, TCGOutOpSubtract, outop_sub),
@@ -5515,6 +5517,8 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp 
*op)
  break;
  
  case INDEX_op_extract:

+case INDEX_op_sextract_i32:
+case INDEX_op_sextract_i64:
  {
  const TCGOutOpExtract *out =
  container_of(all_outop[op->opc], TCGOutOpExtract, base);
diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc
index 6c9d6094a2..00400f6ea7 100644
--- a/tcg/aarch64/tcg-target.c.inc
+++ b/tcg/aarch64/tcg-target.c.inc
@@ -2583,6 +2583,17 @@ static const TCGOutOpExtract outop_extract = {
  .out_rr = tgen_extract,
  };
  
+static void tgen_sextract(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1,

+  unsigned ofs, unsigned len)
+{
+tcg_out_sbfm(s, type, a0, a1, ofs, ofs + len - 1);
+}
+
+static const TCGOutOpExtract outop_sextract = {
+.base.static_constraint = C_O1_I1(r, r),
+.out_rr = tgen_sextract,
+};
+
  static void tcg_out_op(TCGContext *s, TCGOpcode opc, TCGType ext,
 const TCGArg args[TCG_MAX_OP_ARGS],
 const int const_args[TCG_MAX_OP_ARGS])
@@ -2668,11 +2679,6 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, 
TCGType ext,
  tcg_out_dep(s, ext, a0, a2, args[3], args[4]);
  break;
  
-case INDEX_op_sextract_i64:

-case INDEX_op_sextract_i32:
-tcg_out_sbfm(s, ext, a0, a1, a2, a2 + args[3] - 1);
-break;
-
  case INDEX_op_extract2_i64:
  case INDEX_op_extract2_i32:
  tcg_out_extr(s, ext, a0, a2, a1, args[3]);
@@ -3173,8 +3179,6 @@ tcg_target_op_def(TCGOpcode op, TCGType type, unsigned 
flags)
  case INDEX_op_ld_i64:
  case INDEX_op_ext_i32_i64:
  case INDEX_op_extu_i32_i64:
-case INDEX_op_sextract_i32:
-case INDEX_op_sextract_i64:
  return C_O1_I1(r, r);
  
  case INDEX_op_st8_i32:

diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
index bc060b20f2..aebe48679c 100644
--- a/tcg/arm/tcg-target.c.inc
+++ b/tcg/arm/tcg-target.c.inc
@@ -1020,12 +1020,12 @@ static const TCGOutOpExtract outop_extract = {
  .out_rr = tgen_extract,
  };
  
-static void tcg_out_sextract(TCGContext *s, ARMCond cond, TCGReg rd,

- TCGReg rn, int ofs, int len)
+static void tgen_sextract(TCGContext *s, TCGType type, TCGReg rd, TCGReg rn,
+  unsigned ofs, unsigned len)
  {
  if (use_armv7_instructions) {
  /* sbfx */
-tcg_out32(s, 0x07a00050 | (cond << 28) | (rd << 12) | rn
+tcg_out32(s, 0x07a00050 | (COND_AL << 28) | (rd << 12) | rn
| (ofs << 7) | ((len - 1) << 16));
  return;
  }
@@ -1034,17 +1034,24 @@ static void tcg_out_sextract(TCGContext *s, ARMCond 
cond, TCGReg rd,
  switch (len) {
  case 8:
  /* sxtb */
-tcg_out32(s, 0x06af0070 | (cond << 28) | (rd << 12) | (ofs << 7) | rn);
+tcg_out32(s, 0x06af0070 | (COND_AL << 28) |
+  (rd << 12) | (ofs << 7) | rn);
  break;
  case 16:
  /* sxth */
-tcg_out32(s, 0x06bf0070 | (cond << 28) | (rd << 12) | (ofs << 7) | rn);
+tcg_out32(s, 0x06bf0070 | (COND_AL << 28) |
+  (rd << 12) | (ofs << 7) | rn);
  break;
  default:
  g_assert_not_reached();
  }
  }
  
+static const TCGOutOpExtract outop_sextract = {

+.base.static_constraint = C_O1_I1(r, r),
+.out_rr = tgen_sextract,
+};
+
  
  static void tcg_out_ld32u(TCGContext *s, ARMCond cond,

TCGReg rd, 

[PATCH v4 095/163] tcg: Convert sextract to TCGOutOpExtract

2025-04-15 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 tcg/tcg.c|  4 ++
 tcg/aarch64/tcg-target.c.inc | 18 +
 tcg/arm/tcg-target.c.inc | 21 ++-
 tcg/i386/tcg-target.c.inc| 63 
 tcg/loongarch64/tcg-target.c.inc | 49 ++---
 tcg/mips/tcg-target.c.inc| 42 -
 tcg/ppc/tcg-target.c.inc | 49 ++---
 tcg/riscv/tcg-target.c.inc   | 49 ++---
 tcg/s390x/tcg-target.c.inc   | 15 
 tcg/sparc64/tcg-target.c.inc | 18 ++---
 tcg/tci/tcg-target.c.inc | 11 +++---
 11 files changed, 188 insertions(+), 151 deletions(-)

diff --git a/tcg/tcg.c b/tcg/tcg.c
index 5f5b323c66..b86e3daed0 100644
--- a/tcg/tcg.c
+++ b/tcg/tcg.c
@@ -,6 +,8 @@ static const TCGOutOp * const all_outop[NB_OPS] = {
 OUTOP(INDEX_op_rotr, TCGOutOpBinary, outop_rotr),
 OUTOP(INDEX_op_sar, TCGOutOpBinary, outop_sar),
 OUTOP(INDEX_op_setcond, TCGOutOpSetcond, outop_setcond),
+OUTOP(INDEX_op_sextract_i32, TCGOutOpExtract, outop_sextract),
+OUTOP(INDEX_op_sextract_i64, TCGOutOpExtract, outop_sextract),
 OUTOP(INDEX_op_shl, TCGOutOpBinary, outop_shl),
 OUTOP(INDEX_op_shr, TCGOutOpBinary, outop_shr),
 OUTOP(INDEX_op_sub, TCGOutOpSubtract, outop_sub),
@@ -5515,6 +5517,8 @@ static void tcg_reg_alloc_op(TCGContext *s, const TCGOp 
*op)
 break;
 
 case INDEX_op_extract:
+case INDEX_op_sextract_i32:
+case INDEX_op_sextract_i64:
 {
 const TCGOutOpExtract *out =
 container_of(all_outop[op->opc], TCGOutOpExtract, base);
diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc
index 6c9d6094a2..00400f6ea7 100644
--- a/tcg/aarch64/tcg-target.c.inc
+++ b/tcg/aarch64/tcg-target.c.inc
@@ -2583,6 +2583,17 @@ static const TCGOutOpExtract outop_extract = {
 .out_rr = tgen_extract,
 };
 
+static void tgen_sextract(TCGContext *s, TCGType type, TCGReg a0, TCGReg a1,
+  unsigned ofs, unsigned len)
+{
+tcg_out_sbfm(s, type, a0, a1, ofs, ofs + len - 1);
+}
+
+static const TCGOutOpExtract outop_sextract = {
+.base.static_constraint = C_O1_I1(r, r),
+.out_rr = tgen_sextract,
+};
+
 static void tcg_out_op(TCGContext *s, TCGOpcode opc, TCGType ext,
const TCGArg args[TCG_MAX_OP_ARGS],
const int const_args[TCG_MAX_OP_ARGS])
@@ -2668,11 +2679,6 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, 
TCGType ext,
 tcg_out_dep(s, ext, a0, a2, args[3], args[4]);
 break;
 
-case INDEX_op_sextract_i64:
-case INDEX_op_sextract_i32:
-tcg_out_sbfm(s, ext, a0, a1, a2, a2 + args[3] - 1);
-break;
-
 case INDEX_op_extract2_i64:
 case INDEX_op_extract2_i32:
 tcg_out_extr(s, ext, a0, a2, a1, args[3]);
@@ -3173,8 +3179,6 @@ tcg_target_op_def(TCGOpcode op, TCGType type, unsigned 
flags)
 case INDEX_op_ld_i64:
 case INDEX_op_ext_i32_i64:
 case INDEX_op_extu_i32_i64:
-case INDEX_op_sextract_i32:
-case INDEX_op_sextract_i64:
 return C_O1_I1(r, r);
 
 case INDEX_op_st8_i32:
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
index bc060b20f2..aebe48679c 100644
--- a/tcg/arm/tcg-target.c.inc
+++ b/tcg/arm/tcg-target.c.inc
@@ -1020,12 +1020,12 @@ static const TCGOutOpExtract outop_extract = {
 .out_rr = tgen_extract,
 };
 
-static void tcg_out_sextract(TCGContext *s, ARMCond cond, TCGReg rd,
- TCGReg rn, int ofs, int len)
+static void tgen_sextract(TCGContext *s, TCGType type, TCGReg rd, TCGReg rn,
+  unsigned ofs, unsigned len)
 {
 if (use_armv7_instructions) {
 /* sbfx */
-tcg_out32(s, 0x07a00050 | (cond << 28) | (rd << 12) | rn
+tcg_out32(s, 0x07a00050 | (COND_AL << 28) | (rd << 12) | rn
   | (ofs << 7) | ((len - 1) << 16));
 return;
 }
@@ -1034,17 +1034,24 @@ static void tcg_out_sextract(TCGContext *s, ARMCond 
cond, TCGReg rd,
 switch (len) {
 case 8:
 /* sxtb */
-tcg_out32(s, 0x06af0070 | (cond << 28) | (rd << 12) | (ofs << 7) | rn);
+tcg_out32(s, 0x06af0070 | (COND_AL << 28) |
+  (rd << 12) | (ofs << 7) | rn);
 break;
 case 16:
 /* sxth */
-tcg_out32(s, 0x06bf0070 | (cond << 28) | (rd << 12) | (ofs << 7) | rn);
+tcg_out32(s, 0x06bf0070 | (COND_AL << 28) |
+  (rd << 12) | (ofs << 7) | rn);
 break;
 default:
 g_assert_not_reached();
 }
 }
 
+static const TCGOutOpExtract outop_sextract = {
+.base.static_constraint = C_O1_I1(r, r),
+.out_rr = tgen_sextract,
+};
+
 
 static void tcg_out_ld32u(TCGContext *s, ARMCond cond,
   TCGReg rd, TCGReg rn, int32_t offset)
@@ -2399,9 +2406,6 @@ static void tcg_out_op(TCGContext *s, TCGOpcode opc, 
TCGType type,