[5949] target-ppc: memory load/store rework
Revision: 5949
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5949 Author: aurel32 Date: 2008-12-08 18:11:21 +0000 (Mon, 08 Dec 2008)
Log Message:
-----------
target-ppc: memory load/store rework
Rework the memory load/store:
- Unify load/store functions for 32-bit and 64-bit CPU
- Don't swap values twice for bit-reverse load/store functions in little endian mode.
- On a 64-bit CPU in 32-bit mode, do the address truncation for address computation instead of every load store. Truncate the address when incrementing the address (if needed)
- Cache writes to access_types.
- Add a few missing calls to gen_set_access_type()
Modified Paths:
--------------
trunk/target-ppc/op_helper.c
trunk/target-ppc/translate.c
Modified: trunk/target-ppc/op_helper.c
===================================================================
target-ppc/op_helper.c +29 -23
@@ -257,47 +257,51 @@/*****************************************************************************/ /* Memory load and stores */ -static always_inline target_ulong get_addr(target_ulong addr) +static always_inline target_ulong addr_add(target_ulong addr, target_long arg) {#if defined(TARGET_PPC64 ) -if (msr_sf) -return addr; +if (!msr_sf) +return (uint32_t )(addr + arg); else#endif -return (uint32_t )addr; +return addr + arg; }void helper_lmw (target_ulong addr,uint32_t reg) { -for (; reg <32 ; reg++, addr +=4 ) { +for (; reg <32 ; reg++) {if (msr_le) - env->gpr[reg] =bswap32 (ldl (get_addr (addr))); + env->gpr[reg] =bswap32 (ldl (addr));else - env->gpr[reg] =ldl (get_addr (addr)); + env->gpr[reg] =ldl (addr); + addr =addr_add (addr,4 ); } }void helper_stmw (target_ulong addr,uint32_t reg) { -for (; reg <32 ; reg++, addr +=4 ) { +for (; reg <32 ; reg++) {if (msr_le) -stl (get_addr (addr),bswap32 ((uint32_t )env->gpr[reg])); +stl (addr,bswap32 ((uint32_t )env->gpr[reg]));else -stl (get_addr (addr), (uint32_t )env->gpr[reg]); +stl (addr, (uint32_t )env->gpr[reg]); + addr =addr_add (addr,4 ); } }void helper_lsw (target_ulong addr,uint32_t nb,uint32_t reg) {int sh; -for (; nb >3 ; nb -=4 , addr +=4 ) { - env->gpr[reg] =ldl (get_addr (addr)); +for (; nb >3 ; nb -=4 ) { + env->gpr[reg] =ldl (addr); reg = (reg +1 ) %32 ; + addr =addr_add (addr,4 ); }if (unlikely (nb >0 )) { env->gpr[reg] =0 ; -for (sh =24 ; nb >0 ; nb--, addr++, sh -=8 ) { - env->gpr[reg] |=ldub (get_addr (addr)) << sh; +for (sh =24 ; nb >0 ; nb--, sh -=8 ) { + env->gpr[reg] |=ldub (addr) << sh; + addr =addr_add (addr,1 ); } } }
@@ -323,25 +327,26 @@void helper_stsw (target_ulong addr,uint32_t nb,uint32_t reg) {int sh; -for (; nb >3 ; nb -=4 , addr +=4 ) { -stl (get_addr (addr), env->gpr[reg]); +for (; nb >3 ; nb -=4 ) { +stl (addr, env->gpr[reg]); reg = (reg +1 ) %32 ; + addr =addr_add (addr,4 ); }if (unlikely (nb >0 )) { -for (sh =24 ; nb >0 ; nb--, addr++, sh -=8 ) -stb (get_addr (addr), (env->gpr[reg] >> sh) &0xFF ); +for (sh =24 ; nb >0 ; nb--, sh -=8 ) +stb (addr, (env->gpr[reg] >> sh) &0xFF ); + addr =addr_add (addr,1 ); } }static void do_dcbz (target_ulong addr,int dcache_line_size) { -target_long mask =get_addr (~(dcache_line_size -1 )); + addr &= ~(dcache_line_size -1 );int i; - addr &= mask;for (i =0 ; i < dcache_line_size ; i +=4 ) {stl (addr + i ,0 ); } -if ((env->reserve & mask) == addr) +if (env->reserve == addr) env->reserve = (target_ulong)-1ULL ; }
@@ -362,7 +367,7 @@ {uint32_t tmp; - addr =get_addr (addr & ~(env->dcache_line_size -1 )); + addr &= ~(env->dcache_line_size -1 );/* Invalidate one cache line : * PowerPC specification says this is to be treated like a load * (not a fetch) by the MMU. To be sure it will be so,
@@ -378,7 +383,8 @@int i, c, d; d =24 ;for (i =0 ; i < xer_bc; i++) { - c =ldub ((uint32_t )addr++); + c =ldub (addr); + addr =addr_add (addr,1 );/* ra (if not 0) and rb are never modified */ if (likely (reg != rb && (ra ==0 || reg != ra))) { env->gpr[reg] = (env->gpr[reg] & ~(0xFF << d)) | (c << d);
Modified: trunk/target-ppc/translate.c
===================================================================
target-ppc/translate.c +649 -649
2,444 lines not on this page · raw message
Quoted 2 lines · Aurelien Jarno
- Don't swap values twice for bit-reverse load/store functions in little endian mode.
If I've read this correctly, it seems to me that we would still swap twice on little endian hosts when when emulating little endian mode or performing bit-reverse loads/stores. Bit-reverse loads/stores under little endian emulation on a little endian host would have actually resulted in *three* byteswaps!
I'm not sure what the performance impact of this would be, but it's something that I've been wondering about while working on PA-RISC emulation, which will also need to provide a little endian mode.
BTW, I'm wondering if it would be possible to optimise loads/stores with a different endianness to the host on targets that require word aligned addresses. Instead of swapping bytes when loading/storing words, addresses would be modified when loading/storing bytes. For 32-bit targets, what I'm suggesting is something similar to this (although I'm not saying that the casting is a good idea!) :-
extern uint8_t memory[];
uint32_t ldul(target_ulong addr) {
return *(uint32_t)&memory[addr];
}
uint32_t lduw(target_ulong addr) {
return *(uint16_t)&memory[addr ^ 2];
}
uint32_t ldub(target_ulong addr) {
return memory[addr ^ 3];
}
(It looks as though MIPS Magnum emulation might require something like this for emulation of its big endian mode, anyway...)
Cheers,
Signature · 1 line
Stuart Brady
Quoted 10 lines · Stuart Brady
Quoted 2 lines · Aurelien Jarno
- Don't swap values twice for bit-reverse load/store functions in little endian mode.
If I've read this correctly, it seems to me that we would still swap twice on little endian hosts when when emulating little endian mode or performing bit-reverse loads/stores. Bit-reverse loads/stores under little endian emulation on a little endian host would have actually resulted in *three* byteswaps!
Quoted 3 lines
I'm not sure what the performance impact of this would be, but it's something that I've been wondering about while working on PA-RISC emulation, which will also need to provide a little endian mode.
Jocelyn sent a patch to address this. There were some (small) problems with it, so please read the full thread:
http://lists.gnu.org/archive/html/qemu-devel/2007-10/msg00289.html
Quoted 9 lines · Stuart Brady
Quoted 2 lines · Aurelien Jarno
- Don't swap values twice for bit-reverse load/store functions in little endian mode.
If I've read this correctly, it seems to me that we would still swap twice on little endian hosts when when emulating little endian mode or performing bit-reverse loads/stores. Bit-reverse loads/stores under little endian emulation on a little endian host would have actually resulted in *three* byteswaps!
I was actually speaking about swapping in the TCG code. The global byteswapping has been actually reduced from 3 to 2 in the worst case.
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net
Quoted 11 lines · Blue Swirl
Quoted 10 lines · Stuart Brady
Quoted 2 lines · Aurelien Jarno
- Don't swap values twice for bit-reverse load/store functions in little endian mode.
If I've read this correctly, it seems to me that we would still swap twice on little endian hosts when when emulating little endian mode or performing bit-reverse loads/stores. Bit-reverse loads/stores under little endian emulation on a little endian host would have actually resulted in *three* byteswaps!
Quoted 8 lines
Quoted 3 lines
I'm not sure what the performance impact of this would be, but it's something that I've been wondering about while working on PA-RISC emulation, which will also need to provide a little endian mode.
Jocelyn sent a patch to address this. There were some (small) problems with it, so please read the full thread:
http://lists.gnu.org/archive/html/qemu-devel/2007-10/msg00289.html
That looks like a good start if someone wants to work again on that. The switch to TCG probably implies some more changes.
Signature · 4 lines
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73 : :' : Debian developer | Electrical Engineer `. `' [email protected] | [email protected] `- people.debian.org/~aurel32 | www.aurel32.net