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 LoongArch64 sha1 assembly support #66

Closed
wants to merge 1 commit into from
Closed

Add LoongArch64 sha1 assembly support #66

wants to merge 1 commit into from

Conversation

heiher
Copy link

@heiher heiher commented Sep 19, 2023

Add sha1 assembly support for LoongArch64 (A tier-2 with host tools target).

Copy link
Member

@newpavlov newpavlov left a comment

Choose a reason for hiding this comment

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

The assembly looks fairly straightforward.Can you measure whether it results in an improved performance when compared to the software backend in sha1?

sha1/src/lib.rs Show resolved Hide resolved
@heiher
Copy link
Author

heiher commented Sep 19, 2023

The assembly looks fairly straightforward.Can you measure whether it results in an improved performance when compared to the software backend in sha1?

Performance improved slightly. 🥲

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 this 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

@newpavlov
Copy link
Member

newpavlov commented Sep 19, 2023

Hm, the performance difference is relatively small, but well above noise levels, so I guess we can merge this PR. You could squeeze a bit more performance by implementing the looping over blocks inside assembly. It will allow you to keep hasher state in registers without spilling it into memory after processing each block (UPD: unfortunately, the spilling is necessary since we can not preserve old state value in registers).

Note that the asm-hashes repository crates are effectively deprecated and we do not plan to use them in the next release cycle of the hashes repository crates. If you have time, it would be better to adapt this PR to using asm! directly inside the sha1 crate.

@heiher
Copy link
Author

heiher commented Sep 21, 2023

Completed in PR: RustCrypto/hashes#504

@heiher heiher closed this Sep 21, 2023
newpavlov added a commit to RustCrypto/hashes that referenced this pull request Sep 21, 2023
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.

None yet

2 participants