TCG: Improve tb_phys_hash_func()
PATCH 1/1 TCG: Improve tb_phys_hash_func()
Most of emulated CPU have instructions aligned on 16 or 32 bits, while on others GCC tries to align the target jump location. This means that 1/2 or 3/4 of tb_phys_hash entries are never used.
Update the hash function tb_phys_hash_func() to ignore the two lowest bits of the address. This brings a 6% speed-up when booting a MIPS image.
--- exec-all.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
exec-all.h +1 -1
@@ -177,7 +177,7 @@ static inline unsigned int tb_jmp_cache_hash_func(target_ulong pc)static inline unsigned int tb_phys_hash_func (tb_page_addr_t pc) { -return pc & (CODE_GEN_PHYS_HASH_SIZE -1 ); +return (pc >>2 ) & (CODE_GEN_PHYS_HASH_SIZE -1 ); }TranslationBlock *tb_alloc (target_ulong pc);
Signature · 1 line
1.7.2.3
Quoted 7 lines · Aurelien Jarno
Most of emulated CPU have instructions aligned on 16 or 32 bits, while on others GCC tries to align the target jump location. This means that 1/2 or 3/4 of
tb_phys_hashentries are never used.Update the hash function
tb_phys_hash_func()to ignore the two lowest bits of the address. This brings a 6% speed-up when booting a MIPS image.
Nice! The beginning of functions may be aligned to 16 bytes. Would it change the performance figures if one or two more bits were ignored?
Quoted 5 lines · Blue Swirl
Quoted 4 lines · Aurelien Jarno
Most of emulated CPU have instructions aligned on 16 or 32 bits, while on others GCC tries to align the target jump location. This means that 1/2 or 3/4 of
tb_phys_hashentries are never used.
Quoted 7 lines
Quoted 3 lines
Update the hash function
tb_phys_hash_func()to ignore the two lowest bits of the address. This brings a 6% speed-up when booting a MIPS image.Nice! The beginning of functions may be aligned to 16 bytes. Would it change the performance figures if one or two more bits were ignored?
It makes a noticeable difference on how the TBs are dispatched in the hash table, but only by a few percents (slightly more on ppc). I am not able to measure any speed improvement, it is all in the noise.
My guess is that compilers align functions to 16 bytes, but not jump in loops, which are far more numerous that functions starts.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 10 lines · Aurelien Jarno
Quoted 9 lines · Blue Swirl
Quoted 7 lines · Aurelien Jarno
Most of emulated CPU have instructions aligned on 16 or 32 bits, while on others GCC tries to align the target jump location. This means that 1/2 or 3/4 of
tb_phys_hashentries are never used.Update the hash function
tb_phys_hash_func()to ignore the two lowest bits of the address. This brings a 6% speed-up when booting a MIPS image.
Quoted 6 lines
Quoted 3 lines
Nice! The beginning of functions may be aligned to 16 bytes. Would it change the performance figures if one or two more bits were ignored?
It makes a noticeable difference on how the TBs are dispatched in the hash table, but only by a few percents (slightly more on ppc). I am not
Here I meant how TBs are dispatched after my patch has been applied.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net