diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-03-20 18:58:08 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-03-20 18:58:08 +0100 |
| commit | 36d62235b3552f2f5bd19b39d163c80eba567dd6 (patch) | |
| tree | 2c1a6c39460fbf47eae86aa517353fd80461d5e7 /src | |
| parent | 79c4c8bdd3d0c8d02915ec721e5e1a46664b445d (diff) | |
| download | box64-36d62235b3552f2f5bd19b39d163c80eba567dd6.tar.gz box64-36d62235b3552f2f5bd19b39d163c80eba567dd6.zip | |
[DYNAREC] Added 66 39/3B/3C CMP opcodes
Diffstat (limited to 'src')
| -rwxr-xr-x | src/dynarec/dynarec_arm64_66.c | 29 | ||||
| -rwxr-xr-x | src/dynarec/dynarec_arm64_emit_tests.c | 164 | ||||
| -rwxr-xr-x | src/dynarec/dynarec_arm64_helper.h | 4 |
3 files changed, 107 insertions, 90 deletions
diff --git a/src/dynarec/dynarec_arm64_66.c b/src/dynarec/dynarec_arm64_66.c index 64bfe765..10c214f7 100755 --- a/src/dynarec/dynarec_arm64_66.c +++ b/src/dynarec/dynarec_arm64_66.c @@ -258,6 +258,35 @@ uintptr_t dynarec64_66(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin BFIx(xRAX, x1, 0, 16); break; + case 0x39: + INST_NAME("CMP Ew, Gw"); + SETFLAGS(X_ALL, SF_SET); + nextop = F8; + GETGW(x2); + GETEW(x1, 0); + emit_cmp16(dyn, ninst, x1, x2, x3, x4, x5); + break; + case 0x3B: + INST_NAME("CMP Gw, Ew"); + SETFLAGS(X_ALL, SF_SET); + nextop = F8; + GETGW(x1); + GETEW(x2, 0); + emit_cmp16(dyn, ninst, x1, x2, x3, x4, x5); + break; + case 0x3D: + INST_NAME("CMP AX, Iw"); + SETFLAGS(X_ALL, SF_SET); + i32 = F16; + UXTHw(x1, xRAX); + if(i32) { + emit_cmp16_0(dyn, ninst, x1, x3, x4); + } else { + MOV32w(x2, i32); + emit_cmp16(dyn, ninst, x1, x2, x3, x4, x5); + } + break; + case 0xD1: case 0xD3: nextop = F8; diff --git a/src/dynarec/dynarec_arm64_emit_tests.c b/src/dynarec/dynarec_arm64_emit_tests.c index aead03b8..4a6e62f8 100755 --- a/src/dynarec/dynarec_arm64_emit_tests.c +++ b/src/dynarec/dynarec_arm64_emit_tests.c @@ -111,96 +111,84 @@ void emit_cmp32_0(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s3, int } // emit CMP16 instruction, from cmp s1 , s2, using s3 and s4 as scratch -//void emit_cmp16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4) -//{ -// IFX(X_PEND) { -// STR_IMM9(s1, xEmu, offsetof(x64emu_t, op1)); -// STR_IMM9(s2, xEmu, offsetof(x64emu_t, op2)); -// SET_DF(s3, d_cmp16); -// } else { -// SET_DFNONE(s3); -// } -// SUB_REG_LSL_IMM5(s3, s1, s2, 0); // res = s1 - s2 -// IFX(X_PEND) { -// STR_IMM9(s3, xEmu, offsetof(x64emu_t, res)); -// } -// IFX(X_ZF) { -// MOVW(s4, 0xffff); -// TSTS_REG_LSL_IMM5(s3, s4, 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(s4, s3, 15); -// BFI(xFlags, s4, F_SF, 1); -// } -// // bc = (res & (~d | s)) | (~d & s) -// IFX(X_CF|X_AF|X_OF) { -// MVN_REG_LSL_IMM5(s4, s1, 0); // s4 = ~d -// ORR_REG_LSL_IMM5(s4, s4, s2, 0); // s4 = ~d | s -// AND_REG_LSL_IMM5(s4, s4, s3, 0); // s4 = res & (~d | s) -// BIC_REG_LSL_IMM5(s3, s2, s1, 0); // loosing res... s3 = s & ~d -// ORR_REG_LSL_IMM5(s3, s4, s3, 0); // s3 = (res & (~d | s)) | (s & ~d) -// 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_PF) { -// IFX(X_CF|X_AF|X_OF) { -// SUB_REG_LSL_IMM5(s3, s1, s2, 0); -// } -// AND_IMM8(s3, s3, 0xE0); // lsr 5 masking pre-applied -// MOV32(s4, GetParityTab()); -// LDR_REG_LSR_IMM5(s4, s4, s3, 5-2); // x/32 and then *4 because array is integer -// SUB_REG_LSL_IMM5(s3, s1, s2, 0); -// AND_IMM8(s3, s3, 31); -// MVN_REG_LSR_REG(s4, s4, s3); -// BFI(xFlags, s4, F_PF, 1); -// } -//} +void emit_cmp16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5) +{ + IFX(X_PEND) { + STRH_U12(s1, xEmu, offsetof(x64emu_t, op1)); + STRH_U12(s2, xEmu, offsetof(x64emu_t, op2)); + SET_DF(s3, d_cmp16); + } else { + SET_DFNONE(s3); + } + SUBw_REG(s5, s1, s2); // res = s1 - s2 + IFX(X_PEND) { + STRH_U12(s5, xEmu, offsetof(x64emu_t, res)); + } + IFX(X_ZF) { + TSTw_mask(s5, 0, 15); //mask=0xffff + CSETw(s3, cEQ); + BFIw(xFlags, s3, F_ZF, 1); + } + IFX(X_SF) { + LSRw(s4, s5, 15); + BFIw(xFlags, s4, F_SF, 1); + } + // bc = (res & (~d | s)) | (~d & s) + IFX(X_CF|X_AF|X_OF) { + MVNw_REG(s4, s1); // s4 = ~d + ORRw_REG(s4, s4, s2); // s4 = ~d | s + ANDw_REG(s4, s4, s5); // s4 = res & (~d | s) + BICw_REG(s3, s2, s1); // s3 = s & ~d + ORRw_REG(s3, s4, s3); // s3 = (res & (~d | s)) | (s & ~d) + 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_PF) { + emit_pf(dyn, ninst, s5, s3, s4); + } +} // emit CMP16 instruction, from cmp s1 , #0, using s3 and s4 as scratch -//void emit_cmp16_0(dynarec_arm_t* dyn, int ninst, int s1, int s3, int s4) -//{ -// IFX(X_PEND) { -// MOVW(s3, 0); -// STR_IMM9(s1, xEmu, offsetof(x64emu_t, op1)); -// STR_IMM9(s3, xEmu, offsetof(x64emu_t, op2)); -// STR_IMM9(s1, xEmu, offsetof(x64emu_t, res)); -// SET_DF(s3, d_cmp16); -// } else { -// SET_DFNONE(s3); -// } -// // bc = (res & (~d | s)) | (~d & s) = 0 -// IFX(X_CF | X_AF | X_ZF) { -// BIC_IMM8(xFlags, xFlags, (1<<F_CF)|(1<<F_AF)|(1<<F_ZF), 0); -// } -// IFX(X_OF) { -// BFC(xFlags, F_OF, 1); -// } -// IFX(X_ZF) { -// MOVW(s4, 0xffff); -// TSTS_REG_LSL_IMM5(s1, s4, 0); -// ORR_IMM8_COND(cEQ, xFlags, xFlags, 1<<F_ZF, 0); -// } -// IFX(X_SF) { -// MOV_REG_LSR_IMM5(s4, s1, 15); -// BFI(xFlags, s4, F_SF, 1); -// } -// IFX(X_PF) { -// emit_pf(dyn, ninst, s1, s3, s4); -// } -//} +void emit_cmp16_0(dynarec_arm_t* dyn, int ninst, int s1, int s3, int s4) +{ + IFX(X_PEND) { + MOV32w(s3, 0); + STRH_U12(s1, xEmu, offsetof(x64emu_t, op1)); + STRH_U12(s3, xEmu, offsetof(x64emu_t, op2)); + STRH_U12(s1, xEmu, offsetof(x64emu_t, res)); + SET_DF(s3, d_cmp16); + } else { + SET_DFNONE(s3); + } + // bc = (res & (~d | s)) | (~d & s) = 0 + IFX(X_CF | X_AF | X_OF) { + MOV32w(s3, (1<<F_CF)|(1<<F_AF)|(1<<F_OF)); + BICw(xFlags, xFlags, s3); + } + IFX(X_ZF) { + ANDSw_mask(s1, s1, 0, 15); //mask=0xffff + CSETw(s3, cEQ); + BFIw(xFlags, s3, F_ZF, 1); + } + IFX(X_SF) { + LSRw(s4, s1, 15); + BFIw(xFlags, s4, F_SF, 1); + } + IFX(X_PF) { + emit_pf(dyn, ninst, s1, s3, s4); + } +} // emit CMP8 instruction, from cmp s1 , s2, using s3 and s4 as scratch void emit_cmp8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5) { diff --git a/src/dynarec/dynarec_arm64_helper.h b/src/dynarec/dynarec_arm64_helper.h index 1629170a..e4bc025d 100755 --- a/src/dynarec/dynarec_arm64_helper.h +++ b/src/dynarec/dynarec_arm64_helper.h @@ -632,10 +632,10 @@ void call_c(dynarec_arm_t* dyn, int ninst, void* fnc, int reg, int ret, int save //void grab_fsdata(dynarec_arm_t* dyn, uintptr_t addr, int ninst, int reg); //void grab_tlsdata(dynarec_arm_t* dyn, uintptr_t addr, int ninst, int reg); void emit_cmp8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5); -//void emit_cmp16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4); +void emit_cmp16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5); void emit_cmp32(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4, int s5); void emit_cmp8_0(dynarec_arm_t* dyn, int ninst, int s1, int s3, int s4); -//void emit_cmp16_0(dynarec_arm_t* dyn, int ninst, int s1, int s3, int s4); +void emit_cmp16_0(dynarec_arm_t* dyn, int ninst, int s1, int s3, int s4); void emit_cmp32_0(dynarec_arm_t* dyn, int ninst, rex_t rex, int s1, int s3, int s4); void emit_test8(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5); void emit_test16(dynarec_arm_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5); |