#[cfg(target_arch = "wasm32")]
#[inline]
pub fn find_whitespace_end(bytes: &[u8], start: usize) -> usize {
#[cfg(target_feature = "simd128")]
{
return unsafe { find_whitespace_end_simd128(bytes, start) };
}
#[cfg(not(target_feature = "simd128"))]
{
return super::scalar::find_whitespace_end(bytes, start);
}
#[allow(unreachable_code)]
super::scalar::find_whitespace_end(bytes, start)
}
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
use std::arch::wasm32::*;
#[cfg(all(target_arch = "wasm32", target_feature = "simd128"))]
unsafe fn find_whitespace_end_simd128(bytes: &[u8], start: usize) -> usize {
let len = bytes.len();
let mut pos = start;
let v_space = u8x16_splat(b' ');
let v_tab = u8x16_splat(b'\t');
let v_cr = u8x16_splat(b'\r');
let v_nl = u8x16_splat(b'\n');
while pos + 16 <= len {
let chunk = v128_load(bytes.as_ptr().add(pos) as *const v128);
let eq_sp = u8x16_eq(chunk, v_space);
let eq_tb = u8x16_eq(chunk, v_tab);
let eq_cr = u8x16_eq(chunk, v_cr);
let eq_nl = u8x16_eq(chunk, v_nl);
let is_ws = v128_or(v128_or(eq_sp, eq_tb), v128_or(eq_cr, eq_nl));
let mask = i8x16_bitmask(is_ws) as u32 & 0xFFFF;
if mask != 0xFFFF {
let non_ws = (!mask) & 0xFFFF;
pos += non_ws.trailing_zeros() as usize;
return pos;
}
pos += 16;
}
super::scalar::find_whitespace_end(bytes, pos)
}