Re: [PATCH v4 157/163] tcg: Merge INDEX_op_st*_{i32,i64}

2025-04-16 Thread Pierrick Bouvier

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

Signed-off-by: Richard Henderson 
---
  include/tcg/tcg-opc.h| 15 --
  tcg/optimize.c   | 28 +++--
  tcg/tcg-op.c | 14 ++---
  tcg/tcg.c| 45 +---
  tcg/tci.c| 36 +---
  tcg/tci/tcg-target.c.inc | 20 +++---
  6 files changed, 50 insertions(+), 108 deletions(-)

diff --git a/include/tcg/tcg-opc.h b/include/tcg/tcg-opc.h
index 6e8fcefaef..a22433d8b5 100644
--- a/include/tcg/tcg-opc.h
+++ b/include/tcg/tcg-opc.h
@@ -86,6 +86,10 @@ DEF(setcond, 1, 2, 1, TCG_OPF_INT)
  DEF(sextract, 1, 1, 2, TCG_OPF_INT)
  DEF(shl, 1, 2, 0, TCG_OPF_INT)
  DEF(shr, 1, 2, 0, TCG_OPF_INT)
+DEF(st8, 0, 2, 1, TCG_OPF_INT)
+DEF(st16, 0, 2, 1, TCG_OPF_INT)
+DEF(st32, 0, 2, 1, TCG_OPF_INT)
+DEF(st, 0, 2, 1, TCG_OPF_INT)
  DEF(sub, 1, 2, 0, TCG_OPF_INT)
  DEF(xor, 1, 2, 0, TCG_OPF_INT)
  
@@ -99,20 +103,9 @@ DEF(subb1o, 1, 2, 0, TCG_OPF_INT | TCG_OPF_CARRY_OUT)

  DEF(subbi, 1, 2, 0, TCG_OPF_INT | TCG_OPF_CARRY_IN)
  DEF(subbio, 1, 2, 0, TCG_OPF_INT | TCG_OPF_CARRY_IN | TCG_OPF_CARRY_OUT)
  
-/* load/store */

-DEF(st8_i32, 0, 2, 1, 0)
-DEF(st16_i32, 0, 2, 1, 0)
-DEF(st_i32, 0, 2, 1, 0)
-
  DEF(brcond2_i32, 0, 4, 2, TCG_OPF_BB_END | TCG_OPF_COND_BRANCH)
  DEF(setcond2_i32, 1, 4, 1, 0)
  
-/* load/store */

-DEF(st8_i64, 0, 2, 1, 0)
-DEF(st16_i64, 0, 2, 1, 0)
-DEF(st32_i64, 0, 2, 1, 0)
-DEF(st_i64, 0, 2, 1, 0)
-
  /* size changing ops */
  DEF(ext_i32_i64, 1, 1, 0, 0)
  DEF(extu_i32_i64, 1, 1, 0, 0)
diff --git a/tcg/optimize.c b/tcg/optimize.c
index 1da23755e3..cbc519624a 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -30,14 +30,6 @@
  #include "tcg-internal.h"
  #include "tcg-has.h"
  
-#define CASE_OP_32_64(x)\

-glue(glue(case INDEX_op_, x), _i32):\
-glue(glue(case INDEX_op_, x), _i64)
-
-#define CASE_OP_32_64_VEC(x)\
-glue(glue(case INDEX_op_, x), _i32):\
-glue(glue(case INDEX_op_, x), _i64):\
-glue(glue(case INDEX_op_, x), _vec)
  
  typedef struct MemCopyInfo {

  IntervalTreeNode itree;
@@ -2926,19 +2918,16 @@ static bool fold_tcg_st(OptContext *ctx, TCGOp *op)
  }
  
  switch (op->opc) {

-CASE_OP_32_64(st8):
+case INDEX_op_st8:
  lm1 = 0;
  break;
-CASE_OP_32_64(st16):
+case INDEX_op_st16:
  lm1 = 1;
  break;
-case INDEX_op_st32_i64:
-case INDEX_op_st_i32:
+case INDEX_op_st32:
  lm1 = 3;
  break;
-case INDEX_op_st_i64:
-lm1 = 7;
-break;
+case INDEX_op_st:
  case INDEX_op_st_vec:
  lm1 = tcg_type_size(ctx->type) - 1;
  break;
@@ -3126,13 +3115,12 @@ void tcg_optimize(TCGContext *s)
  case INDEX_op_ld_vec:
  done = fold_tcg_ld_memcopy(&ctx, op);
  break;
-CASE_OP_32_64(st8):
-CASE_OP_32_64(st16):
-case INDEX_op_st32_i64:
+case INDEX_op_st8:
+case INDEX_op_st16:
+case INDEX_op_st32:
  done = fold_tcg_st(&ctx, op);
  break;
-case INDEX_op_st_i32:
-case INDEX_op_st_i64:
+case INDEX_op_st:
  case INDEX_op_st_vec:
  done = fold_tcg_st_memcopy(&ctx, op);
  break;
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 680f752cf9..dfa5c38728 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1404,17 +1404,17 @@ void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, 
tcg_target_long offset)
  
  void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)

  {
-tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
+tcg_gen_ldst_op_i32(INDEX_op_st8, arg1, arg2, offset);
  }
  
  void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)

  {
-tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
+tcg_gen_ldst_op_i32(INDEX_op_st16, arg1, arg2, offset);
  }
  
  void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)

  {
-tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
+tcg_gen_ldst_op_i32(INDEX_op_st, arg1, arg2, offset);
  }
  
  
