diff mbox series

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

Message ID 20240119144024.14289-34-anjo@rev.ng (mailing list archive)
State New, archived
Headers show
Series Compile accel/tcg once (partially) | expand

Commit Message

Anton Johansson Jan. 19, 2024, 2:40 p.m. UTC
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(-)

Comments

Richard Henderson Jan. 24, 2024, 3:30 a.m. UTC | #1
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~
diff mbox series

Patch

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;