On 1/9/26 2:02 PM, Richard Henderson wrote:
On 1/9/26 16:31, Pierrick Bouvier wrote:
This define will be used to replace TARGET_LONG_BITS in tcg-op-*
headers. The goal here is to allow a compilation unit to set explicitely
which variant of the arch it's targeting (32 vs 64 bits).

By default, we simple let it defined as TARGET_LONG_BITS, so existing
code does not need to be changed, and we can progressively convert new
files.

target/arm/tcg/* files are cleanly splitted between 32 and 64 bits (with
some TARGET_AARCH64 defines). For other arch, this is a work that will
have to be done before converting them.

Signed-off-by: Pierrick Bouvier <[email protected]>
---
   include/tcg/tcg-op-address-bits.h | 21 +++++++++++++++++++++
   include/tcg/tcg-op-gvec.h         | 11 +++--------
   include/tcg/tcg-op.h              | 22 +++++++---------------
   3 files changed, 31 insertions(+), 23 deletions(-)
   create mode 100644 include/tcg/tcg-op-address-bits.h

diff --git a/include/tcg/tcg-op-address-bits.h 
b/include/tcg/tcg-op-address-bits.h
new file mode 100644
index 00000000000..71e9de65280
--- /dev/null
+++ b/include/tcg/tcg-op-address-bits.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef TCG_OP_ADDRESS_BITS
+#define TCG_OP_ADDRESS_BITS
+
+#ifdef COMPILING_PER_TARGET
+ #include "exec/target_long.h"
+ #ifndef TARGET_ADDRESS_BITS
+  #define TARGET_ADDRESS_BITS TARGET_LONG_BITS
+ #endif
+#else
+ #ifndef TARGET_ADDRESS_BITS
+  #error TARGET_ADDRESS_BITS must be defined for current file
+ #endif
+#endif /* COMPILING_PER_TARGET */
+
+#if TARGET_ADDRESS_BITS != 32 && TARGET_ADDRESS_BITS != 64
+ #error TARGET_ADDRESS_BITS must be 32 or 64
+#endif
+
+#endif /* TCG_OP_ADDRESS_BITS */
diff --git a/include/tcg/tcg-op-gvec.h b/include/tcg/tcg-op-gvec.h
index b0a81ad4bf4..422a270b694 100644
--- a/include/tcg/tcg-op-gvec.h
+++ b/include/tcg/tcg-op-gvec.h
@@ -8,13 +8,10 @@
   #ifndef TCG_TCG_OP_GVEC_H
   #define TCG_TCG_OP_GVEC_H
+#include "tcg/tcg-op-address-bits.h"
   #include "tcg/tcg-op-gvec-common.h"
-#ifndef TARGET_LONG_BITS
-#error must include QEMU headers
-#endif
-
-#if TARGET_LONG_BITS == 64
+#if TARGET_ADDRESS_BITS == 64
   #define tcg_gen_gvec_dup_tl  tcg_gen_gvec_dup_i64
   #define tcg_gen_vec_add8_tl  tcg_gen_vec_add8_i64
   #define tcg_gen_vec_sub8_tl  tcg_gen_vec_sub8_i64
@@ -28,7 +25,7 @@
   #define tcg_gen_vec_shl16i_tl tcg_gen_vec_shl16i_i64
   #define tcg_gen_vec_shr16i_tl tcg_gen_vec_shr16i_i64
   #define tcg_gen_vec_sar16i_tl tcg_gen_vec_sar16i_i64
-#elif TARGET_LONG_BITS == 32
+#elif TARGET_ADDRESS_BITS == 32
   #define tcg_gen_gvec_dup_tl  tcg_gen_gvec_dup_i32
   #define tcg_gen_vec_add8_tl  tcg_gen_vec_add8_i32
   #define tcg_gen_vec_sub8_tl  tcg_gen_vec_sub8_i32
@@ -42,8 +39,6 @@
   #define tcg_gen_vec_shl16i_tl tcg_gen_vec_shl16i_i32
   #define tcg_gen_vec_shr16i_tl tcg_gen_vec_shr16i_i32
   #define tcg_gen_vec_sar16i_tl tcg_gen_vec_sar16i_i32
-#else
-# error
   #endif

Not address related.  Not even close.


#endif
diff --git a/include/tcg/tcg-op.h b/include/tcg/tcg-op.h
index bf76749d1c5..9e4e58a2d4b 100644
--- a/include/tcg/tcg-op.h
+++ b/include/tcg/tcg-op.h
@@ -8,20 +8,14 @@
   #ifndef TCG_TCG_OP_H
   #define TCG_TCG_OP_H
+#include "tcg/tcg-op-address-bits.h"
   #include "tcg/tcg-op-common.h"
   #include "tcg/insn-start-words.h"
-#include "exec/target_long.h"
-#ifndef TARGET_LONG_BITS
-#error must include QEMU headers
-#endif
-
-#if TARGET_LONG_BITS == 32
+#if TARGET_ADDRESS_BITS == 32
   # define TCG_TYPE_TL  TCG_TYPE_I32
-#elif TARGET_LONG_BITS == 64
+#elif TARGET_ADDRESS_BITS == 64
   # define TCG_TYPE_TL  TCG_TYPE_I64
-#else
-# error
   #endif

Ok, there's been a fundamental misunderstanding about what we discussed.

There should be *no* changes to target_long, TCGv or TCG_TYPE_TL.

There should be a *new* file, include/tcg/tcg-op-mem.h which deals with TCGv_va,
TCG_TYPE_VA, and all of the tcg_gen_qemu_{ld,st}* helpers based on that.

The only thing that should happen in tcg-op.h is:

#define TARGET_ADDRESS_BITS  TARGET_LONG_BITS
#include "tcg-op-mem.h"


To be fair, I should have mentioned that I didn't understand why you were insisting to *only* deal with memory operations. Yes, target/arm uses TCGv *only* for addresses, but it's very arm-centric to think about this.

So what's the benefit to split memory operations instead of parameterize TCGv directly? In this case, I agree that TARGET_ADDRESS_BITS is definitely a bad name, but I wanted to stick to the one you said, I should not have though because the end result is not consistent.


r~


Reply via email to