On 04/04/2016 10:30 PM, Emilio G. Cota wrote:
Tests show that the other element checked for in tb_find_physical, cs_base, is always a match when tb_phys+pc+flags are a match, so hashing cs_base is wasteful. It could be that this is an ARM-only thing, though.
The cs_base field is only used by i386 (in 16-bit modes), and sparc (for a TB consisting of only a delay slot).
It may well still turn out to be reasonable to ignore cs_base for hashing.
+static inline +uint32_t tb_hash_func(tb_page_addr_t phys_pc, target_ulong pc, uint64_t flags) { - return (pc >> 2) & (CODE_GEN_PHYS_HASH_SIZE - 1); + struct key { + tb_page_addr_t phys_pc; + target_ulong pc; + uint64_t flags;
The flags field should be uint32_t, not uint64_t. See its definition in TranslationBlock.
+ } QEMU_PACKED k; + unsigned int hash; + + k.phys_pc = phys_pc; + k.pc = pc; + k.flags = flags; + hash = qemu_xxh32((uint32_t *)&k, sizeof(k) / sizeof(uint32_t), 1);
I'm less than happy about putting data into a struct and hashing that memory. Why don't you just take the ideas from xxh32/xxh64 and perform the hash directly right here?
In particular, you've 3 data elements here, a maximum of 5 32-bit words, thus the loop within xxh32 will never roll, so it's mostly dead code.
r~