Skip to content

Commit

Permalink
More x87 fixes ([DYNAREC] too)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed May 22, 2024
1 parent ff702c0 commit 69f0c97
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
30 changes: 25 additions & 5 deletions src/dynarec/dynarec_arm_d9.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,31 @@ uintptr_t dynarecD9(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst,
MOV32(x14, 0b100000100000000);
B_MARK3(c__);
} else { // not in cache, so check Empty status and load it
// load tag
LDRH_IMM8(x3, xEmu, offsetof(x86emu_t, fpu_tags));
if(i2) {
if(i2<0) {
MOV_REG_LSL_IMM5(x3, x3, -i2*2);
} else {
MOV32(x14, 0xffff);
ORR_REG_LSL_IMM5(x3, x3, x14, 16);
MOV_REG_LSR_IMM5(x3, x3, i2*2);
}
}
TSTS_IMM8(x3, 0b11);
MOVW(x14, 0b100000100000000); // empty
B_MARK3(cNE);
// check stack TODO: this test should not be needed, something is wrong with tag handling
LDR_IMM9(x3, xEmu, offsetof(x86emu_t, fpu_stack));
if(i2) {
if(i2<0) {
ADD_IMM8(x3, x3, -i2);
} else {
SUB_IMM8(x3, x3, i2);
}
}
CMPS_IMM8(x3, 0);
B_MARK3(cLE);
// x14 will be the actual top
LDR_IMM9(x14, xEmu, offsetof(x86emu_t, top));
i2 = -dyn->n.x87stack;
Expand All @@ -149,11 +174,6 @@ uintptr_t dynarecD9(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int ninst,
}
AND_IMM8(x14, x14, 7); // (emu->top + i)&7
}
// load tag
LDRH_IMM8(x3, xEmu, offsetof(x86emu_t, fpu_tags));
TSTS_IMM8(x3, 0b11);
MOVW_COND(cNE, x14, 0b100000100000000);
B_MARK3(cNE);
ADD_REG_LSL_IMM5(x1, xEmu, x14, 3);
LDRD_IMM8(x2, x1, offsetof(x86emu_t, x87)); // load r2/r3 with ST0 anyway, for sign extraction
}
Expand Down
8 changes: 4 additions & 4 deletions src/emu/x87emu_private.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,15 +295,15 @@ void fpu_fxsave(x86emu_t* emu, void* ed)
int top = emu->top&7;
int stack = 8-top;
if(top==0) // check if stack is full or empty, based on tag[0]
stack = (emu->fpu_tags&0b11)?8:0;
stack = (emu->fpu_tags)?8:0;
emu->sw.f.F87_TOP = top;
p->ControlWord = emu->cw.x16;
p->StatusWord = emu->sw.x16;
p->MxCsr = emu->mxcsr.x32;
p->MxCsr_Mask = 0;
uint8_t tags = 0;
for (int i=0; i<8; ++i)
tags |= ((emu->fpu_tags>>(i*2))&0b11)?0:1;
tags |= (((emu->fpu_tags>>(i*2))&0b11)?0:1)<<i;
p->TagWord = tags;
p->ErrorOpcode = 0;
p->ErrorOffset = 0;
Expand All @@ -327,12 +327,12 @@ void fpu_fxrstor(x86emu_t* emu, void* ed)
uint8_t tags = p->TagWord;
emu->fpu_tags = 0;
for(int i=0; i<8; ++i)
emu->fpu_tags |= (((tags>>(i*2))&0b1)?0:0b11)<<(i*2);
emu->fpu_tags |= (((tags>>i)&0b1)?0:0b11)<<(i*2);
// copy back MMX regs...
int top = emu->top&7;
int stack = 8-top;
if(top==0) // check if stack is full or empty, based on tag[0]
stack = (emu->fpu_tags&0b11)?8:0;
stack = (emu->fpu_tags)?8:0;
for(int i=0; i<8; ++i)
memcpy((i<stack)?&ST(i):&emu->mmx[i], &p->FloatRegisters[i].q[0], sizeof(mmx87_regs_t));
// copy SSE regs
Expand Down

0 comments on commit 69f0c97

Please sign in to comment.