Skip to content

Commit 965b12d

Browse files
committed
ARM: optimize GPR reads by getting rid of the invalid CPU mode check
1 parent 8c25d6b commit 965b12d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/nba/src/arm/arm7tdmi.hpp

+13-12
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct ARM7TDMI {
8787
p_spsr = &state.spsr[new_bank];
8888
} else {
8989
/* In system/user mode reading from SPSR returns the current CPSR value.
90-
* However writes to SPSR appear to do nothing.
90+
* However, writes to SPSR appear to do nothing.
9191
* We take care of this fact in the MSR implementation.
9292
*/
9393
p_spsr = &state.cpsr;
@@ -118,10 +118,16 @@ struct ARM7TDMI {
118118
state.bank[old_bank][5] = state.r13;
119119
state.bank[old_bank][6] = state.r14;
120120

121-
state.r13 = state.bank[new_bank][5];
122-
state.r14 = state.bank[new_bank][6];
123-
124-
cpu_mode_is_invalid = new_bank == BANK_INVALID;
121+
if(new_bank != BANK_INVALID) [[likely]] {
122+
state.r13 = state.bank[new_bank][5];
123+
state.r14 = state.bank[new_bank][6];
124+
cpu_mode_is_invalid = false;
125+
} else {
126+
for(int i = 0; i < 7; i++) {
127+
state.reg[8 + i] = 0u;
128+
}
129+
cpu_mode_is_invalid = true;
130+
}
125131
}
126132

127133
void LoadState(SaveState const& save_state);
@@ -136,19 +142,14 @@ struct ARM7TDMI {
136142
friend struct TableGen;
137143

138144
auto GetReg(int id) -> u32 {
139-
u32 result = 0;
140-
bool is_banked = id >= 8 && id != 15;
145+
u32 result = state.reg[id];
141146

142-
if(unlikely(ldm_usermode_conflict && is_banked)) {
147+
if(unlikely(ldm_usermode_conflict && id >= 8 && id != 15)) {
143148
// This array holds the current user/sys bank value only if the CPU wasn't in user or system mode all along during the user mode LDM instruction.
144149
// We take care in the LDM implementation that this branch is only taken if that was the case.
145150
result |= state.bank[BANK_NONE][id - 8];
146151
}
147152

148-
if(likely(!cpu_mode_is_invalid || !is_banked)) {
149-
result |= state.reg[id];
150-
}
151-
152153
return result;
153154
}
154155

0 commit comments

Comments
 (0)