Skip to content

Commit ed176fb

Browse files
authored
sha2: fix sha512/x86_avx2 backend for 32-bit targets (#951)
In #943 a call to `_mm_extract_epi64` was introduced in the SHA-512 AVX2 backend, but that intrinsic is only available on `x86_64`. This PR fixes it by using `_mm_extract_epi32` on 32-bit targets. The `sha2` Linux CI jobs for `i686` run the tests on the `x86_64` host but the switch to `cargo-hack` in #485 dropped `--target` from the test commands, the jobs still install the 32-bit target, but Cargo defaults to the host and consequently the coverage is wrong.
1 parent 50a7ea6 commit ed176fb

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

‎.github/workflows/sha2.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ jobs:
8080
targets: ${{ matrix.target }}
8181
- uses: RustCrypto/actions/cargo-hack-install@master
8282
- run: ${{ matrix.deps }}
83-
- run: cargo hack test --feature-powerset
84-
- run: cargo test --all-features
83+
- run: cargo hack test --feature-powerset --target ${{ matrix.target }}
84+
- run: cargo test --all-features --target ${{ matrix.target }}
8585
env:
8686
RUSTFLAGS: -Dwarnings --cfg sha2_backend="soft"
87-
- run: cargo test --all-features
87+
- run: cargo test --all-features --target ${{ matrix.target }}
8888
env:
8989
RUSTFLAGS: -Dwarnings --cfg sha2_backend="soft" --cfg sha2_backend_soft="compact"
9090

‎sha2/CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Changed
1414
- Refactored `riscv_zknh` backends ([#929])
15-
- Improved performance of the SHA-512 `x86-avx2` backend ([#940], [#943])
15+
- Improved performance of the SHA-512 `x86-avx2` backend ([#940], [#943], [#951])
1616

1717
[#929]: https://github.com/RustCrypto/hashes/pull/929
1818
[#935]: https://github.com/RustCrypto/hashes/pull/935
1919
[#940]: https://github.com/RustCrypto/hashes/pull/940
2020
[#943]: https://github.com/RustCrypto/hashes/pull/943
2121
[#948]: https://github.com/RustCrypto/hashes/pull/948
22+
[#951]: https://github.com/RustCrypto/hashes/pull/951
2223

2324
## 0.11.1 (2026-10-12)
2425
### Changed

‎sha2/src/sha512/x86_avx2.rs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,18 @@ fn_sha512_update_x!(sha512_update_x_avx2, "avx2", __m256i, {
323323
#[inline]
324324
#[target_feature(enable = "sse4.1")]
325325
fn extract_u64(a: __m128i) -> [u64; 2] {
326+
#[cfg(target_arch = "x86")]
327+
{
328+
let [lo0, hi0, lo1, hi1] = [
329+
_mm_extract_epi32::<0>(a),
330+
_mm_extract_epi32::<1>(a),
331+
_mm_extract_epi32::<2>(a),
332+
_mm_extract_epi32::<3>(a),
333+
]
334+
.map(|word| u64::from(word.cast_unsigned()));
335+
[lo0 | (hi0 << 32), lo1 | (hi1 << 32)]
336+
}
337+
#[cfg(target_arch = "x86_64")]
326338
[
327339
_mm_extract_epi64::<0>(a).cast_unsigned(),
328340
_mm_extract_epi64::<1>(a).cast_unsigned(),

0 commit comments

Comments
 (0)