Fix EXTR (flipped rgister order)

This commit is contained in:
Liam 2022-11-16 16:10:39 -05:00
parent 7791d3d854
commit 16101049f3
2 changed files with 19 additions and 2 deletions

View file

@ -1408,7 +1408,7 @@ void EmitIR<IR::Opcode::ExtractRegister32>(oaknut::CodeGenerator& code, EmitCont
RegAlloc::Realize(Wresult, Wop1, Wop2); RegAlloc::Realize(Wresult, Wop1, Wop2);
const u8 lsb = args[2].GetImmediateU8(); const u8 lsb = args[2].GetImmediateU8();
code.EXTR(Wresult, Wop1, Wop2, lsb); code.EXTR(Wresult, Wop2, Wop1, lsb); // NB: flipped
} }
template<> template<>
@ -1422,7 +1422,7 @@ void EmitIR<IR::Opcode::ExtractRegister64>(oaknut::CodeGenerator& code, EmitCont
RegAlloc::Realize(Xresult, Xop1, Xop2); RegAlloc::Realize(Xresult, Xop1, Xop2);
const u8 lsb = args[2].GetImmediateU8(); const u8 lsb = args[2].GetImmediateU8();
code.EXTR(Xresult, Xop1, Xop2, lsb); code.EXTR(Xresult, Xop2, Xop1, lsb); // NB: flipped
} }
template<> template<>

View file

@ -1024,6 +1024,23 @@ TEST_CASE("A64: This is an infinite loop if fast dispatch is enabled", "[a64]")
jit.Run(); jit.Run();
} }
TEST_CASE("A64: EXTR", "[a64]") {
A64TestEnv env;
A64::Jit jit{A64::UserConfig{&env}};
env.code_mem.emplace_back(0x93d8fef7); // EXTR X23, X23, X24, #63
env.code_mem.emplace_back(0x14000000); // B .
jit.SetPC(0);
jit.SetRegister(23, 0);
jit.SetRegister(24, 1);
env.ticks_left = 2;
jit.Run();
REQUIRE(jit.GetRegister(23) == 0);
}
TEST_CASE("A64: Optimization failure when folding ADD", "[a64]") { TEST_CASE("A64: Optimization failure when folding ADD", "[a64]") {
A64TestEnv env; A64TestEnv env;
A64::Jit jit{A64::UserConfig{&env}}; A64::Jit jit{A64::UserConfig{&env}};