Skip to content

Commit

Permalink
Keep consistent with dynarec
Browse files Browse the repository at this point in the history
  • Loading branch information
Hagb committed Apr 14, 2024
1 parent d0cc048 commit 36b58b5
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/emu/x86rund9.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ uintptr_t RunD9(x86emu_t *emu, uintptr_t addr)
x86emu_t*emu = test->emu;
#endif

int rount = setround(emu);
int round;
nextop = F8;
switch (nextop) {
case 0xC0:
Expand Down Expand Up @@ -128,14 +128,18 @@ uintptr_t RunD9(x86emu_t *emu, uintptr_t addr)
emu->sw.f.F87_C1 = 0;
break;
case 0xF2: /* FPTAN */
round = setround(emu);
ST0.d = tan(ST0.d);
fesetround(round);
fpu_do_push(emu);
ST0.d = 1.0;
emu->sw.f.F87_C2 = 0;
emu->sw.f.F87_C1 = 0;
break;
case 0xF3: /* FPATAN */
round = setround(emu);
ST1.d = atan2(ST1.d, ST0.d);
fesetround(round);
fpu_do_pop(emu);
emu->sw.f.F87_C1 = 0;
break;
Expand Down Expand Up @@ -204,12 +208,16 @@ uintptr_t RunD9(x86emu_t *emu, uintptr_t addr)
emu->sw.f.F87_C1 = 0;
break;
case 0xFA: /* FSQRT */
round = setround(emu);
ST0.d = sqrt(ST0.d);
fesetround(round);
emu->sw.f.F87_C1 = 0;
break;
case 0xFB: /* FSINCOS */
fpu_do_push(emu);
round = setround(emu);
sincos(ST1.d, &ST1.d, &ST0.d);
fesetround(round);
emu->sw.f.F87_C2 = 0;
emu->sw.f.F87_C1 = 0;
break;
Expand All @@ -224,16 +232,21 @@ uintptr_t RunD9(x86emu_t *emu, uintptr_t addr)
tmp32s = INT32_MIN;
else
tmp32s = ST1.d;
if(ST0.d!=0.0)
if(ST0.d!=0.0) {
round = setround(emu);
ST0.d = ldexp(ST0.d, tmp32s);
fesetround(round);
}
emu->sw.f.F87_C1 = 0;
break;
case 0xFE: /* FSIN */
round = setround(emu);
ST0.d = sin(ST0.d);
emu->sw.f.F87_C2 = 0;
emu->sw.f.F87_C1 = 0;
break;
case 0xFF: /* FCOS */
round = setround(emu);
ST0.d = cos(ST0.d);
emu->sw.f.F87_C2 = 0;
emu->sw.f.F87_C1 = 0;
Expand All @@ -258,7 +271,6 @@ uintptr_t RunD9(x86emu_t *emu, uintptr_t addr)
case 0xE6:
case 0xE7:
case 0xEF:
fesetround(rount);
return 0;
default:
switch((nextop>>3)&7) {
Expand All @@ -274,18 +286,22 @@ uintptr_t RunD9(x86emu_t *emu, uintptr_t addr)
break;
case 2: /* FST Ed, ST0 */
GET_ED;
if(!(((uintptr_t)ED)&3))
if(!(((uintptr_t)ED)&3)) {
round = setround(emu);
*(float*)ED = ST0.d;
else {
fesetround(round);
} else {
f = ST0.d;
memcpy(ED, &f, sizeof(float));
}
break;
case 3: /* FSTP Ed, ST0 */
GET_ED;
if(!(((uintptr_t)ED)&3))
if(!(((uintptr_t)ED)&3)) {
round = setround(emu);
*(float*)ED = ST0.d;
else {
fesetround(round);
} else {
f = ST0.d;
memcpy(ED, &f, sizeof(float));
}
Expand Down Expand Up @@ -318,10 +334,8 @@ uintptr_t RunD9(x86emu_t *emu, uintptr_t addr)
EW->word[0] = emu->cw.x16;
break;
default:
fesetround(rount);
return 0;
}
}
fesetround(rount);
return addr;
}

0 comments on commit 36b58b5

Please sign in to comment.