Skip to content

Commit b3df4cb

Browse files
authored
Migrate the x86_64 folder to vendor types (rust-lang#284)
1 parent c34b4f3 commit b3df4cb

File tree

4 files changed

+85
-97
lines changed

4 files changed

+85
-97
lines changed

coresimd/src/x86/x86_64/sse.rs

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//! `x86_64` Streaming SIMD Extensions (SSE)
22
3-
use v128::*;
3+
use x86::*;
44

55
#[cfg(test)]
66
use stdsimd_test::assert_instr;
77

88
#[allow(improper_ctypes)]
99
extern "C" {
1010
#[link_name = "llvm.x86.sse.cvtss2si64"]
11-
fn cvtss2si64(a: f32x4) -> i64;
11+
fn cvtss2si64(a: __m128) -> i64;
1212
#[link_name = "llvm.x86.sse.cvttss2si64"]
13-
fn cvttss2si64(a: f32x4) -> i64;
13+
fn cvttss2si64(a: __m128) -> i64;
1414
#[link_name = "llvm.x86.sse.cvtsi642ss"]
15-
fn cvtsi642ss(a: f32x4, b: i64) -> f32x4;
15+
fn cvtsi642ss(a: __m128, b: i64) -> __m128;
1616
}
1717

1818
/// Convert the lowest 32 bit float in the input vector to a 64 bit integer.
@@ -27,7 +27,7 @@ extern "C" {
2727
#[inline(always)]
2828
#[target_feature(enable = "sse")]
2929
#[cfg_attr(test, assert_instr(cvtss2si))]
30-
pub unsafe fn _mm_cvtss_si64(a: f32x4) -> i64 {
30+
pub unsafe fn _mm_cvtss_si64(a: __m128) -> i64 {
3131
cvtss2si64(a)
3232
}
3333

@@ -43,7 +43,7 @@ pub unsafe fn _mm_cvtss_si64(a: f32x4) -> i64 {
4343
#[inline(always)]
4444
#[target_feature(enable = "sse")]
4545
#[cfg_attr(test, assert_instr(cvttss2si))]
46-
pub unsafe fn _mm_cvttss_si64(a: f32x4) -> i64 {
46+
pub unsafe fn _mm_cvttss_si64(a: __m128) -> i64 {
4747
cvttss2si64(a)
4848
}
4949

@@ -55,21 +55,21 @@ pub unsafe fn _mm_cvttss_si64(a: f32x4) -> i64 {
5555
#[inline(always)]
5656
#[target_feature(enable = "sse")]
5757
#[cfg_attr(test, assert_instr(cvtsi2ss))]
58-
pub unsafe fn _mm_cvtsi64_ss(a: f32x4, b: i64) -> f32x4 {
58+
pub unsafe fn _mm_cvtsi64_ss(a: __m128, b: i64) -> __m128 {
5959
cvtsi642ss(a, b)
6060
}
6161

6262
#[cfg(test)]
6363
mod tests {
64-
use v128::*;
65-
use x86::x86_64::sse;
64+
use std::f32::NAN;
65+
use std::i64::MIN;
6666

6767
use stdsimd_test::simd_test;
6868

69+
use x86::*;
70+
6971
#[simd_test = "sse"]
70-
unsafe fn _mm_cvtss_si64() {
71-
use std::f32::NAN;
72-
use std::i64::MIN;
72+
unsafe fn test_mm_cvtss_si64() {
7373
let inputs = &[
7474
(42.0f32, 42i64),
7575
(-31.4, -31),
@@ -83,8 +83,8 @@ mod tests {
8383
];
8484
for i in 0..inputs.len() {
8585
let (xi, e) = inputs[i];
86-
let x = f32x4::new(xi, 1.0, 3.0, 4.0);
87-
let r = sse::_mm_cvtss_si64(x);
86+
let x = _mm_setr_ps(xi, 1.0, 3.0, 4.0);
87+
let r = _mm_cvtss_si64(x);
8888
assert_eq!(
8989
e,
9090
r,
@@ -98,9 +98,7 @@ mod tests {
9898
}
9999

100100
#[simd_test = "sse"]
101-
unsafe fn _mm_cvttss_si64() {
102-
use std::f32::NAN;
103-
use std::i64::MIN;
101+
unsafe fn test_mm_cvttss_si64() {
104102
let inputs = &[
105103
(42.0f32, 42i64),
106104
(-31.4, -31),
@@ -117,8 +115,8 @@ mod tests {
117115
];
118116
for i in 0..inputs.len() {
119117
let (xi, e) = inputs[i];
120-
let x = f32x4::new(xi, 1.0, 3.0, 4.0);
121-
let r = sse::_mm_cvttss_si64(x);
118+
let x = _mm_setr_ps(xi, 1.0, 3.0, 4.0);
119+
let r = _mm_cvttss_si64(x);
122120
assert_eq!(
123121
e,
124122
r,
@@ -132,7 +130,7 @@ mod tests {
132130
}
133131

134132
#[simd_test = "sse"]
135-
pub unsafe fn _mm_cvtsi64_ss() {
133+
pub unsafe fn test_mm_cvtsi64_ss() {
136134
let inputs = &[
137135
(4555i64, 4555.0f32),
138136
(322223333, 322223330.0),
@@ -144,19 +142,10 @@ mod tests {
144142

145143
for i in 0..inputs.len() {
146144
let (x, f) = inputs[i];
147-
let a = f32x4::new(5.0, 6.0, 7.0, 8.0);
148-
let r = sse::_mm_cvtsi64_ss(a, x);
149-
let e = a.replace(0, f);
150-
assert_eq!(
151-
e,
152-
r,
153-
"TestCase #{} _mm_cvtsi64_ss({:?}, {}) = {:?}, expected: {:?}",
154-
i,
155-
a,
156-
x,
157-
r,
158-
e
159-
);
145+
let a = _mm_setr_ps(5.0, 6.0, 7.0, 8.0);
146+
let r = _mm_cvtsi64_ss(a, x);
147+
let e = _mm_setr_ps(f, 6.0, 7.0, 8.0);
148+
assert_eq_m128(e, r);
160149
}
161150
}
162151
}

coresimd/src/x86/x86_64/sse2.rs

Lines changed: 42 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
//! `x86_64`'s Streaming SIMD Extensions 2 (SSE2)
22
3-
use v128::*;
3+
use x86::*;
4+
use simd_llvm::*;
45

56
#[cfg(test)]
67
use stdsimd_test::assert_instr;
78

89
#[allow(improper_ctypes)]
910
extern "C" {
1011
#[link_name = "llvm.x86.sse2.cvtsd2si64"]
11-
fn cvtsd2si64(a: f64x2) -> i64;
12+
fn cvtsd2si64(a: __m128d) -> i64;
1213
#[link_name = "llvm.x86.sse2.cvttsd2si64"]
13-
fn cvttsd2si64(a: f64x2) -> i64;
14+
fn cvttsd2si64(a: __m128d) -> i64;
1415
}
1516

1617
/// Convert the lower double-precision (64-bit) floating-point element in a to
1718
/// a 64-bit integer.
1819
#[inline(always)]
1920
#[target_feature(enable = "sse2")]
2021
#[cfg_attr(test, assert_instr(cvtsd2si))]
21-
pub unsafe fn _mm_cvtsd_si64(a: f64x2) -> i64 {
22+
pub unsafe fn _mm_cvtsd_si64(a: __m128d) -> i64 {
2223
cvtsd2si64(a)
2324
}
2425

2526
/// Alias for [`_mm_cvtsd_si64`](fn._mm_cvtsd_si64_ss.html).
2627
#[inline(always)]
2728
#[target_feature(enable = "sse2")]
2829
#[cfg_attr(test, assert_instr(cvtsd2si))]
29-
pub unsafe fn _mm_cvtsd_si64x(a: f64x2) -> i64 {
30+
pub unsafe fn _mm_cvtsd_si64x(a: __m128d) -> i64 {
3031
_mm_cvtsd_si64(a)
3132
}
3233

@@ -35,15 +36,15 @@ pub unsafe fn _mm_cvtsd_si64x(a: f64x2) -> i64 {
3536
#[inline(always)]
3637
#[target_feature(enable = "sse2")]
3738
#[cfg_attr(test, assert_instr(cvttsd2si))]
38-
pub unsafe fn _mm_cvttsd_si64(a: f64x2) -> i64 {
39+
pub unsafe fn _mm_cvttsd_si64(a: __m128d) -> i64 {
3940
cvttsd2si64(a)
4041
}
4142

4243
/// Alias for [`_mm_cvttsd_si64`](fn._mm_cvttsd_si64_ss.html).
4344
#[inline(always)]
4445
#[target_feature(enable = "sse2")]
4546
#[cfg_attr(test, assert_instr(cvttsd2si))]
46-
pub unsafe fn _mm_cvttsd_si64x(a: f64x2) -> i64 {
47+
pub unsafe fn _mm_cvttsd_si64x(a: __m128d) -> i64 {
4748
_mm_cvttsd_si64(a)
4849
}
4950

@@ -63,32 +64,32 @@ pub unsafe fn _mm_stream_si64(mem_addr: *mut i64, a: i64) {
6364
#[inline(always)]
6465
#[target_feature(enable = "sse2")]
6566
#[cfg_attr(all(test, not(windows)), assert_instr(movq))]
66-
pub unsafe fn _mm_cvtsi64_si128(a: i64) -> i64x2 {
67-
i64x2::new(a, 0)
67+
pub unsafe fn _mm_cvtsi64_si128(a: i64) -> __m128i {
68+
_mm_set_epi64x(0, a)
6869
}
6970

7071
/// Return a vector whose lowest element is `a` and all higher elements are
7172
/// `0`.
7273
#[inline(always)]
7374
#[target_feature(enable = "sse2")]
7475
#[cfg_attr(all(test, not(windows)), assert_instr(movq))]
75-
pub unsafe fn _mm_cvtsi64x_si128(a: i64) -> i64x2 {
76+
pub unsafe fn _mm_cvtsi64x_si128(a: i64) -> __m128i {
7677
_mm_cvtsi64_si128(a)
7778
}
7879

7980
/// Return the lowest element of `a`.
8081
#[inline(always)]
8182
#[target_feature(enable = "sse2")]
8283
#[cfg_attr(all(test, not(windows)), assert_instr(movq))]
83-
pub unsafe fn _mm_cvtsi128_si64(a: i64x2) -> i64 {
84-
a.extract(0)
84+
pub unsafe fn _mm_cvtsi128_si64(a: __m128i) -> i64 {
85+
simd_extract(a, 0)
8586
}
8687

8788
/// Return the lowest element of `a`.
8889
#[inline(always)]
8990
#[target_feature(enable = "sse2")]
9091
#[cfg_attr(all(test, not(windows)), assert_instr(movq))]
91-
pub unsafe fn _mm_cvtsi128_si64x(a: i64x2) -> i64 {
92+
pub unsafe fn _mm_cvtsi128_si64x(a: __m128i) -> i64 {
9293
_mm_cvtsi128_si64(a)
9394
}
9495

@@ -97,85 +98,81 @@ pub unsafe fn _mm_cvtsi128_si64x(a: i64x2) -> i64 {
9798
#[inline(always)]
9899
#[target_feature(enable = "sse2")]
99100
#[cfg_attr(test, assert_instr(cvtsi2sd))]
100-
pub unsafe fn _mm_cvtsi64_sd(a: f64x2, b: i64) -> f64x2 {
101-
a.replace(0, b as f64)
101+
pub unsafe fn _mm_cvtsi64_sd(a: __m128d, b: i64) -> __m128d {
102+
simd_insert(a, 0, b as f64)
102103
}
103104

104105
/// Return `a` with its lower element replaced by `b` after converting it to
105106
/// an `f64`.
106107
#[inline(always)]
107108
#[target_feature(enable = "sse2")]
108109
#[cfg_attr(test, assert_instr(cvtsi2sd))]
109-
pub unsafe fn _mm_cvtsi64x_sd(a: f64x2, b: i64) -> f64x2 {
110+
pub unsafe fn _mm_cvtsi64x_sd(a: __m128d, b: i64) -> __m128d {
110111
_mm_cvtsi64_sd(a, b)
111112
}
112113

113114
#[cfg(test)]
114115
mod tests {
116+
use std::{f64, i64};
117+
115118
use stdsimd_test::simd_test;
116119

117-
use v128::*;
118-
use x86::x86_64::sse2;
120+
use x86::*;
119121

120122
#[simd_test = "sse2"]
121-
unsafe fn _mm_cvtsd_si64() {
122-
use std::{f64, i64};
123+
unsafe fn test_mm_cvtsd_si64() {
123124

124-
let r = sse2::_mm_cvtsd_si64(f64x2::new(-2.0, 5.0));
125+
let r = _mm_cvtsd_si64(_mm_setr_pd(-2.0, 5.0));
125126
assert_eq!(r, -2_i64);
126127

127-
let r = sse2::_mm_cvtsd_si64(f64x2::new(f64::MAX, f64::MIN));
128+
let r = _mm_cvtsd_si64(_mm_setr_pd(f64::MAX, f64::MIN));
128129
assert_eq!(r, i64::MIN);
129130
}
130131

131132
#[simd_test = "sse2"]
132-
unsafe fn _mm_cvtsd_si64x() {
133-
use std::{f64, i64};
134-
135-
let r = sse2::_mm_cvtsd_si64x(f64x2::new(f64::NAN, f64::NAN));
133+
unsafe fn test_mm_cvtsd_si64x() {
134+
let r = _mm_cvtsd_si64x(_mm_setr_pd(f64::NAN, f64::NAN));
136135
assert_eq!(r, i64::MIN);
137136
}
138137

139138
#[simd_test = "sse2"]
140-
unsafe fn _mm_cvttsd_si64() {
141-
let a = f64x2::new(-1.1, 2.2);
142-
let r = sse2::_mm_cvttsd_si64(a);
139+
unsafe fn test_mm_cvttsd_si64() {
140+
let a = _mm_setr_pd(-1.1, 2.2);
141+
let r = _mm_cvttsd_si64(a);
143142
assert_eq!(r, -1_i64);
144143
}
145144

146145
#[simd_test = "sse2"]
147-
unsafe fn _mm_cvttsd_si64x() {
148-
use std::{f64, i64};
149-
150-
let a = f64x2::new(f64::NEG_INFINITY, f64::NAN);
151-
let r = sse2::_mm_cvttsd_si64x(a);
146+
unsafe fn test_mm_cvttsd_si64x() {
147+
let a = _mm_setr_pd(f64::NEG_INFINITY, f64::NAN);
148+
let r = _mm_cvttsd_si64x(a);
152149
assert_eq!(r, i64::MIN);
153150
}
154151

155152
#[simd_test = "sse2"]
156-
unsafe fn _mm_stream_si64() {
153+
unsafe fn test_mm_stream_si64() {
157154
let a: i64 = 7;
158155
let mut mem = ::std::boxed::Box::<i64>::new(-1);
159-
sse2::_mm_stream_si64(&mut *mem as *mut i64, a);
156+
_mm_stream_si64(&mut *mem as *mut i64, a);
160157
assert_eq!(a, *mem);
161158
}
162159

163160
#[simd_test = "sse2"]
164-
unsafe fn _mm_cvtsi64_si128() {
165-
let r = sse2::_mm_cvtsi64_si128(5);
166-
assert_eq!(r, i64x2::new(5, 0));
161+
unsafe fn test_mm_cvtsi64_si128() {
162+
let r = _mm_cvtsi64_si128(5);
163+
assert_eq!(r, _mm_setr_epi64x(5, 0));
167164
}
168165

169166
#[simd_test = "sse2"]
170-
unsafe fn _mm_cvtsi128_si64() {
171-
let r = sse2::_mm_cvtsi128_si64(i64x2::new(5, 0));
167+
unsafe fn test_mm_cvtsi128_si64() {
168+
let r = _mm_cvtsi128_si64(_mm_setr_epi64x(5, 0));
172169
assert_eq!(r, 5);
173170
}
174171

175172
#[simd_test = "sse2"]
176-
unsafe fn _mm_cvtsi64_sd() {
177-
let a = f64x2::splat(3.5);
178-
let r = sse2::_mm_cvtsi64_sd(a, 5);
179-
assert_eq!(r, f64x2::new(5.0, 3.5));
173+
unsafe fn test_mm_cvtsi64_sd() {
174+
let a = _mm_set1_pd(3.5);
175+
let r = _mm_cvtsi64_sd(a, 5);
176+
assert_eq_m128d(r, _mm_setr_pd(5.0, 3.5));
180177
}
181178
}

0 commit comments

Comments
 (0)