Skip to content

Commit da295ff

Browse files
committed
Fix the stream intrinsics
They should use a platform-specific address management.
1 parent bb74d8f commit da295ff

File tree

9 files changed

+82
-59
lines changed

9 files changed

+82
-59
lines changed

crates/core_arch/src/x86/avx.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,8 +1738,8 @@ pub unsafe fn _mm256_lddqu_si256(mem_addr: *const __m256i) -> __m256i {
17381738
#[stable(feature = "simd_x86", since = "1.27.0")]
17391739
pub unsafe fn _mm256_stream_si256(mem_addr: *mut __m256i, a: __m256i) {
17401740
crate::arch::asm!(
1741-
"vmovntdq [{mem_addr}], {a}",
1742-
mem_addr = in(reg) mem_addr,
1741+
vps!("vmovntdq", ",{a}"),
1742+
p = in(reg) mem_addr,
17431743
a = in(ymm_reg) a,
17441744
options(nostack, preserves_flags),
17451745
);
@@ -1766,8 +1766,8 @@ pub unsafe fn _mm256_stream_si256(mem_addr: *mut __m256i, a: __m256i) {
17661766
#[allow(clippy::cast_ptr_alignment)]
17671767
pub unsafe fn _mm256_stream_pd(mem_addr: *mut f64, a: __m256d) {
17681768
crate::arch::asm!(
1769-
"vmovntpd [{mem_addr}], {a}",
1770-
mem_addr = in(reg) mem_addr,
1769+
vps!("vmovntpd", ",{a}"),
1770+
p = in(reg) mem_addr,
17711771
a = in(ymm_reg) a,
17721772
options(nostack, preserves_flags),
17731773
);
@@ -1795,8 +1795,8 @@ pub unsafe fn _mm256_stream_pd(mem_addr: *mut f64, a: __m256d) {
17951795
#[allow(clippy::cast_ptr_alignment)]
17961796
pub unsafe fn _mm256_stream_ps(mem_addr: *mut f32, a: __m256) {
17971797
crate::arch::asm!(
1798-
"vmovntps [{mem_addr}], {a}",
1799-
mem_addr = in(reg) mem_addr,
1798+
vps!("vmovntps", ",{a}"),
1799+
p = in(reg) mem_addr,
18001800
a = in(ymm_reg) a,
18011801
options(nostack, preserves_flags),
18021802
);

crates/core_arch/src/x86/avx2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3149,9 +3149,9 @@ pub unsafe fn _mm256_srlv_epi64(a: __m256i, count: __m256i) -> __m256i {
31493149
pub unsafe fn _mm256_stream_load_si256(mem_addr: *const __m256i) -> __m256i {
31503150
let dst: __m256i;
31513151
crate::arch::asm!(
3152-
"vmovntdqa {a}, [{mem_addr}]",
3152+
vpl!("vmovntdqa {a}"),
31533153
a = out(ymm_reg) dst,
3154-
mem_addr = in(reg) mem_addr,
3154+
p = in(reg) mem_addr,
31553155
options(pure, readonly, nostack, preserves_flags),
31563156
);
31573157
dst

crates/core_arch/src/x86/avx512bw.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use crate::{
88
#[cfg(test)]
99
use stdarch_test::assert_instr;
1010

11-
use super::avx512f::{vpl, vps};
12-
1311
/// Compute the absolute value of packed signed 16-bit integers in a, and store the unsigned results in dst.
1412
///
1513
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_abs_epi16&expand=30)

crates/core_arch/src/x86/avx512f.rs

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,6 @@ use crate::{
55
mem, ptr,
66
};
77

8-
// x86-32 wants to use a 32-bit address size, but asm! defaults to using the full
9-
// register name (e.g. rax). We have to explicitly override the placeholder to
10-
// use the 32-bit register name in that case.
11-
12-
#[cfg(target_pointer_width = "32")]
13-
macro_rules! vpl {
14-
($inst:expr) => {
15-
concat!($inst, ", [{p:e}]")
16-
};
17-
}
18-
#[cfg(target_pointer_width = "64")]
19-
macro_rules! vpl {
20-
($inst:expr) => {
21-
concat!($inst, ", [{p}]")
22-
};
23-
}
24-
#[cfg(target_pointer_width = "32")]
25-
macro_rules! vps {
26-
($inst1:expr, $inst2:expr) => {
27-
concat!($inst1, " [{p:e}]", $inst2)
28-
};
29-
}
30-
#[cfg(target_pointer_width = "64")]
31-
macro_rules! vps {
32-
($inst1:expr, $inst2:expr) => {
33-
concat!($inst1, " [{p}]", $inst2)
34-
};
35-
}
36-
37-
pub(crate) use {vpl, vps};
38-
398
#[cfg(test)]
409
use stdarch_test::assert_instr;
4110

@@ -28013,8 +27982,8 @@ pub unsafe fn _mm_mask_testn_epi64_mask(k: __mmask8, a: __m128i, b: __m128i) ->
2801327982
#[allow(clippy::cast_ptr_alignment)]
2801427983
pub unsafe fn _mm512_stream_ps(mem_addr: *mut f32, a: __m512) {
2801527984
crate::arch::asm!(
28016-
"vmovntps [{mem_addr}], {a}",
28017-
mem_addr = in(reg) mem_addr,
27985+
vps!("vmovntps", ",{a}"),
27986+
p = in(reg) mem_addr,
2801827987
a = in(zmm_reg) a,
2801927988
options(nostack, preserves_flags),
2802027989
);
@@ -28039,8 +28008,8 @@ pub unsafe fn _mm512_stream_ps(mem_addr: *mut f32, a: __m512) {
2803928008
#[allow(clippy::cast_ptr_alignment)]
2804028009
pub unsafe fn _mm512_stream_pd(mem_addr: *mut f64, a: __m512d) {
2804128010
crate::arch::asm!(
28042-
"vmovntpd [{mem_addr}], {a}",
28043-
mem_addr = in(reg) mem_addr,
28011+
vps!("vmovntpd", ",{a}"),
28012+
p = in(reg) mem_addr,
2804428013
a = in(zmm_reg) a,
2804528014
options(nostack, preserves_flags),
2804628015
);
@@ -28065,13 +28034,32 @@ pub unsafe fn _mm512_stream_pd(mem_addr: *mut f64, a: __m512d) {
2806528034
#[allow(clippy::cast_ptr_alignment)]
2806628035
pub unsafe fn _mm512_stream_si512(mem_addr: *mut i32, a: __m512i) {
2806728036
crate::arch::asm!(
28068-
"vmovntdq [{mem_addr}], {a}",
28069-
mem_addr = in(reg) mem_addr,
28037+
vps!("vmovntdq", ",{a}"),
28038+
p = in(reg) mem_addr,
2807028039
a = in(zmm_reg) a,
2807128040
options(nostack, preserves_flags),
2807228041
);
2807328042
}
2807428043

28044+
/// Load 512-bits of integer data from memory into dst using a non-temporal memory hint. mem_addr
28045+
/// must be aligned on a 64-byte boundary or a general-protection exception may be generated. To
28046+
/// minimize caching, the data is flagged as non-temporal (unlikely to be used again soon)
28047+
///
28048+
/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_stream_load_si256)
28049+
#[inline]
28050+
#[target_feature(enable = "avx512f")]
28051+
#[unstable(feature = "stdarch_x86_avx512", issue = "111137")]
28052+
pub unsafe fn _mm512_stream_load_si512(mem_addr: *const __m512i) -> __m512i {
28053+
let dst: __m512i;
28054+
crate::arch::asm!(
28055+
vpl!("vmovntdqa {a}"),
28056+
a = out(zmm_reg) dst,
28057+
p = in(reg) mem_addr,
28058+
options(pure, readonly, nostack, preserves_flags),
28059+
);
28060+
dst
28061+
}
28062+
2807528063
/// Sets packed 32-bit integers in `dst` with the supplied values.
2807628064
///
2807728065
/// [Intel's documentation]( https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm512_set_ps&expand=4931)
@@ -54510,6 +54498,13 @@ mod tests {
5451054498
}
5451154499
}
5451254500

54501+
#[simd_test(enable = "avx512f")]
54502+
unsafe fn test_mm512_stream_load_si512() {
54503+
let a = _mm512_set_epi64(1, 2, 3, 4, 5, 6, 7, 8);
54504+
let r = _mm512_stream_load_si512(core::ptr::addr_of!(a) as *const _);
54505+
assert_eq_m512i(a, r);
54506+
}
54507+
5451354508
#[simd_test(enable = "avx512f")]
5451454509
unsafe fn test_mm512_reduce_add_epi32() {
5451554510
let a = _mm512_set1_epi32(1);

crates/core_arch/src/x86/macros.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,33 @@ macro_rules! assert_approx_eq {
5757
);
5858
}};
5959
}
60+
61+
// x86-32 wants to use a 32-bit address size, but asm! defaults to using the full
62+
// register name (e.g. rax). We have to explicitly override the placeholder to
63+
// use the 32-bit register name in that case.
64+
65+
#[cfg(target_pointer_width = "32")]
66+
macro_rules! vpl {
67+
($inst:expr) => {
68+
concat!($inst, ", [{p:e}]")
69+
};
70+
}
71+
#[cfg(target_pointer_width = "64")]
72+
macro_rules! vpl {
73+
($inst:expr) => {
74+
concat!($inst, ", [{p}]")
75+
};
76+
}
77+
78+
#[cfg(target_pointer_width = "32")]
79+
macro_rules! vps {
80+
($inst1:expr, $inst2:expr) => {
81+
concat!($inst1, " [{p:e}]", $inst2)
82+
};
83+
}
84+
#[cfg(target_pointer_width = "64")]
85+
macro_rules! vps {
86+
($inst1:expr, $inst2:expr) => {
87+
concat!($inst1, " [{p}]", $inst2)
88+
};
89+
}

crates/core_arch/src/x86/sse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,8 +1992,8 @@ extern "C" {
19921992
#[allow(clippy::cast_ptr_alignment)]
19931993
pub unsafe fn _mm_stream_ps(mem_addr: *mut f32, a: __m128) {
19941994
crate::arch::asm!(
1995-
"movntps [{mem_addr}], {a}",
1996-
mem_addr = in(reg) mem_addr,
1995+
vps!("movntps", ",{a}"),
1996+
p = in(reg) mem_addr,
19971997
a = in(xmm_reg) a,
19981998
options(nostack, preserves_flags),
19991999
);

crates/core_arch/src/x86/sse2.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,8 +1312,8 @@ pub unsafe fn _mm_storel_epi64(mem_addr: *mut __m128i, a: __m128i) {
13121312
#[stable(feature = "simd_x86", since = "1.27.0")]
13131313
pub unsafe fn _mm_stream_si128(mem_addr: *mut __m128i, a: __m128i) {
13141314
crate::arch::asm!(
1315-
"movntdq [{mem_addr}], {a}",
1316-
mem_addr = in(reg) mem_addr,
1315+
vps!("movntdq", ",{a}"),
1316+
p = in(reg) mem_addr,
13171317
a = in(xmm_reg) a,
13181318
options(nostack, preserves_flags),
13191319
);
@@ -1339,8 +1339,8 @@ pub unsafe fn _mm_stream_si128(mem_addr: *mut __m128i, a: __m128i) {
13391339
#[stable(feature = "simd_x86", since = "1.27.0")]
13401340
pub unsafe fn _mm_stream_si32(mem_addr: *mut i32, a: i32) {
13411341
crate::arch::asm!(
1342-
"movnti [{mem_addr}], {a:e}", // `:e` for 32bit value
1343-
mem_addr = in(reg) mem_addr,
1342+
vps!("movnti", ",{a:e}"), // `:e` for 32bit value
1343+
p = in(reg) mem_addr,
13441344
a = in(reg) a,
13451345
options(nostack, preserves_flags),
13461346
);
@@ -2542,8 +2542,8 @@ pub unsafe fn _mm_loadl_pd(a: __m128d, mem_addr: *const f64) -> __m128d {
25422542
#[allow(clippy::cast_ptr_alignment)]
25432543
pub unsafe fn _mm_stream_pd(mem_addr: *mut f64, a: __m128d) {
25442544
crate::arch::asm!(
2545-
"movntpd [{mem_addr}], {a}",
2546-
mem_addr = in(reg) mem_addr,
2545+
vps!("movntpd", ",{a}"),
2546+
p = in(reg) mem_addr,
25472547
a = in(xmm_reg) a,
25482548
options(nostack, preserves_flags),
25492549
);

crates/core_arch/src/x86/sse41.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,9 +1154,9 @@ pub unsafe fn _mm_test_mix_ones_zeros(a: __m128i, mask: __m128i) -> i32 {
11541154
pub unsafe fn _mm_stream_load_si128(mem_addr: *const __m128i) -> __m128i {
11551155
let dst: __m128i;
11561156
crate::arch::asm!(
1157-
"movntdqa {a}, [{mem_addr}]",
1157+
vpl!("movntdqa {a}"),
11581158
a = out(xmm_reg) dst,
1159-
mem_addr = in(reg) mem_addr,
1159+
p = in(reg) mem_addr,
11601160
options(pure, readonly, nostack, preserves_flags),
11611161
);
11621162
dst

crates/core_arch/src/x86_64/sse2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ pub unsafe fn _mm_cvttsd_si64x(a: __m128d) -> i64 {
7979
#[stable(feature = "simd_x86", since = "1.27.0")]
8080
pub unsafe fn _mm_stream_si64(mem_addr: *mut i64, a: i64) {
8181
crate::arch::asm!(
82-
"movnti [{mem_addr}], {a}",
83-
mem_addr = in(reg) mem_addr,
82+
"movnti [{p}], {a}",
83+
p = in(reg) mem_addr,
8484
a = in(reg) a,
8585
options(nostack, preserves_flags),
8686
);

0 commit comments

Comments
 (0)