Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -18,6 +18,7 @@ path = "examples/escape.rs"

[features]
codspeed = ["criterion2/codspeed"]
avx512 = []
asan = [] # for ASAN

[[bench]]
Expand Down
12 changes: 9 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) }
Expand Down
2 changes: 1 addition & 1 deletion src/simd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down