Potential speed improvements for SHA512 via BMI2 instructions
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- rust
- Lĩnh vực
- cryptography, performance
Hướng nghiên cứu
Bắt đầu bằng cách xem xét sha2/src/sha512/x86_avx2.rs và triển khai BMI2 core_arch x86_64 được tham chiếu để xác định hỗ trợ lệnh hiện có. Chạy lệnh benchmark sha2 của issue trên một hệ thống x64 tương đương và so sánh kết quả với các triển khai được trích dẫn. Được xem là hoàn tất khi tính khả thi và tác động đo được của hỗ trợ BMI2 đối với hiệu năng SHA512 đã được xác lập.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I recently looked into the sha2 crate performance, specifically for performing many consecutive SHA512 calculations on modern x64 processors which do not yet have the brand-new SHA512 instructions mentioned in #634.
As documented in https://github.com/RustCrypto/asm-hashes/issues/83 and https://github.com/RustCrypto/asm-hashes/issues/82, the now-deprecated asm feature target of sha2 0.10.x is slower than the native AVX2 enabled native Rust with intrinsics. Upon closer inspection, this makes sense since the chosen asm code doesn't use AVX or other newer CPU technologies at all.
In comparison with other implementations such as libgcrypt's which have specially optimized asm code like sha512-avx2-bmi2-amd64.S, those are roughly ~25% faster for SHA512 than the sha2 crate in quick benchmarks.
- Tested on AMD Zen3
Ryzen 5950Xunder Linux RUSTFLAGS='-C target-cpu=native' cargo +nightly bench -p sha2hastest sha512_10000 [...] =894 MB/slibgcrypttests/bench-slope --repetitions 10000shows 1084 MiB/s- The benchmark harnesses may not be fully comparable and have different units, this is just some quick testing to get the relevant ballpark numbers (!)
Another well-known project with this optimization level is the Linux kernel, see arch/x86/crypto/sha512-avx2-asm.S.
Based on observations made as part of https://github.com/RustCrypto/asm-hashes/issues/83 , a potential explanation for this is that the current native optimized Rust code in sha2/src/sha512/x86_avx2.rs uses AVX2, but not BMI2. For the assembler implementations, the BMI2 instruction RORX made a significant performance difference. Also, the terminology is a bit fuzzy here. Since BMI2 seems to be present on all common processors that have AVX2, it's sometimes mentioned as belonging to AVX2, but is technically separate, see Wikipedia.
The bmi2 target feature was around for a while since https://github.com/rust-lang/rust/issues/30462 . I'm not an expert on Rust intrinsics, but the RORX instruction seems to be missing from the current core_arch/src/x86_64/bmi2.rs instructions implemented by core::arch::x86_64?
If the instruction itself isn't available, that may be a major roadblock to using it in sha2 for SHA512. I'm not sure of the exact backstory here, but https://github.com/gnzlbg/bitintr/issues/2 seems to hint at the lack of RORX and other similar instruction availability since 2017, so it doesn't look like a regression.
To summarize, I suspect that once there is support for this particular BMI2 CPU instruction, it may be possible to squeeze additional SHA512 performance out of existing CPUs.
Notably, this does not rely on the more recent AVX512 instruction set or VSHA512 instruction set. It also probably won't be relevant for SHA1/SHA256 where faster mechanisms are commonly available and in use by sha2 on most modern CPUs.
- Ngôn ngữ chính
- Rust
- Star
- 2.3k
- Fork
- 341
- Merge trung bình
- 12 giờ 31 phút
- Pull request đã merge (30 ngày)
- 2
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của RustCrypto/hashes
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
RustCrypto/hashes#912 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
RustCrypto/hashes#909 · 4 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
RustCrypto/hashes#908 ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
RustCrypto/hashes#763 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
RustCrypto/hashes#747 · 1 bình luận ·
Tất cả issue của RustCrypto/hashes
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
nautechsystems/nautilus_trader#5095 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
stellar/rs-soroban-env#1739 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
bug good first issue package: quic
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100