Skip to content

Commit

Permalink
Switch to not compiling with a non SIMD capable cpu settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Licenser committed Feb 7, 2020
1 parent 2ba76cb commit 41d08f3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ swar-number-parsing = []
serde_impl = [ "serde", "serde_json", "halfbrown/serde" ]
# Support for ARM NEON SIMD
neon = ["simd-lite"]
# Allow fallback to non simd CPUs
allow-non-simd = []
# for testing allocations
alloc = ["alloc_counter"]
# don't inline code - used for debugging
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ To be able to take advantage of simdjson your system needs to be SIMD compatible

simd-json.rs supports AVX2, SSE4.2 and NEON.

Unless the `allow-non-simd` feature is passed simd-json will fail to compile, this is to prevent unexpected slowness in fallback mode that can be hard to understand.

### allocator

For best performance we highly suggest using [mimalloc](https://crates.io/crates/mimalloc) or [jemalloc](https://crates.io/crates/jemalloc) instead of the system allocator used by default.
Expand Down
50 changes: 38 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,11 @@ pub use crate::avx2::deser::*;
#[cfg(target_feature = "avx2")]
use crate::avx2::stage1::{SimdInput, SIMDINPUT_LENGTH, SIMDJSON_PADDING};

#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(target_feature = "avx2")
))]
#[cfg(all(target_feature = "sse42", not(target_feature = "avx2")))]
mod sse42;
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(target_feature = "avx2")
))]
#[cfg(all(target_feature = "sse42", not(target_feature = "avx2")))]
pub use crate::sse42::deser::*;
#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
not(target_feature = "avx2")
))]
#[cfg(all(target_feature = "sse42", not(target_feature = "avx2")))]
use crate::sse42::stage1::{SimdInput, SIMDINPUT_LENGTH, SIMDJSON_PADDING};

#[cfg(all(target_feature = "neon", feature = "neon"))]
Expand All @@ -183,6 +174,41 @@ pub use crate::neon::deser::*;
#[cfg(all(target_feature = "neon", feature = "neon"))]
use crate::neon::stage1::{SimdInput, SIMDINPUT_LENGTH, SIMDJSON_PADDING};

// We import this as generics
#[cfg(all(not(any(
target_feature = "sse42",
target_feature = "avx2",
target_feature = "neon"
))))]
mod sse42;
#[cfg(all(not(any(
target_feature = "sse42",
target_feature = "avx2",
target_feature = "neon"
))))]
#[cfg(all(not(any(
target_feature = "sse42",
target_feature = "avx2",
target_feature = "neon"
))))]
pub use crate::sse42::deser::*;
#[cfg(all(not(any(
target_feature = "sse42",
target_feature = "avx2",
target_feature = "neon"
))))]
use crate::sse42::stage1::{SimdInput, SIMDINPUT_LENGTH, SIMDJSON_PADDING};

#[cfg(all(
not(feature = "allow-non-simd"),
not(any(
target_feature = "sse42",
target_feature = "avx2",
target_feature = "neon"
))
))]
fn please_compile_with_a_simd_compatible_cpu_setting_read_the_simdjonsrs_readme() -> ! {}

use crate::utf8check::ProcessedUtfBytes;

mod stage2;
Expand Down

0 comments on commit 41d08f3

Please sign in to comment.