diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-03-20 18:38:17 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-03-20 18:38:17 +0100 |
| commit | 6be2c376e2b5bf784418618c6ae260be6a7a200f (patch) | |
| tree | 24a0e6898eb1f74f92bb7fa2b4c39df9f81111c2 /src | |
| parent | db22d8b1c9a7f20c1c92dd69caead6806717b817 (diff) | |
| download | box64-6be2c376e2b5bf784418618c6ae260be6a7a200f.tar.gz box64-6be2c376e2b5bf784418618c6ae260be6a7a200f.zip | |
[DYNAREC] Added (66) 28..2D SUB opcodes
Diffstat (limited to 'src')
| -rwxr-xr-x | src/dynarec/dynarec_arm64_00.c | 28 | ||||
| -rwxr-xr-x | src/dynarec/dynarec_arm64_66.c | 28 | ||||
| -rwxr-xr-x | src/dynarec/dynarec_arm64_emit_math.c | 201 | ||||
| -rwxr-xr-x | src/dynarec/dynarec_arm64_helper.h | 4 |
4 files changed, 154 insertions, 107 deletions
diff --git a/src/dynarec/dynarec_arm64_00.c b/src/dynarec/dynarec_arm64_00.c index c5c6658c..7daf88fd 100755 --- a/src/dynarec/dynarec_arm64_00.c +++ b/src/dynarec/dynarec_arm64_00.c @@ -325,6 +325,15 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin emit_and32c(dyn, ninst, rex, xRAX, i64, x3, x4); break; + case 0x28: + INST_NAME("SUB Eb, Gb"); + SETFLAGS(X_ALL, SF_SET); + nextop = F8; + GETEB(x1, 0); + GETGB(x2); + emit_sub8(dyn, ninst, x1, x2, x4, x5); + EBBACK; + break; case 0x29: INST_NAME("SUB Ed, Gd"); SETFLAGS(X_ALL, SF_SET); @@ -334,7 +343,15 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin emit_sub32(dyn, ninst, rex, ed, gd, x3, x4); WBACK; break; - + case 0x2A: + INST_NAME("SUB Gb, Eb"); + SETFLAGS(X_ALL, SF_SET); + nextop = F8; + GETEB(x2, 0); + GETGB(x1); + emit_sub8(dyn, ninst, x1, x2, x3, x4); + GBBACK; + break; case 0x2B: INST_NAME("SUB Gd, Ed"); SETFLAGS(X_ALL, SF_SET); @@ -343,7 +360,14 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin GETED(0); emit_sub32(dyn, ninst, rex, gd, ed, x3, x4); break; - + case 0x2C: + INST_NAME("SUB AL, Ib"); + SETFLAGS(X_ALL, SF_SET); + u8 = F8; + UXTBw(x1, xRAX); + emit_sub8c(dyn, ninst, x1, u8, x3, x4, x5); + BFIx(xRAX, x1, 0, 8); + break; case 0x2D: INST_NAME("SUB EAX, Id"); SETFLAGS(X_ALL, SF_SET); diff --git a/src/dynarec/dynarec_arm64_66.c b/src/dynarec/dynarec_arm64_66.c index 1f2d568f..dcbefd77 100755 --- a/src/dynarec/dynarec_arm64_66.c +++ b/src/dynarec/dynarec_arm64_66.c @@ -202,6 +202,34 @@ uintptr_t dynarec64_66(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin BFIx(xRAX, x1, 0, 16); break; + case 0x29: + INST_NAME("SUB Ew, Gw"); + SETFLAGS(X_ALL, SF_SET); + nextop = F8; + GETGW(x2); + GETEW(x1, 0); + emit_sub16(dyn, ninst, x1, x2, x4, x5); + EWBACK; + break; + case 0x2B: + INST_NAME("SUB Gw, Ew"); + SETFLAGS(X_ALL, SF_SET); + nextop = F8; + GETGW(x1); + GETEW(x2, 0); + emit_sub16(dyn, ninst, x1, x2, x3, x4); + GWBACK; + break; + case 0x2D: + INST_NAME("SUB AX, Iw"); + SETFLAGS(X_ALL, SF_SET); + i32 = F16; + UXTHw(x1, xRAX); + MOV32w(x2, i32); + emit_sub16(dyn, ninst, x1, x2, x3, x4); + BFIw(xRAX, x1, 0, 16); + break; + case 0xD1: case 0xD3: nextop = F8; diff --git a/src/dynarec/dynarec_arm64_emit_math.c b/src/dynarec/dynarec_arm64_emit_math.c index 7ecef218..5bb03da2 100755 --- a/src/dynarec/dynarec_arm64_emit_math.c +++ b/src/dynarec/dynarec_arm64_emit_math.c @@ -384,57 +384,55 @@ void emit_add8c(dynarec_arm_t* dyn, int ninst, int s1, int c, int s3, int s4, in } // emit SUB8 instruction, from s1 , s2, store result in s1 using s3 and s4 as scratch, with save_s4 is s4 need to be saved -//void emit_sub8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int save_s4) -//{ -// IFX(X_PEND) { -// STR_IMM9(s1, xEmu, offsetof(x64emu_t, op1)); -// STR_IMM9(s2, xEmu, offsetof(x64emu_t, op2)); -// SET_DF(s3, d_sub8); -// } else IFX(X_ALL) { -// SET_DFNONE(s3); -// } -// IFX(X_AF|X_OF|X_CF|X_PF){if(save_s4) {PUSH(xSP, 1<<s4);}} -// IFX(X_AF|X_OF|X_CF) { -// MVN_REG_LSL_IMM5(s3, s1, 0); -// ORR_REG_LSL_IMM5(s3, s3, s2, 0); // s3 = ~op1 | op2 -// BIC_REG_LSL_IMM5(s4, s2, s1, 0); // s4 = ~op1 & op2 -// } -// -// SUB_REG_LSL_IMM5(s1, s1, s2, 0); -// IFX(X_PEND) { -// STR_IMM9(s1, xEmu, offsetof(x64emu_t, res)); -// } -// IFX(X_AF|X_OF|X_CF) { -// AND_REG_LSL_IMM5(s3, s3, s1, 0); // s3 = (~op1 | op2) & res -// ORR_REG_LSL_IMM5(s3, s3, s4, 0); // s3 = (~op1 & op2) | ((~op1 | op2) & res) -// IFX(X_CF) { -// MOV_REG_LSR_IMM5(s4, s3, 7); -// BFI(xFlags, s4, F_CF, 1); // CF : bc & 0x80 -// } -// IFX(X_AF) { -// MOV_REG_LSR_IMM5(s4, s3, 3); -// BFI(xFlags, s4, F_AF, 1); // AF: bc & 0x08 -// } -// IFX(X_OF) { -// MOV_REG_LSR_IMM5(s4, s3, 6); -// XOR_REG_LSR_IMM8(s4, s4, s4, 1); -// BFI(xFlags, s4, F_OF, 1); // OF: ((bc >> 6) ^ ((bc>>6)>>1)) & 1 -// } -// } -// IFX(X_ZF) { -// ANDS_IMM8(s1, s1, 0xff); -// ORR_IMM8_COND(cEQ, xFlags, xFlags, 1<<F_ZF, 0); -// BIC_IMM8_COND(cNE, xFlags, xFlags, 1<<F_ZF, 0); -// } -// IFX(X_SF) { -// MOV_REG_LSR_IMM5(s3, s1, 7); -// BFI(xFlags, s3, F_SF, 1); -// } -// IFX(X_PF) { -// emit_pf(dyn, ninst, s1, s3, s4); -// } -// IFX(X_AF|X_OF|X_CF|X_PF){if(save_s4) {POP(xSP, 1<<s4);}} -//} +void emit_sub8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4) +{ + IFX(X_PEND) { + STRB_U12(s1, xEmu, offsetof(x64emu_t, op1)); + STRB_U12(s2, xEmu, offsetof(x64emu_t, op2)); + SET_DF(s3, d_sub8); + } else IFX(X_ALL) { + SET_DFNONE(s3); + } + IFX(X_AF|X_OF|X_CF) { + MVNw_REG(s3, s1); + ORRw_REG(s3, s3, s2); // s3 = ~op1 | op2 + BICw_REG(s4, s2, s1); // s4 = ~op1 & op2 + } + + SUBw_REG(s1, s1, s2); + IFX(X_PEND) { + STRB_U12(s1, xEmu, offsetof(x64emu_t, res)); + } + IFX(X_AF|X_OF|X_CF) { + ANDw_REG(s3, s3, s1); // s3 = (~op1 | op2) & res + ORRw_REG(s3, s3, s4); // s3 = (~op1 & op2) | ((~op1 | op2) & res) + IFX(X_CF) { + LSRw(s4, s3, 7); + BFIw(xFlags, s4, F_CF, 1); // CF : bc & 0x80 + } + IFX(X_AF) { + LSRw(s4, s3, 3); + BFIw(xFlags, s4, F_AF, 1); // AF: bc & 0x08 + } + IFX(X_OF) { + LSRw(s4, s3, 6); + EORw_REG_LSR(s4, s4, s4, 1); + BFIw(xFlags, s4, F_OF, 1); // OF: ((bc >> 6) ^ ((bc>>6)>>1)) & 1 + } + } + IFX(X_ZF) { + ANDSw_mask(s1, s1, 0, 7); //mask=0xff + CSETw(s3, cEQ); + BFIw(xFlags, s3, F_ZF, 1); + } + IFX(X_SF) { + LSRw(s3, s1, 7); + BFIw(xFlags, s3, F_SF, 1); + } + IFX(X_PF) { + emit_pf(dyn, ninst, s1, s3, s4); + } +} // emit SUB8 instruction, from s1 , constant c, store result in s1 using s3 and s4 as scratch void emit_sub8c(dynarec_arm_t* dyn, int ninst, int s1, int c, int s3, int s4, int s5) @@ -611,58 +609,55 @@ void emit_add16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4) //} // emit SUB16 instruction, from s1 , s2, store result in s1 using s3 and s4 as scratch, with save_s4 is s4 need to be saved -//void emit_sub16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int save_s4) -//{ -// IFX(X_PEND) { -// STR_IMM9(s1, xEmu, offsetof(x64emu_t, op1)); -// STR_IMM9(s2, xEmu, offsetof(x64emu_t, op2)); -// SET_DF(s3, d_sub16); -// } else IFX(X_ALL) { -// SET_DFNONE(s3); -// } -// IFX(X_AF|X_OF|X_CF|X_PF){if(save_s4) {PUSH(xSP, 1<<s4);}} -// IFX(X_AF|X_OF|X_CF) { -// MVN_REG_LSL_IMM5(s3, s1, 0); -// ORR_REG_LSL_IMM5(s3, s3, s2, 0); // s3 = ~op1 | op2 -// BIC_REG_LSL_IMM5(s4, s2, s1, 0); // s4 = ~op1 & op2 -// } -// -// SUB_REG_LSL_IMM5(s1, s1, s2, 0); -// IFX(X_PEND) { -// STR_IMM9(s1, xEmu, offsetof(x64emu_t, res)); -// } -// IFX(X_AF|X_OF|X_CF) { -// AND_REG_LSL_IMM5(s3, s3, s1, 0); // s3 = (~op1 | op2) & res -// ORR_REG_LSL_IMM5(s3, s3, s4, 0); // s3 = (~op1 & op2) | ((~op1 | op2) & res) -// IFX(X_CF) { -// MOV_REG_LSR_IMM5(s4, s3, 15); -// BFI(xFlags, s4, F_CF, 1); // CF : bc & 0x8000 -// } -// IFX(X_AF) { -// MOV_REG_LSR_IMM5(s4, s3, 3); -// BFI(xFlags, s4, F_AF, 1); // AF: bc & 0x08 -// } -// IFX(X_OF) { -// MOV_REG_LSR_IMM5(s4, s3, 14); -// XOR_REG_LSR_IMM8(s4, s4, s4, 1); -// BFI(xFlags, s4, F_OF, 1); // OF: ((bc >> 14) ^ ((bc>>14)>>1)) & 1 -// } -// } -// IFX(X_ZF) { -// UXTH(s1, s1, 0); -// TSTS_REG_LSL_IMM5(s1, s1, 0); -// ORR_IMM8_COND(cEQ, xFlags, xFlags, 1<<F_ZF, 0); -// BIC_IMM8_COND(cNE, xFlags, xFlags, 1<<F_ZF, 0); -// } -// IFX(X_SF) { -// MOV_REG_LSR_IMM5(s3, s1, 15); -// BFI(xFlags, s3, F_SF, 1); -// } -// IFX(X_PF) { -// emit_pf(dyn, ninst, s1, s3, s4); -// } -// IFX(X_AF|X_OF|X_CF|X_PF){if(save_s4) {POP(xSP, 1<<s4);}} -//} +void emit_sub16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4) +{ + IFX(X_PEND) { + STRH_U12(s1, xEmu, offsetof(x64emu_t, op1)); + STRH_U12(s2, xEmu, offsetof(x64emu_t, op2)); + SET_DF(s3, d_sub16); + } else IFX(X_ALL) { + SET_DFNONE(s3); + } + IFX(X_AF|X_OF|X_CF) { + MVNw_REG(s3, s1); + ORRw_REG(s3, s3, s2); // s3 = ~op1 | op2 + BICw_REG(s4, s2, s1); // s4 = ~op1 & op2 + } + + SUBw_REG(s1, s1, s2); + IFX(X_PEND) { + STRH_U12(s1, xEmu, offsetof(x64emu_t, res)); + } + IFX(X_AF|X_OF|X_CF) { + ANDw_REG(s3, s3, s1); // s3 = (~op1 | op2) & res + ORRw_REG(s3, s3, s4); // s3 = (~op1 & op2) | ((~op1 | op2) & res) + IFX(X_CF) { + LSRw(s4, s3, 15); + BFIw(xFlags, s4, F_CF, 1); // CF : bc & 0x8000 + } + IFX(X_AF) { + LSRw(s4, s3, 3); + BFIw(xFlags, s4, F_AF, 1); // AF: bc & 0x08 + } + IFX(X_OF) { + LSRw(s4, s3, 14); + EORw_REG_LSR(s4, s4, s4, 1); + BFIw(xFlags, s4, F_OF, 1); // OF: ((bc >> 14) ^ ((bc>>14)>>1)) & 1 + } + } + IFX(X_ZF) { + ANDSw_mask(s1, s1, 0, 15); //mask=0xffff + CSETw(s3, cEQ); + BFIw(xFlags, s3, F_ZF, 1); + } + IFX(X_SF) { + LSRw(s3, s1, 15); + BFIw(xFlags, s3, F_SF, 1); + } + IFX(X_PF) { + emit_pf(dyn, ninst, s1, s3, s4); + } +} // emit SUB16 instruction, from s1 , constant c, store result in s1 using s3 and s4 as scratch //void emit_sub16c(dynarec_arm_t* dyn, int ninst, int s1, int c, int s3, int s4) diff --git a/src/dynarec/dynarec_arm64_helper.h b/src/dynarec/dynarec_arm64_helper.h index ed3bc1c0..09503ab9 100755 --- a/src/dynarec/dynarec_arm64_helper.h +++ b/src/dynarec/dynarec_arm64_helper.h @@ -646,7 +646,7 @@ void emit_add8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4); void emit_add8c(dynarec_arm_t* dyn, int ninst, int s1, int32_t c, int s3, int s4, int s5); void emit_sub32(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4); void emit_sub32c(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int64_t c, int s3, int s4, int s5); -//void emit_sub8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4); +void emit_sub8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4); void emit_sub8c(dynarec_arm_t* dyn, int ninst, int s1, int32_t c, int s3, int s4, int s5); void emit_or32(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4); void emit_or32c(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int64_t c, int s3, int s4); @@ -662,7 +662,7 @@ void emit_and8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4); void emit_and8c(dynarec_arm_t* dyn, int ninst, int s1, int32_t c, int s3, int s4); void emit_add16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4); //void emit_add16c(dynarec_arm_t* dyn, int ninst, int s1, int32_t c, int s3, int s4); -//void emit_sub16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int save_s4); +void emit_sub16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4); //void emit_sub16c(dynarec_arm_t* dyn, int ninst, int s1, int32_t c, int s3, int s4); void emit_or16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4); //void emit_or16c(dynarec_arm_t* dyn, int ninst, int s1, int32_t c, int s3, int s4); |