Skip to content

Commit 9e6c2e1

Browse files
committed
progress
1 parent f87d506 commit 9e6c2e1

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

src/macros.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,28 @@ macro_rules! define_impl {
3636
assert!(idx < $nelems);
3737
unsafe { simd_insert(self, idx, val) }
3838
}
39+
40+
#[inline(always)]
41+
pub fn load(slice: &[$elemty], offset: usize) -> $name {
42+
assert!(slice[offset..].len() >= $nelems);
43+
unsafe { $name::load_unchecked(slice, offset) }
44+
}
45+
46+
#[inline(always)]
47+
pub unsafe fn load_unchecked(
48+
slice: &[$elemty],
49+
offset: usize,
50+
) -> $name {
51+
use std::mem::size_of;
52+
use std::ptr;
53+
54+
let mut x = $name::splat(0 as $elemty);
55+
ptr::copy_nonoverlapping(
56+
slice.get_unchecked(offset) as *const $elemty as *const u8,
57+
&mut x as *mut $name as *mut u8,
58+
size_of::<$name>());
59+
x
60+
}
3961
}
4062
}
4163
}

src/x86/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ pub type __m128i = ::v128::i8x16;
88
// mod sse;
99
mod sse2;
1010
mod ssse3;
11+
mod sse42;

src/x86/sse42.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// use v128::*;
2+
use x86::__m128i;
3+
4+
pub const _SIDD_UBYTE_OPS: i8 = 0b00000000;
5+
pub const _SIDD_UWORD_OPS: i8 = 0b00000001;
6+
pub const _SIDD_SBYTE_OPS: i8 = 0b00000010;
7+
pub const _SIDD_SWORD_OPS: i8 = 0b00000011;
8+
9+
pub const _SIDD_CMP_EQUAL_ANY: i8 = 0b00000000;
10+
pub const _SIDD_CMP_RANGES: i8 = 0b00000100;
11+
pub const _SIDD_CMP_EQUAL_EACH: i8 = 0b00001000;
12+
pub const _SIDD_CMP_EQUAL_ORDERED: i8 = 0b00001100;
13+
14+
pub const _SIDD_POSITIVE_POLARITY: i8 = 0b00000000;
15+
pub const _SIDD_NEGATIVE_POLARITY: i8 = 0b00010000;
16+
pub const _SIDD_MASKED_NEGATIVE_POLARITY: i8 = 0b00110000;
17+
18+
pub const _SIDD_LEAST_SIGNIFICANT: i8 = 0b00000000;
19+
pub const _SIDD_MOST_SIGNIFICANT: i8 = 0b01000000;
20+
21+
#[inline(always)]
22+
#[target_feature = "+sse4.2"]
23+
pub fn _mm_cmpestri(
24+
a: __m128i,
25+
la: i32,
26+
b: __m128i,
27+
lb: i32,
28+
imm8: i8,
29+
) -> i32 {
30+
unsafe { pcmpestri128(a, la, b, lb, imm8) }
31+
}
32+
33+
#[allow(improper_ctypes)]
34+
extern {
35+
#[link_name = "llvm.x86.sse42.pcmpestri128"]
36+
fn pcmpestri128(a: __m128i, la: i32, b: __m128i, lb: i32, imm8: i8) -> i32;
37+
}
38+
39+
#[cfg(test)]
40+
mod tests {
41+
use v128::*;
42+
use x86::{__m128i, sse42};
43+
44+
#[test]
45+
#[target_feature = "+sse4.2"]
46+
fn _mm_cmpestri() {
47+
let a = &b"bar "[..];
48+
let b = &b"foobar "[..];
49+
let va = __m128i::from(u8x16::load(a, 0));
50+
let vb = __m128i::from(u8x16::load(b, 0));
51+
let i = sse42::_mm_cmpestri(
52+
va, 3, vb, 6,
53+
sse42::_SIDD_CMP_EQUAL_ORDERED | sse42::_SIDD_MOST_SIGNIFICANT);
54+
assert_eq!(3, i);
55+
}
56+
}

src/x86/ssse3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn _mm_abs_epi8(a: i8x16) -> u8x16 {
1111
#[allow(improper_ctypes)]
1212
extern {
1313
#[link_name = "llvm.x86.ssse3.pabs.b.128"]
14-
pub fn pabsb128(a: i8x16) -> u8x16;
14+
fn pabsb128(a: i8x16) -> u8x16;
1515
}
1616

1717
#[cfg(test)]

0 commit comments

Comments
 (0)