|
| 1 | +#![feature(target_feature)] |
| 2 | + |
1 | 3 | extern crate stdsimd;
|
2 | 4 |
|
3 | 5 | use std::env;
|
4 | 6 | use stdsimd as s;
|
5 | 7 |
|
6 | 8 | #[inline(never)]
|
7 |
| -fn foobar(a: s::f64x2, b: s::f64x2) -> bool { |
8 |
| - s::_mm_ucomieq_sd(a, b) |
| 9 | +#[target_feature = "+sse4.2"] |
| 10 | +fn index(needle: &str, haystack: &str) -> usize { |
| 11 | + assert!(needle.len() <= 16 && haystack.len() <= 16); |
| 12 | + |
| 13 | + let (needle_len, hay_len) = (needle.len(), haystack.len()); |
| 14 | + |
| 15 | + let mut needle = needle.to_string().into_bytes(); |
| 16 | + needle.resize(16, 0); |
| 17 | + let vneedle = s::__m128i::from(s::u8x16::load(&needle, 0)); |
| 18 | + |
| 19 | + let mut haystack = haystack.to_string().into_bytes(); |
| 20 | + haystack.resize(16, 0); |
| 21 | + let vhaystack = s::__m128i::from(s::u8x16::load(&haystack, 0)); |
| 22 | + |
| 23 | + s::_mm_cmpestri( |
| 24 | + vneedle, needle_len as i32, vhaystack, hay_len as i32, |
| 25 | + s::_SIDD_CMP_EQUAL_ORDERED) as usize |
9 | 26 | }
|
10 | 27 |
|
11 | 28 | fn main() {
|
12 |
| - let x0: f64 = env::args().nth(1).unwrap().parse().unwrap(); |
13 |
| - let x1: f64 = env::args().nth(2).unwrap().parse().unwrap(); |
14 |
| - let x2: f64 = env::args().nth(3).unwrap().parse().unwrap(); |
15 |
| - let x3: f64 = env::args().nth(4).unwrap().parse().unwrap(); |
| 29 | + // let x0: f64 = env::args().nth(1).unwrap().parse().unwrap(); |
| 30 | + // let x1: f64 = env::args().nth(2).unwrap().parse().unwrap(); |
| 31 | + // let x2: f64 = env::args().nth(3).unwrap().parse().unwrap(); |
| 32 | + // let x3: f64 = env::args().nth(4).unwrap().parse().unwrap(); |
16 | 33 | // let y0: i32 = env::args().nth(5).unwrap().parse().unwrap();
|
17 | 34 | // let y1: i32 = env::args().nth(6).unwrap().parse().unwrap();
|
18 | 35 | // let y2: i32 = env::args().nth(7).unwrap().parse().unwrap();
|
19 | 36 | // let y3: i32 = env::args().nth(8).unwrap().parse().unwrap();
|
20 | 37 |
|
21 |
| - let a = s::f64x2::new(x0, x1); |
22 |
| - let b = s::f64x2::new(x2, x3); |
| 38 | + // let a = s::f64x2::new(x0, x1); |
| 39 | + // let b = s::f64x2::new(x2, x3); |
23 | 40 | // let r = s::_mm_cmplt_sd(a, b);
|
24 |
| - let r = foobar(a, b); |
25 |
| - println!("{:?}", r); |
| 41 | + // let r = foobar(a, b); |
| 42 | + |
| 43 | + |
| 44 | + let needle = env::args().nth(1).unwrap(); |
| 45 | + let haystack = env::args().nth(2).unwrap(); |
| 46 | + println!("{:?}", index(&needle, &haystack)); |
26 | 47 | }
|
0 commit comments