8000 [RV64_DYNAREC] Fixed some opcodes caught by cosim by xctan · Pull Request #1561 · ptitSeb/box64 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[RV64_DYNAREC] Fixed some opcodes caught by cosim #1561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dynarec/rv64/dynarec_rv64_00_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ uintptr_t dynarec64_00_2(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
case 0x9F:
INST_NAME("LAHF");
READFLAGS(X_CF | X_PF | X_AF | X_ZF | X_SF);
ANDI(x1, xFlags, 0xFF);
ANDI(x1, xFlags, 0b11010111); // leave reserved bits out (we are using one as OF2)
SLLI(x1, x1, 8);
MOV64x(x2, 0xffffffffffff00ffLL);
AND(xRAX, xRAX, x2);
Expand Down
2 changes: 2 additions & 0 deletions src/dynarec/rv64/dynarec_rv64_00_3.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETEDW(x4, x1, 0);
CALL_(rex.w?((void*)rcl64):((void*)rcl32), ed, x4);
WBACK;
if(!wback && !rex.w) ZEROUP(ed);
break;
case 3:
INST_NAME("RCR Ed, Ib");
Expand All @@ -209,6 +210,7 @@ uintptr_t dynarec64_00_3(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETEDW(x4, x1, 0);
CALL_(rex.w?((void*)rcr64):((void*)rcr32), ed, x4);
WBACK;
if(!wback && !rex.w) ZEROUP(ed);
break;
case 4:
case 6:
Expand Down
11 changes: 7 additions & 4 deletions src/dynarec/rv64/dynarec_rv64_0f.c
Original file line number Diff line number Diff line change
8000 Expand Up @@ -2068,13 +2068,13 @@ uintptr_t dynarec64_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
ORI(xFlags, xFlags, 1 << F_CF);
XOR(ed, ed, x6);
}
MARK;
if (wback) {
SDxw(ed, wback, fixedaddress);
SMWRITE();
} else if(!rex.w) {
ZEROUP(ed);
}
MARK;
break;
case 7:
INST_NAME("BTC Ed, Ib");
Expand Down Expand Up @@ -2219,11 +2219,14 @@ uintptr_t dynarec64_0F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
nextop = F8;
GETEB(x1, 0);
GETGB(x2);
MV(x9, ed);
if (!(MODREG && wback == gb1 && !!(wb2) == !!(gb2)))
MV(x9, ed);
emit_add8(dyn, ninst, ed, gd, x4, x5);
MV(gd, x9);
if (!(MODREG && wback == gb1 && !!(wb2) == !!(gb2)))
MV(gd, x9);
EBBACK(x5, 0);
GBBACK(x5);
if (!(MODREG && wback == gb1 && !!(wb2) == !!(gb2)))
GBBACK(x5);
break;
case 0xC1:
INST_NAME("XADD Ed, Gd");
Expand Down
42 changes: 21 additions & 21 deletions src/dynarec/rv64/dynarec_rv64_66.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ uintptr_t dynarec64_66(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
INST_NAME("ADC AX, Iw");
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
i16 = F16;
u64 = F16;
ZEXTH(x1, xRAX);
MOV32w(x2, i16);
MOV64x(x2, u64);
emit_adc16(dyn, ninst, x1, x2, x3, x4, x5);
INSH(xRAX, x1, x3, x4, 1, 0);
break;
Expand Down Expand Up @@ -185,8 +185,8 @@ uintptr_t dynarec64_66(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
ZEXTH(x1, xRAX);
i16 = F16;
MOV64xw(x2, i16);
u64 = F16;
MOV64x(x2, u64);
emit_sbb16(dyn, ninst, x1, x2, x3, x4, x5);
INSH(xRAX, x1, x3, x4, 1, 0);
break;
Expand Down Expand Up @@ -455,17 +455,17 @@ uintptr_t dynarec64_66(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
if(opcode==0x81) {INST_NAME("ADD Ew, Iw");} else {INST_NAME("ADD Ew, Ib");}
SETFLAGS(X_ALL, SF_SET_PENDING);
GETEW(x1, (opcode==0x81)?2:1);
if(opcode==0x81) i16 = F16S; else i16 = F8S;
MOV64x(x5, i16);
if(opcode==0x81) u64 = F16; else u64 = F8;
MOV64x(x5, u64);
emit_add16(dyn, ninst, ed, x5, x2, x4, x6);
EWBACK;
break;
case 1: // OR
if(opcode==0x81) {INST_NAME("OR Ew, Iw");} else {INST_NAME("OR Ew, Ib");}
SETFLAGS(X_ALL, SF_SET_PENDING);
GETEW(x1, (opcode==0x81)?2:1);
if(opcode==0x81) i16 = F16S; else i16 = F8S;
MOV64x(x5, i16);
if(opcode==0x81) u64 = F16; else u64 = F8;
MOV64x(x5, u64);
emit_or16(dyn, ninst, x1, x5, x2, x4);
EWBACK;
break;
Expand All @@ -474,8 +474,8 @@ uintptr_t dynarec64_66(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
GETEW(x1, (opcode==0x81)?2:1);
if(opcode==0x81) i16 = F16S; else i16 = F8S;
MOV64x(x5, i16);
if(opcode==0x81) u64 = F16; else u64 = F8;
MOV64x(x5, u64);
emit_adc16(dyn, ninst, x1, x5, x2, x4, x6);
EWBACK;
break;
Expand All @@ -484,45 +484,45 @@ uintptr_t dynarec64_66(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni
READFLAGS(X_CF);
SETFLAGS(X_ALL, SF_SET_PENDING);
GETEW(x1, (opcode==0x81)?2:1);
if(opcode==0x81) i16 = F16S; else i16 = F8S;
MOV64x(x5, i16);
if(opcode==0x81) u64 = F16; else u64 = F8;
MOV64x(x5, u64);
emit_sbb16(dyn, ninst, x1, x5, x2, x4, x6);
EWBACK;
break;
case 4: // AND
if(opcode==0x81) {INST_NAME("AND Ew, Iw");} else {INST_NAME("AND Ew, Ib");}
SETFLAGS(X_ALL, SF_SET_PENDING);
GETEW(x1, (opcode==0x81)?2:1);
if(opcode==0x81) i16 = F16S; else i16 = F8S;
MOV64x(x5, i16);
if(opcode==0x81) u64 = F16; else u64 = F8;
MOV64x(x5, u64);
emit_and16(dyn, ninst, x1, x5, x2, x4);
EWBACK;
break;
case 5: // SUB
if(opcode==0x81) {INST_NAME("SUB Ew, Iw");} else {INST_NAME("SUB Ew, Ib");}
SETFLAGS(X_ALL, SF_SET_PENDING);
GETEW(x1, (opcode==0x81)?2:1);
if(opcode==0x81) i16 = F16S; else i16 = F8S;
MOV32w(x5, i16);
if(opcode==0x81) u64 = F16; else u64 = F8;
MOV64x(x5, u64);
emit_sub16(dyn, ninst, x1, x5, x2, x4, x6);
EWBACK;
break;
case 6: // XOR
if(opcode==0x81) {INST_NAME("XOR Ew, Iw");} else {INST_NAME("XOR Ew, Ib");}
SETFLAGS(X_ALL, SF_SET_PENDING);
GETEW(x1, (opcode==0x81)?2:1);
if(opcode==0x81) i16 = F16S; else i16 = F8S;
MOV32w(x5, i16);
if(opcode==0x81) u64 = F16; else u64 = F8;
MOV64x(x5, u64);
emit_xor16(dyn, ninst, x1, x5, x2, x4, x6);
EWBACK;
break;
case 7: // CMP
if(opcode==0x81) {INST_NAME("CMP Ew, Iw");} else {INST_NAME("CMP Ew, Ib");}
SETFLAGS(X_ALL, SF_SET_PENDING);
GETEW(x1, (opcode==0x81)?2:1);
if(opcode==0x81) i16 = F16S; else i16 = F8S;
if(i16) {
MOV64x(x2, i16);
if(opcode==0x81) u64 = F16; else u64 = F8;
if(u64) {
MOV64x(x2, u64);
emit_cmp16(dyn, ninst, x1, x2, x3, x4, x5, x6);
} else
emit_cmp16_0(dyn, ninst, x1, x3, x4);
Expand Down
25 changes: 14 additions & 11 deletions src/dynarec/rv64/dynarec_rv64_660f.c
Original file line number Diff line number Diff line change
Expand Up @@ -2302,7 +2302,7 @@ uintptr_t dynarec64_660F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
GETEW(x1, 0);
GETGW(x2);
u8 = F8;
emit_shrd16c(dyn, ninst, rex, ed, gd, u8, x3, x4);
emit_shrd16c(dyn, ninst, rex, ed, gd, u8, x3, x4, x5);
EWBACK;
break;
case 0xAF:
Expand Down Expand Up @@ -2420,8 +2420,8 @@ uintptr_t dynarec64_660F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
ORI(xFlags, xFlags, 1 << F_CF);
XOR(ed, ed, x6);
}
EWBACK;
MARK;
EWBACK;
break;
case 7:
INST_NAME("BTC Ew, Ib");
Expand All @@ -2433,7 +2433,7 @@ uintptr_t dynarec64_660F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
BEXTI(x3, ed, u8); // F_CF is 1
ANDI(xFlags, xFlags, ~1);
OR(xFlags, xFlags, x3);
if (u8 <= 0x10) {
if (u8 <= 10) {
XORI(ed, ed, (1LL << u8));
} else {
MOV64xw(x3, (1LL << u8));
Expand Down Expand Up @@ -2547,11 +2547,14 @@ uintptr_t dynarec64_660F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
nextop = F8;
GETGW(x1);
GETEW(x2, 0);
MV(x9, ed);
if (!(MODREG && wback == xRAX + ((nextop & 0x38) >> 3) + (rex.r << 3)))
MV(x9, ed);
emit_add16(dyn, ninst, ed, gd, x4, x5, x6);
MV(gd, x9);
if (!(MODREG && wback == xRAX + ((nextop & 0x38) >> 3) + (rex.r << 3)))
MV(gd, x9);
EWBACK;
GWBACK;
if (!(MODREG && wback == xRAX + ((nextop & 0x38) >> 3) + (rex.r << 3)))
GWBACK;
break;
case 0xC2:
INST_NAME("CMPPD Gx, Ex, Ib");
Expand Down Expand Up @@ -2656,13 +2659,13 @@ uintptr_t dynarec64_660F(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
REV8xw(gd, gd, x1, x2, x3, x4);
} else {
ANDI(x1, gd, 0xff);
SLLI(x1, x1, 8);
SRLI(x2, gd, 8);
SLLI(x1, x1, 8);
ANDI(x2, x2, 0xff);
SRLI(x3, gd, 16);
SLLI(x4, x3, 16);
AND(x1, x4, x1);
AND(gd, x1, x2);
SRLI(gd, gd, 16);
OR(x1, x1, x2);
SLLI(gd, gd, 16);
OR(gd, gd, x1);
}
break;
case 0xD1:
Expand Down
9 changes: 5 additions & 4 deletions src/dynarec/rv64/dynarec_rv64_66f0.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ uintptr_t dynarec64_66F0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
uint8_t wback, wb1, wb2, gb1, gb2;
int32_t i32;
int64_t i64, j64;
uint64_t u64;
int64_t fixedaddress;
int unscaled;
MAYUSE(gb1);
Expand Down Expand Up @@ -127,18 +128,18 @@ uintptr_t dynarec64_66F0(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int
}
SETFLAGS(X_ALL, SF_SET_PENDING);
if(MODREG) {
if(opcode==0x81) i32 = F16S; else i32 = F8S;
if(opcode==0x81) u64 = F16; else u64 = F8;
ed = xRAX+(nextop&7)+(rex.b<<3);
MOV32w(x5, i32);
MOV64x(x5, u64);
ZEXTH(x6, ed);
emit_add16(dyn, ninst, x6, x5, x3, x4, x2);
SRLI(ed, ed, 16);
SLLI(ed, ed, 16);
OR(ed, ed, x6);
} else {
addr = geted(dyn, addr, ninst, nextop, &wback, x2, x1, &fixedaddress, rex, LOCK_LOCK, 0, (opcode==0x81)?2:1);
if(opcode==0x81) i32 = F16S; else i32 = F8S;
MOV32w(x5, i32);
if(opcode==0x81) u64 = F16; else u64 = F8;
MOV64x(x5, u64);

ANDI(x3, wback, 0b10);
BNEZ_MARK(x3);
Expand Down
2 changes: 1 addition & 1 deletion src/dynarec/rv64/dynarec_rv64_emit_logic.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ void emit_and32c(dynarec_rv64_t* dyn, int ninst, rex_t rex, int s1, int64_t c, i
MOV64xw(s3, c);
AND(s1, s1, s3); // res = s1 & s2
}
if (!rex.w && c<0 && c>=-2048) ZEROUP(s1);
if (!rex.w) ZEROUP(s1);

IFX(X_PEND) {
SDxw(s1, xEmu, offsetof(x64emu_t, res));
Expand Down
Loading
0