Skip to content

Commit bf455ec

Browse files
committed
include/exec: Use uintptr_t in CPUTLBEntry
Since we no longer support 64-bit guests on 32-bit hosts, we can use a 32-bit type on a 32-bit host. This shrinks the size of the structure to 16 bytes on a 32-bit host. Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Richard Henderson <[email protected]>
1 parent a70af12 commit bf455ec

File tree

5 files changed

+19
-46
lines changed

5 files changed

+19
-46
lines changed

accel/tcg/cputlb.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,15 @@ static inline uint64_t tlb_read_idx(const CPUTLBEntry *entry,
104104
{
105105
/* Do not rearrange the CPUTLBEntry structure members. */
106106
QEMU_BUILD_BUG_ON(offsetof(CPUTLBEntry, addr_read) !=
107-
MMU_DATA_LOAD * sizeof(uint64_t));
107+
MMU_DATA_LOAD * sizeof(uintptr_t));
108108
QEMU_BUILD_BUG_ON(offsetof(CPUTLBEntry, addr_write) !=
109-
MMU_DATA_STORE * sizeof(uint64_t));
109+
MMU_DATA_STORE * sizeof(uintptr_t));
110110
QEMU_BUILD_BUG_ON(offsetof(CPUTLBEntry, addr_code) !=
111-
MMU_INST_FETCH * sizeof(uint64_t));
111+
MMU_INST_FETCH * sizeof(uintptr_t));
112112

113-
#if TARGET_LONG_BITS == 32
114-
/* Use qatomic_read, in case of addr_write; only care about low bits. */
115-
const uint32_t *ptr = (uint32_t *)&entry->addr_idx[access_type];
116-
ptr += HOST_BIG_ENDIAN;
117-
return qatomic_read(ptr);
118-
#else
119-
const uint64_t *ptr = &entry->addr_idx[access_type];
113+
const uintptr_t *ptr = &entry->addr_idx[access_type];
120114
/* ofs might correspond to .addr_write, so use qatomic_read */
121115
return qatomic_read(ptr);
122-
#endif
123116
}
124117

125118
static inline uint64_t tlb_addr_write(const CPUTLBEntry *entry)
@@ -899,14 +892,8 @@ static void tlb_reset_dirty_range_locked(CPUTLBEntry *tlb_entry,
899892
addr &= TARGET_PAGE_MASK;
900893
addr += tlb_entry->addend;
901894
if ((addr - start) < length) {
902-
#if TARGET_LONG_BITS == 32
903-
uint32_t *ptr_write = (uint32_t *)&tlb_entry->addr_write;
904-
ptr_write += HOST_BIG_ENDIAN;
905-
qatomic_set(ptr_write, *ptr_write | TLB_NOTDIRTY);
906-
#else
907895
qatomic_set(&tlb_entry->addr_write,
908896
tlb_entry->addr_write | TLB_NOTDIRTY);
909-
#endif
910897
}
911898
}
912899
}

include/exec/tlb-common.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
#ifndef EXEC_TLB_COMMON_H
2020
#define EXEC_TLB_COMMON_H 1
2121

22-
#define CPU_TLB_ENTRY_BITS 5
22+
#define CPU_TLB_ENTRY_BITS (HOST_LONG_BITS == 32 ? 4 : 5)
2323

