Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/x86arch #246

Merged
merged 5 commits into from
Oct 7, 2022
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
16 changes: 10 additions & 6 deletions src/numberparse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ use crate::StaticNode;
use crate::{mem, static_cast_i64, Deserializer, ErrorType, Result};

#[cfg(all(target_arch = "x86", feature = "swar-number-parsing"))]
use std::arch::x86::{
__m128i, _mm_cvtsi128_si32, _mm_loadu_si128, _mm_madd_epi16, _mm_maddubs_epi16,
_mm_packus_epi32, _mm_set1_epi8, _mm_setr_epi16, _mm_setr_epi8, _mm_sub_epi8,
};
use std::arch::x86 as arch;

#[cfg(all(target_arch = "x86_64", feature = "swar-number-parsing"))]
use std::arch::x86_64::{
use std::arch::x86_64 as arch;

#[cfg(all(
any(target_arch = "x86", target_arch = "x86_64"),
feature = "swar-number-parsing"
))]
use arch::{
__m128i, _mm_cvtsi128_si32, _mm_loadu_si128, _mm_madd_epi16, _mm_maddubs_epi16,
_mm_packus_epi32, _mm_set1_epi8, _mm_setr_epi16, _mm_setr_epi8, _mm_sub_epi8,
};
Expand Down Expand Up @@ -150,7 +154,7 @@ fn parse_eight_digits_unrolled(chars: &[u8]) -> u32 {
chars
.get_kinda_unchecked(0..16)
.as_ptr()
.cast::<std::arch::x86_64::__m128i>(),
.cast::<arch::__m128i>(),
),
ascii0,
);
Expand Down
27 changes: 10 additions & 17 deletions src/sse42/deser.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#[cfg(target_arch = "x86")]
use std::arch::x86::{
__m128i, _mm_cmpeq_epi8, _mm_loadu_si128, _mm_movemask_epi8, _mm_set1_epi8, _mm_storeu_si128,
};
use std::arch::x86 as arch;

#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::{
use std::arch::x86_64 as arch;

use arch::{
__m128i, _mm_cmpeq_epi8, _mm_loadu_si128, _mm_movemask_epi8, _mm_set1_epi8, _mm_storeu_si128,
};

Expand Down Expand Up @@ -44,9 +45,8 @@ impl<'de> Deserializer<'de> {
let mut src_i: usize = 0;
let mut len = src_i;
loop {
let v: __m128i = unsafe {
_mm_loadu_si128(src.as_ptr().add(src_i).cast::<std::arch::x86_64::__m128i>())
};
let v: __m128i =
unsafe { _mm_loadu_si128(src.as_ptr().add(src_i).cast::<arch::__m128i>()) };

// store to dest unconditionally - we can overwrite the bits we don't like
// later
Expand Down Expand Up @@ -98,18 +98,11 @@ impl<'de> Deserializer<'de> {

// To be more conform with upstream
loop {
let v: __m128i = unsafe {
_mm_loadu_si128(src.as_ptr().add(src_i).cast::<std::arch::x86_64::__m128i>())
};
let v: __m128i =
unsafe { _mm_loadu_si128(src.as_ptr().add(src_i).cast::<arch::__m128i>()) };

unsafe {
_mm_storeu_si128(
buffer
.as_mut_ptr()
.add(dst_i)
.cast::<std::arch::x86_64::__m128i>(),
v,
);
_mm_storeu_si128(buffer.as_mut_ptr().add(dst_i).cast::<arch::__m128i>(), v);
};

// store to dest unconditionally - we can overwrite the bits we don't like
Expand Down
31 changes: 15 additions & 16 deletions src/sse42/stage1.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
use crate::{static_cast_i32, static_cast_u32, Stage1Parse};
#[cfg(target_arch = "x86")]
use std::arch::x86::{
use std::arch::x86 as arch;

#[cfg(target_arch = "x86_64")]
use std::arch::x86_64 as arch;

#[cfg(target_arch = "x86")]
use arch::{
__m128i, _mm_add_epi32, _mm_and_si128, _mm_cmpeq_epi8, _mm_cmpgt_epi8, _mm_loadu_si128,
_mm_max_epu8, _mm_movemask_epi8, _mm_or_si128, _mm_set1_epi8, _mm_set_epi32, _mm_setr_epi8,
_mm_setzero_si128, _mm_shuffle_epi8, _mm_srli_epi32, _mm_storeu_si128, _mm_testz_si128,
};

#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::{
use arch::{
__m128i, _mm_add_epi32, _mm_and_si128, _mm_cmpeq_epi8, _mm_loadu_si128, _mm_max_epu8,
_mm_movemask_epi8, _mm_set1_epi8, _mm_set_epi32, _mm_setr_epi8, _mm_setzero_si128,
_mm_shuffle_epi8, _mm_srli_epi32, _mm_storeu_si128,
Expand Down Expand Up @@ -43,10 +50,10 @@ impl SimdInput {
pub(crate) fn new(ptr: &[u8]) -> Self {
unsafe {
Self {
v0: _mm_loadu_si128(ptr.as_ptr().cast::<std::arch::x86_64::__m128i>()),
v1: _mm_loadu_si128(ptr.as_ptr().add(16).cast::<std::arch::x86_64::__m128i>()),
v2: _mm_loadu_si128(ptr.as_ptr().add(32).cast::<std::arch::x86_64::__m128i>()),
v3: _mm_loadu_si128(ptr.as_ptr().add(48).cast::<std::arch::x86_64::__m128i>()),
v0: _mm_loadu_si128(ptr.as_ptr().cast::<arch::__m128i>()),
v1: _mm_loadu_si128(ptr.as_ptr().add(16).cast::<arch::__m128i>()),
v2: _mm_loadu_si128(ptr.as_ptr().add(32).cast::<arch::__m128i>()),
v3: _mm_loadu_si128(ptr.as_ptr().add(48).cast::<arch::__m128i>()),
}
}
}
Expand All @@ -57,10 +64,7 @@ impl Stage1Parse<__m128i> for SimdInput {
#[cfg(target_feature = "pclmulqdq")]
#[allow(clippy::cast_sign_loss)]
fn compute_quote_mask(quote_bits: u64) -> u64 {
#[cfg(target_arch = "x86")]
use std::arch::x86::{_mm_clmulepi64_si128, _mm_cvtsi128_si64, _mm_set_epi64x};
#[cfg(target_arch = "x86_64")]
use std::arch::x86_64::{_mm_clmulepi64_si128, _mm_cvtsi128_si64, _mm_set_epi64x};
use arch::{_mm_clmulepi64_si128, _mm_cvtsi128_si64, _mm_set_epi64x};

unsafe {
_mm_cvtsi128_si64(_mm_clmulepi64_si128(
Expand Down Expand Up @@ -275,12 +279,7 @@ impl Stage1Parse<__m128i> for SimdInput {

let v: __m128i = _mm_set_epi32(v3, v2, v1, v0);
let v: __m128i = _mm_add_epi32(idx_64_v, v);
_mm_storeu_si128(
base.as_mut_ptr()
.add(l)
.cast::<std::arch::x86_64::__m128i>(),
v,
);
_mm_storeu_si128(base.as_mut_ptr().add(l).cast::<arch::__m128i>(), v);
}
l += 4;
}
Expand Down