[RFC PATCH 33/34] accel/tcg: Make translator.c (partially) target independent

Anton Johansson via posted 34 patches 10 months, 1 week ago
[RFC PATCH 33/34] accel/tcg: Make translator.c (partially) target independent
Posted by Anton Johansson via 10 months, 1 week ago
Make CPUState offset calculations target independent by using that
CPUState and CPUArchState are statically guaranteed to lie next to each
other in memory.

Signed-off-by: Anton Johansson <anjo@rev.ng>
---
 accel/tcg/translator.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
index 65219b52eb..43303577d7 100644
--- a/accel/tcg/translator.c
+++ b/accel/tcg/translator.c
@@ -19,8 +19,8 @@
 static void gen_io_start(void)
 {
     tcg_gen_st_i32(tcg_constant_i32(1), tcg_env,
-                   offsetof(ArchCPU, parent_obj.neg.can_do_io) -
-                   offsetof(ArchCPU, env));
+                   offsetof(CPUState, neg.can_do_io) -
+                   sizeof(CPUState));
 }
 
 bool translator_io_start(DisasContextBase *db)
@@ -53,8 +53,8 @@ static TCGOp *gen_tb_start(uint32_t cflags)
     TCGOp *icount_start_insn = NULL;
 
     tcg_gen_ld_i32(count, tcg_env,
-                   offsetof(ArchCPU, parent_obj.neg.icount_decr.u32)
-                   - offsetof(ArchCPU, env));
+                   offsetof(CPUState, neg.icount_decr.u32) -
+                   sizeof(CPUState));
 
     if (cflags & CF_USE_ICOUNT) {
         /*
@@ -82,8 +82,8 @@ static TCGOp *gen_tb_start(uint32_t cflags)
 
     if (cflags & CF_USE_ICOUNT) {
         tcg_gen_st16_i32(count, tcg_env,
-                         offsetof(ArchCPU, parent_obj.neg.icount_decr.u16.low)
-                         - offsetof(ArchCPU, env));
+                         offsetof(CPUState, neg.icount_decr.u16.low) -
+                         sizeof(CPUState));
         /*
          * cpu->can_do_io is cleared automatically here at the beginning of
          * each translation block.  The cost is minimal and only paid for
@@ -92,8 +92,8 @@ static TCGOp *gen_tb_start(uint32_t cflags)
          * go with gen_io_start().
          */
         tcg_gen_st_i32(tcg_constant_i32(0), tcg_env,
-                       offsetof(ArchCPU, parent_obj.neg.can_do_io) -
-                       offsetof(ArchCPU, env));
+                       offsetof(CPUState, neg.can_do_io) -
+                       sizeof(CPUState));
     }
 
     return icount_start_insn;
-- 
2.43.0
Re: [RFC PATCH 33/34] accel/tcg: Make translator.c (partially) target independent
Posted by Richard Henderson 10 months, 1 week ago
On 1/20/24 00:40, Anton Johansson wrote:
> Make CPUState offset calculations target independent by using that
> CPUState and CPUArchState are statically guaranteed to lie next to each
> other in memory.
> 
> Signed-off-by: Anton Johansson<anjo@rev.ng>
> ---
>   accel/tcg/translator.c | 16 ++++++++--------
>   1 file changed, 8 insertions(+), 8 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~