qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL
@ 2023-02-27 13:51 Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 01/27] include/exec: Introduce `CF_PCREL` Anton Johansson via
                   ` (27 more replies)
  0 siblings, 28 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

This patchset entirely replaces the macro TARGET_TB_PCREL with
a field in TranslationBlock.cflags called CF_PCREL, and is a
first step towards removing target-specific assumptions from
non-target/ directories.

The grand goal is to allow for heterogeneous QEMU binaries
consisting of multiple frontends.

RFC: https://lists.nongnu.org/archive/html/qemu-devel/2022-12/msg04518.html

Changes in v2:
  * Setting of CF_PCREL (previously patch 3) was split in two and moved
    up front (to patch 2 and 3);

  * Replacing of TARGET_TB_PCREL (previously patch 2) was split into
    four patches (patches [4,7]), one for each affected submodule;

  * Removal of TARGET_TB_PCREL (previously patch 3) was moved into
    separate patches, one for each submodule (patches [8,10]);

  * Patch 11 was introduced in response to feedback, and removes
    CF_PCREL checks in functions in tb-jmp-cache.h, these functions were
    always called in a context where CF_PCREL was already being checked.
    These tb-jmp-cache.h functions were then removed in favour of manual
    inlining;

  * Patches [12,26] replaces calls to tb_pc() with a member access
    tb->pc, the motivation being that tb_pc() was (almost) always called
    in a context where CF_PCREL was already being checked;

  * Finally patch 27 removes tb_pc() which is no longer used.

Changes in v3:
  * Added reviewed-bys on remaining patches.

Anton Johansson (27):
  include/exec: Introduce `CF_PCREL`
  target/i386: set `CF_PCREL` in `x86_cpu_realizefn`
  target/arm: set `CF_PCREL` in `arm_cpu_realizefn`
  accel/tcg: Replace `TARGET_TB_PCREL` with `CF_PCREL`
  include/exec: Replace `TARGET_TB_PCREL` with `CF_PCREL`
  target/arm: Replace `TARGET_TB_PCREL` with `CF_PCREL`
  target/i386: Replace `TARGET_TB_PCREL` with `CF_PCREL`
  include/exec: Remove `TARGET_TB_PCREL` define
  target/arm: Remove `TARGET_TB_PCREL` define
  target/i386: Remove `TARGET_TB_PCREL` define
  accel/tcg: Move jmp-cache `CF_PCREL` checks to caller
  accel/tcg: Replace `tb_pc()` with `tb->pc`
  target/tricore: Replace `tb_pc()` with `tb->pc`
  target/sparc: Replace `tb_pc()` with `tb->pc`
  target/sh4: Replace `tb_pc()` with `tb->pc`
  target/rx: Replace `tb_pc()` with `tb->pc`
  target/riscv: Replace `tb_pc()` with `tb->pc`
  target/openrisc: Replace `tb_pc()` with `tb->pc`
  target/mips: Replace `tb_pc()` with `tb->pc`
  target/microblaze: Replace `tb_pc()` with `tb->pc`
  target/loongarch: Replace `tb_pc()` with `tb->pc`
  target/i386: Replace `tb_pc()` with `tb->pc`
  target/hppa: Replace `tb_pc()` with `tb->pc`
  target/hexagon: Replace `tb_pc()` with `tb->pc`
  target/avr: Replace `tb_pc()` with `tb->pc`
  target/arm: Replace `tb_pc()` with `tb->pc`
  include/exec: Remove `tb_pc()`

 accel/tcg/cpu-exec.c                    | 64 +++++++++++++++++--------
 accel/tcg/internal.h                    | 10 ++--
 accel/tcg/perf.c                        |  2 +-
 accel/tcg/tb-jmp-cache.h                | 42 +---------------
 accel/tcg/tb-maint.c                    | 10 ++--
 accel/tcg/translate-all.c               | 16 +++----
 include/exec/cpu-defs.h                 |  3 --
 include/exec/exec-all.h                 | 21 ++------
 target/arm/cpu-param.h                  |  2 -
 target/arm/cpu.c                        | 17 ++++---
 target/arm/translate-a64.c              |  8 ++--
 target/arm/translate.c                  |  6 +--
 target/arm/translate.h                  |  2 +-
 target/avr/cpu.c                        |  3 +-
 target/hexagon/cpu.c                    |  4 +-
 target/hppa/cpu.c                       |  8 ++--
 target/i386/cpu-param.h                 |  4 --
 target/i386/cpu.c                       |  5 ++
 target/i386/helper.c                    |  2 +-
 target/i386/tcg/tcg-cpu.c               |  8 ++--
 target/i386/tcg/translate.c             | 26 +++++-----
 target/loongarch/cpu.c                  |  6 ++-
 target/microblaze/cpu.c                 |  4 +-
 target/mips/tcg/exception.c             |  3 +-
 target/mips/tcg/sysemu/special_helper.c |  2 +-
 target/openrisc/cpu.c                   |  4 +-
 target/riscv/cpu.c                      |  7 ++-
 target/rx/cpu.c                         |  3 +-
 target/sh4/cpu.c                        |  6 ++-
 target/sparc/cpu.c                      |  4 +-
 target/tricore/cpu.c                    |  3 +-
 31 files changed, 152 insertions(+), 153 deletions(-)

--
2.39.1


^ permalink raw reply	[flat|nested] 33+ messages in thread

* [PATCH v3 01/27] include/exec: Introduce `CF_PCREL`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 02/27] target/i386: set `CF_PCREL` in `x86_cpu_realizefn` Anton Johansson via
                   ` (26 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Adds a new field to TranslationBlock.cflags denoting whether or not the
instructions of a given translation block are pc-relative. This field
aims to replace the macro `TARGET_TB_PCREL`.

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/exec/exec-all.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 0e36f4d063..9186a58554 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -545,6 +545,7 @@ struct TranslationBlock {
 #define CF_INVALID       0x00040000 /* TB is stale. Set with @jmp_lock held */
 #define CF_PARALLEL      0x00080000 /* Generate code for a parallel context */
 #define CF_NOIRQ         0x00100000 /* Generate an uninterruptible TB */
+#define CF_PCREL         0x00200000 /* Opcodes in TB are PC-relative */
 #define CF_CLUSTER_MASK  0xff000000 /* Top 8 bits are cluster ID */
 #define CF_CLUSTER_SHIFT 24
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 02/27] target/i386: set `CF_PCREL` in `x86_cpu_realizefn`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 01/27] include/exec: Introduce `CF_PCREL` Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 03/27] target/arm: set `CF_PCREL` in `arm_cpu_realizefn` Anton Johansson via
                   ` (25 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 4d2b8d0444..5be294b122 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -6404,6 +6404,11 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
     static bool ht_warned;
     unsigned requested_lbr_fmt;
 
+    /* Use pc-relative instructions in system-mode */
+#ifndef CONFIG_USER_ONLY
+    cs->tcg_cflags |= CF_PCREL;
+#endif
+
     if (cpu->apic_id == UNASSIGNED_APIC_ID) {
         error_setg(errp, "apic-id property was not initialized properly");
         return;
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 03/27] target/arm: set `CF_PCREL` in `arm_cpu_realizefn`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 01/27] include/exec: Introduce `CF_PCREL` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 02/27] target/i386: set `CF_PCREL` in `x86_cpu_realizefn` Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 04/27] accel/tcg: Replace `TARGET_TB_PCREL` with `CF_PCREL` Anton Johansson via
                   ` (24 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/cpu.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 876ab8f3bf..c38420a4d1 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1554,6 +1554,11 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
     Error *local_err = NULL;
     bool no_aa32 = false;
 
+    /* Use pc-relative instructions in system-mode */
+#ifndef CONFIG_USER_ONLY
+    cs->tcg_cflags |= CF_PCREL;
+#endif
+
     /* If we needed to query the host kernel for the CPU features
      * then it's possible that might have failed in the initfn, but
      * this is the first point where we can report it.
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 04/27] accel/tcg: Replace `TARGET_TB_PCREL` with `CF_PCREL`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (2 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 03/27] target/arm: set `CF_PCREL` in `arm_cpu_realizefn` Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 05/27] include/exec: " Anton Johansson via
                   ` (23 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 accel/tcg/cpu-exec.c      |  8 +++----
 accel/tcg/internal.h      | 10 ++++----
 accel/tcg/perf.c          |  2 +-
 accel/tcg/tb-jmp-cache.h  | 48 +++++++++++++++++++--------------------
 accel/tcg/tb-maint.c      |  8 +++----
 accel/tcg/translate-all.c | 14 ++++++------
 6 files changed, 44 insertions(+), 46 deletions(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 5357608b14..92b833adcf 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -185,7 +185,7 @@ static bool tb_lookup_cmp(const void *p, const void *d)
     const TranslationBlock *tb = p;
     const struct tb_desc *desc = d;
 
-    if ((TARGET_TB_PCREL || tb_pc(tb) == desc->pc) &&
+    if ((tb_cflags(tb) & CF_PCREL || tb_pc(tb) == desc->pc) &&
         tb_page_addr0(tb) == desc->page_addr0 &&
         tb->cs_base == desc->cs_base &&
         tb->flags == desc->flags &&
@@ -237,7 +237,7 @@ static TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc,
         return NULL;
     }
     desc.page_addr0 = phys_pc;
-    h = tb_hash_func(phys_pc, (TARGET_TB_PCREL ? 0 : pc),
+    h = tb_hash_func(phys_pc, (cflags & CF_PCREL ? 0 : pc),
                      flags, cflags, *cpu->trace_dstate);
     return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp);
 }
@@ -256,7 +256,7 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc,
 
     hash = tb_jmp_cache_hash_func(pc);
     jc = cpu->tb_jmp_cache;
-    tb = tb_jmp_cache_get_tb(jc, hash);
+    tb = tb_jmp_cache_get_tb(jc, cflags, hash);
 
     if (likely(tb &&
                tb_jmp_cache_get_pc(jc, hash, tb) == pc &&
@@ -459,7 +459,7 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
         if (cc->tcg_ops->synchronize_from_tb) {
             cc->tcg_ops->synchronize_from_tb(cpu, last_tb);
         } else {
-            assert(!TARGET_TB_PCREL);
+            tcg_debug_assert(!(tb_cflags(last_tb) & CF_PCREL));
             assert(cc->set_pc);
             cc->set_pc(cpu, tb_pc(last_tb));
         }
diff --git a/accel/tcg/internal.h b/accel/tcg/internal.h
index 6edff16fb0..261924e7fa 100644
--- a/accel/tcg/internal.h
+++ b/accel/tcg/internal.h
@@ -57,11 +57,11 @@ void cpu_restore_state_from_tb(CPUState *cpu, TranslationBlock *tb,
 /* Return the current PC from CPU, which may be cached in TB. */
 static inline target_ulong log_pc(CPUState *cpu, const TranslationBlock *tb)
 {
-#if TARGET_TB_PCREL
-    return cpu->cc->get_pc(cpu);
-#else
-    return tb_pc(tb);
-#endif
+    if (tb_cflags(tb) & CF_PCREL) {
+        return cpu->cc->get_pc(cpu);
+    } else {
+        return tb_pc(tb);
+    }
 }
 
 #endif /* ACCEL_TCG_INTERNAL_H */
diff --git a/accel/tcg/perf.c b/accel/tcg/perf.c
index ae19f6e28f..65e35ea3b9 100644
--- a/accel/tcg/perf.c
+++ b/accel/tcg/perf.c
@@ -328,7 +328,7 @@ void perf_report_code(uint64_t guest_pc, TranslationBlock *tb,
     for (insn = 0; insn < tb->icount; insn++) {
         /* FIXME: This replicates the restore_state_to_opc() logic. */
         q[insn].address = tcg_ctx->gen_insn_data[insn][0];
-        if (TARGET_TB_PCREL) {
+        if (tb_cflags(tb) & CF_PCREL) {
             q[insn].address |= (guest_pc & TARGET_PAGE_MASK);
         } else {
 #if defined(TARGET_I386)
diff --git a/accel/tcg/tb-jmp-cache.h b/accel/tcg/tb-jmp-cache.h
index b3f6e78835..083939b302 100644
--- a/accel/tcg/tb-jmp-cache.h
+++ b/accel/tcg/tb-jmp-cache.h
@@ -14,53 +14,51 @@
 
 /*
  * Accessed in parallel; all accesses to 'tb' must be atomic.
- * For TARGET_TB_PCREL, accesses to 'pc' must be protected by
- * a load_acquire/store_release to 'tb'.
+ * For CF_PCREL, accesses to 'pc' must be protected by a
+ * load_acquire/store_release to 'tb'.
  */
 struct CPUJumpCache {
     struct rcu_head rcu;
     struct {
         TranslationBlock *tb;
-#if TARGET_TB_PCREL
         target_ulong pc;
-#endif
     } array[TB_JMP_CACHE_SIZE];
 };
 
 static inline TranslationBlock *
-tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t hash)
+tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t cflags, uint32_t hash)
 {
-#if TARGET_TB_PCREL
-    /* Use acquire to ensure current load of pc from jc. */
-    return qatomic_load_acquire(&jc->array[hash].tb);
-#else
-    /* Use rcu_read to ensure current load of pc from *tb. */
-    return qatomic_rcu_read(&jc->array[hash].tb);
-#endif
+    if (cflags & CF_PCREL) {
+        /* Use acquire to ensure current load of pc from jc. */
+        return qatomic_load_acquire(&jc->array[hash].tb);
+    } else {
+        /* Use rcu_read to ensure current load of pc from *tb. */
+        return qatomic_rcu_read(&jc->array[hash].tb);
+    }
 }
 
 static inline target_ulong
 tb_jmp_cache_get_pc(CPUJumpCache *jc, uint32_t hash, TranslationBlock *tb)
 {
-#if TARGET_TB_PCREL
-    return jc->array[hash].pc;
-#else
-    return tb_pc(tb);
-#endif
+    if (tb_cflags(tb) & CF_PCREL) {
+        return jc->array[hash].pc;
+    } else {
+        return tb_pc(tb);
+    }
 }
 
 static inline void
 tb_jmp_cache_set(CPUJumpCache *jc, uint32_t hash,
                  TranslationBlock *tb, target_ulong pc)
 {
-#if TARGET_TB_PCREL
-    jc->array[hash].pc = pc;
-    /* Use store_release on tb to ensure pc is written first. */
-    qatomic_store_release(&jc->array[hash].tb, tb);
-#else
-    /* Use the pc value already stored in tb->pc. */
-    qatomic_set(&jc->array[hash].tb, tb);
-#endif
+    if (tb_cflags(tb) & CF_PCREL) {
+        jc->array[hash].pc = pc;
+        /* Use store_release on tb to ensure pc is written first. */
+        qatomic_store_release(&jc->array[hash].tb, tb);
+    } else{
+        /* Use the pc value already stored in tb->pc. */
+        qatomic_set(&jc->array[hash].tb, tb);
+    }
 }
 
 #endif /* ACCEL_TCG_TB_JMP_CACHE_H */
diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index b3d6529ae2..2dbc2ce172 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -44,7 +44,7 @@ static bool tb_cmp(const void *ap, const void *bp)
     const TranslationBlock *a = ap;
     const TranslationBlock *b = bp;
 
-    return ((TARGET_TB_PCREL || tb_pc(a) == tb_pc(b)) &&
+    return ((tb_cflags(a) & CF_PCREL || tb_pc(a) == tb_pc(b)) &&
             a->cs_base == b->cs_base &&
             a->flags == b->flags &&
             (tb_cflags(a) & ~CF_INVALID) == (tb_cflags(b) & ~CF_INVALID) &&
@@ -847,7 +847,7 @@ static void tb_jmp_cache_inval_tb(TranslationBlock *tb)
 {
     CPUState *cpu;
 
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(tb) & CF_PCREL) {
         /* A TB may be at any virtual address */
         CPU_FOREACH(cpu) {
             tcg_flush_jmp_cache(cpu);
@@ -885,7 +885,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
 
     /* remove the TB from the hash list */
     phys_pc = tb_page_addr0(tb);
-    h = tb_hash_func(phys_pc, (TARGET_TB_PCREL ? 0 : tb_pc(tb)),
+    h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb_pc(tb)),
                      tb->flags, orig_cflags, tb->trace_vcpu_dstate);
     if (!qht_remove(&tb_ctx.htable, tb, h)) {
         return;
@@ -966,7 +966,7 @@ TranslationBlock *tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
     tb_record(tb, p, p2);
 
     /* add in the hash table */
-    h = tb_hash_func(phys_pc, (TARGET_TB_PCREL ? 0 : tb_pc(tb)),
+    h = tb_hash_func(phys_pc, (tb->cflags & CF_PCREL ? 0 : tb_pc(tb)),
                      tb->flags, tb->cflags, tb->trace_vcpu_dstate);
     qht_insert(&tb_ctx.htable, tb, h, &existing_tb);
 
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 9e925c10f3..6ae3cc9d71 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -135,7 +135,7 @@ static int encode_search(TranslationBlock *tb, uint8_t *block)
 
         for (j = 0; j < TARGET_INSN_START_WORDS; ++j) {
             if (i == 0) {
-                prev = (!TARGET_TB_PCREL && j == 0 ? tb_pc(tb) : 0);
+                prev = (!(tb_cflags(tb) & CF_PCREL) && j == 0 ? tb_pc(tb) : 0);
             } else {
                 prev = tcg_ctx->gen_insn_data[i - 1][j];
             }
@@ -170,7 +170,7 @@ static int cpu_unwind_data_from_tb(TranslationBlock *tb, uintptr_t host_pc,
     }
 
     memset(data, 0, sizeof(uint64_t) * TARGET_INSN_START_WORDS);
-    if (!TARGET_TB_PCREL) {
+    if (!(tb_cflags(tb) & CF_PCREL)) {
         data[0] = tb_pc(tb);
     }
 
@@ -341,9 +341,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
 
     gen_code_buf = tcg_ctx->code_gen_ptr;
     tb->tc.ptr = tcg_splitwx_to_rx(gen_code_buf);
-#if !TARGET_TB_PCREL
-    tb->pc = pc;
-#endif
+    if (!(cflags & CF_PCREL)) {
+        tb->pc = pc;
+    }
     tb->cs_base = cs_base;
     tb->flags = flags;
     tb->cflags = cflags;
@@ -408,8 +408,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
     tb->tc.size = gen_code_size;
 
     /*
-     * For TARGET_TB_PCREL, attribute all executions of the generated
-     * code to its first mapping.
+     * For CF_PCREL, attribute all executions of the generated code
+     * to its first mapping.
      */
     perf_report_code(pc, tb, tcg_splitwx_to_rx(gen_code_buf));
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 05/27] include/exec: Replace `TARGET_TB_PCREL` with `CF_PCREL`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (3 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 04/27] accel/tcg: Replace `TARGET_TB_PCREL` with `CF_PCREL` Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 06/27] target/arm: " Anton Johansson via
                   ` (22 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/exec/exec-all.h | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index 9186a58554..f1615af7cb 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -505,22 +505,20 @@ struct tb_tc {
 };
 
 struct TranslationBlock {
-#if !TARGET_TB_PCREL
     /*
      * Guest PC corresponding to this block.  This must be the true
      * virtual address.  Therefore e.g. x86 stores EIP + CS_BASE, and
      * targets like Arm, MIPS, HP-PA, which reuse low bits for ISA or
      * privilege, must store those bits elsewhere.
      *
-     * If TARGET_TB_PCREL, the opcodes for the TranslationBlock are
-     * written such that the TB is associated only with the physical
-     * page and may be run in any virtual address context.  In this case,
-     * PC must always be taken from ENV in a target-specific manner.
+     * If CF_PCREL, the opcodes for the TranslationBlock are written
+     * such that the TB is associated only with the physical page and
+     * may be run in any virtual address context.  In this case, PC
+     * must always be taken from ENV in a target-specific manner.
      * Unwind information is taken as offsets from the page, to be
      * deposited into the "current" PC.
      */
     target_ulong pc;
-#endif
 
     /*
      * Target-specific data associated with the TranslationBlock, e.g.:
@@ -614,22 +612,19 @@ struct TranslationBlock {
     uintptr_t jmp_dest[2];
 };
 
-/* Hide the read to avoid ifdefs for TARGET_TB_PCREL. */
-static inline target_ulong tb_pc(const TranslationBlock *tb)
-{
-#if TARGET_TB_PCREL
-    qemu_build_not_reached();
-#else
-    return tb->pc;
-#endif
-}
-
 /* Hide the qatomic_read to make code a little easier on the eyes */
 static inline uint32_t tb_cflags(const TranslationBlock *tb)
 {
     return qatomic_read(&tb->cflags);
 }
 
+/* Hide the read to avoid ifdefs for CF_PCREL. */
+static inline target_ulong tb_pc(const TranslationBlock *tb)
+{
+    assert(!(tb_cflags(tb) & CF_PCREL));
+    return tb->pc;
+}
+
 static inline tb_page_addr_t tb_page_addr0(const TranslationBlock *tb)
 {
 #ifdef CONFIG_USER_ONLY
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 06/27] target/arm: Replace `TARGET_TB_PCREL` with `CF_PCREL`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (4 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 05/27] include/exec: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 07/27] target/i386: " Anton Johansson via
                   ` (21 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/cpu.c           | 8 ++++----
 target/arm/translate-a64.c | 8 ++++----
 target/arm/translate.c     | 6 +++---
 target/arm/translate.h     | 2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index c38420a4d1..c05cb86a47 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -78,8 +78,8 @@ static vaddr arm_cpu_get_pc(CPUState *cs)
 void arm_cpu_synchronize_from_tb(CPUState *cs,
                                  const TranslationBlock *tb)
 {
-    /* The program counter is always up to date with TARGET_TB_PCREL. */
-    if (!TARGET_TB_PCREL) {
+    /* The program counter is always up to date with CF_PCREL. */
+    if (!(tb_cflags(tb) & CF_PCREL)) {
         CPUARMState *env = cs->env_ptr;
         /*
          * It's OK to look at env for the current mode here, because it's
@@ -100,7 +100,7 @@ void arm_restore_state_to_opc(CPUState *cs,
     CPUARMState *env = cs->env_ptr;
 
     if (is_a64(env)) {
-        if (TARGET_TB_PCREL) {
+        if (tb_cflags(tb) & CF_PCREL) {
             env->pc = (env->pc & TARGET_PAGE_MASK) | data[0];
         } else {
             env->pc = data[0];
@@ -108,7 +108,7 @@ void arm_restore_state_to_opc(CPUState *cs,
         env->condexec_bits = 0;
         env->exception.syndrome = data[2] << ARM_INSN_START_WORD2_SHIFT;
     } else {
-        if (TARGET_TB_PCREL) {
+        if (tb_cflags(tb) & CF_PCREL) {
             env->regs[15] = (env->regs[15] & TARGET_PAGE_MASK) | data[0];
         } else {
             env->regs[15] = data[0];
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
index da9f877476..b6d00b81da 100644
--- a/target/arm/translate-a64.c
+++ b/target/arm/translate-a64.c
@@ -143,7 +143,7 @@ static void reset_btype(DisasContext *s)
 static void gen_pc_plus_diff(DisasContext *s, TCGv_i64 dest, target_long diff)
 {
     assert(s->pc_save != -1);
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(s->base.tb) & CF_PCREL) {
         tcg_gen_addi_i64(dest, cpu_pc, (s->pc_curr - s->pc_save) + diff);
     } else {
         tcg_gen_movi_i64(dest, s->pc_curr + diff);
@@ -393,7 +393,7 @@ static void gen_goto_tb(DisasContext *s, int n, int64_t diff)
          * update to pc to the unlinked path.  A long chain of links
          * can thus avoid many updates to the PC.
          */
-        if (TARGET_TB_PCREL) {
+        if (tb_cflags(s->base.tb) & CF_PCREL) {
             gen_a64_update_pc(s, diff);
             tcg_gen_goto_tb(n);
         } else {
@@ -4297,7 +4297,7 @@ static void disas_pc_rel_adr(DisasContext *s, uint32_t insn)
     if (page) {
         /* ADRP (page based) */
         offset <<= 12;
-        /* The page offset is ok for TARGET_TB_PCREL. */
+        /* The page offset is ok for CF_PCREL. */
         offset -= s->pc_curr & 0xfff;
     }
 
@@ -14809,7 +14809,7 @@ static void aarch64_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
     DisasContext *dc = container_of(dcbase, DisasContext, base);
     target_ulong pc_arg = dc->base.pc_next;
 
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(dcbase->tb) & CF_PCREL) {
         pc_arg &= ~TARGET_PAGE_MASK;
     }
     tcg_gen_insn_start(pc_arg, 0, 0);
diff --git a/target/arm/translate.c b/target/arm/translate.c
index c23a3462bf..0e7d3b8561 100644
--- a/target/arm/translate.c
+++ b/target/arm/translate.c
@@ -269,7 +269,7 @@ static target_long jmp_diff(DisasContext *s, target_long diff)
 static void gen_pc_plus_diff(DisasContext *s, TCGv_i32 var, target_long diff)
 {
     assert(s->pc_save != -1);
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(s->base.tb) & CF_PCREL) {
         tcg_gen_addi_i32(var, cpu_R[15], (s->pc_curr - s->pc_save) + diff);
     } else {
         tcg_gen_movi_i32(var, s->pc_curr + diff);
@@ -2620,7 +2620,7 @@ static void gen_goto_tb(DisasContext *s, int n, target_long diff)
          * update to pc to the unlinked path.  A long chain of links
          * can thus avoid many updates to the PC.
          */
-        if (TARGET_TB_PCREL) {
+        if (tb_cflags(s->base.tb) & CF_PCREL) {
             gen_update_pc(s, diff);
             tcg_gen_goto_tb(n);
         } else {
@@ -9542,7 +9542,7 @@ static void arm_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
     uint32_t condexec_bits;
     target_ulong pc_arg = dc->base.pc_next;
 
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(dcbase->tb) & CF_PCREL) {
         pc_arg &= ~TARGET_PAGE_MASK;
     }
     if (dc->eci) {
diff --git a/target/arm/translate.h b/target/arm/translate.h
index 3717824b75..4001372acd 100644
--- a/target/arm/translate.h
+++ b/target/arm/translate.h
@@ -23,7 +23,7 @@ typedef struct DisasContext {
     /* The address of the current instruction being translated. */
     target_ulong pc_curr;
     /*
-     * For TARGET_TB_PCREL, the full value of cpu_pc is not known
+     * For CF_PCREL, the full value of cpu_pc is not known
      * (although the page offset is known).  For convenience, the
      * translation loop uses the full virtual address that triggered
      * the translation, from base.pc_start through pc_curr.
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 07/27] target/i386: Replace `TARGET_TB_PCREL` with `CF_PCREL`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (5 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 06/27] target/arm: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 08/27] include/exec: Remove `TARGET_TB_PCREL` define Anton Johansson via
                   ` (20 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/helper.c        |  2 +-
 target/i386/tcg/tcg-cpu.c   |  6 +++---
 target/i386/tcg/translate.c | 26 +++++++++++++-------------
 3 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/target/i386/helper.c b/target/i386/helper.c
index 0ac2da066d..8857444819 100644
--- a/target/i386/helper.c
+++ b/target/i386/helper.c
@@ -520,7 +520,7 @@ static inline target_ulong get_memio_eip(CPUX86State *env)
     }
 
     /* Per x86_restore_state_to_opc. */
-    if (TARGET_TB_PCREL) {
+    if (cs->tcg_cflags & CF_PCREL) {
         return (env->eip & TARGET_PAGE_MASK) | data[0];
     } else {
         return data[0] - env->segs[R_CS].base;
diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c
index 79ac5908f7..c090ce152b 100644
--- a/target/i386/tcg/tcg-cpu.c
+++ b/target/i386/tcg/tcg-cpu.c
@@ -49,8 +49,8 @@ static void x86_cpu_exec_exit(CPUState *cs)
 static void x86_cpu_synchronize_from_tb(CPUState *cs,
                                         const TranslationBlock *tb)
 {
-    /* The instruction pointer is always up to date with TARGET_TB_PCREL. */
-    if (!TARGET_TB_PCREL) {
+    /* The instruction pointer is always up to date with CF_PCREL. */
+    if (!(tb_cflags(tb) & CF_PCREL)) {
         CPUX86State *env = cs->env_ptr;
         env->eip = tb_pc(tb) - tb->cs_base;
     }
@@ -64,7 +64,7 @@ static void x86_restore_state_to_opc(CPUState *cs,
     CPUX86State *env = &cpu->env;
     int cc_op = data[1];
 
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(tb) & CF_PCREL) {
         env->eip = (env->eip & TARGET_PAGE_MASK) | data[0];
     } else {
         env->eip = data[0] - tb->cs_base;
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index 9d9392b009..3fed6d96f9 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -545,7 +545,7 @@ static inline void gen_op_st_rm_T0_A0(DisasContext *s, int idx, int d)
 static void gen_update_eip_cur(DisasContext *s)
 {
     assert(s->pc_save != -1);
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(s->base.tb) & CF_PCREL) {
         tcg_gen_addi_tl(cpu_eip, cpu_eip, s->base.pc_next - s->pc_save);
     } else {
         tcg_gen_movi_tl(cpu_eip, s->base.pc_next - s->cs_base);
@@ -556,7 +556,7 @@ static void gen_update_eip_cur(DisasContext *s)
 static void gen_update_eip_next(DisasContext *s)
 {
     assert(s->pc_save != -1);
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(s->base.tb) & CF_PCREL) {
         tcg_gen_addi_tl(cpu_eip, cpu_eip, s->pc - s->pc_save);
     } else {
         tcg_gen_movi_tl(cpu_eip, s->pc - s->cs_base);
@@ -588,7 +588,7 @@ static TCGv_i32 eip_next_i32(DisasContext *s)
     if (CODE64(s)) {
         return tcg_constant_i32(-1);
     }
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(s->base.tb) & CF_PCREL) {
         TCGv_i32 ret = tcg_temp_new_i32();
         tcg_gen_trunc_tl_i32(ret, cpu_eip);
         tcg_gen_addi_i32(ret, ret, s->pc - s->pc_save);
@@ -601,7 +601,7 @@ static TCGv_i32 eip_next_i32(DisasContext *s)
 static TCGv eip_next_tl(DisasContext *s)
 {
     assert(s->pc_save != -1);
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(s->base.tb) & CF_PCREL) {
         TCGv ret = tcg_temp_new();
         tcg_gen_addi_tl(ret, cpu_eip, s->pc - s->pc_save);
         return ret;
@@ -613,7 +613,7 @@ static TCGv eip_next_tl(DisasContext *s)
 static TCGv eip_cur_tl(DisasContext *s)
 {
     assert(s->pc_save != -1);
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(s->base.tb) & CF_PCREL) {
         TCGv ret = tcg_temp_new();
         tcg_gen_addi_tl(ret, cpu_eip, s->base.pc_next - s->pc_save);
         return ret;
@@ -1830,7 +1830,7 @@ static void gen_rot_rm_T1(DisasContext *s, MemOp ot, int op1, int is_right)
     tcg_temp_free_i32(t0);
     tcg_temp_free_i32(t1);
 
-    /* The CC_OP value is no longer predictable.  */ 
+    /* The CC_OP value is no longer predictable.  */
     set_cc_op(s, CC_OP_DYNAMIC);
 }
 
@@ -1923,7 +1923,7 @@ static void gen_rotc_rm_T1(DisasContext *s, MemOp ot, int op1,
         gen_op_ld_v(s, ot, s->T0, s->A0);
     else
         gen_op_mov_v_reg(s, ot, s->T0, op1);
-    
+
     if (is_right) {
         switch (ot) {
         case MO_8:
@@ -2319,7 +2319,7 @@ static TCGv gen_lea_modrm_1(DisasContext *s, AddressParts a, bool is_vsib)
         ea = cpu_regs[a.base];
     }
     if (!ea) {
-        if (TARGET_TB_PCREL && a.base == -2) {
+        if (tb_cflags(s->base.tb) & CF_PCREL && a.base == -2) {
             /* With cpu_eip ~= pc_save, the expression is pc-relative. */
             tcg_gen_addi_tl(s->A0, cpu_eip, a.disp - s->pc_save);
         } else {
@@ -2867,7 +2867,7 @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num)
     if (!CODE64(s)) {
         if (ot == MO_16) {
             mask = 0xffff;
-            if (TARGET_TB_PCREL && CODE32(s)) {
+            if (tb_cflags(s->base.tb) & CF_PCREL && CODE32(s)) {
                 use_goto_tb = false;
             }
         } else {
@@ -2879,7 +2879,7 @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num)
     gen_update_cc_op(s);
     set_cc_op(s, CC_OP_DYNAMIC);
 
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(s->base.tb) & CF_PCREL) {
         tcg_gen_addi_tl(cpu_eip, cpu_eip, new_pc - s->pc_save);
         /*
          * If we can prove the branch does not leave the page and we have
@@ -2896,13 +2896,13 @@ static void gen_jmp_rel(DisasContext *s, MemOp ot, int diff, int tb_num)
         translator_use_goto_tb(&s->base, new_eip + s->cs_base)) {
         /* jump to same page: we can use a direct jump */
         tcg_gen_goto_tb(tb_num);
-        if (!TARGET_TB_PCREL) {
+        if (!(tb_cflags(s->base.tb) & CF_PCREL)) {
             tcg_gen_movi_tl(cpu_eip, new_eip);
         }
         tcg_gen_exit_tb(s->base.tb, tb_num);
         s->base.is_jmp = DISAS_NORETURN;
     } else {
-        if (!TARGET_TB_PCREL) {
+        if (!(tb_cflags(s->base.tb) & CF_PCREL)) {
             tcg_gen_movi_tl(cpu_eip, new_eip);
         }
         if (s->jmp_opt) {
@@ -7065,7 +7065,7 @@ static void i386_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu)
     target_ulong pc_arg = dc->base.pc_next;
 
     dc->prev_insn_end = tcg_last_op();
-    if (TARGET_TB_PCREL) {
+    if (tb_cflags(dcbase->tb) & CF_PCREL) {
         pc_arg -= dc->cs_base;
         pc_arg &= ~TARGET_PAGE_MASK;
     }
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 08/27] include/exec: Remove `TARGET_TB_PCREL` define
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (6 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 07/27] target/i386: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 09/27] target/arm: " Anton Johansson via
                   ` (19 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/exec/cpu-defs.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
index 21309cf567..67239b4e5e 100644
--- a/include/exec/cpu-defs.h
+++ b/include/exec/cpu-defs.h
@@ -54,9 +54,6 @@
 #  error TARGET_PAGE_BITS must be defined in cpu-param.h
 # endif
 #endif
-#ifndef TARGET_TB_PCREL
-# define TARGET_TB_PCREL 0
-#endif
 
 #define TARGET_LONG_SIZE (TARGET_LONG_BITS / 8)
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 09/27] target/arm: Remove `TARGET_TB_PCREL` define
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (7 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 08/27] include/exec: Remove `TARGET_TB_PCREL` define Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 10/27] target/i386: " Anton Johansson via
                   ` (18 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/cpu-param.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/target/arm/cpu-param.h b/target/arm/cpu-param.h
index 53cac9c89b..b7bde18986 100644
--- a/target/arm/cpu-param.h
+++ b/target/arm/cpu-param.h
@@ -31,8 +31,6 @@
 # define TARGET_PAGE_BITS_VARY
 # define TARGET_PAGE_BITS_MIN  10
 
-# define TARGET_TB_PCREL 1
-
 /*
  * Cache the attrs and shareability fields from the page table entry.
  *
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 10/27] target/i386: Remove `TARGET_TB_PCREL` define
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (8 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 09/27] target/arm: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 11/27] accel/tcg: Move jmp-cache `CF_PCREL` checks to caller Anton Johansson via
                   ` (17 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/cpu-param.h | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/target/i386/cpu-param.h b/target/i386/cpu-param.h
index f579b16bd2..abad52af20 100644
--- a/target/i386/cpu-param.h
+++ b/target/i386/cpu-param.h
@@ -25,8 +25,4 @@
 #define TARGET_PAGE_BITS 12
 #define NB_MMU_MODES 5
 
-#ifndef CONFIG_USER_ONLY
-# define TARGET_TB_PCREL 1
-#endif
-
 #endif
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 11/27] accel/tcg: Move jmp-cache `CF_PCREL` checks to caller
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (9 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 10/27] target/i386: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 12/27] accel/tcg: Replace `tb_pc()` with `tb->pc` Anton Johansson via
                   ` (16 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

tb-jmp-cache.h contains a few small functions that only exist to hide a
CF_PCREL check, however the caller often already performs such a check.

This patch moves CF_PCREL checks from the callee to the caller, and also
removes these functions which now only hide an access of the jmp-cache.

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 accel/tcg/cpu-exec.c     | 56 +++++++++++++++++++++++++++++-----------
 accel/tcg/tb-jmp-cache.h | 36 --------------------------
 2 files changed, 41 insertions(+), 51 deletions(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 92b833adcf..5efa8bf42a 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -256,21 +256,46 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc,
 
     hash = tb_jmp_cache_hash_func(pc);
     jc = cpu->tb_jmp_cache;
-    tb = tb_jmp_cache_get_tb(jc, cflags, hash);
-
-    if (likely(tb &&
-               tb_jmp_cache_get_pc(jc, hash, tb) == pc &&
-               tb->cs_base == cs_base &&
-               tb->flags == flags &&
-               tb->trace_vcpu_dstate == *cpu->trace_dstate &&
-               tb_cflags(tb) == cflags)) {
-        return tb;
-    }
-    tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags);
-    if (tb == NULL) {
-        return NULL;
+
+    if (cflags & CF_PCREL) {
+        /* Use acquire to ensure current load of pc from jc. */
+        tb =  qatomic_load_acquire(&jc->array[hash].tb);
+
+        if (likely(tb &&
+                   jc->array[hash].pc == pc &&
+                   tb->cs_base == cs_base &&
+                   tb->flags == flags &&
+                   tb->trace_vcpu_dstate == *cpu->trace_dstate &&
+                   tb_cflags(tb) == cflags)) {
+            return tb;
+        }
+        tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags);
+        if (tb == NULL) {
+            return NULL;
+        }
+        jc->array[hash].pc = pc;
+        /* Use store_release on tb to ensure pc is written first. */
+        qatomic_store_release(&jc->array[hash].tb, tb);
+    } else {
+        /* Use rcu_read to ensure current load of pc from *tb. */
+        tb = qatomic_rcu_read(&jc->array[hash].tb);
+
+        if (likely(tb &&
+                   tb_pc(tb) == pc &&
+                   tb->cs_base == cs_base &&
+                   tb->flags == flags &&
+                   tb->trace_vcpu_dstate == *cpu->trace_dstate &&
+                   tb_cflags(tb) == cflags)) {
+            return tb;
+        }
+        tb = tb_htable_lookup(cpu, pc, cs_base, flags, cflags);
+        if (tb == NULL) {
+            return NULL;
+        }
+        /* Use the pc value already stored in tb->pc. */
+        qatomic_set(&jc->array[hash].tb, tb);
     }
-    tb_jmp_cache_set(jc, hash, tb, pc);
+
     return tb;
 }
 
@@ -959,7 +984,8 @@ cpu_exec_loop(CPUState *cpu, SyncClocks *sc)
                  * for the fast lookup
                  */
                 h = tb_jmp_cache_hash_func(pc);
-                tb_jmp_cache_set(cpu->tb_jmp_cache, h, tb, pc);
+                /* Use the pc value already stored in tb->pc. */
+                qatomic_set(&cpu->tb_jmp_cache->array[h].tb, tb);
             }
 
 #ifndef CONFIG_USER_ONLY
diff --git a/accel/tcg/tb-jmp-cache.h b/accel/tcg/tb-jmp-cache.h
index 083939b302..bee87eb840 100644
--- a/accel/tcg/tb-jmp-cache.h
+++ b/accel/tcg/tb-jmp-cache.h
@@ -25,40 +25,4 @@ struct CPUJumpCache {
     } array[TB_JMP_CACHE_SIZE];
 };
 
-static inline TranslationBlock *
-tb_jmp_cache_get_tb(CPUJumpCache *jc, uint32_t cflags, uint32_t hash)
-{
-    if (cflags & CF_PCREL) {
-        /* Use acquire to ensure current load of pc from jc. */
-        return qatomic_load_acquire(&jc->array[hash].tb);
-    } else {
-        /* Use rcu_read to ensure current load of pc from *tb. */
-        return qatomic_rcu_read(&jc->array[hash].tb);
-    }
-}
-
-static inline target_ulong
-tb_jmp_cache_get_pc(CPUJumpCache *jc, uint32_t hash, TranslationBlock *tb)
-{
-    if (tb_cflags(tb) & CF_PCREL) {
-        return jc->array[hash].pc;
-    } else {
-        return tb_pc(tb);
-    }
-}
-
-static inline void
-tb_jmp_cache_set(CPUJumpCache *jc, uint32_t hash,
-                 TranslationBlock *tb, target_ulong pc)
-{
-    if (tb_cflags(tb) & CF_PCREL) {
-        jc->array[hash].pc = pc;
-        /* Use store_release on tb to ensure pc is written first. */
-        qatomic_store_release(&jc->array[hash].tb, tb);
-    } else{
-        /* Use the pc value already stored in tb->pc. */
-        qatomic_set(&jc->array[hash].tb, tb);
-    }
-}
-
 #endif /* ACCEL_TCG_TB_JMP_CACHE_H */
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 12/27] accel/tcg: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (10 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 11/27] accel/tcg: Move jmp-cache `CF_PCREL` checks to caller Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 13/27] target/tricore: " Anton Johansson via
                   ` (15 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 accel/tcg/cpu-exec.c      | 6 +++---
 accel/tcg/internal.h      | 2 +-
 accel/tcg/tb-maint.c      | 8 ++++----
 accel/tcg/translate-all.c | 4 ++--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
index 5efa8bf42a..9fb0fabf95 100644
--- a/accel/tcg/cpu-exec.c
+++ b/accel/tcg/cpu-exec.c
@@ -185,7 +185,7 @@ static bool tb_lookup_cmp(const void *p, const void *d)
     const TranslationBlock *tb = p;
     const struct tb_desc *desc = d;
 
-    if ((tb_cflags(tb) & CF_PCREL || tb_pc(tb) == desc->pc) &&
+    if ((tb_cflags(tb) & CF_PCREL || tb->pc == desc->pc) &&
         tb_page_addr0(tb) == desc->page_addr0 &&
         tb->cs_base == desc->cs_base &&
         tb->flags == desc->flags &&
@@ -281,7 +281,7 @@ static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc,
         tb = qatomic_rcu_read(&jc->array[hash].tb);
 
         if (likely(tb &&
-                   tb_pc(tb) == pc &&
+                   tb->pc == pc &&
                    tb->cs_base == cs_base &&
                    tb->flags == flags &&
                    tb->trace_vcpu_dstate == *cpu->trace_dstate &&
@@ -486,7 +486,7 @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
         } else {
             tcg_debug_assert(!(tb_cflags(last_tb) & CF_PCREL));
             assert(cc->set_pc);
-            cc->set_pc(cpu, tb_pc(last_tb));
+            cc->set_pc(cpu, last_tb->pc);
         }
         if (qemu_loglevel_mask(CPU_LOG_EXEC)) {
             target_ulong pc = log_pc(cpu, last_tb);
diff --git a/accel/tcg/internal.h b/accel/tcg/internal.h
index 261924e7fa..17b52ecdb7 100644
--- a/accel/tcg/internal.h
+++ b/accel/tcg/internal.h
@@ -60,7 +60,7 @@ static inline target_ulong log_pc(CPUState *cpu, const TranslationBlock *tb)
     if (tb_cflags(tb) & CF_PCREL) {
         return cpu->cc->get_pc(cpu);
     } else {
-        return tb_pc(tb);
+        return tb->pc;
     }
 }
 
diff --git a/accel/tcg/tb-maint.c b/accel/tcg/tb-maint.c
index 2dbc2ce172..efefa08ee1 100644
--- a/accel/tcg/tb-maint.c
+++ b/accel/tcg/tb-maint.c
@@ -44,7 +44,7 @@ static bool tb_cmp(const void *ap, const void *bp)
     const TranslationBlock *a = ap;
     const TranslationBlock *b = bp;
 
-    return ((tb_cflags(a) & CF_PCREL || tb_pc(a) == tb_pc(b)) &&
+    return ((tb_cflags(a) & CF_PCREL || a->pc == b->pc) &&
             a->cs_base == b->cs_base &&
             a->flags == b->flags &&
             (tb_cflags(a) & ~CF_INVALID) == (tb_cflags(b) & ~CF_INVALID) &&
@@ -853,7 +853,7 @@ static void tb_jmp_cache_inval_tb(TranslationBlock *tb)
             tcg_flush_jmp_cache(cpu);
         }
     } else {
-        uint32_t h = tb_jmp_cache_hash_func(tb_pc(tb));
+        uint32_t h = tb_jmp_cache_hash_func(tb->pc);
 
         CPU_FOREACH(cpu) {
             CPUJumpCache *jc = cpu->tb_jmp_cache;
@@ -885,7 +885,7 @@ static void do_tb_phys_invalidate(TranslationBlock *tb, bool rm_from_page_list)
 
     /* remove the TB from the hash list */
     phys_pc = tb_page_addr0(tb);
-    h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb_pc(tb)),
+    h = tb_hash_func(phys_pc, (orig_cflags & CF_PCREL ? 0 : tb->pc),
                      tb->flags, orig_cflags, tb->trace_vcpu_dstate);
     if (!qht_remove(&tb_ctx.htable, tb, h)) {
         return;
@@ -966,7 +966,7 @@ TranslationBlock *tb_link_page(TranslationBlock *tb, tb_page_addr_t phys_pc,
     tb_record(tb, p, p2);
 
     /* add in the hash table */
-    h = tb_hash_func(phys_pc, (tb->cflags & CF_PCREL ? 0 : tb_pc(tb)),
+    h = tb_hash_func(phys_pc, (tb->cflags & CF_PCREL ? 0 : tb->pc),
                      tb->flags, tb->cflags, tb->trace_vcpu_dstate);
     qht_insert(&tb_ctx.htable, tb, h, &existing_tb);
 
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index 6ae3cc9d71..389d0a940b 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -135,7 +135,7 @@ static int encode_search(TranslationBlock *tb, uint8_t *block)
 
         for (j = 0; j < TARGET_INSN_START_WORDS; ++j) {
             if (i == 0) {
-                prev = (!(tb_cflags(tb) & CF_PCREL) && j == 0 ? tb_pc(tb) : 0);
+                prev = (!(tb_cflags(tb) & CF_PCREL) && j == 0 ? tb->pc : 0);
             } else {
                 prev = tcg_ctx->gen_insn_data[i - 1][j];
             }
@@ -171,7 +171,7 @@ static int cpu_unwind_data_from_tb(TranslationBlock *tb, uintptr_t host_pc,
 
     memset(data, 0, sizeof(uint64_t) * TARGET_INSN_START_WORDS);
     if (!(tb_cflags(tb) & CF_PCREL)) {
-        data[0] = tb_pc(tb);
+        data[0] = tb->pc;
     }
 
     /*
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 13/27] target/tricore: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (11 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 12/27] accel/tcg: Replace `tb_pc()` with `tb->pc` Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-04-19  8:56   ` Bastian Koppelmann
  2023-02-27 13:51 ` [PATCH v3 14/27] target/sparc: " Anton Johansson via
                   ` (14 subsequent siblings)
  27 siblings, 1 reply; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/tricore/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c
index 594cd1efd5..d0a9272961 100644
--- a/target/tricore/cpu.c
+++ b/target/tricore/cpu.c
@@ -55,7 +55,8 @@ static void tricore_cpu_synchronize_from_tb(CPUState *cs,
     TriCoreCPU *cpu = TRICORE_CPU(cs);
     CPUTriCoreState *env = &cpu->env;
 
-    env->PC = tb_pc(tb);
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+    env->PC = tb->pc;
 }
 
 static void tricore_restore_state_to_opc(CPUState *cs,
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 14/27] target/sparc: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (12 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 13/27] target/tricore: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 15/27] target/sh4: " Anton Johansson via
                   ` (13 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/sparc/cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c
index 1734ef8dc6..e329a7aece 100644
--- a/target/sparc/cpu.c
+++ b/target/sparc/cpu.c
@@ -25,6 +25,7 @@
 #include "exec/exec-all.h"
 #include "hw/qdev-properties.h"
 #include "qapi/visitor.h"
+#include "tcg/tcg.h"
 
 //#define DEBUG_FEATURES
 
@@ -707,7 +708,8 @@ static void sparc_cpu_synchronize_from_tb(CPUState *cs,
 {
     SPARCCPU *cpu = SPARC_CPU(cs);
 
-    cpu->env.pc = tb_pc(tb);
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+    cpu->env.pc = tb->pc;
     cpu->env.npc = tb->cs_base;
 }
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 15/27] target/sh4: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (13 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 14/27] target/sparc: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 16/27] target/rx: " Anton Johansson via
                   ` (12 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/sh4/cpu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/target/sh4/cpu.c b/target/sh4/cpu.c
index f0934b20fa..61769ffdfa 100644
--- a/target/sh4/cpu.c
+++ b/target/sh4/cpu.c
@@ -26,6 +26,7 @@
 #include "migration/vmstate.h"
 #include "exec/exec-all.h"
 #include "fpu/softfloat-helpers.h"
+#include "tcg/tcg.h"
 
 static void superh_cpu_set_pc(CPUState *cs, vaddr value)
 {
@@ -46,7 +47,8 @@ static void superh_cpu_synchronize_from_tb(CPUState *cs,
 {
     SuperHCPU *cpu = SUPERH_CPU(cs);
 
-    cpu->env.pc = tb_pc(tb);
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+    cpu->env.pc = tb->pc;
     cpu->env.flags = tb->flags & TB_FLAG_ENVFLAGS_MASK;
 }
 
@@ -73,7 +75,7 @@ static bool superh_io_recompile_replay_branch(CPUState *cs,
     CPUSH4State *env = &cpu->env;
 
     if ((env->flags & (TB_FLAG_DELAY_SLOT | TB_FLAG_DELAY_SLOT_COND))
-        && env->pc != tb_pc(tb)) {
+        && !(cs->tcg_cflags & CF_PCREL) && env->pc != tb->pc) {
         env->pc -= 2;
         env->flags &= ~(TB_FLAG_DELAY_SLOT | TB_FLAG_DELAY_SLOT_COND);
         return true;
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 16/27] target/rx: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (14 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 15/27] target/sh4: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 17/27] target/riscv: " Anton Johansson via
                   ` (11 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/rx/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/rx/cpu.c b/target/rx/cpu.c
index 219ef28e46..67452e310c 100644
--- a/target/rx/cpu.c
+++ b/target/rx/cpu.c
@@ -44,7 +44,8 @@ static void rx_cpu_synchronize_from_tb(CPUState *cs,
 {
     RXCPU *cpu = RX_CPU(cs);
 
-    cpu->env.pc = tb_pc(tb);
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+    cpu->env.pc = tb->pc;
 }
 
 static void rx_restore_state_to_opc(CPUState *cs,
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 17/27] target/riscv: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (15 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 16/27] target/rx: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 23:05   ` Palmer Dabbelt
  2023-02-27 13:51 ` [PATCH v3 18/27] target/openrisc: " Anton Johansson via
                   ` (10 subsequent siblings)
  27 siblings, 1 reply; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/riscv/cpu.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 93b52b826c..9eb748a283 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -34,6 +34,7 @@
 #include "fpu/softfloat-helpers.h"
 #include "sysemu/kvm.h"
 #include "kvm_riscv.h"
+#include "tcg/tcg.h"
 
 /* RISC-V CPU definitions */
 
@@ -533,10 +534,12 @@ static void riscv_cpu_synchronize_from_tb(CPUState *cs,
     CPURISCVState *env = &cpu->env;
     RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL);
 
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+
     if (xl == MXL_RV32) {
-        env->pc = (int32_t)tb_pc(tb);
+        env->pc = (int32_t) tb->pc;
     } else {
-        env->pc = tb_pc(tb);
+        env->pc = tb->pc;
     }
 }
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 18/27] target/openrisc: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (16 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 17/27] target/riscv: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 19/27] target/mips: " Anton Johansson via
                   ` (9 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/openrisc/cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c
index 4c11a1f7ad..0ce4f796fa 100644
--- a/target/openrisc/cpu.c
+++ b/target/openrisc/cpu.c
@@ -22,6 +22,7 @@
 #include "qemu/qemu-print.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "tcg/tcg.h"
 
 static void openrisc_cpu_set_pc(CPUState *cs, vaddr value)
 {
@@ -43,7 +44,8 @@ static void openrisc_cpu_synchronize_from_tb(CPUState *cs,
 {
     OpenRISCCPU *cpu = OPENRISC_CPU(cs);
 
-    cpu->env.pc = tb_pc(tb);
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+    cpu->env.pc = tb->pc;
 }
 
 static void openrisc_restore_state_to_opc(CPUState *cs,
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 19/27] target/mips: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (17 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 18/27] target/openrisc: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 20/27] target/microblaze: " Anton Johansson via
                   ` (8 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/mips/tcg/exception.c             | 3 ++-
 target/mips/tcg/sysemu/special_helper.c | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/target/mips/tcg/exception.c b/target/mips/tcg/exception.c
index 96e61170e6..da49a93912 100644
--- a/target/mips/tcg/exception.c
+++ b/target/mips/tcg/exception.c
@@ -82,7 +82,8 @@ void mips_cpu_synchronize_from_tb(CPUState *cs, const TranslationBlock *tb)
     MIPSCPU *cpu = MIPS_CPU(cs);
     CPUMIPSState *env = &cpu->env;
 
-    env->active_tc.PC = tb_pc(tb);
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+    env->active_tc.PC = tb->pc;
     env->hflags &= ~MIPS_HFLAG_BMASK;
     env->hflags |= tb->flags & MIPS_HFLAG_BMASK;
 }
diff --git a/target/mips/tcg/sysemu/special_helper.c b/target/mips/tcg/sysemu/special_helper.c
index 3c5f35c759..93276f789d 100644
--- a/target/mips/tcg/sysemu/special_helper.c
+++ b/target/mips/tcg/sysemu/special_helper.c
@@ -94,7 +94,7 @@ bool mips_io_recompile_replay_branch(CPUState *cs, const TranslationBlock *tb)
     CPUMIPSState *env = &cpu->env;
 
     if ((env->hflags & MIPS_HFLAG_BMASK) != 0
-        && env->active_tc.PC != tb_pc(tb)) {
+        && !(cs->tcg_cflags & CF_PCREL) && env->active_tc.PC != tb->pc) {
         env->active_tc.PC -= (env->hflags & MIPS_HFLAG_B16 ? 2 : 4);
         env->hflags &= ~MIPS_HFLAG_BMASK;
         return true;
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 20/27] target/microblaze: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (18 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 19/27] target/mips: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 21/27] target/loongarch: " Anton Johansson via
                   ` (7 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/microblaze/cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index a2d2f5c340..03c2c4db1f 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -30,6 +30,7 @@
 #include "exec/exec-all.h"
 #include "exec/gdbstub.h"
 #include "fpu/softfloat-helpers.h"
+#include "tcg/tcg.h"
 
 static const struct {
     const char *name;
@@ -97,7 +98,8 @@ static void mb_cpu_synchronize_from_tb(CPUState *cs,
 {
     MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
 
-    cpu->env.pc = tb_pc(tb);
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+    cpu->env.pc = tb->pc;
     cpu->env.iflags = tb->flags & IFLAGS_TB_MASK;
 }
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 21/27] target/loongarch: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (19 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 20/27] target/microblaze: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 22/27] target/i386: " Anton Johansson via
                   ` (6 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/loongarch/cpu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 290ab4d526..e5efe4ebd7 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -18,6 +18,7 @@
 #include "fpu/softfloat-helpers.h"
 #include "cpu-csr.h"
 #include "sysemu/reset.h"
+#include "tcg/tcg.h"
 
 const char * const regnames[32] = {
     "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
@@ -321,7 +322,8 @@ static void loongarch_cpu_synchronize_from_tb(CPUState *cs,
     LoongArchCPU *cpu = LOONGARCH_CPU(cs);
     CPULoongArchState *env = &cpu->env;
 
-    env->pc = tb_pc(tb);
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+    env->pc = tb->pc;
 }
 
 static void loongarch_restore_state_to_opc(CPUState *cs,
@@ -599,7 +601,7 @@ static ObjectClass *loongarch_cpu_class_by_name(const char *cpu_model)
 
     oc = object_class_by_name(cpu_model);
     if (!oc) {
-        g_autofree char *typename 
+        g_autofree char *typename
             = g_strdup_printf(LOONGARCH_CPU_TYPE_NAME("%s"), cpu_model);
         oc = object_class_by_name(typename);
         if (!oc) {
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 22/27] target/i386: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (20 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 21/27] target/loongarch: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 23/27] target/hppa: " Anton Johansson via
                   ` (5 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/i386/tcg/tcg-cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/target/i386/tcg/tcg-cpu.c b/target/i386/tcg/tcg-cpu.c
index c090ce152b..b942c306d6 100644
--- a/target/i386/tcg/tcg-cpu.c
+++ b/target/i386/tcg/tcg-cpu.c
@@ -52,7 +52,7 @@ static void x86_cpu_synchronize_from_tb(CPUState *cs,
     /* The instruction pointer is always up to date with CF_PCREL. */
     if (!(tb_cflags(tb) & CF_PCREL)) {
         CPUX86State *env = cs->env_ptr;
-        env->eip = tb_pc(tb) - tb->cs_base;
+        env->eip = tb->pc - tb->cs_base;
     }
 }
 
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 23/27] target/hppa: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (21 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 22/27] target/i386: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 13:51 ` [PATCH v3 24/27] target/hexagon: " Anton Johansson via
                   ` (4 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/hppa/cpu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/target/hppa/cpu.c b/target/hppa/cpu.c
index 55c190280e..11022f9c99 100644
--- a/target/hppa/cpu.c
+++ b/target/hppa/cpu.c
@@ -26,7 +26,7 @@
 #include "qemu/module.h"
 #include "exec/exec-all.h"
 #include "fpu/softfloat.h"
-
+#include "tcg/tcg.h"
 
 static void hppa_cpu_set_pc(CPUState *cs, vaddr value)
 {
@@ -48,8 +48,10 @@ static void hppa_cpu_synchronize_from_tb(CPUState *cs,
 {
     HPPACPU *cpu = HPPA_CPU(cs);
 
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+
 #ifdef CONFIG_USER_ONLY
-    cpu->env.iaoq_f = tb_pc(tb);
+    cpu->env.iaoq_f = tb->pc;
     cpu->env.iaoq_b = tb->cs_base;
 #else
     /* Recover the IAOQ values from the GVA + PRIV.  */
@@ -59,7 +61,7 @@ static void hppa_cpu_synchronize_from_tb(CPUState *cs,
     int32_t diff = cs_base;
 
     cpu->env.iasq_f = iasq_f;
-    cpu->env.iaoq_f = (tb_pc(tb) & ~iasq_f) + priv;
+    cpu->env.iaoq_f = (tb->pc & ~iasq_f) + priv;
     if (diff) {
         cpu->env.iaoq_b = cpu->env.iaoq_f + diff;
     }
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 24/27] target/hexagon: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (22 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 23/27] target/hppa: " Anton Johansson via
@ 2023-02-27 13:51 ` Anton Johansson via
  2023-02-27 17:24   ` Taylor Simpson
  2023-02-27 13:52 ` [PATCH v3 25/27] target/avr: " Anton Johansson via
                   ` (3 subsequent siblings)
  27 siblings, 1 reply; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:51 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/hexagon/cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c
index 807037c586..ab40cfc283 100644
--- a/target/hexagon/cpu.c
+++ b/target/hexagon/cpu.c
@@ -23,6 +23,7 @@
 #include "qapi/error.h"
 #include "hw/qdev-properties.h"
 #include "fpu/softfloat-helpers.h"
+#include "tcg/tcg.h"
 
 static void hexagon_v67_cpu_init(Object *obj)
 {
@@ -263,7 +264,8 @@ static void hexagon_cpu_synchronize_from_tb(CPUState *cs,
 {
     HexagonCPU *cpu = HEXAGON_CPU(cs);
     CPUHexagonState *env = &cpu->env;
-    env->gpr[HEX_REG_PC] = tb_pc(tb);
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+    env->gpr[HEX_REG_PC] = tb->pc;
 }
 
 static bool hexagon_cpu_has_work(CPUState *cs)
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 25/27] target/avr: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (23 preceding siblings ...)
  2023-02-27 13:51 ` [PATCH v3 24/27] target/hexagon: " Anton Johansson via
@ 2023-02-27 13:52 ` Anton Johansson via
  2023-02-27 13:52 ` [PATCH v3 26/27] target/arm: " Anton Johansson via
                   ` (2 subsequent siblings)
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/avr/cpu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/target/avr/cpu.c b/target/avr/cpu.c
index d0139804b9..a24c23c247 100644
--- a/target/avr/cpu.c
+++ b/target/avr/cpu.c
@@ -54,7 +54,8 @@ static void avr_cpu_synchronize_from_tb(CPUState *cs,
     AVRCPU *cpu = AVR_CPU(cs);
     CPUAVRState *env = &cpu->env;
 
-    env->pc_w = tb_pc(tb) / 2; /* internally PC points to words */
+    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
+    env->pc_w = tb->pc / 2; /* internally PC points to words */
 }
 
 static void avr_restore_state_to_opc(CPUState *cs,
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 26/27] target/arm: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (24 preceding siblings ...)
  2023-02-27 13:52 ` [PATCH v3 25/27] target/avr: " Anton Johansson via
@ 2023-02-27 13:52 ` Anton Johansson via
  2023-02-27 13:52 ` [PATCH v3 27/27] include/exec: Remove `tb_pc()` Anton Johansson via
  2023-02-27 19:52 ` [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Richard Henderson
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 target/arm/cpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index c05cb86a47..db8f62beae 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -86,9 +86,9 @@ void arm_cpu_synchronize_from_tb(CPUState *cs,
          * never possible for an AArch64 TB to chain to an AArch32 TB.
          */
         if (is_a64(env)) {
-            env->pc = tb_pc(tb);
+            env->pc = tb->pc;
         } else {
-            env->regs[15] = tb_pc(tb);
+            env->regs[15] = tb->pc;
         }
     }
 }
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* [PATCH v3 27/27] include/exec: Remove `tb_pc()`
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (25 preceding siblings ...)
  2023-02-27 13:52 ` [PATCH v3 26/27] target/arm: " Anton Johansson via
@ 2023-02-27 13:52 ` Anton Johansson via
  2023-02-27 19:52 ` [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Richard Henderson
  27 siblings, 0 replies; 33+ messages in thread
From: Anton Johansson via @ 2023-02-27 13:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu, kbastian

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/exec/exec-all.h | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index f1615af7cb..c03c271995 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -618,13 +618,6 @@ static inline uint32_t tb_cflags(const TranslationBlock *tb)
     return qatomic_read(&tb->cflags);
 }
 
-/* Hide the read to avoid ifdefs for CF_PCREL. */
-static inline target_ulong tb_pc(const TranslationBlock *tb)
-{
-    assert(!(tb_cflags(tb) & CF_PCREL));
-    return tb->pc;
-}
-
 static inline tb_page_addr_t tb_page_addr0(const TranslationBlock *tb)
 {
 #ifdef CONFIG_USER_ONLY
-- 
2.39.1



^ permalink raw reply related	[flat|nested] 33+ messages in thread

* RE: [PATCH v3 24/27] target/hexagon: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 ` [PATCH v3 24/27] target/hexagon: " Anton Johansson via
@ 2023-02-27 17:24   ` Taylor Simpson
  0 siblings, 0 replies; 33+ messages in thread
From: Taylor Simpson @ 2023-02-27 17:24 UTC (permalink / raw)
  To: Anton Johansson, qemu-devel@nongnu.org
  Cc: ale@rev.ng, richard.henderson@linaro.org, pbonzini@redhat.com,
	eduardo@habkost.net, peter.maydell@linaro.org, mrolnik@gmail.com,
	gaosong@loongson.cn, yangxiaojuan@loongson.cn,
	edgar.iglesias@gmail.com, philmd@linaro.org, shorne@gmail.com,
	palmer@dabbelt.com, alistair.francis@wdc.com,
	bin.meng@windriver.com, ysato@users.sourceforge.jp,
	mark.cave-ayland@ilande.co.uk, atar4qemu@gmail.com,
	kbastian@mail.uni-paderborn.de



> -----Original Message-----
> From: Anton Johansson <anjo@rev.ng>
> Sent: Monday, February 27, 2023 6:52 AM
> To: qemu-devel@nongnu.org
> Cc: ale@rev.ng; richard.henderson@linaro.org; pbonzini@redhat.com;
> eduardo@habkost.net; peter.maydell@linaro.org; mrolnik@gmail.com;
> Taylor Simpson <tsimpson@quicinc.com>; gaosong@loongson.cn;
> yangxiaojuan@loongson.cn; edgar.iglesias@gmail.com; philmd@linaro.org;
> shorne@gmail.com; palmer@dabbelt.com; alistair.francis@wdc.com;
> bin.meng@windriver.com; ysato@users.sourceforge.jp; mark.cave-
> ayland@ilande.co.uk; atar4qemu@gmail.com; kbastian@mail.uni-
> paderborn.de
> Subject: [PATCH v3 24/27] target/hexagon: Replace `tb_pc()` with `tb->pc`
> 
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  target/hexagon/cpu.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/target/hexagon/cpu.c b/target/hexagon/cpu.c index
> 807037c586..ab40cfc283 100644
> --- a/target/hexagon/cpu.c
> +++ b/target/hexagon/cpu.c
> @@ -23,6 +23,7 @@
>  #include "qapi/error.h"
>  #include "hw/qdev-properties.h"
>  #include "fpu/softfloat-helpers.h"
> +#include "tcg/tcg.h"
> 
>  static void hexagon_v67_cpu_init(Object *obj)  { @@ -263,7 +264,8 @@
> static void hexagon_cpu_synchronize_from_tb(CPUState *cs,  {
>      HexagonCPU *cpu = HEXAGON_CPU(cs);
>      CPUHexagonState *env = &cpu->env;
> -    env->gpr[HEX_REG_PC] = tb_pc(tb);
> +    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
> +    env->gpr[HEX_REG_PC] = tb->pc;
>  }

Reviewed-by: Taylor Simpson <tsimpson@quicinc.com>


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL
  2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
                   ` (26 preceding siblings ...)
  2023-02-27 13:52 ` [PATCH v3 27/27] include/exec: Remove `tb_pc()` Anton Johansson via
@ 2023-02-27 19:52 ` Richard Henderson
  27 siblings, 0 replies; 33+ messages in thread
From: Richard Henderson @ 2023-02-27 19:52 UTC (permalink / raw)
  To: Anton Johansson, qemu-devel
  Cc: ale, pbonzini, eduardo, peter.maydell, mrolnik, tsimpson, gaosong,
	yangxiaojuan, edgar.iglesias, philmd, shorne, palmer,
	alistair.francis, bin.meng, ysato, mark.cave-ayland, atar4qemu,
	kbastian

On 2/27/23 03:51, Anton Johansson wrote:
> This patchset entirely replaces the macro TARGET_TB_PCREL with
> a field in TranslationBlock.cflags called CF_PCREL, and is a
> first step towards removing target-specific assumptions from
> non-target/ directories.
> 
> The grand goal is to allow for heterogeneous QEMU binaries
> consisting of multiple frontends.
> 
> RFC: https://lists.nongnu.org/archive/html/qemu-devel/2022-12/msg04518.html
> 
> Changes in v2:
>    * Setting of CF_PCREL (previously patch 3) was split in two and moved
>      up front (to patch 2 and 3);
> 
>    * Replacing of TARGET_TB_PCREL (previously patch 2) was split into
>      four patches (patches [4,7]), one for each affected submodule;
> 
>    * Removal of TARGET_TB_PCREL (previously patch 3) was moved into
>      separate patches, one for each submodule (patches [8,10]);
> 
>    * Patch 11 was introduced in response to feedback, and removes
>      CF_PCREL checks in functions in tb-jmp-cache.h, these functions were
>      always called in a context where CF_PCREL was already being checked.
>      These tb-jmp-cache.h functions were then removed in favour of manual
>      inlining;
> 
>    * Patches [12,26] replaces calls to tb_pc() with a member access
>      tb->pc, the motivation being that tb_pc() was (almost) always called
>      in a context where CF_PCREL was already being checked;
> 
>    * Finally patch 27 removes tb_pc() which is no longer used.
> 
> Changes in v3:
>    * Added reviewed-bys on remaining patches.

Queuing to tcg-next.  Thanks,

r~


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v3 17/27] target/riscv: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 ` [PATCH v3 17/27] target/riscv: " Anton Johansson via
@ 2023-02-27 23:05   ` Palmer Dabbelt
  2023-02-27 23:08     ` Richard Henderson
  0 siblings, 1 reply; 33+ messages in thread
From: Palmer Dabbelt @ 2023-02-27 23:05 UTC (permalink / raw)
  To: anjo
  Cc: qemu-devel, ale, Richard Henderson, pbonzini, eduardo,
	Peter Maydell, mrolnik, tsimpson, gaosong, yangxiaojuan,
	edgar.iglesias, philmd, shorne, Alistair Francis, bin.meng, ysato,
	mark.cave-ayland, atar4qemu, kbastian

On Mon, 27 Feb 2023 05:51:52 PST (-0800), anjo@rev.ng wrote:
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  target/riscv/cpu.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 93b52b826c..9eb748a283 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -34,6 +34,7 @@
>  #include "fpu/softfloat-helpers.h"
>  #include "sysemu/kvm.h"
>  #include "kvm_riscv.h"
> +#include "tcg/tcg.h"
>
>  /* RISC-V CPU definitions */
>
> @@ -533,10 +534,12 @@ static void riscv_cpu_synchronize_from_tb(CPUState *cs,
>      CPURISCVState *env = &cpu->env;
>      RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL);
>
> +    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
> +
>      if (xl == MXL_RV32) {
> -        env->pc = (int32_t)tb_pc(tb);
> +        env->pc = (int32_t) tb->pc;
>      } else {
> -        env->pc = tb_pc(tb);
> +        env->pc = tb->pc;
>      }
>  }

Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>

Thanks!  I'm going to assume you want these to stay together, but LMK if 
you were looking to aim this at the RISC-V tree.


^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v3 17/27] target/riscv: Replace `tb_pc()` with `tb->pc`
  2023-02-27 23:05   ` Palmer Dabbelt
@ 2023-02-27 23:08     ` Richard Henderson
  0 siblings, 0 replies; 33+ messages in thread
From: Richard Henderson @ 2023-02-27 23:08 UTC (permalink / raw)
  To: Palmer Dabbelt, anjo; +Cc: qemu-devel

On 2/27/23 13:05, Palmer Dabbelt wrote:
> On Mon, 27 Feb 2023 05:51:52 PST (-0800), anjo@rev.ng wrote:
>> Signed-off-by: Anton Johansson <anjo@rev.ng>
>> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>  target/riscv/cpu.c | 7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
>> index 93b52b826c..9eb748a283 100644
>> --- a/target/riscv/cpu.c
>> +++ b/target/riscv/cpu.c
>> @@ -34,6 +34,7 @@
>>  #include "fpu/softfloat-helpers.h"
>>  #include "sysemu/kvm.h"
>>  #include "kvm_riscv.h"
>> +#include "tcg/tcg.h"
>>
>>  /* RISC-V CPU definitions */
>>
>> @@ -533,10 +534,12 @@ static void riscv_cpu_synchronize_from_tb(CPUState *cs,
>>      CPURISCVState *env = &cpu->env;
>>      RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL);
>>
>> +    tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
>> +
>>      if (xl == MXL_RV32) {
>> -        env->pc = (int32_t)tb_pc(tb);
>> +        env->pc = (int32_t) tb->pc;
>>      } else {
>> -        env->pc = tb_pc(tb);
>> +        env->pc = tb->pc;
>>      }
>>  }
> 
> Reviewed-by: Palmer Dabbelt <palmer@rivosinc.com>
> Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
> 
> Thanks!  I'm going to assume you want these to stay together, but LMK if you were looking 
> to aim this at the RISC-V tree.

I've queued to tcg-next, so they'll stay together.
I've now added your r-b.


r~



^ permalink raw reply	[flat|nested] 33+ messages in thread

* Re: [PATCH v3 13/27] target/tricore: Replace `tb_pc()` with `tb->pc`
  2023-02-27 13:51 ` [PATCH v3 13/27] target/tricore: " Anton Johansson via
@ 2023-04-19  8:56   ` Bastian Koppelmann
  0 siblings, 0 replies; 33+ messages in thread
From: Bastian Koppelmann @ 2023-04-19  8:56 UTC (permalink / raw)
  To: Anton Johansson via
  Cc: ale, richard.henderson, pbonzini, eduardo, peter.maydell, mrolnik,
	tsimpson, gaosong, yangxiaojuan, edgar.iglesias, philmd, shorne,
	palmer, alistair.francis, bin.meng, ysato, mark.cave-ayland,
	atar4qemu

On Mon, Feb 27, 2023 at 02:51:48PM +0100, Anton Johansson via wrote:
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  target/tricore/cpu.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>

Cheers,
Bastian


^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2023-04-19  8:57 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-02-27 13:51 [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 01/27] include/exec: Introduce `CF_PCREL` Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 02/27] target/i386: set `CF_PCREL` in `x86_cpu_realizefn` Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 03/27] target/arm: set `CF_PCREL` in `arm_cpu_realizefn` Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 04/27] accel/tcg: Replace `TARGET_TB_PCREL` with `CF_PCREL` Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 05/27] include/exec: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 06/27] target/arm: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 07/27] target/i386: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 08/27] include/exec: Remove `TARGET_TB_PCREL` define Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 09/27] target/arm: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 10/27] target/i386: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 11/27] accel/tcg: Move jmp-cache `CF_PCREL` checks to caller Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 12/27] accel/tcg: Replace `tb_pc()` with `tb->pc` Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 13/27] target/tricore: " Anton Johansson via
2023-04-19  8:56   ` Bastian Koppelmann
2023-02-27 13:51 ` [PATCH v3 14/27] target/sparc: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 15/27] target/sh4: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 16/27] target/rx: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 17/27] target/riscv: " Anton Johansson via
2023-02-27 23:05   ` Palmer Dabbelt
2023-02-27 23:08     ` Richard Henderson
2023-02-27 13:51 ` [PATCH v3 18/27] target/openrisc: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 19/27] target/mips: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 20/27] target/microblaze: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 21/27] target/loongarch: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 22/27] target/i386: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 23/27] target/hppa: " Anton Johansson via
2023-02-27 13:51 ` [PATCH v3 24/27] target/hexagon: " Anton Johansson via
2023-02-27 17:24   ` Taylor Simpson
2023-02-27 13:52 ` [PATCH v3 25/27] target/avr: " Anton Johansson via
2023-02-27 13:52 ` [PATCH v3 26/27] target/arm: " Anton Johansson via
2023-02-27 13:52 ` [PATCH v3 27/27] include/exec: Remove `tb_pc()` Anton Johansson via
2023-02-27 19:52 ` [PATCH v3 00/27] Replace TARGET_TB_PCREL with CF_PCREL Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).