Skip to content

Commit

Permalink
Merge pull request #3305 from Sonicadvance1/fix_crash2
Browse files Browse the repository at this point in the history
JIT: Fixes crash in TestNZ
  • Loading branch information
alyssarosenzweig authored Dec 2, 2023
2 parents c8ef77c + 3e2ba6d commit a8ab8bb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion FEXCore/Source/Interface/Core/JIT/Arm64/ALUOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ DEF_OP(SbbNZCV) {

DEF_OP(TestNZ) {
auto Op = IROp->C<IR::IROp_TestNZ>();
const uint8_t OpSize = Op->Size;
const uint8_t OpSize = IROp->Size;
const auto EmitSize = OpSize == 8 ? ARMEmitter::Size::i64Bit : ARMEmitter::Size::i32Bit;

uint64_t Const;
Expand Down
2 changes: 1 addition & 1 deletion FEXCore/Source/Interface/Core/OpcodeDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ friend class FEXCore::IR::PassManager;
}

void SetNZ_ZeroCV(unsigned SrcSize, OrderedNode *Res) {
_TestNZ(SrcSize, Res, Res);
_TestNZ(IR::SizeToOpSize(SrcSize), Res, Res);
CachedNZCV = _LoadNZCV();
PossiblySetNZCVBits = (1u << 31) | (1u << 30);
NZCVDirty = false;
Expand Down
3 changes: 2 additions & 1 deletion FEXCore/Source/Interface/IR/IR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1083,8 +1083,9 @@
"Size == FEXCore::IR::OpSize::i32Bit || Size == FEXCore::IR::OpSize::i64Bit"
]
},
"TestNZ u8:$Size, GPR:$Src1, GPR:$Src2": {
"TestNZ OpSize:#Size, GPR:$Src1, GPR:$Src2": {
"Desc": ["Set NZCV for the binary AND of two GPRs, setting N and Z accordingly and zeroing C and V"],
"DestSize": "Size",
"HasSideEffects": true
},
"GPR = Lshl OpSize:#Size, GPR:$Src1, GPR:$Src2": {
Expand Down
15 changes: 15 additions & 0 deletions unittests/ASM/FEX_bugs/ShiftConstantBug.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%ifdef CONFIG
{
"RegData": {
"RAX": "0x500000020"
}
}
%endif

; FEX had a bug in its `TestNZ` opcode where it would try to load a constant in to the tst instruction
; If the constant didn't fit in a logical encoding it would generate invalid instructions and also crash.
; This snippet of code was found in libGLX.so.0.0.0 when trying to load steamwebhelper.
mov eax, 0x28000001
shl rax, 0x5

hlt

0 comments on commit a8ab8bb

Please sign in to comment.