@@ -434,9 +434,13 @@ void tcg_exec_unrealizefn(CPUState *cpu);
static inline void cpu_set_cpustate_pointers(ArchCPU *cpu)
{
cpu->parent_obj.env_ptr = &cpu->env;
- cpu->parent_obj.icount_decr_ptr = &cpu->neg.icount_decr;
+ cpu->parent_obj.icount_decr_ptr = &cpu->parent_obj.neg.icount_decr;
}
+/* Validate correct placement of CPUArchState. */
+QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
+QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
+
/**
* env_archcpu(env)
* @env: The architecture environment
@@ -445,7 +449,7 @@ static inline void cpu_set_cpustate_pointers(ArchCPU *cpu)
*/
static inline ArchCPU *env_archcpu(CPUArchState *env)
{
- return container_of(env, ArchCPU, env);
+ return (void *)env - sizeof(CPUState);
}
/**
@@ -456,15 +460,9 @@ static inline ArchCPU *env_archcpu(CPUArchState *env)
*/
static inline CPUState *env_cpu(CPUArchState *env)
{
- return &env_archcpu(env)->parent_obj;
+ return (void *)env - sizeof(CPUState);
}
-/*
- * Validate placement of CPUNegativeOffsetState.
- */
-QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) - offsetof(ArchCPU, neg) >=
- sizeof(CPUNegativeOffsetState) + __alignof(CPUArchState));
-
/**
* env_neg(env)
* @env: The architecture environment
@@ -473,8 +471,7 @@ QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) - offsetof(ArchCPU, neg) >=
*/
static inline CPUNegativeOffsetState *env_neg(CPUArchState *env)
{
- ArchCPU *arch_cpu = container_of(env, ArchCPU, env);
- return &arch_cpu->neg;
+ return (void *)env - sizeof(CPUNegativeOffsetState);
}
/**
@@ -485,8 +482,7 @@ static inline CPUNegativeOffsetState *env_neg(CPUArchState *env)
*/
static inline CPUNegativeOffsetState *cpu_neg(CPUState *cpu)
{
- ArchCPU *arch_cpu = container_of(cpu, ArchCPU, parent_obj);
- return &arch_cpu->neg;
+ return &cpu->neg;
}
/**
@@ -345,8 +345,8 @@ typedef union IcountDecr {
} IcountDecr;
/*
- * This structure must be placed in ArchCPU immediately
- * before CPUArchState, as a field named "neg".
+ * Elements of CPUState most efficiently accessed from CPUArchState,
+ * via small negative offsets.
*/
typedef struct CPUNegativeOffsetState {
CPUTLB tlb;
@@ -584,8 +584,18 @@ struct CPUState {
/* track IOMMUs whose translations we've cached in the TCG TLB */
GArray *iommu_notifiers;
+
+ /*
+ * MUST BE LAST in order to minimize the displacement to CPUArchState.
+ * This will be verified within exec/cpu-all.h.
+ */
+ CPUNegativeOffsetState neg;
};
+/* Validate placement of CPUNegativeOffsetState. */
+QEMU_BUILD_BUG_ON(offsetof(CPUState, neg) + sizeof(CPUNegativeOffsetState)
+ != sizeof(CPUState));
+
typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
extern CPUTailQ cpus;
@@ -263,7 +263,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUAlphaState env;
/* This alarm doesn't exist in real hardware; we wish it did. */
@@ -856,7 +856,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUARMState env;
/* Coprocessor information */
@@ -148,7 +148,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUAVRState env;
};
@@ -178,7 +178,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUCRISState env;
};
@@ -141,7 +141,7 @@ struct ArchCPU {
/*< private >*/
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
+
CPUHexagonState env;
bool lldb_compat;
@@ -231,7 +231,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUHPPAState env;
QEMUTimer *alarm_timer;
};
@@ -1900,7 +1900,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUX86State env;
VMChangeStateEntry *vmsentry;
@@ -373,7 +373,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPULoongArchState env;
QEMUTimer timer;
uint32_t phy_id;
@@ -168,7 +168,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUM68KState env;
};
@@ -345,15 +345,15 @@ typedef struct {
struct ArchCPU {
/*< private >*/
CPUState parent_obj;
-
/*< public >*/
+
+ CPUMBState env;
+
bool ns_axi_dp;
bool ns_axi_ip;
bool ns_axi_dc;
bool ns_axi_ic;
- CPUNegativeOffsetState neg;
- CPUMBState env;
MicroBlazeCPUConfig cfg;
};
@@ -1213,10 +1213,10 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
+ CPUMIPSState env;
+
Clock *clock;
Clock *count_div; /* Divider for CP0_Count clock */
- CPUNegativeOffsetState neg;
- CPUMIPSState env;
};
@@ -218,7 +218,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUNios2State env;
bool diverr_present;
@@ -305,7 +305,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUOpenRISCState env;
};
@@ -1317,7 +1317,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUPPCState env;
int vcpu_id;
@@ -388,7 +388,7 @@ struct ArchCPU {
/* < private > */
CPUState parent_obj;
/* < public > */
- CPUNegativeOffsetState neg;
+
CPURISCVState env;
char *dyn_csr_xml;
@@ -111,7 +111,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPURXState env;
};
@@ -170,7 +170,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUS390XState env;
S390CPUModel *model;
/* needed for live migration */
@@ -208,7 +208,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUSH4State env;
};
@@ -561,7 +561,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUSPARCState env;
};
@@ -192,7 +192,6 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- CPUNegativeOffsetState neg;
CPUTriCoreState env;
};
@@ -560,9 +560,8 @@ struct ArchCPU {
CPUState parent_obj;
/*< public >*/
- Clock *clock;
- CPUNegativeOffsetState neg;
CPUXtensaState env;
+ Clock *clock;
};
@@ -344,8 +344,8 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
tcg_ctx->page_bits = TARGET_PAGE_BITS;
tcg_ctx->page_mask = TARGET_PAGE_MASK;
tcg_ctx->tlb_dyn_max_bits = CPU_TLB_DYN_MAX_BITS;
- tcg_ctx->tlb_fast_offset =
- (int)offsetof(ArchCPU, neg.tlb.f) - (int)offsetof(ArchCPU, env);
+ tcg_ctx->tlb_fast_offset = (int)offsetof(ArchCPU, parent_obj.neg.tlb.f)
+ - (int)offsetof(ArchCPU, env);
#endif
tcg_ctx->insn_start_words = TARGET_INSN_START_WORDS;
#ifdef TCG_GUEST_DEFAULT_MO
@@ -53,8 +53,8 @@ static TCGOp *gen_tb_start(uint32_t cflags)
TCGOp *icount_start_insn = NULL;
tcg_gen_ld_i32(count, cpu_env,
- offsetof(ArchCPU, neg.icount_decr.u32) -
- offsetof(ArchCPU, env));
+ offsetof(ArchCPU, parent_obj.neg.icount_decr.u32)
+ - offsetof(ArchCPU, env));
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, cpu_env,
- offsetof(ArchCPU, neg.icount_decr.u16.low) -
- offsetof(ArchCPU, env));
+ offsetof(ArchCPU, parent_obj.neg.icount_decr.u16.low)
+ - offsetof(ArchCPU, env));
/*
* cpu->can_do_io is cleared automatically here at the beginning of
* each translation block. The cost is minimal and only paid for
Retain the separate structure to emphasize its importance. Enforce CPUArchState always follows CPUState without padding. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- include/exec/cpu-all.h | 22 +++++++++------------- include/hw/core/cpu.h | 14 ++++++++++++-- target/alpha/cpu.h | 1 - target/arm/cpu.h | 1 - target/avr/cpu.h | 1 - target/cris/cpu.h | 1 - target/hexagon/cpu.h | 2 +- target/hppa/cpu.h | 1 - target/i386/cpu.h | 1 - target/loongarch/cpu.h | 1 - target/m68k/cpu.h | 1 - target/microblaze/cpu.h | 6 +++--- target/mips/cpu.h | 4 ++-- target/nios2/cpu.h | 1 - target/openrisc/cpu.h | 1 - target/ppc/cpu.h | 1 - target/riscv/cpu.h | 2 +- target/rx/cpu.h | 1 - target/s390x/cpu.h | 1 - target/sh4/cpu.h | 1 - target/sparc/cpu.h | 1 - target/tricore/cpu.h | 1 - target/xtensa/cpu.h | 3 +-- accel/tcg/translate-all.c | 4 ++-- accel/tcg/translator.c | 8 ++++---- 25 files changed, 35 insertions(+), 46 deletions(-)