Skip to content

Commit 37f9991

Browse files
authored
chore: hide avx512 behind feature flag (#39)
* chore: hide avx512 behind feature flag * clippy
1 parent 1d36b0c commit 37f9991

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ members = ["cpu-features"]
55
name = "json-escape-simd"
66
version = "3.0.0"
77
edition = "2024"
8-
rust-version = "1.89.0"
8+
rust-version = "1.85.0"
99
include = ["src/**/*.rs"]
1010
description = "Optimized SIMD routines for escaping JSON strings."
1111
license = "MIT"
@@ -18,6 +18,7 @@ path = "examples/escape.rs"
1818

1919
[features]
2020
codspeed = ["criterion2/codspeed"]
21+
avx512 = []
2122
asan = [] # for ASAN
2223

2324
[[bench]]

src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//!
33
//! Only takes the string escaping part to avoid the abstraction overhead.
44
5+
#![allow(clippy::incompatible_msrv)]
6+
57
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
68
use std::arch::is_x86_feature_detected;
79

@@ -297,9 +299,13 @@ fn format_string(value: &str, dst: &mut [u8]) -> usize {
297299

298300
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
299301
{
300-
if is_x86_feature_detected!("avx512f") {
301-
unsafe { simd::avx512::format_string(value, dst) }
302-
} else if is_x86_feature_detected!("avx2") {
302+
#[cfg(feature = "avx512")]
303+
{
304+
if is_x86_feature_detected!("avx512f") {
305+
return unsafe { simd::avx512::format_string(value, dst) };
306+
}
307+
}
308+
if is_x86_feature_detected!("avx2") {
303309
unsafe { simd::avx2::format_string(value, dst) }
304310
} else if is_x86_feature_detected!("sse2") {
305311
unsafe { simd::sse2::format_string(value, dst) }

src/simd/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
44
pub(crate) mod avx2;
5-
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
5+
#[cfg(all(any(target_arch = "x86_64", target_arch = "x86"), feature = "avx512"))]
66
pub(crate) mod avx512;
77
pub mod bits;
88
#[cfg(target_arch = "aarch64")]

0 commit comments

Comments
 (0)