cmov: add riscv32 optimised mask generation #1396
Merged
+20
−3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the changes brought by this commit
Currently, arm assembly is used to optimise for performance and have stronger guarantees that compiler optimisations will not insert branching during mask generation.
This commit introduces the same for the
riscv32architecture.I managed to run successfully some of
cmov's integration tests (the test inregressionand the 94 tests ofcore_impls) on a real target: a board with anesp32c6chip.Discussion on the state of constant time instructions of RISC-V machines
Additionally, it may be worth alerting the user of the state of constant time instruction in RISC-V: to my knowledge, a RISC-V machine is not guaranteed to have any constant time instructions in general. Only the machines declaring that they have the
Zktextension must guarantee that the given subset of instructions described in theZktspecification are constant time. In practice, a RISC-V machine may have constant time implementations for some or all "expected" instructions without declaring they support theZktextension.To be conservative, this crate should maybe be configured not to compile if the
zkttarget feature is not enabled. However, this is maybe too conservative since, AFAIK, there are not a lot of chip declaring that they support this extension.(Also, the
Zicondextension provides a new instruction similar tocselorcmov. If it is welcome here, I may work on a different PR adding a new backend for targets having thezicondfeature enabled)