[dynarmic] fix seven A32 and x64 defects (#4598)

- [x] I have read and followed the [Contribution Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/CONTRIBUTING.md#code-contributions).
- [x] I have read and followed the [Coding Guidelines](https://git.eden-emu.dev/eden-emu/eden/src/branch/master/docs/policies/Coding.md) to the best of my ability.
- [x] I have read and followed the [website policy](https://git.eden-emu.dev/eden-emu/site-policy).
- [ ] I affirm that the content of this pull request body was written and submitted entirely by me, in my own words, and not by an AI agent or LLM.
- [ ] I affirm that I did not read any of this, and understand that my pull request will be closed if I check this box.
- [x] I affirm that, by submitting this pull request, I am responsible for all of the changes contained within these commits.

-------------------

Seven dynarmic fixes, one commit each with a test that fails without it, after a first commit that makes `dynarmic_tests` build again:

- Tests don't build on master: #4513's SM3/SM4 tests call `SM4E` with three operands and `SM3PARTW1/W2` with four (they take two and three), which oaknut 2.0.3 rejects. Only the calls change; the expected values were already right (checked against the Arm pseudocode).
- A32 SHA-1 (`SHA1C/P/M/H/SU0/SU1`) was never translated.
- `CLZ` (16-bit lanes) on AVX-512 got lanes 4-7 wrong.
- 32-bit `SDIV` by zero on x64 returned the dividend instead of 0.
- `FRINT` through the soft-float fallback read the rounding mode and exactness one byte off.
- `SQSHLU` on x64 didn't saturate 8/16-bit lanes and cut 64-bit lanes to 32 bits.
- `SM4E`/`SM4EKEY` on x64: `lea` with the S-box's absolute address throws in Xbyak in a PIE build, so #4513's `A64: SM4` aborts.
- `FCVTZS`/`FCVTZU` (vector) `#64` without SSE4.1 called a null thunk. To reach it on a modern CPU, `DYNARMIC_HOST_FEATURE_OVERRIDE` (CMake option, off by default) lets `DYNARMIC_HOST_FEATURES=<hex mask>` hide host features in test builds, and ctest also runs the suite as SSE2-only.

Tested on Linux x86_64 (AVX-512), each case alone on master (7a6d055094) with these tests, then this PR:

| | master + these tests | this PR |
|---|---|---|
| A32 SHA-1 (2 cases), `A64: SM4` | abort | pass |
| SDIV/UDIV by zero (A32, A64), VRINTX/VRINTA, FRINT, SQSHLU, `A64: CLZ` | fail | pass |
| FCVTZS/FCVTZU `#64` | passes (SSE4.1 path) | passes |
| whole suite | | 141 pass, 1 skipped (needs its variable); as SSE2-only, all 142 pass |

Assisted-by: Claude Opus 5.5 (Aogo) (wrote the patches and tests, rebased them, ran the checks above and wrote this description)
Co-authored-by: AO55 <AO55@reden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4598
Reviewed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
DraQuimeraVeeandAO55 authored and crueter committed 2026-11-08 03:27:22 +01:00
1 parent 63a94c0caa
commit 35f0dd7c1c
17 files changed
+512 -15

No files matched your search

+1
View File
@@ -18,6 +18,7 @@ else()
endif()
option(DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT "Enables support for systems that require W^X" ${REQUIRE_WX})
option(DYNARMIC_TESTS_USE_UNICORN "Enable fuzzing tests against unicorn" OFF)
option(DYNARMIC_HOST_FEATURE_OVERRIDE "Let DYNARMIC_HOST_FEATURES=<hex mask> hide x64 host features (test builds only)" OFF)
CMAKE_DEPENDENT_OPTION(DYNARMIC_USE_LLVM "Support disassembly of jitted x86_64 code using LLVM" OFF "NOT YUZU_DISABLE_LLVM" OFF)
# Set hard requirements for C++
+3
View File
@@ -398,6 +398,9 @@ if (DYNARMIC_USE_LLVM)
target_compile_definitions(dynarmic PRIVATE DYNARMIC_USE_LLVM=1 ${LLVM_DEFINITIONS})
llvm_config(dynarmic USE_SHARED armdesc armdisassembler aarch64desc aarch64disassembler x86desc x86disassembler)
endif()
if (DYNARMIC_HOST_FEATURE_OVERRIDE)
target_compile_definitions(dynarmic PRIVATE DYNARMIC_HOST_FEATURE_OVERRIDE=1)
endif()
if (DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT)
target_compile_definitions(dynarmic PRIVATE DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT=1)
endif()
@@ -8,6 +8,8 @@
#include "dynarmic/backend/x64/block_of_code.h"
#include <cstdlib>
#ifdef _WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
@@ -119,11 +121,13 @@ static const HostFeature features = []() {
f |= HostFeature::FastBMI2;
}
}
#ifdef DYNARMIC_HOST_FEATURE_OVERRIDE
// Test builds only: DYNARMIC_HOST_FEATURES=<hex mask> hides features to reach the fallbacks.
if (const char* mask = std::getenv("DYNARMIC_HOST_FEATURES"); mask && *mask)
f &= static_cast<HostFeature>(std::strtoull(mask, nullptr, 16));
#endif
return f;
}();
HostFeature GetHostFeatures() {
return features;
}
#ifdef __APPLE__
bool IsUnderRosetta() {
@@ -140,6 +144,10 @@ bool IsUnderRosetta() {
} // anonymous namespace
HostFeature GetHostFeatures() {
return features;
}
BlockOfCode::BlockOfCode(RunCodeCallbacks cb, JitStateInfo jsi, size_t total_code_size, std::function<void(BlockOfCode&)> rcp)
: Xbyak::CodeGenerator(total_code_size
#ifdef DYNARMIC_ENABLE_NO_EXECUTE_SUPPORT
@@ -1204,6 +1204,7 @@ void EmitX64::EmitSignedDiv32(EmitContext& ctx, IR::Inst* inst) {
auto const divisor = ctx.reg_alloc.UseGpr(code, args[1]).cvt32();
Xbyak::Label end, ok;
code.test(divisor, divisor);
code.cmovz(eax, divisor); // x / 0 == 0
code.jz(end, code.T_NEAR);
code.cmp(divisor, u32(-1)); // is sign extended
code.jne(ok, code.T_NEAR);
@@ -1054,8 +1054,8 @@ void EmitX64::EmitFPRecipStepFused64(EmitContext& ctx, IR::Inst* inst) {
/// 8-15 exact (!= 0)
template<typename FPT>
static u64 EmitFPRoundThunk(u64 input, FP::FPSR& fpsr, FP::FPCR fpcr, u32 extra_args) {
auto const exact = ((extra_args >> 16) & 0xff) != 0;
auto const rounding_mode = FP::RoundingMode((extra_args >> 8) & 0xff);
auto const exact = ((extra_args >> 8) & 0xff) != 0;
auto const rounding_mode = FP::RoundingMode((extra_args >> 0) & 0xff);
return FP::FPRoundInt<FPT>(FPT(input), fpcr, rounding_mode, exact, fpsr);
}
@@ -53,7 +53,7 @@ void EmitX64::EmitSM4AccessSubstitutionBox(EmitContext& ctx, IR::Inst* inst) {
const Xbyak::Reg tmp1 = ctx.reg_alloc.ScratchGpr(code);
// return subtitution_box[index * 1];
code.movzx(tmp0.cvt32(), tmp0.cvt8());
code.lea(tmp1, code.ptr[std::addressof(substitution_box)]);
code.mov(tmp1, std::bit_cast<u64>(substitution_box.data()));
code.movzx(tmp1, code.byte[tmp1 + tmp0 * 1]);
ctx.reg_alloc.DefineValue(code, inst, tmp1);
}
@@ -903,7 +903,8 @@ void EmitX64::EmitVectorCountLeadingZeros16(EmitContext& ctx, IR::Inst* inst) {
// then subtract 16-bit cuz of the zext32
/*4*/ code.vpmovzxwd(tmp0.cvt256(), tmp0);
/*4*/ code.vplzcntd(tmp0.cvt256(), tmp0.cvt256());
/*1*/ code.vpxor(tmp1, tmp1, tmp1);
// an XMM vpackusdw reads only the low half of the YMM: bring lanes 4-7 down for it
/*3*/ code.vextracti128(tmp1, tmp0.cvt256(), 1);
/*1*/ code.vpackusdw(tmp0, tmp0, tmp1);
/*1*/ code.vpaddw(tmp0, tmp0, code.BConst<16>(xword, 65520));
/*4*/ code.vzeroupper();
@@ -5139,9 +5140,9 @@ static bool VectorSignedSaturatedShiftLeftUnsigned(VectorArray<T>& dst, const Ve
bool qc_flag = false;
for (size_t i = 0; i < dst.size(); i++) {
auto const element = data[i];
auto const shifted = U(element) << U(T(shift_amount));
U const shifted = U(U(element) << U(T(shift_amount)));
auto const shifted_test = shifted >> U(T(shift_amount));
auto result = 0;
T result = 0;
if (element > 0 && shifted_test != U(element))
result = T((std::numeric_limits<U>::max)());
if (element > 0 && shifted_test == U(element))
@@ -2158,7 +2158,8 @@ void EmitFPVectorToFixed(BlockOfCode& code, EmitContext& ctx, IR::Inst* inst) {
ROUNDING_MODE_CASE(CASE, 0x3c) \
ROUNDING_MODE_CASE(CASE, 0x3d) \
ROUNDING_MODE_CASE(CASE, 0x3e) \
ROUNDING_MODE_CASE(CASE, 0x3f)
ROUNDING_MODE_CASE(CASE, 0x3f) \
ROUNDING_MODE_CASE(CASE, 0x40)
ROUNDING_MODE_SWITCH(ToNearest_TieEven)
ROUNDING_MODE_SWITCH(TowardsPlusInfinity)
@@ -67,4 +67,7 @@ constexpr HostFeature operator&=(HostFeature& result, HostFeature f) {
return result = (result & f);
}
/// What the JIT uses: the host's features, less any that DYNARMIC_HOST_FEATURES hides.
HostFeature GetHostFeatures();
} // namespace Dynarmic::Backend::X64
@@ -16,8 +16,8 @@ INST(v8_AESD, "AESD", "111100111D11zz00dddd001101M0mmmm")
INST(v8_AESMC, "AESMC", "111100111D11zz00dddd001110M0mmmm")
INST(v8_AESIMC, "AESIMC", "111100111D11zz00dddd001111M0mmmm")
INST(arm_UDF, "UNALLOCATED", "111100111-11--01----001010-0----")
INST(arm_UDF, "UNALLOCATED (SHA1H)", "111100111-11--01----001011-0----")
INST(arm_UDF, "UNALLOCATED (SHA1SU1)", "111100111-11--10----001110-0----")
INST(v8_SHA1H, "SHA1H", "111100111D11zz01dddd001011M0mmmm")
INST(v8_SHA1SU1, "SHA1SU1", "111100111D11zz10dddd001110M0mmmm")
INST(v8_SHA256SU0, "SHA256SU0", "111100111D11zz10dddd001111M0mmmm")
INST(asimd_VCLS, "VCLS", "111100111D11zz00dddd01000QM0mmmm")
INST(asimd_VCLZ, "VCLZ", "111100111D11zz00dddd01001QM0mmmm")
@@ -64,6 +64,10 @@ INST(asimd_VEOR_reg, "VEOR (register)", "111100110D00nnnndddd0001NQM1mmmm")
INST(asimd_VBSL, "VBSL", "111100110D01nnnndddd0001NQM1mmmm")
INST(asimd_VBIT, "VBIT", "111100110D10nnnndddd0001NQM1mmmm")
INST(asimd_VBIF, "VBIF", "111100110D11nnnndddd0001NQM1mmmm")
INST(v8_SHA1C, "SHA1C", "111100100D00nnnndddd1100NQM0mmmm")
INST(v8_SHA1P, "SHA1P", "111100100D01nnnndddd1100NQM0mmmm")
INST(v8_SHA1M, "SHA1M", "111100100D10nnnndddd1100NQM0mmmm")
INST(v8_SHA1SU0, "SHA1SU0", "111100100D11nnnndddd1100NQM0mmmm")
INST(v8_SHA256H, "SHA256H", "111100110D00nnnndddd1100NQM0mmmm")
INST(v8_SHA256H2, "SHA256H2", "111100110D01nnnndddd1100NQM0mmmm")
INST(v8_SHA256SU1, "SHA256SU1", "111100110D10nnnndddd1100NQM0mmmm")
@@ -885,6 +885,10 @@ struct TranslatorVisitor final {
bool asimd_VPMIN_float(bool D, bool sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm);
bool asimd_VRECPS(bool D, bool sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm);
bool asimd_VRSQRTS(bool D, bool sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm);
bool v8_SHA1C(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm);
bool v8_SHA1P(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm);
bool v8_SHA1M(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm);
bool v8_SHA1SU0(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm);
bool v8_SHA256H(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm);
bool v8_SHA256H2(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm);
bool v8_SHA256SU1(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm);
@@ -931,6 +935,8 @@ struct TranslatorVisitor final {
bool v8_AESE(bool D, size_t sz, size_t Vd, bool M, size_t Vm);
bool v8_AESIMC(bool D, size_t sz, size_t Vd, bool M, size_t Vm);
bool v8_AESMC(bool D, size_t sz, size_t Vd, bool M, size_t Vm);
bool v8_SHA1H(bool D, size_t sz, size_t Vd, bool M, size_t Vm);
bool v8_SHA1SU1(bool D, size_t sz, size_t Vd, bool M, size_t Vm);
bool v8_SHA256SU0(bool D, size_t sz, size_t Vd, bool M, size_t Vm);
bool asimd_VCLS(bool D, size_t sz, size_t Vd, bool Q, bool M, size_t Vm);
bool asimd_VCLZ(bool D, size_t sz, size_t Vd, bool Q, bool M, size_t Vm);
@@ -244,6 +244,58 @@ bool WideInstruction(TranslatorVisitor& v, bool U, bool D, size_t sz, size_t Vn,
// ASIMD Three registers of the same length
namespace {
IR::U32 SHA1Choose(IREmitter& ir, IR::U32 x, IR::U32 y, IR::U32 z) {
return ir.Eor(ir.And(ir.Eor(y, z), x), z);
}
IR::U32 SHA1Majority(IREmitter& ir, IR::U32 x, IR::U32 y, IR::U32 z) {
return ir.Or(ir.And(x, y), ir.And(ir.Or(x, y), z));
}
IR::U32 SHA1Parity(IREmitter& ir, IR::U32 x, IR::U32 y, IR::U32 z) {
return ir.Eor(ir.Eor(y, z), x);
}
using SHA1HashUpdateFunction = IR::U32(IREmitter&, IR::U32, IR::U32, IR::U32);
// Four rounds of SHA1C, SHA1M or SHA1P: X is Qd, Y the low word of Qn, W is Qm. Same
// computation as the A64 translation.
bool SHA1HashUpdate(TranslatorVisitor& v, bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm, SHA1HashUpdateFunction fn) {
if (!Q || mcl::bit::get_bit<0>(Vd) || mcl::bit::get_bit<0>(Vn) || mcl::bit::get_bit<0>(Vm)) {
return v.UndefinedInstruction();
}
const auto d = ToVector(Q, Vd, D);
const auto n = ToVector(Q, Vn, N);
const auto m = ToVector(Q, Vm, M);
IR::U128 x = v.ir.GetVector(d);
IR::U32 y = v.ir.VectorGetElement(32, v.ir.GetVector(n), 0);
const IR::U128 w = v.ir.GetVector(m);
for (size_t i = 0; i < 4; i++) {
const IR::U32 low_x = v.ir.VectorGetElement(32, x, 0);
const IR::U32 after_low_x = v.ir.VectorGetElement(32, x, 1);
const IR::U32 before_high_x = v.ir.VectorGetElement(32, x, 2);
const IR::U32 high_x = v.ir.VectorGetElement(32, x, 3);
const IR::U32 t = fn(v.ir, after_low_x, before_high_x, high_x);
const IR::U32 w_segment = v.ir.VectorGetElement(32, w, i);
y = v.ir.Add(v.ir.Add(v.ir.Add(y, v.ir.RotateRight(low_x, v.ir.Imm8(27))), t), w_segment);
x = v.ir.VectorSetElement(32, x, 1, v.ir.RotateRight(after_low_x, v.ir.Imm8(2)));
// <Y, X> = ROL(Y:X, 32): every word of X moves up one, Y becomes the lowest.
const IR::U128 shuffled_x = v.ir.VectorRotateWholeVectorRight(x, 96);
x = v.ir.VectorSetElement(32, shuffled_x, 0, y);
y = high_x;
}
v.ir.SetVector(d, x);
return true;
}
} // Anonymous namespace
bool TranslatorVisitor::asimd_VHADD(bool U, bool D, size_t sz, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm) {
if (Q && (mcl::bit::get_bit<0>(Vd) || mcl::bit::get_bit<0>(Vn) || mcl::bit::get_bit<0>(Vm))) {
return UndefinedInstruction();
@@ -842,6 +894,39 @@ bool TranslatorVisitor::asimd_VRSQRTS(bool D, bool sz, size_t Vn, size_t Vd, boo
});
}
bool TranslatorVisitor::v8_SHA1C(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm) {
return SHA1HashUpdate(*this, D, Vn, Vd, N, Q, M, Vm, SHA1Choose);
}
bool TranslatorVisitor::v8_SHA1P(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm) {
return SHA1HashUpdate(*this, D, Vn, Vd, N, Q, M, Vm, SHA1Parity);
}
bool TranslatorVisitor::v8_SHA1M(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm) {
return SHA1HashUpdate(*this, D, Vn, Vd, N, Q, M, Vm, SHA1Majority);
}
bool TranslatorVisitor::v8_SHA1SU0(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm) {
if (!Q || mcl::bit::get_bit<0>(Vd) || mcl::bit::get_bit<0>(Vn) || mcl::bit::get_bit<0>(Vm)) {
return UndefinedInstruction();
}
const auto d = ToVector(Q, Vd, D);
const auto n = ToVector(Q, Vn, N);
const auto m = ToVector(Q, Vm, M);
const IR::U128 x = ir.GetVector(d);
const IR::U128 y = ir.GetVector(n);
const IR::U128 z = ir.GetVector(m);
// op2 = Qn<63:0> : Qd<127:64>
const IR::U128 high_d = ir.VectorSetElement(64, ir.ZeroVector(), 0, ir.VectorGetElement(64, x, 1));
const IR::U128 op2 = ir.VectorSetElement(64, high_d, 1, ir.VectorGetElement(64, y, 0));
ir.SetVector(d, ir.VectorEor(ir.VectorEor(op2, x), z));
return true;
}
bool TranslatorVisitor::v8_SHA256H(bool D, size_t Vn, size_t Vd, bool N, bool Q, bool M, size_t Vm) {
if (!Q || mcl::bit::get_bit<0>(Vd) || mcl::bit::get_bit<0>(Vn) || mcl::bit::get_bit<0>(Vm)) {
return UndefinedInstruction();
@@ -241,6 +241,44 @@ bool TranslatorVisitor::v8_AESMC(bool D, size_t sz, size_t Vd, bool M, size_t Vm
return true;
}
bool TranslatorVisitor::v8_SHA1H(bool D, size_t sz, size_t Vd, bool M, size_t Vm) {
if (sz != 0b10 || mcl::bit::get_bit<0>(Vd) || mcl::bit::get_bit<0>(Vm)) {
return UndefinedInstruction();
}
const auto d = ToVector(true, Vd, D);
const auto m = ToVector(true, Vm, M);
// Qd = ZeroExtend(ROL(Qm<31:0>, 30))
const IR::U32 word = ir.VectorGetElement(32, ir.GetVector(m), 0);
const IR::U32 rotated = ir.RotateRight(word, ir.Imm8(2));
ir.SetVector(d, ir.ZeroExtendToQuad(rotated));
return true;
}
bool TranslatorVisitor::v8_SHA1SU1(bool D, size_t sz, size_t Vd, bool M, size_t Vm) {
if (sz != 0b10 || mcl::bit::get_bit<0>(Vd) || mcl::bit::get_bit<0>(Vm)) {
return UndefinedInstruction();
}
const auto d = ToVector(true, Vd, D);
const auto m = ToVector(true, Vm, M);
const IR::U128 x = ir.GetVector(d);
const IR::U128 y = ir.GetVector(m);
// T = X EOR LSR(Y, 32); every word of T rotated left by one, the top one also EOR ROL(T<31:0>, 2)
const IR::U128 y_down = ir.VectorSetElement(32, ir.VectorRotateWholeVectorRight(y, 32), 3, ir.Imm32(0));
const IR::U128 t = ir.VectorEor(x, y_down);
const IR::U128 rotated_t = ir.VectorRotateLeft(32, t, 1);
const IR::U32 low_t_rol2 = ir.RotateRight(ir.VectorGetElement(32, rotated_t, 0), ir.Imm8(31));
const IR::U32 high = ir.Eor(low_t_rol2, ir.VectorGetElement(32, rotated_t, 3));
ir.SetVector(d, ir.VectorSetElement(32, rotated_t, 3, high));
return true;
}
bool TranslatorVisitor::v8_SHA256SU0(bool D, size_t sz, size_t Vd, bool M, size_t Vm) {
if (sz != 0b10 || mcl::bit::get_bit<0>(Vd) || mcl::bit::get_bit<0>(Vm)) {
return UndefinedInstruction();
@@ -6,6 +6,8 @@
* SPDX-License-Identifier: 0BSD
*/
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "dynarmic/tests/A32/testenv.h"
@@ -707,3 +709,209 @@ TEST_CASE("arm: tbx", "[arm][A32]") {
REQUIRE(jit.ExtRegs()[19 * 2 + 0] == 0x05'02'01'00);
REQUIRE(jit.ExtRegs()[19 * 2 + 1] == 0x20'1F'10'0F);
}
TEST_CASE("arm: SHA-1 of one block with the crypto extension", "[arm][A32]") {
// SHA-1("abc"), one padded block, through SHA1C/P/M, SHA1H, SHA1SU0 and SHA1SU1: the state in
// q0 and s4, a copy in q2 and s12, the message in q8-q11, the round constants in q12-q15.
ArmTestEnv test_env;
A32::Jit jit{GetUserConfig(&test_env)};
test_env.code_mem = {
0xf22088e8, // vadd.i32 q4, q8, q12
0xf2720ce4, // sha1su0.32 q8, q9, q10
0xf3fa03a6, // sha1su1.32 q8, q11
0xf3b9a2c0, // sha1h.32 q5, q0
0xf2020c48, // sha1c.32 q0, q1, q4
0xf22288e8, // vadd.i32 q4, q9, q12
0xf2742ce6, // sha1su0.32 q9, q10, q11
0xf3fa23a0, // sha1su1.32 q9, q8
0xf3b922c0, // sha1h.32 q1, q0
0xf20a0c48, // sha1c.32 q0, q5, q4
0xf22488e8, // vadd.i32 q4, q10, q12
0xf2764ce0, // sha1su0.32 q10, q11, q8
0xf3fa43a2, // sha1su1.32 q10, q9
0xf3b9a2c0, // sha1h.32 q5, q0
0xf2020c48, // sha1c.32 q0, q1, q4
0xf22688e8, // vadd.i32 q4, q11, q12
0xf2706ce2, // sha1su0.32 q11, q8, q9
0xf3fa63a4, // sha1su1.32 q11, q10
0xf3b922c0, // sha1h.32 q1, q0
0xf20a0c48, // sha1c.32 q0, q5, q4
0xf22088e8, // vadd.i32 q4, q8, q12
0xf2720ce4, // sha1su0.32 q8, q9, q10
0xf3fa03a6, // sha1su1.32 q8, q11
0xf3b9a2c0, // sha1h.32 q5, q0
0xf2020c48, // sha1c.32 q0, q1, q4
0xf22288ea, // vadd.i32 q4, q9, q13
0xf2742ce6, // sha1su0.32 q9, q10, q11
0xf3fa23a0, // sha1su1.32 q9, q8
0xf3b922c0, // sha1h.32 q1, q0
0xf21a0c48, // sha1p.32 q0, q5, q4
0xf22488ea, // vadd.i32 q4, q10, q13
0xf2764ce0, // sha1su0.32 q10, q11, q8
0xf3fa43a2, // sha1su1.32 q10, q9
0xf3b9a2c0, // sha1h.32 q5, q0
0xf2120c48, // sha1p.32 q0, q1, q4
0xf22688ea, // vadd.i32 q4, q11, q13
0xf2706ce2, // sha1su0.32 q11, q8, q9
0xf3fa63a4, // sha1su1.32 q11, q10
0xf3b922c0, // sha1h.32 q1, q0
0xf21a0c48, // sha1p.32 q0, q5, q4
0xf22088ea, // vadd.i32 q4, q8, q13
0xf2720ce4, // sha1su0.32 q8, q9, q10
0xf3fa03a6, // sha1su1.32 q8, q11
0xf3b9a2c0, // sha1h.32 q5, q0
0xf2120c48, // sha1p.32 q0, q1, q4
0xf22288ea, // vadd.i32 q4, q9, q13
0xf2742ce6, // sha1su0.32 q9, q10, q11
0xf3fa23a0, // sha1su1.32 q9, q8
0xf3b922c0, // sha1h.32 q1, q0
0xf21a0c48, // sha1p.32 q0, q5, q4
0xf22488ec, // vadd.i32 q4, q10, q14
0xf2764ce0, // sha1su0.32 q10, q11, q8
0xf3fa43a2, // sha1su1.32 q10, q9
0xf3b9a2c0, // sha1h.32 q5, q0
0xf2220c48, // sha1m.32 q0, q1, q4
0xf22688ec, // vadd.i32 q4, q11, q14
0xf2706ce2, // sha1su0.32 q11, q8, q9
0xf3fa63a4, // sha1su1.32 q11, q10
0xf3b922c0, // sha1h.32 q1, q0
0xf22a0c48, // sha1m.32 q0, q5, q4
0xf22088ec, // vadd.i32 q4, q8, q14
0xf2720ce4, // sha1su0.32 q8, q9, q10
0xf3fa03a6, // sha1su1.32 q8, q11
0xf3b9a2c0, // sha1h.32 q5, q0
0xf2220c48, // sha1m.32 q0, q1, q4
0xf22288ec, // vadd.i32 q4, q9, q14
0xf2742ce6, // sha1su0.32 q9, q10, q11
0xf3fa23a0, // sha1su1.32 q9, q8
0xf3b922c0, // sha1h.32 q1, q0
0xf22a0c48, // sha1m.32 q0, q5, q4
0xf22488ec, // vadd.i32 q4, q10, q14
0xf2764ce0, // sha1su0.32 q10, q11, q8
0xf3fa43a2, // sha1su1.32 q10, q9
0xf3b9a2c0, // sha1h.32 q5, q0
0xf2220c48, // sha1m.32 q0, q1, q4
0xf22688ee, // vadd.i32 q4, q11, q15
0xf2706ce2, // sha1su0.32 q11, q8, q9
0xf3fa63a4, // sha1su1.32 q11, q10
0xf3b922c0, // sha1h.32 q1, q0
0xf21a0c48, // sha1p.32 q0, q5, q4
0xf22088ee, // vadd.i32 q4, q8, q15
0xf3b9a2c0, // sha1h.32 q5, q0
0xf2120c48, // sha1p.32 q0, q1, q4
0xf22288ee, // vadd.i32 q4, q9, q15
0xf3b922c0, // sha1h.32 q1, q0
0xf21a0c48, // sha1p.32 q0, q5, q4
0xf22488ee, // vadd.i32 q4, q10, q15
0xf3b9a2c0, // sha1h.32 q5, q0
0xf2120c48, // sha1p.32 q0, q1, q4
0xf22688ee, // vadd.i32 q4, q11, q15
0xf3b922c0, // sha1h.32 q1, q0
0xf21a0c48, // sha1p.32 q0, q5, q4
0xf2200844, // vadd.i32 q0, q0, q2
0xf2222846, // vadd.i32 q1, q1, q3
0xeafffffe, // b +#0
};
const std::array<u32, 16> message{0x61626380, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x18};
const std::array<u32, 4> constants{0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6};
const std::array<u32, 4> abcd{0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476};
const u32 e = 0xc3d2e1f0;
for (size_t i = 0; i < message.size(); i++) {
jit.ExtRegs()[32 + i] = message[i];
}
for (size_t i = 0; i < 16; i++) {
jit.ExtRegs()[48 + i] = constants[i / 4];
}
for (size_t i = 0; i < 4; i++) {
jit.ExtRegs()[0 + i] = abcd[i];
jit.ExtRegs()[8 + i] = abcd[i];
}
jit.ExtRegs()[4] = e;
jit.ExtRegs()[12] = e;
jit.SetCpsr(0x000001d0); // User-mode
test_env.ticks_left = test_env.code_mem.size();
CheckedRun([&]() { jit.Run(); });
REQUIRE(jit.ExtRegs()[0] == 0xa9993e36);
REQUIRE(jit.ExtRegs()[1] == 0x4706816a);
REQUIRE(jit.ExtRegs()[2] == 0xba3e2571);
REQUIRE(jit.ExtRegs()[3] == 0x7850c26c);
REQUIRE(jit.ExtRegs()[4] == 0x9cd0d89d);
}
TEST_CASE("arm: SHA1H clears the rest of the destination", "[arm][A32]") {
ArmTestEnv test_env;
A32::Jit jit{GetUserConfig(&test_env)};
test_env.code_mem = {
0xf3b9a2c0, // sha1h.32 q5, q0
0xeafffffe, // b +#0
};
jit.ExtRegs()[0] = 0x80000001;
for (size_t i = 20; i < 24; i++) {
jit.ExtRegs()[i] = 0xdeadbeef;
}
jit.SetCpsr(0x000001d0); // User-mode
test_env.ticks_left = 2;
CheckedRun([&]() { jit.Run(); });
REQUIRE(jit.ExtRegs()[20] == 0x60000000);
REQUIRE(jit.ExtRegs()[21] == 0);
REQUIRE(jit.ExtRegs()[22] == 0);
REQUIRE(jit.ExtRegs()[23] == 0);
}
TEST_CASE("arm: sdiv and udiv by zero", "[arm][A32]") {
ArmTestEnv test_env;
A32::Jit jit{GetUserConfig(&test_env)};
test_env.code_mem = {
0xe712f011, // sdiv r2, r1, r0
0xe733f011, // udiv r3, r1, r0
0xeafffffe, // b +#0
};
jit.Regs()[0] = 0;
jit.Regs()[1] = 0x12345678;
jit.Regs()[2] = 0xdeadbeef;
jit.Regs()[3] = 0xdeadbeef;
jit.SetCpsr(0x000001d0); // User-mode
test_env.ticks_left = 3;
CheckedRun([&]() { jit.Run(); });
REQUIRE(jit.Regs()[2] == 0);
REQUIRE(jit.Regs()[3] == 0);
}
TEST_CASE("arm: vrintx and vrinta through the soft-float fallback", "[arm][A32]") {
ArmTestEnv test_env;
A32::Jit jit{GetUserConfig(&test_env)};
test_env.code_mem = {
0xeeb70b41, // vrintx.f64 d0, d1
0xfeb82b43, // vrinta.f64 d2, d3
0xeafffffe, // b +#0
};
jit.ExtRegs()[2] = 0x33333333; // d1 = 0.3
jit.ExtRegs()[3] = 0x3fd33333;
jit.ExtRegs()[6] = 0x00000000; // d3 = 2.5
jit.ExtRegs()[7] = 0x40040000;
jit.SetFpscr(0); // round to nearest
jit.SetCpsr(0x000001d0); // User-mode
test_env.ticks_left = 3;
CheckedRun([&]() { jit.Run(); });
REQUIRE(jit.ExtRegs()[0] == 0); // 0.0
REQUIRE(jit.ExtRegs()[1] == 0);
REQUIRE(jit.ExtRegs()[4] == 0); // 3.0, ties away from zero
REQUIRE(jit.ExtRegs()[5] == 0x40080000);
}
+126 -3
View File
@@ -2642,7 +2642,8 @@ TEST_CASE("A64: SM4", "[a64]") {
oaknut::VectorCodeGenerator code{env.code_mem, nullptr};
code.SM4EKEY(V4.S4(), V0.S4(), V1.S4());
code.SM4E(V5.S4(), V0.S4(), V1.S4());
code.MOV(V5.B16(), V0.B16());
code.SM4E(V5.S4(), V1.S4());
jit.SetPC(0);
jit.SetVector(0, {0xefcdab8967452301, 0x1032547698badcfe});
@@ -2673,7 +2674,7 @@ TEST_CASE("A64: SM3", "[a64]") {
SECTION("SM3PARTW1") {
A64::Jit jit{jit_user_config};
oaknut::VectorCodeGenerator code{env.code_mem, nullptr};
code.SM3PARTW1(V0.S4(), V0.S4(), V1.S4(), V2.S4());
code.SM3PARTW1(V0.S4(), V1.S4(), V2.S4());
jit.SetPC(0);
jit.SetVector(0, {0xec4aff517369c667, 0x46e3fbf2abbacd29});
jit.SetVector(1, {0x8de7e81bf854c27c, 0x9ac99f33632e5a76});
@@ -2685,7 +2686,7 @@ TEST_CASE("A64: SM3", "[a64]") {
SECTION("SM3PARTW2") {
A64::Jit jit{jit_user_config};
oaknut::VectorCodeGenerator code{env.code_mem, nullptr};
code.SM3PARTW2(V0.S4(), V0.S4(), V1.S4(), V2.S4());
code.SM3PARTW2(V0.S4(), V1.S4(), V2.S4());
jit.SetPC(0);
jit.SetVector(0, {0xec4aff517369c667, 0x46e3fbf2abbacd29});
jit.SetVector(1, {0x8de7e81bf854c27c, 0x9ac99f33632e5a76});
@@ -2695,3 +2696,125 @@ TEST_CASE("A64: SM3", "[a64]") {
CHECK(jit.GetVector(0) == Vector{0x30010fe70da43740, 0x6702425b4a3a05d4});
}
}
TEST_CASE("A64: SDIV and UDIV by zero", "[a64]") {
A64TestEnv env;
A64::UserConfig jit_user_config{};
jit_user_config.callbacks = &env;
A64::Jit jit{jit_user_config};
env.code_mem.emplace_back(0x1ac20c20); // SDIV W0, W1, W2
env.code_mem.emplace_back(0x9ac20c23); // SDIV X3, X1, X2
env.code_mem.emplace_back(0x1ac20824); // UDIV W4, W1, W2
env.code_mem.emplace_back(0x14000000); // B .
jit.SetRegister(0, 0xdeadbeef);
jit.SetRegister(1, 0x12345678);
jit.SetRegister(2, 0);
jit.SetRegister(3, 0xdeadbeef);
jit.SetRegister(4, 0xdeadbeef);
jit.SetPC(0);
env.ticks_left = 4;
CheckedRun([&]() { jit.Run(); });
// Division by zero gives zero, whatever the dividend.
REQUIRE(jit.GetRegister(0) == 0);
REQUIRE(jit.GetRegister(3) == 0);
REQUIRE(jit.GetRegister(4) == 0);
}
TEST_CASE("A64: FRINT through the soft-float fallback", "[a64]") {
A64TestEnv env;
A64::UserConfig jit_user_config{};
jit_user_config.callbacks = &env;
A64::Jit jit{jit_user_config};
// FRINTX, FRINTA and every half-precision FRINT skip ROUNDSD/ROUNDSS on any host.
env.code_mem.emplace_back(0x1e674020); // FRINTX D0, D1
env.code_mem.emplace_back(0x1e664062); // FRINTA D2, D3
env.code_mem.emplace_back(0x1e2640a4); // FRINTA S4, S5
env.code_mem.emplace_back(0x1ee4c0e6); // FRINTP H6, H7
env.code_mem.emplace_back(0x1ee54128); // FRINTM H8, H9
env.code_mem.emplace_back(0x1ee7416a); // FRINTX H10, H11
env.code_mem.emplace_back(0x14000000); // B .
jit.SetVector(1, {0x3fd3333333333333, 0}); // 0.3
jit.SetVector(3, {0x4004000000000000, 0}); // 2.5
jit.SetVector(5, {0xbf000000, 0}); // -0.5f
jit.SetVector(7, {0x0478, 0}); // 6.8e-5 (half)
jit.SetVector(9, {0xa75c, 0}); // -0.0287 (half)
jit.SetVector(11, {0x3421, 0}); // 0.258 (half)
jit.SetFpcr(0); // round to nearest
jit.SetFpsr(0);
jit.SetPC(0);
env.ticks_left = 7;
CheckedRun([&]() { jit.Run(); });
REQUIRE(jit.GetVector(0) == Vector{0, 0}); // 0.0, from FPCR's rounding
REQUIRE(jit.GetVector(2) == Vector{0x4008000000000000, 0}); // 3.0, ties away from zero
REQUIRE(jit.GetVector(4) == Vector{0xbf800000, 0}); // -1.0f
REQUIRE(jit.GetVector(6) == Vector{0x3c00, 0}); // 1.0
REQUIRE(jit.GetVector(8) == Vector{0xbc00, 0}); // -1.0
REQUIRE(jit.GetVector(10) == Vector{0, 0}); // 0.0
REQUIRE((jit.GetFpsr() & 0x10) != 0); // FRINTX raised Inexact
}
TEST_CASE("A64: SQSHLU saturates 8/16/64-bit lanes", "[a64]") {
A64TestEnv env;
A64::UserConfig jit_user_config{};
jit_user_config.callbacks = &env;
A64::Jit jit{jit_user_config};
env.code_mem.emplace_back(0x2f0b6420); // SQSHLU V0.8B, V1.8B, #3
env.code_mem.emplace_back(0x2f146462); // SQSHLU V2.4H, V3.4H, #4
env.code_mem.emplace_back(0x6f4064a4); // SQSHLU V4.2D, V5.2D, #0
env.code_mem.emplace_back(0x7f5864e6); // SQSHLU D6, D7, #24
env.code_mem.emplace_back(0x14000000); // B .
jit.SetVector(1, {0x8ecb02792c32fe49, 0});
jit.SetVector(3, {0x80007fff10000fff, 0});
jit.SetVector(5, {0xef319b929116dc5a, 0x362758dfbfb5c4db});
jit.SetVector(7, {0x00000000bf800000, 0});
jit.SetFpsr(0);
jit.SetPC(0);
env.ticks_left = 5;
CheckedRun([&]() { jit.Run(); });
// Positive lanes that overflow saturate to all ones, negative lanes become zero.
REQUIRE(jit.GetVector(0) == Vector{0x000010ffffff00ff, 0});
REQUIRE(jit.GetVector(2) == Vector{0x0000fffffffffff0, 0});
REQUIRE(jit.GetVector(4) == Vector{0, 0x362758dfbfb5c4db});
REQUIRE(jit.GetVector(6) == Vector{0x00bf800000000000, 0});
REQUIRE(FP::FPSR{jit.GetFpsr()}.QC());
}
TEST_CASE("A64: FCVTZS and FCVTZU (vector) with 64 fraction bits", "[a64]") {
A64TestEnv env;
A64::UserConfig jit_user_config{};
jit_user_config.callbacks = &env;
A64::Jit jit{jit_user_config};
// Without SSE4.1 these go through the soft-float fallback (DYNARMIC_HOST_FEATURES=0).
env.code_mem.emplace_back(0x4f40fc20); // FCVTZS V0.2D, V1.2D, #64
env.code_mem.emplace_back(0x6f40fc62); // FCVTZU V2.2D, V3.2D, #64
env.code_mem.emplace_back(0x4f40fca4); // FCVTZS V4.2D, V5.2D, #64
env.code_mem.emplace_back(0x6f40fca6); // FCVTZU V6.2D, V5.2D, #64
env.code_mem.emplace_back(0x14000000); // B .
jit.SetVector(1, {0x3fd0000000000000, 0xbfe0000000000000}); // 0.25, -0.5
jit.SetVector(3, {0x3fe8000000000000, 0x3c00000000000000}); // 0.75, 2^-63
jit.SetVector(5, {0x3ff0000000000000, 0xbff0000000000000}); // 1.0, -1.0
jit.SetPC(0);
env.ticks_left = 5;
CheckedRun([&]() { jit.Run(); });
// Each lane times 2^64, toward zero; 1.0 and -1.0 saturate.
REQUIRE(jit.GetVector(0) == Vector{0x4000000000000000, 0x8000000000000000});
REQUIRE(jit.GetVector(2) == Vector{0xc000000000000000, 0x0000000000000002});
REQUIRE(jit.GetVector(4) == Vector{0x7fffffffffffffff, 0x8000000000000000});
REQUIRE(jit.GetVector(6) == Vector{0xffffffffffffffff, 0});
}
+5
View File
@@ -132,3 +132,8 @@ target_compile_options(dynarmic_tests PRIVATE ${DYNARMIC_CXX_FLAGS})
target_compile_definitions(dynarmic_tests PRIVATE FMT_USE_USER_DEFINED_LITERALS=1)
add_test(NAME dynarmic_tests COMMAND dynarmic_tests --durations yes)
if (DYNARMIC_HOST_FEATURE_OVERRIDE AND "x86_64" IN_LIST ARCHITECTURE)
# Every host feature hidden, as on an SSE2-only host, so the x64 fallbacks run.
add_test(NAME dynarmic_tests_sse2 COMMAND dynarmic_tests "~[unicorn]" --durations yes)
set_tests_properties(dynarmic_tests_sse2 PROPERTIES ENVIRONMENT DYNARMIC_HOST_FEATURES=0)
endif()
+10
View File
@@ -10,10 +10,12 @@
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <catch2/catch_test_macros.hpp>
#include "dynarmic/backend/x64/host_feature.h"
#include "dynarmic/backend/x64/xbyak.h"
TEST_CASE("Host CPU supports", "[a64]") {
@@ -115,3 +117,11 @@ TEST_CASE("Host CPU supports", "[a64]") {
}
std::putchar('\n');
}
TEST_CASE("x64: DYNARMIC_HOST_FEATURES hides host features", "[x64]") {
const char* mask = std::getenv("DYNARMIC_HOST_FEATURES");
if (!mask || !*mask)
SKIP("set DYNARMIC_HOST_FEATURES in a build with DYNARMIC_HOST_FEATURE_OVERRIDE");
const auto seen = static_cast<std::uint64_t>(Dynarmic::Backend::X64::GetHostFeatures());
REQUIRE((seen & ~std::uint64_t(std::strtoull(mask, nullptr, 16))) == 0);
}