diff --git a/Cargo.toml b/Cargo.toml index 5b143b7..836dd56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ members = ["cpu-features"] name = "json-escape-simd" version = "3.0.0" edition = "2024" -rust-version = "1.89.0" +rust-version = "1.85.0" include = ["src/**/*.rs"] description = "Optimized SIMD routines for escaping JSON strings." license = "MIT" @@ -18,6 +18,7 @@ path = "examples/escape.rs" [features] codspeed = ["criterion2/codspeed"] +avx512 = [] asan = [] # for ASAN [[bench]] diff --git a/src/lib.rs b/src/lib.rs index 6b55f7c..f285c52 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,8 @@ //! //! Only takes the string escaping part to avoid the abstraction overhead. +#![allow(clippy::incompatible_msrv)] + #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] use std::arch::is_x86_feature_detected; @@ -297,9 +299,13 @@ fn format_string(value: &str, dst: &mut [u8]) -> usize { #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { - if is_x86_feature_detected!("avx512f") { - unsafe { simd::avx512::format_string(value, dst) } - } else if is_x86_feature_detected!("avx2") { + #[cfg(feature = "avx512")] + { + if is_x86_feature_detected!("avx512f") { + return unsafe { simd::avx512::format_string(value, dst) }; + } + } + if is_x86_feature_detected!("avx2") { unsafe { simd::avx2::format_string(value, dst) } } else if is_x86_feature_detected!("sse2") { unsafe { simd::sse2::format_string(value, dst) } diff --git a/src/simd/mod.rs b/src/simd/mod.rs index 419f7e2..e401069 100644 --- a/src/simd/mod.rs +++ b/src/simd/mod.rs @@ -2,7 +2,7 @@ #[cfg(any(target_arch = "x86_64", target_arch = "x86"))] pub(crate) mod avx2; -#[cfg(any(target_arch = "x86_64", target_arch = "x86"))] +#[cfg(all(any(target_arch = "x86_64", target_arch = "x86"), feature = "avx512"))] pub(crate) mod avx512; pub mod bits; #[cfg(target_arch = "aarch64")]