From d540b78480eeeffb7950dc542ee385367cd67ae7 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 14 Oct 2025 19:55:23 +0800 Subject: [PATCH 1/2] chore: hide avx512 behind feature flag --- Cargo.toml | 3 ++- src/lib.rs | 10 +++++++--- src/simd/mod.rs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) 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..bdaa81a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -297,9 +297,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")] From 9c508345014450cd6d055650e43967b803f79de7 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Tue, 14 Oct 2025 20:01:08 +0800 Subject: [PATCH 2/2] clippy --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index bdaa81a..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;