Skip to content

Commit 93b7900

Browse files
committed
Make sse3 functions const
1 parent c9d6394 commit 93b7900

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

crates/core_arch/src/x86/sse3.rs

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use stdarch_test::assert_instr;
1414
#[target_feature(enable = "sse3")]
1515
#[cfg_attr(test, assert_instr(addsubps))]
1616
#[stable(feature = "simd_x86", since = "1.27.0")]
17-
pub fn _mm_addsub_ps(a: __m128, b: __m128) -> __m128 {
17+
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
18+
pub const fn _mm_addsub_ps(a: __m128, b: __m128) -> __m128 {
1819
unsafe {
1920
let a = a.as_f32x4();
2021
let b = b.as_f32x4();
@@ -32,7 +33,8 @@ pub fn _mm_addsub_ps(a: __m128, b: __m128) -> __m128 {
3233
#[target_feature(enable = "sse3")]
3334
#[cfg_attr(test, assert_instr(addsubpd))]
3435
#[stable(feature = "simd_x86", since = "1.27.0")]
35-
pub fn _mm_addsub_pd(a: __m128d, b: __m128d) -> __m128d {
36+
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
37+
pub const fn _mm_addsub_pd(a: __m128d, b: __m128d) -> __m128d {
3638
unsafe {
3739
let a = a.as_f64x2();
3840
let b = b.as_f64x2();
@@ -50,7 +52,8 @@ pub fn _mm_addsub_pd(a: __m128d, b: __m128d) -> __m128d {
5052
#[target_feature(enable = "sse3")]
5153
#[cfg_attr(test, assert_instr(haddpd))]
5254
#[stable(feature = "simd_x86", since = "1.27.0")]
53-
pub fn _mm_hadd_pd(a: __m128d, b: __m128d) -> __m128d {
55+
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
56+
pub const fn _mm_hadd_pd(a: __m128d, b: __m128d) -> __m128d {
5457
unsafe {
5558
let even = simd_shuffle!(a, b, [0, 2]);
5659
let odd = simd_shuffle!(a, b, [1, 3]);
@@ -66,7 +69,8 @@ pub fn _mm_hadd_pd(a: __m128d, b: __m128d) -> __m128d {
6669
#[target_feature(enable = "sse3")]
6770
#[cfg_attr(test, assert_instr(haddps))]
6871
#[stable(feature = "simd_x86", since = "1.27.0")]
69-
pub fn _mm_hadd_ps(a: __m128, b: __m128) -> __m128 {
72+
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
73+
pub const fn _mm_hadd_ps(a: __m128, b: __m128) -> __m128 {
7074
unsafe {
7175
let even = simd_shuffle!(a, b, [0, 2, 4, 6]);
7276
let odd = simd_shuffle!(a, b, [1, 3, 5, 7]);
@@ -82,7 +86,8 @@ pub fn _mm_hadd_ps(a: __m128, b: __m128) -> __m128 {
8286
#[target_feature(enable = "sse3")]
8387
#[cfg_attr(test, assert_instr(hsubpd))]
8488
#[stable(feature = "simd_x86", since = "1.27.0")]
85-
pub fn _mm_hsub_pd(a: __m128d, b: __m128d) -> __m128d {
89+
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
90+
pub const fn _mm_hsub_pd(a: __m128d, b: __m128d) -> __m128d {
8691
unsafe {
8792
let even = simd_shuffle!(a, b, [0, 2]);
8893
let odd = simd_shuffle!(a, b, [1, 3]);
@@ -98,7 +103,8 @@ pub fn _mm_hsub_pd(a: __m128d, b: __m128d) -> __m128d {
98103
#[target_feature(enable = "sse3")]
99104
#[cfg_attr(test, assert_instr(hsubps))]
100105
#[stable(feature = "simd_x86", since = "1.27.0")]
101-
pub fn _mm_hsub_ps(a: __m128, b: __m128) -> __m128 {
106+
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
107+
pub const fn _mm_hsub_ps(a: __m128, b: __m128) -> __m128 {
102108
unsafe {
103109
let even = simd_shuffle!(a, b, [0, 2, 4, 6]);
104110
let odd = simd_shuffle!(a, b, [1, 3, 5, 7]);
@@ -127,7 +133,8 @@ pub unsafe fn _mm_lddqu_si128(mem_addr: *const __m128i) -> __m128i {
127133
#[target_feature(enable = "sse3")]
128134
#[cfg_attr(test, assert_instr(movddup))]
129135
#[stable(feature = "simd_x86", since = "1.27.0")]
130-
pub fn _mm_movedup_pd(a: __m128d) -> __m128d {
136+
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
137+
pub const fn _mm_movedup_pd(a: __m128d) -> __m128d {
131138
unsafe { simd_shuffle!(a, a, [0, 0]) }
132139
}
133140

@@ -139,7 +146,8 @@ pub fn _mm_movedup_pd(a: __m128d) -> __m128d {
139146
#[target_feature(enable = "sse3")]
140147
#[cfg_attr(test, assert_instr(movddup))]
141148
#[stable(feature = "simd_x86", since = "1.27.0")]
142-
pub unsafe fn _mm_loaddup_pd(mem_addr: *const f64) -> __m128d {
149+
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
150+
pub const unsafe fn _mm_loaddup_pd(mem_addr: *const f64) -> __m128d {
143151
_mm_load1_pd(mem_addr)
144152
}
145153

@@ -151,7 +159,8 @@ pub unsafe fn _mm_loaddup_pd(mem_addr: *const f64) -> __m128d {
151159
#[target_feature(enable = "sse3")]
152160
#[cfg_attr(test, assert_instr(movshdup))]
153161
#[stable(feature = "simd_x86", since = "1.27.0")]
154-
pub fn _mm_movehdup_ps(a: __m128) -> __m128 {
162+
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
163+
pub const fn _mm_movehdup_ps(a: __m128) -> __m128 {
155164
unsafe { simd_shuffle!(a, a, [1, 1, 3, 3]) }
156165
}
157166

@@ -163,7 +172,8 @@ pub fn _mm_movehdup_ps(a: __m128) -> __m128 {
163172
#[target_feature(enable = "sse3")]
164173
#[cfg_attr(test, assert_instr(movsldup))]
165174
#[stable(feature = "simd_x86", since = "1.27.0")]
166-
pub fn _mm_moveldup_ps(a: __m128) -> __m128 {
175+
#[rustc_const_unstable(feature = "stdarch_const_x86", issue = "149298")]
176+
pub const fn _mm_moveldup_ps(a: __m128) -> __m128 {
167177
unsafe { simd_shuffle!(a, a, [0, 0, 2, 2]) }
168178
}
169179

@@ -175,52 +185,53 @@ unsafe extern "C" {
175185

176186
#[cfg(test)]
177187
mod tests {
188+
use crate::core_arch::assert_eq_const as assert_eq;
178189
use stdarch_test::simd_test;
179190

180191
use crate::core_arch::x86::*;
181192

182193
#[simd_test(enable = "sse3")]
183-
unsafe fn test_mm_addsub_ps() {
194+
const unsafe fn test_mm_addsub_ps() {
184195
let a = _mm_setr_ps(-1.0, 5.0, 0.0, -10.0);
185196
let b = _mm_setr_ps(-100.0, 20.0, 0.0, -5.0);
186197
let r = _mm_addsub_ps(a, b);
187198
assert_eq_m128(r, _mm_setr_ps(99.0, 25.0, 0.0, -15.0));
188199
}
189200

190201
#[simd_test(enable = "sse3")]
191-
unsafe fn test_mm_addsub_pd() {
202+
const unsafe fn test_mm_addsub_pd() {
192203
let a = _mm_setr_pd(-1.0, 5.0);
193204
let b = _mm_setr_pd(-100.0, 20.0);
194205
let r = _mm_addsub_pd(a, b);
195206
assert_eq_m128d(r, _mm_setr_pd(99.0, 25.0));
196207
}
197208

198209
#[simd_test(enable = "sse3")]
199-
unsafe fn test_mm_hadd_pd() {
210+
const unsafe fn test_mm_hadd_pd() {
200211
let a = _mm_setr_pd(-1.0, 5.0);
201212
let b = _mm_setr_pd(-100.0, 20.0);
202213
let r = _mm_hadd_pd(a, b);
203214
assert_eq_m128d(r, _mm_setr_pd(4.0, -80.0));
204215
}
205216

206217
#[simd_test(enable = "sse3")]
207-
unsafe fn test_mm_hadd_ps() {
218+
const unsafe fn test_mm_hadd_ps() {
208219
let a = _mm_setr_ps(-1.0, 5.0, 0.0, -10.0);
209220
let b = _mm_setr_ps(-100.0, 20.0, 0.0, -5.0);
210221
let r = _mm_hadd_ps(a, b);
211222
assert_eq_m128(r, _mm_setr_ps(4.0, -10.0, -80.0, -5.0));
212223
}
213224

214225
#[simd_test(enable = "sse3")]
215-
unsafe fn test_mm_hsub_pd() {
226+
const unsafe fn test_mm_hsub_pd() {
216227
let a = _mm_setr_pd(-1.0, 5.0);
217228
let b = _mm_setr_pd(-100.0, 20.0);
218229
let r = _mm_hsub_pd(a, b);
219230
assert_eq_m128d(r, _mm_setr_pd(-6.0, -120.0));
220231
}
221232

222233
#[simd_test(enable = "sse3")]
223-
unsafe fn test_mm_hsub_ps() {
234+
const unsafe fn test_mm_hsub_ps() {
224235
let a = _mm_setr_ps(-1.0, 5.0, 0.0, -10.0);
225236
let b = _mm_setr_ps(-100.0, 20.0, 0.0, -5.0);
226237
let r = _mm_hsub_ps(a, b);
@@ -241,28 +252,28 @@ mod tests {
241252
}
242253

243254
#[simd_test(enable = "sse3")]
244-
unsafe fn test_mm_movedup_pd() {
255+
const unsafe fn test_mm_movedup_pd() {
245256
let a = _mm_setr_pd(-1.0, 5.0);
246257
let r = _mm_movedup_pd(a);
247258
assert_eq_m128d(r, _mm_setr_pd(-1.0, -1.0));
248259
}
249260

250261
#[simd_test(enable = "sse3")]
251-
unsafe fn test_mm_movehdup_ps() {
262+
const unsafe fn test_mm_movehdup_ps() {
252263
let a = _mm_setr_ps(-1.0, 5.0, 0.0, -10.0);
253264
let r = _mm_movehdup_ps(a);
254265
assert_eq_m128(r, _mm_setr_ps(5.0, 5.0, -10.0, -10.0));
255266
}
256267

257268
#[simd_test(enable = "sse3")]
258-
unsafe fn test_mm_moveldup_ps() {
269+
const unsafe fn test_mm_moveldup_ps() {
259270
let a = _mm_setr_ps(-1.0, 5.0, 0.0, -10.0);
260271
let r = _mm_moveldup_ps(a);
261272
assert_eq_m128(r, _mm_setr_ps(-1.0, -1.0, 0.0, 0.0));
262273
}
263274

264275
#[simd_test(enable = "sse3")]
265-
unsafe fn test_mm_loaddup_pd() {
276+
const unsafe fn test_mm_loaddup_pd() {
266277
let d = -5.0;
267278
let r = _mm_loaddup_pd(&d);
268279
assert_eq_m128d(r, _mm_setr_pd(d, d));

0 commit comments

Comments
 (0)