Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 02970a6

Browse files
committed
Add support for target builtins
1 parent 14c33f5 commit 02970a6

20 files changed

+778
-336
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ perf.data.old
1313
/rust
1414
/simple-raytracer
1515
/regex
16+
/rand
1617
gimple*
1718
*asm
1819
res

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ set -e
22

33
export CARGO_INCREMENTAL=0
44

5-
if [ -f ./gcc_path ]; then
5+
if [ -f ./gcc_path ]; then
66
export GCC_PATH=$(cat gcc_path)
77
else
88
echo 'Please put the path to your custom build of libgccjit in the file `gcc_path`, see Readme.md for details'
@@ -38,7 +38,7 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
3838
fi
3939
fi
4040

41-
export RUSTFLAGS="$linker -Cpanic=abort -Csymbol-mangling-version=v0 -Cdebuginfo=2 -Clto=off -Zpanic-abort-tests -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot"
41+
export RUSTFLAGS="$CG_RUSTFLAGS $linker -Cpanic=abort -Csymbol-mangling-version=v0 -Cdebuginfo=2 -Clto=off -Zpanic-abort-tests -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot"
4242

4343
# FIXME(antoyo): remove once the atomic shim is gone
4444
if [[ `uname` == 'Darwin' ]]; then
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
From a8fb97120d71252538b6b026695df40d02696bdb Mon Sep 17 00:00:00 2001
2+
From: bjorn3 <bjorn3@users.noreply.github.com>
3+
Date: Sat, 15 Aug 2020 20:04:38 +0200
4+
Subject: [PATCH] [rand] Disable failing test
5+
6+
---
7+
src/distributions/uniform.rs | 3 ++-
8+
1 file changed, 2 insertions(+), 1 deletion(-)
9+
10+
diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs
11+
index 480b859..c80bb6f 100644
12+
--- a/src/distributions/uniform.rs
13+
+++ b/src/distributions/uniform.rs
14+
@@ -1085,7 +1085,7 @@ mod tests {
15+
_ => panic!("`UniformDurationMode` was not serialized/deserialized correctly")
16+
}
17+
}
18+
-
19+
+
20+
#[test]
21+
#[cfg(feature = "serde1")]
22+
fn test_uniform_serialization() {
23+
@@ -1314,6 +1314,7 @@ mod tests {
24+
not(target_arch = "wasm32"),
25+
not(target_arch = "asmjs")
26+
))]
27+
+ #[ignore] // FIXME
28+
fn test_float_assertions() {
29+
use super::SampleUniform;
30+
use std::panic::catch_unwind;
31+
--
32+
2.20.1

example/std_example.rs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ fn main() {
9393

9494
println!("{:?}", std::intrinsics::caller_location());
9595

96-
/*unsafe {
96+
unsafe {
9797
test_simd();
98-
}*/
98+
}
9999

100100
Box::pin(move |mut _task_context| {
101101
yield ();
@@ -104,15 +104,15 @@ fn main() {
104104
println!("End");
105105
}
106106

107-
/*#[target_feature(enable = "sse2")]
107+
#[target_feature(enable = "sse2")]
108108
unsafe fn test_simd() {
109109
let x = _mm_setzero_si128();
110110
let y = _mm_set1_epi16(7);
111111
let or = _mm_or_si128(x, y);
112112
let cmp_eq = _mm_cmpeq_epi8(y, y);
113113
let cmp_lt = _mm_cmplt_epi8(y, y);
114114

115-
/*assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]);
115+
assert_eq!(std::mem::transmute::<_, [u16; 8]>(or), [7, 7, 7, 7, 7, 7, 7, 7]);
116116
assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_eq), [0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff]);
117117
assert_eq!(std::mem::transmute::<_, [u16; 8]>(cmp_lt), [0, 0, 0, 0, 0, 0, 0, 0]);
118118

@@ -124,14 +124,14 @@ unsafe fn test_simd() {
124124
test_mm_cvtepi8_epi16();
125125
test_mm_cvtsi128_si64();
126126

127-
// FIXME(#666) implement `#[rustc_arg_required_const(..)]` support
128-
//test_mm_extract_epi8();
127+
test_mm_extract_epi8();
128+
test_mm_insert_epi16();
129129

130130
let mask1 = _mm_movemask_epi8(dbg!(_mm_setr_epi8(255u8 as i8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)));
131-
assert_eq!(mask1, 1);*/
132-
}*/
131+
assert_eq!(mask1, 1);
132+
}
133133

134-
/*#[target_feature(enable = "sse2")]
134+
#[target_feature(enable = "sse2")]
135135
unsafe fn test_mm_slli_si128() {
136136
#[rustfmt::skip]
137137
let a = _mm_setr_epi8(
@@ -155,22 +155,9 @@ unsafe fn test_mm_slli_si128() {
155155
);
156156
let r = _mm_slli_si128(a, 16);
157157
assert_eq_m128i(r, _mm_set1_epi8(0));
158-
159-
#[rustfmt::skip]
160-
let a = _mm_setr_epi8(
161-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
162-
);
163-
let r = _mm_slli_si128(a, -1);
164-
assert_eq_m128i(_mm_set1_epi8(0), r);
165-
166-
#[rustfmt::skip]
167-
let a = _mm_setr_epi8(
168-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
169-
);
170-
let r = _mm_slli_si128(a, -0x80000000);
171-
assert_eq_m128i(r, _mm_set1_epi8(0));
172158
}
173159

160+
174161
#[target_feature(enable = "sse2")]
175162
unsafe fn test_mm_movemask_epi8() {
176163
#[rustfmt::skip]
@@ -254,10 +241,19 @@ unsafe fn test_mm_extract_epi8() {
254241
8, 9, 10, 11, 12, 13, 14, 15
255242
);
256243
let r1 = _mm_extract_epi8(a, 0);
257-
let r2 = _mm_extract_epi8(a, 19);
244+
let r2 = _mm_extract_epi8(a, 3);
258245
assert_eq!(r1, 0xFF);
259246
assert_eq!(r2, 3);
260-
}*/
247+
}
248+
249+
#[cfg(target_arch = "x86_64")]
250+
#[target_feature(enable = "sse2")]
251+
unsafe fn test_mm_insert_epi16() {
252+
let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
253+
let r = _mm_insert_epi16(a, 9, 0);
254+
let e = _mm_setr_epi16(9, 1, 2, 3, 4, 5, 6, 7);
255+
assert_eq_m128i(r, e);
256+
}
261257

