macro_rules! define_simd_primitives {
() => {
#[cfg(target_arch = "x86_64")]
#[allow(unused_imports)]
use std::arch::x86_64::{
__m128i, _mm_andnot_si128, _mm_cmpeq_epi8, _mm_loadu_si128, _mm_max_epu8,
_mm_movemask_epi8, _mm_or_si128, _mm_set1_epi8,
};
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
#[allow(unused_imports)]
use std::arch::wasm32::{
u8x16_bitmask, u8x16_eq, u8x16_max, u8x16_splat, v128_andnot, v128_load, v128_or,
};
#[allow(unused_macros)]
macro_rules! simd_splat {
($val:expr) => {{
#[cfg(target_arch = "x86_64")]
{
_mm_set1_epi8($val as i8)
}
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
{
u8x16_splat($val)
}
}};
}
#[allow(unused_macros)]
macro_rules! simd_load {
($ptr:expr) => {{
#[cfg(target_arch = "x86_64")]
{
_mm_loadu_si128(($ptr).cast::<__m128i>())
}
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
{
v128_load(($ptr).cast())
}
}};
}
#[allow(unused_macros)]
macro_rules! simd_mask {
($chunk:expr, $vec:expr) => {{
#[cfg(target_arch = "x86_64")]
{
_mm_movemask_epi8(_mm_cmpeq_epi8($chunk, $vec)) as u32
}
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
{
u8x16_bitmask(u8x16_eq($chunk, $vec)) as u32
}
}};
}
#[allow(unused_macros)]
macro_rules! simd_cmpeq {
($a:expr, $b:expr) => {{
#[cfg(target_arch = "x86_64")]
{
_mm_cmpeq_epi8($a, $b)
}
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
{
u8x16_eq($a, $b)
}
}};
}
#[allow(unused_macros)]
macro_rules! simd_bitmask {
($v:expr) => {{
#[cfg(target_arch = "x86_64")]
{
_mm_movemask_epi8($v) as u32
}
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
{
u8x16_bitmask($v) as u32
}
}};
}
#[allow(unused_macros)]
macro_rules! simd_or {
($a:expr, $b:expr) => {{
#[cfg(target_arch = "x86_64")]
{
_mm_or_si128($a, $b)
}
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
{
v128_or($a, $b)
}
}};
}
#[allow(unused_macros)]
macro_rules! simd_max_epu8 {
($a:expr, $b:expr) => {{
#[cfg(target_arch = "x86_64")]
{
_mm_max_epu8($a, $b)
}
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
{
u8x16_max($a, $b)
}
}};
}
#[allow(unused_macros)]
macro_rules! simd_andnot {
($negate:expr, $other:expr) => {{
#[cfg(target_arch = "x86_64")]
{
_mm_andnot_si128($negate, $other)
}
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
{
v128_andnot($other, $negate)
}
}};
}
};
}
pub(crate) use define_simd_primitives;