Skip to content

Commit 937e4a8

Browse files
committed
Improve compile and runtime feature detection
1 parent 4859a31 commit 937e4a8

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

src/arch/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ pub(crate) unsafe fn update(state: u64, bytes: &[u8], params: CrcParams) -> u64
7070
pub(crate) unsafe fn update(state: u64, bytes: &[u8], params: CrcParams) -> u64 {
7171
use std::arch::is_x86_feature_detected;
7272

73-
if bytes.len() >= 256 && is_x86_feature_detected!("vpclmulqdq") {
73+
if bytes.len() >= 256
74+
&& is_x86_feature_detected!("vpclmulqdq")
75+
&& is_x86_feature_detected!("avx512f")
76+
&& is_x86_feature_detected!("avx512vl")
77+
{
7478
let ops = Vpclmulqdq512Ops::new();
7579

7680
return match params.width {
@@ -134,7 +138,10 @@ pub fn get_target() -> String {
134138

135139
#[cfg(target_arch = "x86_64")]
136140
{
137-
if is_x86_feature_detected!("vpclmulqdq") {
141+
if is_x86_feature_detected!("vpclmulqdq")
142+
&& is_x86_feature_detected!("avx512f")
143+
&& is_x86_feature_detected!("avx512vl")
144+
{
138145
return "x86_64-avx512-vpclmulqdq".to_string();
139146
}
140147

src/crc32/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
pub mod algorithm;
66
pub mod consts;
77

8-
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
8+
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
99
pub(crate) mod fusion;

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ use crate::crc32::consts::{
110110
CRC32_ISCSI, CRC32_ISO_HDLC, CRC32_JAMCRC, CRC32_MEF, CRC32_MPEG_2, CRC32_XFER,
111111
};
112112

113-
#[cfg(any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64"))]
113+
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
114114
use crate::crc32::fusion;
115115

116116
use crate::crc64::consts::{

0 commit comments

Comments
 (0)