262258
#[derive(PartialEq)]
263259
enum LoopState {

patches/0024-core-Disable-portable-simd-test.patch

Lines changed: 0 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -7,167 +7,6 @@ Subject: [PATCH] [core] Disable portable-simd test
77
library/core/tests/lib.rs | 1 -
88
1 file changed, 1 deletion(-)
99

10-
diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
11-
index aa1ad93..95fbf55 100644
12-
--- a/library/core/src/lib.rs
13-
+++ b/library/core/src/lib.rs
14-
@@ -398,23 +398,4 @@ pub mod arch {
15-
}
16-
}
17-
18-
-// Pull in the `core_simd` crate directly into libcore. The contents of
19-
-// `core_simd` are in a different repository: rust-lang/portable-simd.
20-
-//
21-
-// `core_simd` depends on libcore, but the contents of this module are
22-
-// set up in such a way that directly pulling it here works such that the
23-
-// crate uses this crate as its libcore.
24-
-#[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
25-
-#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
26-
-#[allow(rustdoc::bare_urls)]
27-
-#[unstable(feature = "portable_simd", issue = "86656")]
28-
-mod core_simd;
29-
-
30-
-#[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
31-
-#[unstable(feature = "portable_simd", issue = "86656")]
32-
-pub mod simd {
33-
- #[unstable(feature = "portable_simd", issue = "86656")]
34-
- pub use crate::core_simd::simd::*;
35-
-}
36-
-
37-
include!("primitive_docs.rs");
38-
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
39-
index cd38c3a..ad632dc 100644
40-
--- a/library/core/src/slice/mod.rs
41-
+++ b/library/core/src/slice/mod.rs
42-
@@ -17,6 +17,5 @@ use crate::ptr;
43-
use crate::result::Result;
44-
use crate::result::Result::{Err, Ok};
45-
-use crate::simd::{self, Simd};
46-
use crate::slice;
47-
48-
#[unstable(
49-
@@ -3475,121 +3474,6 @@ impl<T> [T] {
50-
}
51-
}
52-
53-
- /// Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.
54-
- ///
55-
- /// This is a safe wrapper around [`slice::align_to`], so has the same weak
56-
- /// postconditions as that method. You're only assured that
57-
- /// `self.len() == prefix.len() + middle.len() * LANES + suffix.len()`.
58-
- ///
59-
- /// Notably, all of the following are possible:
60-
- /// - `prefix.len() >= LANES`.
61-
- /// - `middle.is_empty()` despite `self.len() >= 3 * LANES`.
62-
- /// - `suffix.len() >= LANES`.
63-
- ///
64-
- /// That said, this is a safe method, so if you're only writing safe code,
65-
- /// then this can at most cause incorrect logic, not unsoundness.
66-
- ///
67-
- /// # Panics
68-
- ///
69-
- /// This will panic if the size of the SIMD type is different from
70-
- /// `LANES` times that of the scalar.
71-
- ///
72-
- /// At the time of writing, the trait restrictions on `Simd<T, LANES>` keeps
73-
- /// that from ever happening, as only power-of-two numbers of lanes are
74-
- /// supported. It's possible that, in the future, those restrictions might
75-
- /// be lifted in a way that would make it possible to see panics from this
76-
- /// method for something like `LANES == 3`.
77-
- ///
78-
- /// # Examples
79-
- ///
80-
- /// ```
81-
- /// #![feature(portable_simd)]
82-
- ///
83-
- /// let short = &[1, 2, 3];
84-
- /// let (prefix, middle, suffix) = short.as_simd::<4>();
85-
- /// assert_eq!(middle, []); // Not enough elements for anything in the middle
86-
- ///
87-
- /// // They might be split in any possible way between prefix and suffix
88-
- /// let it = prefix.iter().chain(suffix).copied();
89-
- /// assert_eq!(it.collect::<Vec<_>>(), vec![1, 2, 3]);
90-
- ///
91-
- /// fn basic_simd_sum(x: &[f32]) -> f32 {
92-
- /// use std::ops::Add;
93-
- /// use std::simd::f32x4;
94-
- /// let (prefix, middle, suffix) = x.as_simd();
95-
- /// let sums = f32x4::from_array([
96-
- /// prefix.iter().copied().sum(),
97-
- /// 0.0,
98-
- /// 0.0,
99-
- /// suffix.iter().copied().sum(),
100-
- /// ]);
101-
- /// let sums = middle.iter().copied().fold(sums, f32x4::add);
102-
- /// sums.reduce_sum()
103-
- /// }
104-
- ///
105-
- /// let numbers: Vec<f32> = (1..101).map(|x| x as _).collect();
106-
- /// assert_eq!(basic_simd_sum(&numbers[1..99]), 4949.0);
107-
- /// ```
108-
- #[unstable(feature = "portable_simd", issue = "86656")]
109-
- pub fn as_simd<const LANES: usize>(&self) -> (&[T], &[Simd<T, LANES>], &[T])
110-
- where
111-
- Simd<T, LANES>: AsRef<[T; LANES]>,
112-
- T: simd::SimdElement,
113-
- simd::LaneCount<LANES>: simd::SupportedLaneCount,
114-
- {
115-
- // These are expected to always match, as vector types are laid out like
116-
- // arrays per <https://llvm.org/docs/LangRef.html#vector-type>, but we
117-
- // might as well double-check since it'll optimize away anyhow.
118-
- assert_eq!(mem::size_of::<Simd<T, LANES>>(), mem::size_of::<[T; LANES]>());
119-
-
120-
- // SAFETY: The simd types have the same layout as arrays, just with
121-
- // potentially-higher alignment, so the de-facto transmutes are sound.
122-
- unsafe { self.align_to() }
123-
- }
124-
-
125-
- /// Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.
126-
- ///
127-
- /// This is a safe wrapper around [`slice::align_to_mut`], so has the same weak
128-
- /// postconditions as that method. You're only assured that
129-
- /// `self.len() == prefix.len() + middle.len() * LANES + suffix.len()`.
130-
- ///
131-
- /// Notably, all of the following are possible:
132-
- /// - `prefix.len() >= LANES`.
133-
- /// - `middle.is_empty()` despite `self.len() >= 3 * LANES`.
134-
- /// - `suffix.len() >= LANES`.
135-
- ///
136-
- /// That said, this is a safe method, so if you're only writing safe code,
137-
- /// then this can at most cause incorrect logic, not unsoundness.
138-
- ///
139-
- /// This is the mutable version of [`slice::as_simd`]; see that for examples.
140-
- ///
141-
- /// # Panics
142-
- ///
143-
- /// This will panic if the size of the SIMD type is different from
144-
- /// `LANES` times that of the scalar.
145-
- ///
146-
- /// At the time of writing, the trait restrictions on `Simd<T, LANES>` keeps
147-
- /// that from ever happening, as only power-of-two numbers of lanes are
148-
- /// supported. It's possible that, in the future, those restrictions might
149-
- /// be lifted in a way that would make it possible to see panics from this
150-
- /// method for something like `LANES == 3`.
151-
- #[unstable(feature = "portable_simd", issue = "86656")]
152-
- pub fn as_simd_mut<const LANES: usize>(&mut self) -> (&mut [T], &mut [Simd<T, LANES>], &mut [T])
153-
- where
154-
- Simd<T, LANES>: AsMut<[T; LANES]>,
155-
- T: simd::SimdElement,
156-
- simd::LaneCount<LANES>: simd::SupportedLaneCount,
157-
- {
158-
- // These are expected to always match, as vector types are laid out like
159-
- // arrays per <https://llvm.org/docs/LangRef.html#vector-type>, but we
160-
- // might as well double-check since it'll optimize away anyhow.
161-
- assert_eq!(mem::size_of::<Simd<T, LANES>>(), mem::size_of::<[T; LANES]>());
162-
-
163-
- // SAFETY: The simd types have the same layout as arrays, just with
164-
- // potentially-higher alignment, so the de-facto transmutes are sound.
165-
- unsafe { self.align_to_mut() }
166-
- }
167-
-
168-
/// Checks if the elements of this slice are sorted.
169-
///
170-
/// That is, for each element `a` and its following element `b`, `a <= b` must hold. If the
17110
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
17211
index 06c7be0..359e2e7 100644
17312
--- a/library/core/tests/lib.rs
@@ -188,41 +27,3 @@ index 06c7be0..359e2e7 100644
18827
mod slice;
18928
mod str;
19029
mod str_lossy;
191-
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
192-
index 5dc586d..b6fc48f 100644
193-
--- a/library/std/src/lib.rs
194-
+++ b/library/std/src/lib.rs
195-
@@ -312,6 +312,5 @@
196-
#![feature(panic_can_unwind)]
197-
#![feature(panic_unwind)]
198-
#![feature(platform_intrinsics)]
199-
-#![feature(portable_simd)]
200-
#![feature(prelude_import)]
201-
#![feature(ptr_as_uninit)]
202-
@@ -508,23 +508,6 @@ pub mod time;
203-
#[unstable(feature = "once_cell", issue = "74465")]
204-
pub mod lazy;
205-
206-
-// Pull in `std_float` crate into libstd. The contents of
207-
-// `std_float` are in a different repository: rust-lang/portable-simd.
208-
-#[path = "../../portable-simd/crates/std_float/src/lib.rs"]
209-
-#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
210-
-#[allow(rustdoc::bare_urls)]
211-
-#[unstable(feature = "portable_simd", issue = "86656")]
212-
-mod std_float;
213-
-
214-
-#[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
215-
-#[unstable(feature = "portable_simd", issue = "86656")]
216-
-pub mod simd {
217-
- #[doc(inline)]
218-
- pub use crate::std_float::StdFloat;
219-
- #[doc(inline)]
220-
- pub use core::simd::*;
221-
-}
222-
-
223-
#[stable(feature = "futures_api", since = "1.36.0")]
224-
pub mod task {
225-
//! Types and Traits for working with asynchronous tasks.
226-
--
227-
2.26.2.7.g19db9cfb68
228-

prepare.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ source prepare_build.sh
55

66
cargo install hyperfine || echo "Skipping hyperfine install"
77

8+
git clone https://github.com/rust-random/rand.git || echo "rust-random/rand has already been cloned"
9+
pushd rand
10+
git checkout -- .
11+
git checkout 0f933f9c7176e53b2a3c7952ded484e1783f0bf1
12+
git am ../crate_patches/*-rand-*.patch
13+
popd
14+
815
git clone https://github.com/rust-lang/regex.git || echo "rust-lang/regex has already been cloned"
916
pushd regex
1017
git checkout -- .

0 commit comments

Comments
 (0)