Skip to content
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

Add asm!-based backend for LoongArch64 targets #504

Merged
merged 6 commits into from
Sep 21, 2023

Conversation

newpavlov
Copy link
Member

@newpavlov newpavlov commented Sep 20, 2023

Based on code from RustCrypto/asm-hashes#66

@heiher
Can you check whether I translated assembly correctly? Both by running tests and by manual inspection of the code.

Also it would be nice if cross had support for LoongArch64, so we could run tests properly in our CI.

Copy link
Contributor

@heiher heiher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patch.

sha1/src/compress/loongarch64_asm.rs Show resolved Hide resolved
sha1/src/compress/loongarch64_asm.rs Show resolved Hide resolved
@heiher
Copy link
Contributor

heiher commented Sep 20, 2023

And now

On Loongson 3A5000 @ 2.3GHz:

Without this patch:

test sha1_10    ... bench:          33 ns/iter (+/- 0) = 303 MB/s
test sha1_100   ... bench:         308 ns/iter (+/- 0) = 324 MB/s
test sha1_1000  ... bench:       2,559 ns/iter (+/- 2) = 390 MB/s
test sha1_10000 ... bench:      25,057 ns/iter (+/- 11) = 399 MB/s

With asm-hashes patch:

test sha1_10    ... bench:          32 ns/iter (+/- 0) = 312 MB/s
test sha1_100   ... bench:         291 ns/iter (+/- 0) = 343 MB/s
test sha1_1000  ... bench:       2,450 ns/iter (+/- 1) = 408 MB/s
test sha1_10000 ... bench:      24,079 ns/iter (+/- 12) = 415 MB/s

With this patch: 👍

test sha1_10    ... bench:          31 ns/iter (+/- 0) = 322 MB/s
test sha1_100   ... bench:         286 ns/iter (+/- 0) = 349 MB/s
test sha1_1000  ... bench:       2,408 ns/iter (+/- 1) = 415 MB/s
test sha1_10000 ... bench:      23,637 ns/iter (+/- 12) = 423 MB/s

@newpavlov
Copy link
Member Author

@heiher
Your findings are fixed. Can you verify that this implementation passes the tests (do not forget to enable the loongarch64_asm feature)? If it does, then I think we can merge and release it.

@heiher
Copy link
Contributor

heiher commented Sep 21, 2023

@newpavlov Thank you. The tests are PASSED.

$ cargo test -F loongarch64_asm
   Compiling version_check v0.9.4
   Compiling typenum v1.16.0
   Compiling proc-macro-hack v0.5.20+deprecated
   Compiling blobby v0.3.1
   Compiling cfg-if v1.0.0
   Compiling generic-array v0.14.7
   Compiling hex-literal-impl v0.2.3
   Compiling hex-literal v0.2.2
   Compiling crypto-common v0.1.6
   Compiling block-buffer v0.10.4
   Compiling digest v0.10.7
   Compiling sha1 v0.10.5 (/home/hev/rust/hashes/sha1)
    Finished test [optimized + debuginfo] target(s) in 5.48s
     Running unittests src/lib.rs (/home/hev/rust/hashes/target/debug/deps/sha1-efff1781e455b298)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests/mod.rs (/home/hev/rust/hashes/target/debug/deps/mod-bf2a6b498c858bf9)

running 2 tests
test sha1_main ... ok
test sha1_rand ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.05s

   Doc-tests sha1

running 1 test
test sha1/src/lib.rs - (line 14) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.34s

@newpavlov newpavlov merged commit 7aba4b5 into master Sep 21, 2023
209 checks passed
@newpavlov newpavlov deleted the sha1/loongarch64_asm branch September 21, 2023 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants