-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use sha2-asm for feature compress on aarch64? #220
Comments
IIUC your use case, you can use # Cargo.toml
[target."cfg(not(target_arch = \"aarch64\"))".dependencies]
sha2 = { version = "0.9.1", features = [ "compress" ] }
[target."cfg(target_arch = \"aarch64\")".dependencies]
sha2-asm = "0.5" // code
#[cfg(not(target_arch = "aarch64"))]
fn compress256(state: &mut [u32; 8], blocks: &[Block]) {
sha2::compress256(state, blocks);
}
#[cfg(target_arch = "aarch64")]
fn compress256(state: &mut [u32; 8], blocks: &[Block]) {
for block in blocks {
sha2_asm::compress256(state, block);
}
} You will need some glue code to handle conversion between
It could be worth to open an issue in the Rust language repository for that. The current assembly version is mostly intended as a temporary workaround around instability of the ARM intrinsics. Also note that for the best possible performance we probably have to work on RustCrypto/asm-hashes#26. |
Correctly, this would solve my problem.
Totally agree, it is definitely an issue.
Great idea! I think I can do it for |
Hm, I think a better solution would be to check availability of the SHA extension on x86 and use the intrinsic backend even if the |
Sounds reasonable. Is this OK?
|
Hi, does the code below match your thoughts?
The SHA extension on x86 is checked in With this, applications can just use I'am sorry if I misunderstand what you mean. Regards. |
Hi,
We met real performance issue when we tested the application
lotus
(dependent onsha2
with featurecompress
) onaarch64
platform.The root cause is, for
aarch64
only with featurecompress
, thesha2::compress256
does not use theaarch64
accelerators, e.g.sha256su0
, it degradates tosoft_compress
.We tried three ways to solve this.
A. Add feature
compress, asm
in applications foraarch64
when usingsha2::compress256
.To keep
x86
platforms using the intrinsics other thanasm
, modifications toCargo.toml
of applications would be:However, this will enable both "compress" and "asm" no matter on
aarch64
orx86
.This is a known BUG of
cargo
, see [1][2], the solution is still unstable.B. Implement the instrinsic like we did for
x86
. We needcore::arch::aarch64::*
to do this.It is still unstable for
aarch64
, we investigated the assembly generated forvsha256su0q_u32
,there are extra two memory loads before the actual
sha256su0
.So as of now, the intrinsic can not deliver the best performance as the
asm
did.C. Use
sha2-asm
foraarch64
with featurecompress
, like:We want to fix the performance issue via
C
, it would be OK for bothaarch64
andx86
.With it, the package is easy to import by applications and delivers same performance with feature
compress
andasm
.Suggestions?
Regards.
[1] rust-lang/cargo#2524
[2] rust-lang/cargo#7914
The text was updated successfully, but these errors were encountered: