qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 07/10] tb hash: hash phys_pc, pc, and flags with


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH 07/10] tb hash: hash phys_pc, pc, and flags with xxhash
Date: Tue, 5 Apr 2016 17:48:07 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0


On 05/04/2016 17:41, Richard Henderson wrote:
> 
>> +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.

I think it's fine to use the struct.  The exact size of the struct
varies from 3 to 5 32-bit words, so it's hard to write nice
size-dependent code for the hash.

Paolo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]