Repository navigation
Fix randomx_get_flags not reporting hardware AES on RISC-V - #370
thomasbuilds wants to merge 1 commit into
Conversation
hyc
left a comment
There was a problem hiding this comment.
If the CPU has hardware AES but HAVE_AES is not being defined, then the right thing to do is to fix that, not muck around here.
|
Yes, HAVE_AES should be 1 on RISC-V because there are AES instruction extensions there. |
614502d to
6788dd3
Compare
b63be62 to
d21bbd8
Compare
987069b to
0892094
Compare
|
|
||
| runTest("Hardware AES not supported", !HAVE_AES && !randomx::cpu.hasAes(), []() { | ||
| #ifdef __riscv | ||
| constexpr bool hardAesCheckedAtRuntime = true; |
There was a problem hiding this comment.
I think this change is unnecessary. hard AES will always be checked at runtime on platforms that have hardware AES support.
The HAVE_AES define means this particular chip family has hardware AES support, but we always have to check at runtime whether the current chip has it or not.
There was a problem hiding this comment.
This test covers that runtime check on RISC-V: allocate() rejects RANDOMX_FLAG_HARD_AES there unless cpu.hasAes() (#349). With HAVE_AES now 1 on RISC-V, the old condition would skip it, including in the riscv64 CI job, where it runs today. Other platforms don't check cpu.hasAes() in allocate() so a plain !cpu.hasAes() would fail the Win32, ppc64le and two arm64 CI jobs, where cpu.hasAes() is always false but the CPU has AES. #369 will replace __riscv here with HAVE_AES_CHECKER.
|
|
||
| #ifndef HAVE_AES | ||
| static const char* platformError = "Platform doesn't support hardware AES"; | ||
| #if !defined(HAVE_AES) || defined(__riscv) |
There was a problem hiding this comment.
Likewise, I think this change is unnecessary.
There was a problem hiding this comment.
randomx_get_flags()reportsRANDOMX_FLAG_HARD_AESonly ifHAVE_AESis 1, which it never was on RISC-V:rx_aesenc_vec_i128/rx_aesdec_vec_i128had no RISC-V implementation. So callers that take their flags from it, such as Monero andrandomx-benchmark --auto, used software AES even where hardware AES was detected.This implements both functions with Zvkned in
aes_hash_rv64_zvkned.cpp, the file already compiled with Zvkned, and setsHAVE_AESto 1 on RISC-V. They are only called fromRANDOMX_FLAG_HARD_AESVMs, whichVmBase::allocate()rejects unlesscpu.hasAes(). In those VMs, the interpreter's v2 AES mix now uses them instead of software AES.platformErrorstays defined on RISC-V, whereallocate()uses it, and is now aconstpointer so GCC's-Walldoesn't flag it as unused. The "Hardware AES not supported" test still runs on RISC-V whenevercpu.hasAes()is false.