pulp_wasm_simd_flag/
lib.rs

1#![no_std]
2
3#[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))]
4mod wasm {
5	use core::sync::atomic;
6	static SIMD128: atomic::AtomicBool = atomic::AtomicBool::new(cfg!(target_feature = "simd128"));
7	static RELAXED_SIMD: atomic::AtomicBool =
8		atomic::AtomicBool::new(cfg!(target_feature = "relaxed-simd"));
9
10	#[inline]
11	pub fn enable_simd128() {
12		SIMD128.store(true, atomic::Ordering::Relaxed);
13	}
14
15	#[inline]
16	pub fn disable_simd128() {
17		disable_relaxed_simd();
18		SIMD128.store(false, atomic::Ordering::Relaxed);
19	}
20
21	#[inline]
22	pub fn is_simd128_enabled() -> bool {
23		cfg!(target_feature = "simd128") || SIMD128.load(atomic::Ordering::Relaxed)
24	}
25
26	#[inline]
27	pub fn enable_relaxed_simd() {
28		enable_simd128();
29		RELAXED_SIMD.store(true, atomic::Ordering::Relaxed);
30	}
31
32	#[inline]
33	pub fn disable_relaxed_simd() {
34		RELAXED_SIMD.store(false, atomic::Ordering::Relaxed);
35	}
36
37	#[inline]
38	pub fn is_relaxed_simd_enabled() -> bool {
39		cfg!(target_feature = "relaxed-simd") || RELAXED_SIMD.load(atomic::Ordering::Relaxed)
40	}
41}
42#[cfg(any(target_arch = "wasm32", target_arch = "wasm64"))]
43pub use wasm::*;