@@ -1540,7 +1540,7 @@ void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, tcg_target_long offset)

  void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
  {
  if (TCG_TARGET_REG_BITS == 64) {
-tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
+tcg_gen_ldst_op_i64(INDEX_op_st8, arg1, arg2, offset);
  } else {
  tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
  }
@@ -1549,7 +1549,7 @@ void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, 
tcg_target_long offset)
  void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
  {
  if (TCG_TARGET_REG_BITS == 64) {
-tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
+

Re: [PATCH v4 157/163] tcg: Merge INDEX_op_st*_{i32,i64}

2025-04-16 Thread Philippe Mathieu-Daudé

On 15/4/25 21:25, Richard Henderson wrote:

Signed-off-by: Richard Henderson 
---
  include/tcg/tcg-opc.h| 15 --
  tcg/optimize.c   | 28 +++--
  tcg/tcg-op.c | 14 ++---
  tcg/tcg.c| 45 +---
  tcg/tci.c| 36 +---
  tcg/tci/tcg-target.c.inc | 20 +++---
  6 files changed, 50 insertions(+), 108 deletions(-)




diff --git a/tcg/optimize.c b/tcg/optimize.c
index 1da23755e3..cbc519624a 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -30,14 +30,6 @@




@@ -2926,19 +2918,16 @@ static bool fold_tcg_st(OptContext *ctx, TCGOp *op)
  }
  
  switch (op->opc) {

-CASE_OP_32_64(st8):
+case INDEX_op_st8:
  lm1 = 0;
  break;
-CASE_OP_32_64(st16):
+case INDEX_op_st16:
  lm1 = 1;
  break;
-case INDEX_op_st32_i64:
-case INDEX_op_st_i32:
+case INDEX_op_st32:
  lm1 = 3;
  break;
-case INDEX_op_st_i64:
-lm1 = 7;
-break;
+case INDEX_op_st:
  case INDEX_op_st_vec:
  lm1 = tcg_type_size(ctx->type) - 1;
  break;


Unrelated nitpicking comment while looking at what lm1 is,
I'd find clearer for tcg_type_size() to return an unsigned
type, and lm1 be a uintptr_t one. Matter of taste I suppose.

Regardless,
Reviewed-by: Philippe Mathieu-Daudé 




[PATCH v4 157/163] tcg: Merge INDEX_op_st*_{i32,i64}

2025-04-15 Thread Richard Henderson
Signed-off-by: Richard Henderson 
---
 include/tcg/tcg-opc.h| 15 --
 tcg/optimize.c   | 28 +++--
 tcg/tcg-op.c | 14 ++---
 tcg/tcg.c| 45 +---
 tcg/tci.c| 36 +---
 tcg/tci/tcg-target.c.inc | 20 +++---
 6 files changed, 50 insertions(+), 108 deletions(-)

diff --git a/include/tcg/tcg-opc.h b/include/tcg/tcg-opc.h
index 6e8fcefaef..a22433d8b5 100644
--- a/include/tcg/tcg-opc.h
+++ b/include/tcg/tcg-opc.h
@@ -86,6 +86,10 @@ DEF(setcond, 1, 2, 1, TCG_OPF_INT)
 DEF(sextract, 1, 1, 2, TCG_OPF_INT)
 DEF(shl, 1, 2, 0, TCG_OPF_INT)
 DEF(shr, 1, 2, 0, TCG_OPF_INT)
+DEF(st8, 0, 2, 1, TCG_OPF_INT)
+DEF(st16, 0, 2, 1, TCG_OPF_INT)
+DEF(st32, 0, 2, 1, TCG_OPF_INT)
+DEF(st, 0, 2, 1, TCG_OPF_INT)
 DEF(sub, 1, 2, 0, TCG_OPF_INT)
 DEF(xor, 1, 2, 0, TCG_OPF_INT)
 
@@ -99,20 +103,9 @@ DEF(subb1o, 1, 2, 0, TCG_OPF_INT | TCG_OPF_CARRY_OUT)
 DEF(subbi, 1, 2, 0, TCG_OPF_INT | TCG_OPF_CARRY_IN)
 DEF(subbio, 1, 2, 0, TCG_OPF_INT | TCG_OPF_CARRY_IN | TCG_OPF_CARRY_OUT)
 
-/* load/store */
-DEF(st8_i32, 0, 2, 1, 0)
-DEF(st16_i32, 0, 2, 1, 0)
-DEF(st_i32, 0, 2, 1, 0)
-
 DEF(brcond2_i32, 0, 4, 2, TCG_OPF_BB_END | TCG_OPF_COND_BRANCH)
 DEF(setcond2_i32, 1, 4, 1, 0)
 
-/* load/store */
-DEF(st8_i64, 0, 2, 1, 0)
-DEF(st16_i64, 0, 2, 1, 0)
-DEF(st32_i64, 0, 2, 1, 0)
-DEF(st_i64, 0, 2, 1, 0)
-
 /* size changing ops */
 DEF(ext_i32_i64, 1, 1, 0, 0)
 DEF(extu_i32_i64, 1, 1, 0, 0)
diff --git a/tcg/optimize.c b/tcg/optimize.c
index 1da23755e3..cbc519624a 100644
--- a/tcg/optimize.c
+++ b/tcg/optimize.c
@@ -30,14 +30,6 @@
 #include "tcg-internal.h"
 #include "tcg-has.h"
 
-#define CASE_OP_32_64(x)\
-glue(glue(case INDEX_op_, x), _i32):\
-glue(glue(case INDEX_op_, x), _i64)
-
-#define CASE_OP_32_64_VEC(x)\
-glue(glue(case INDEX_op_, x), _i32):\
-glue(glue(case INDEX_op_, x), _i64):\
-glue(glue(case INDEX_op_, x), _vec)
 
 typedef struct MemCopyInfo {
 IntervalTreeNode itree;
@@ -2926,19 +2918,16 @@ static bool fold_tcg_st(OptContext *ctx, TCGOp *op)
 }
 
 switch (op->opc) {
-CASE_OP_32_64(st8):
+case INDEX_op_st8:
 lm1 = 0;
 break;
-CASE_OP_32_64(st16):
+case INDEX_op_st16:
 lm1 = 1;
 break;
-case INDEX_op_st32_i64:
-case INDEX_op_st_i32:
+case INDEX_op_st32:
 lm1 = 3;
 break;
-case INDEX_op_st_i64:
-lm1 = 7;
-break;
+case INDEX_op_st:
 case INDEX_op_st_vec:
 lm1 = tcg_type_size(ctx->type) - 1;
 break;
@@ -3126,13 +3115,12 @@ void tcg_optimize(TCGContext *s)
 case INDEX_op_ld_vec:
 done = fold_tcg_ld_memcopy(&ctx, op);
 break;
-CASE_OP_32_64(st8):
-CASE_OP_32_64(st16):
-case INDEX_op_st32_i64:
+case INDEX_op_st8:
+case INDEX_op_st16:
+case INDEX_op_st32:
 done = fold_tcg_st(&ctx, op);
 break;
-case INDEX_op_st_i32:
-case INDEX_op_st_i64:
+case INDEX_op_st:
 case INDEX_op_st_vec:
 done = fold_tcg_st_memcopy(&ctx, op);
 break;
diff --git a/tcg/tcg-op.c b/tcg/tcg-op.c
index 680f752cf9..dfa5c38728 100644
--- a/tcg/tcg-op.c
+++ b/tcg/tcg-op.c
@@ -1404,17 +1404,17 @@ void tcg_gen_ld_i32(TCGv_i32 ret, TCGv_ptr arg2, 
tcg_target_long offset)
 
 void tcg_gen_st8_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
 {
-tcg_gen_ldst_op_i32(INDEX_op_st8_i32, arg1, arg2, offset);
+tcg_gen_ldst_op_i32(INDEX_op_st8, arg1, arg2, offset);
 }
 
 void tcg_gen_st16_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
 {
-tcg_gen_ldst_op_i32(INDEX_op_st16_i32, arg1, arg2, offset);
+tcg_gen_ldst_op_i32(INDEX_op_st16, arg1, arg2, offset);
 }
 
 void tcg_gen_st_i32(TCGv_i32 arg1, TCGv_ptr arg2, tcg_target_long offset)
 {
-tcg_gen_ldst_op_i32(INDEX_op_st_i32, arg1, arg2, offset);
+tcg_gen_ldst_op_i32(INDEX_op_st, arg1, arg2, offset);
 }
 
 
@@ -1540,7 +1540,7 @@ void tcg_gen_ld_i64(TCGv_i64 ret, TCGv_ptr arg2, 
tcg_target_long offset)
 void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
 {
 if (TCG_TARGET_REG_BITS == 64) {
-tcg_gen_ldst_op_i64(INDEX_op_st8_i64, arg1, arg2, offset);
+tcg_gen_ldst_op_i64(INDEX_op_st8, arg1, arg2, offset);
 } else {
 tcg_gen_st8_i32(TCGV_LOW(arg1), arg2, offset);
 }
@@ -1549,7 +1549,7 @@ void tcg_gen_st8_i64(TCGv_i64 arg1, TCGv_ptr arg2, 
tcg_target_long offset)
 void tcg_gen_st16_i64(TCGv_i64 arg1, TCGv_ptr arg2, tcg_target_long offset)
 {
 if (TCG_TARGET_REG_BITS == 64) {
-tcg_gen_ldst_op_i64(INDEX_op_st16_i64, arg1, arg2, offset);
+tcg_gen_ldst_op_i64(INDEX_op_st16, arg1, arg2, offset);
 } else {
 tcg_gen_st16_i32(TCGV_LOW(arg1), arg2, offset);
 }
@@ -1558,7