mirror of
https://github.com/wownero/RandomWOW.git
synced 2026-10-20 08:48:42 +02:00
ISUB_R fix for ARM/RISC-V JIT (#325)
When `src = dst` and `imm = 0x80000000` in ISUB_R, the JIT generated the wrong code because negating 0x80000000 (-2^31) resulted in -2^31 again, not +2^31. Also added the test to `tests.cpp` to check this case (can be verified by disabling the fix in jit_compiler_a64/jit_compiler_rv64). (cherry picked from commit 3babb8767e83da6154bec43037f3b9f947c5e200)
This commit is contained in:
+19
-1
@@ -59,7 +59,7 @@ void runTest(const char* name, bool condition, FUNC f) {
|
||||
std::cout << "[";
|
||||
std::cout.width(2);
|
||||
std::cout << std::right << ++testNo << "] ";
|
||||
std::cout.width(40);
|
||||
std::cout.width(44);
|
||||
std::cout << std::left << name << " ... ";
|
||||
std::cout.flush();
|
||||
if (condition) {
|
||||
@@ -1001,6 +1001,20 @@ int main() {
|
||||
assert(equalsHex(hash, "c56414121acda1713c2f2a819d8ae38aed7c80c35c2a769298d34f03833cd5f1"));
|
||||
};
|
||||
|
||||
auto test_f = [&] {
|
||||
uint8_t key_u[RANDOMX_HASH_SIZE] = {
|
||||
0x77, 0x97, 0x37, 0x3e, 0xa4, 0x63, 0x31, 0x94, 0x64, 0x0b, 0xf8, 0xd8, 0xc3, 0xb6, 0x67, 0x24, 0xd6, 0xaa, 0x7b, 0xd2, 0xdc, 0x20, 0xe0, 0x09, 0xdf, 0x2f, 0x8f, 0x17, 0x10, 0xab, 0xe8, 0x24
|
||||
};
|
||||
char key[RANDOMX_HASH_SIZE];
|
||||
|
||||
// workaround for picky compilers
|
||||
memcpy(key, key_u, sizeof(key_u));
|
||||
|
||||
char hash[RANDOMX_HASH_SIZE];
|
||||
calcHexHash(key, "1010e1eaf8cf067b37b5f0ee031ab23ed1755e090a3af4415830145853e2be3e1f6821fed84dae58d00e00da5214d6c1f2d0622e0abd51f9373d04e0b0f8e6d6514d90689721c4aac5a9bb0d", &hash);
|
||||
assert(equalsHex(hash, "78af2a1864c42abce36d2e8983e13df99b2af0ce1362999af09fab004d4435a8"));
|
||||
};
|
||||
|
||||
runTest("Hash test 1a (interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_a);
|
||||
|
||||
runTest("Hash test 1b (interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_b);
|
||||
@@ -1011,6 +1025,8 @@ int main() {
|
||||
|
||||
runTest("Hash test 1e (interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_e);
|
||||
|
||||
runTest("Hash test 1f (ISUB_R edge case, interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_f);
|
||||
|
||||
if (RANDOMX_HAVE_COMPILER) {
|
||||
randomx_release_cache(cache);
|
||||
randomx_destroy_vm(vm);
|
||||
@@ -1034,6 +1050,8 @@ int main() {
|
||||
|
||||
runTest("Hash test 2e (compiler)", RANDOMX_HAVE_COMPILER && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_e);
|
||||
|
||||
runTest("Hash test 2f (ISUB_R edge case, compiler)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_f);
|
||||
|
||||
auto flags = randomx_get_flags();
|
||||
|
||||
randomx_release_cache(cache);
|
||||
|
||||
Reference in New Issue
Block a user