2424
/* Minimalized TLB entry for use by TCG fast path. */
2525
typedef union CPUTLBEntry {
2626
struct {
27-
uint64_t addr_read;
28-
uint64_t addr_write;
29-
uint64_t addr_code;
27+
uintptr_t addr_read;
28+
uintptr_t addr_write;
29+
uintptr_t addr_code;
3030
/*
3131
* Addend to virtual address to get host address. IO accesses
3232
* use the corresponding iotlb value.
@@ -37,7 +37,7 @@ typedef union CPUTLBEntry {
3737
* Padding to get a power of two size, as well as index
3838
* access to addr_{read,write,code}.
3939
*/
40-
uint64_t addr_idx[(1 << CPU_TLB_ENTRY_BITS) / sizeof(uint64_t)];
40+
uintptr_t addr_idx[(1 << CPU_TLB_ENTRY_BITS) / sizeof(uintptr_t)];
4141
} CPUTLBEntry;
4242

4343
QEMU_BUILD_BUG_ON(sizeof(CPUTLBEntry) != (1 << CPU_TLB_ENTRY_BITS));

tcg/arm/tcg-target.c.inc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,6 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h,
15001500
* Add the tlb_table pointer, creating the CPUTLBEntry address in R1.
15011501
* Load the tlb comparator into R2 and the fast path addend into R1.
15021502
*/
1503-
QEMU_BUILD_BUG_ON(HOST_BIG_ENDIAN);
15041503
if (cmp_off == 0) {
15051504
tcg_out_ld32_rwb(s, COND_AL, TCG_REG_R2, TCG_REG_R1, TCG_REG_R0);
15061505
} else {

tcg/mips/tcg-target.c.inc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,18 +1262,16 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h,
12621262
/* Add the tlb_table pointer, creating the CPUTLBEntry address. */
12631263
tcg_out_opc_reg(s, ALIAS_PADD, TCG_TMP3, TCG_TMP3, TCG_TMP1);
12641264

1265-
if (TCG_TARGET_REG_BITS == 32 || addr_type == TCG_TYPE_I32) {
1266-
/* Load the (low half) tlb comparator. */
1265+
/* Load the tlb comparator. */
1266+
if (TCG_TARGET_REG_BITS == 64 && addr_type == TCG_TYPE_I32) {
12671267
tcg_out_ld(s, TCG_TYPE_I32, TCG_TMP0, TCG_TMP3,
12681268
cmp_off + HOST_BIG_ENDIAN * 4);
12691269
} else {
1270-
tcg_out_ld(s, TCG_TYPE_I64, TCG_TMP0, TCG_TMP3, cmp_off);
1270+
tcg_out_ld(s, TCG_TYPE_REG, TCG_TMP0, TCG_TMP3, cmp_off);
12711271
}
12721272

1273-
if (TCG_TARGET_REG_BITS == 64 || addr_type == TCG_TYPE_I32) {
1274-
/* Load the tlb addend for the fast path. */
1275-
tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP3, TCG_TMP3, add_off);
1276-
}
1273+
/* Load the tlb addend for the fast path. */
1274+
tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP3, TCG_TMP3, add_off);
12771275

12781276
/*
12791277
* Mask the page bits, keeping the alignment bits to compare against.

tcg/ppc/tcg-target.c.inc

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,27 +2490,16 @@ static TCGLabelQemuLdst *prepare_host_addr(TCGContext *s, HostAddress *h,
24902490
tcg_out32(s, AND | SAB(TCG_REG_TMP1, TCG_REG_TMP1, TCG_REG_R0));
24912491

24922492
/*
2493-
* Load the (low part) TLB comparator into TMP2.
2493+
* Load the TLB comparator into TMP2.
24942494
* For 64-bit host, always load the entire 64-bit slot for simplicity.
24952495
* We will ignore the high bits with tcg_out_cmp(..., addr_type).
24962496
*/
2497-
if (TCG_TARGET_REG_BITS == 64) {
2498-
if (cmp_off == 0) {
2499-
tcg_out32(s, LDUX | TAB(TCG_REG_TMP2,
2500-
TCG_REG_TMP1, TCG_REG_TMP2));
2501-
} else {
2502-
tcg_out32(s, ADD | TAB(TCG_REG_TMP1,
2503-
TCG_REG_TMP1, TCG_REG_TMP2));
2504-
tcg_out_ld(s, TCG_TYPE_I64, TCG_REG_TMP2,
2505-
TCG_REG_TMP1, cmp_off);
2506-
}
2507-
} else if (cmp_off == 0 && !HOST_BIG_ENDIAN) {
2508-
tcg_out32(s, LWZUX | TAB(TCG_REG_TMP2,
2509-
TCG_REG_TMP1, TCG_REG_TMP2));
2497+
if (cmp_off == 0) {
2498+
tcg_out32(s, (TCG_TARGET_REG_BITS == 64 ? LDUX : LWZUX)
2499+
| TAB(TCG_REG_TMP2, TCG_REG_TMP1, TCG_REG_TMP2));
25102500
} else {
25112501
tcg_out32(s, ADD | TAB(TCG_REG_TMP1, TCG_REG_TMP1, TCG_REG_TMP2));
2512-
tcg_out_ld(s, TCG_TYPE_I32, TCG_REG_TMP2, TCG_REG_TMP1,
2513-
cmp_off + 4 * HOST_BIG_ENDIAN);
2502+
tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_TMP2, TCG_REG_TMP1, cmp_off);
25142503
}
25152504

25162505
/*

0 commit comments

Comments
 (0)