Skip to content

Commit 86a99cd

Browse files
committed
Update feature detection
1 parent 40e2b9c commit 86a99cd

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

src/arch/mod.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,20 @@ pub(crate) unsafe fn update(state: u64, bytes: &[u8], params: CrcParams) -> u64
5454
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
5555
#[target_feature(enable = "sse2,sse4.1,pclmulqdq")]
5656
pub(crate) unsafe fn update(state: u64, bytes: &[u8], params: CrcParams) -> u64 {
57-
let ops = X86Ops;
57+
update_x86_sse(state, bytes, params)
58+
}
5859

59-
match params.width {
60-
64 => algorithm::update::<X86Ops, Width64>(state, bytes, params, &ops),
61-
32 => algorithm::update::<X86Ops, Width32>(state as u32, bytes, params, &ops) as u64,
62-
_ => panic!("Unsupported CRC width: {}", params.width),
63-
}
60+
#[rustversion::since(1.89)]
61+
#[inline]
62+
#[cfg(target_arch = "x86")]
63+
#[target_feature(enable = "sse2,sse4.1,pclmulqdq")]
64+
pub(crate) unsafe fn update(state: u64, bytes: &[u8], params: CrcParams) -> u64 {
65+
update_x86_sse(state, bytes, params)
6466
}
6567

6668
#[rustversion::since(1.89)]
6769
#[inline]
68-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
70+
#[cfg(target_arch = "x86_64")]
6971
#[target_feature(enable = "sse2,sse4.1,pclmulqdq")]
7072
pub(crate) unsafe fn update(state: u64, bytes: &[u8], params: CrcParams) -> u64 {
7173
use std::arch::is_x86_feature_detected;
@@ -106,6 +108,19 @@ pub(crate) unsafe fn update(state: u64, bytes: &[u8], params: CrcParams) -> u64
106108
software::update(state, bytes, params)
107109
}
108110

111+
#[inline]
112+
#[cfg(target_arch = "x86")]
113+
#[target_feature(enable = "sse2,sse4.1,pclmulqdq")]
114+
unsafe fn update_x86_sse(state: u64, bytes: &[u8], params: CrcParams) -> u64 {
115+
let ops = X86Ops;
116+
117+
match params.width {
118+
64 => algorithm::update::<X86Ops, Width64>(state, bytes, params, &ops),
119+
32 => algorithm::update::<X86Ops, Width32>(state as u32, bytes, params, &ops) as u64,
120+
_ => panic!("Unsupported CRC width: {}", params.width),
121+
}
122+
}
123+
109124
#[rustversion::before(1.89)]
110125
pub fn get_target() -> String {
111126
#[cfg(target_arch = "aarch64")]

src/crc32/fusion/x86.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ pub fn crc32_iscsi(crc: u32, data: &[u8]) -> u32 {
2929
#[rustversion::since(1.89)]
3030
#[inline(always)]
3131
pub fn crc32_iscsi(crc: u32, data: &[u8]) -> u32 {
32-
if is_x86_feature_detected!("vpclmulqdq") {
32+
if is_x86_feature_detected!("vpclmulqdq")
33+
&& is_x86_feature_detected!("avx512f")
34+
&& is_x86_feature_detected!("avx512vl")
35+
{
3336
unsafe {
3437
return crc32_iscsi_avx512_vpclmulqdq_v3x2(crc, data.as_ptr(), data.len());
3538
}

0 commit comments

Comments
 (0)