Skip to content

Commit

Permalink
Merge pull request #1515 from Sonicadvance1/fix_ptest
Browse files Browse the repository at this point in the history
OpcodeDispatcher: Fixes ptest flags calculation.
  • Loading branch information
Stefanos Kornilios Mitsis Poiitidis authored Jan 13, 2022
2 parents 7768f69 + 4e2220c commit 0a8717d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2233,8 +2233,14 @@ void OpDispatchBuilder::PTestOp(OpcodeArgs) {
Test2 = _Select(FEXCore::IR::COND_EQ,
Test2, ZeroConst, OneConst, ZeroConst);

// Careful, these flags are different between {V,}PTEST and VTESTP{S,D}
SetRFLAG<FEXCore::X86State::RFLAG_ZF_LOC>(Test1);
SetRFLAG<FEXCore::X86State::RFLAG_CF_LOC>(Test2);

SetRFLAG<FEXCore::X86State::RFLAG_AF_LOC>(ZeroConst);
SetRFLAG<FEXCore::X86State::RFLAG_SF_LOC>(ZeroConst);
SetRFLAG<FEXCore::X86State::RFLAG_OF_LOC>(ZeroConst);
SetRFLAG<FEXCore::X86State::RFLAG_PF_LOC>(ZeroConst);
}

void OpDispatchBuilder::PHMINPOSUWOp(OpcodeArgs) {
Expand Down
32 changes: 32 additions & 0 deletions unittests/ASM/H0F38/66_17_2.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
%ifdef CONFIG
{
"RegData": {
"RAX": "0xFFFFFFFFFFFF43FF",
"RBX": "0"
}
}
%endif

; Set EFLAGS to known value with sahf
mov rax, -1
sahf

movups xmm0, [rel .data]
; Tests a bug that FEX had where ptest would not set OF, SF, AF, PF to zero
ptest xmm0, xmm0

; Now load back
; ZF = 1
; CF = 1
; OF, SF, AF, PF should be zero
lahf

; lahf doesn't get OF, get it with seto
mov rbx, 0
seto bl

hlt

.data:
dq 0
dq 0

0 comments on commit 0a8717d

Please sign in to comment.