From 9e15d771c8c65cb6670514bbb0fa7281048531ab Mon Sep 17 00:00:00 2001 From: Yang Liu Date: Tue, 14 Mar 2023 19:03:14 +0800 Subject: [RV64_DYNAREC] Added 85 TEST opcode (#563) --- src/dynarec/rv64/dynarec_rv64_00.c | 9 ++++- src/dynarec/rv64/dynarec_rv64_emit_tests.c | 54 ++++++++++++++++++++++++++++++ src/dynarec/rv64/dynarec_rv64_helper.h | 2 +- 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/dynarec/rv64/dynarec_rv64_emit_tests.c (limited to 'src') diff --git a/src/dynarec/rv64/dynarec_rv64_00.c b/src/dynarec/rv64/dynarec_rv64_00.c index a574ce4c..563bdf6a 100644 --- a/src/dynarec/rv64/dynarec_rv64_00.c +++ b/src/dynarec/rv64/dynarec_rv64_00.c @@ -118,7 +118,14 @@ uintptr_t dynarec64_00(dynarec_rv64_t* dyn, uintptr_t addr, uintptr_t ip, int ni DEFAULT; } break; - + case 0x85: + INST_NAME("TEST Ed, Gd"); + SETFLAGS(X_ALL, SF_SET_PENDING); + nextop=F8; + GETGD; + GETED(0); + emit_test32(dyn, ninst, rex, ed, gd, x3, x4, x5); + break; case 0x89: INST_NAME("MOV Ed, Gd"); nextop=F8; diff --git a/src/dynarec/rv64/dynarec_rv64_emit_tests.c b/src/dynarec/rv64/dynarec_rv64_emit_tests.c new file mode 100644 index 00000000..d12bb7f9 --- /dev/null +++ b/src/dynarec/rv64/dynarec_rv64_emit_tests.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "debug.h" +#include "box64context.h" +#include "dynarec.h" +#include "emu/x64emu_private.h" +#include "emu/x64run_private.h" +#include "x64run.h" +#include "x64emu.h" +#include "box64stack.h" +#include "callback.h" +#include "emu/x64run_private.h" +#include "x64trace.h" +#include "dynarec_native.h" +#include "../tools/bridge_private.h" + +#include "rv64_printer.h" +#include "dynarec_rv64_private.h" +#include "dynarec_rv64_functions.h" +#include "dynarec_rv64_helper.h" + +// emit TEST32 instruction, from test s1, s2, using s3 and s4 as scratch +void emit_test32(dynarec_rv64_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4, int s5) +{ + CLEAR_FLAGS(); + IFX_PENDOR0 { + SET_DF(s3, rex.w?d_tst64:d_tst32); + } else { + SET_DFNONE(s4); + } + + AND(s3, s1, s2); // res = s1 & s2 + + IFX_PENDOR0 { + SDxw(s3, xEmu, offsetof(x64emu_t, res)); + } + IFX(X_SF) { + if (!rex.w) ZEROUP(s3); + SRLI(s4, s3, rex.w?63:31); + BEQZ(s4, 4); + ORI(xFlags, xFlags, 1 << F_SF); + } + IFX(X_ZF) { + BNEZ(s3, 4); + ORI(xFlags, xFlags, F_ZF); + } + IFX(X_PF) { + emit_pf(dyn, ninst, s3, s4, s5); + } +} diff --git a/src/dynarec/rv64/dynarec_rv64_helper.h b/src/dynarec/rv64/dynarec_rv64_helper.h index 84eaa0df..cdba7721 100644 --- a/src/dynarec/rv64/dynarec_rv64_helper.h +++ b/src/dynarec/rv64/dynarec_rv64_helper.h @@ -336,7 +336,7 @@ void jump_to_next(dynarec_rv64_t* dyn, uintptr_t ip, int reg, int ninst); //void emit_cmp32_0(dynarec_rv64_t* dyn, int ninst, rex_t rex, int s1, int s3, int s4); //void emit_test8(dynarec_rv64_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5); //void emit_test16(dynarec_rv64_t* dyn, int ninst, int s1, int s2, int s3, int s4, int s5); -//void emit_test32(dynarec_rv64_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4); +void emit_test32(dynarec_rv64_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4, int s5); //void emit_add32(dynarec_rv64_t* dyn, int ninst, rex_t rex, int s1, int s2, int s3, int s4); //void emit_add32c(dynarec_rv64_t* dyn, int ninst, rex_t rex, int s1, int64_t c, int s3, int s4, int s5); //void emit_add8(dynarec_rv64_t* dyn, int ninst, int s1, int s2, int s3, int s4); -- cgit 1.4.1