Skip to content

Feature/simd #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ perf.data.old
/rust
/simple-raytracer
/regex
/rand
gimple*
*asm
res
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ set -e

export CARGO_INCREMENTAL=0

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

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"
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"

# FIXME(antoyo): remove once the atomic shim is gone
if [[ `uname` == 'Darwin' ]]; then
Expand Down
32 changes: 32 additions & 0 deletions crate_patches/0002-rand-Disable-failing-test.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
From a8fb97120d71252538b6b026695df40d02696bdb Mon Sep 17 00:00:00 2001
From: bjorn3 <bjorn3@users.noreply.github.com>
Date: Sat, 15 Aug 2020 20:04:38 +0200
Subject: [PATCH] [rand] Disable failing test

---
src/distributions/uniform.rs | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/distributions/uniform.rs b/src/distributions/uniform.rs
index 480b859..c80bb6f 100644
--- a/src/distributions/uniform.rs
+++ b/src/distributions/uniform.rs
@@ -1085,7 +1085,7 @@ mod tests {
_ => panic!("`UniformDurationMode` was not serialized/deserialized correctly")
}
}
-
+
#[test]
#[cfg(feature = "serde1")]
fn test_uniform_serialization() {
@@ -1314,6 +1314,7 @@ mod tests {
not(target_arch = "wasm32"),
not(target_arch = "asmjs")
))]
+ #[ignore] // FIXME
fn test_float_assertions() {
use super::SampleUniform;
use std::panic::catch_unwind;
--
2.20.1
46 changes: 21 additions & 25 deletions example/std_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ fn main() {

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

/*unsafe {
unsafe {
test_simd();
}*/
}

Box::pin(move |mut _task_context| {
yield ();
Expand All @@ -104,15 +104,15 @@ fn main() {
println!("End");
}

/*#[target_feature(enable = "sse2")]
#[target_feature(enable = "sse2")]
unsafe fn test_simd() {
let x = _mm_setzero_si128();
let y = _mm_set1_epi16(7);
let or = _mm_or_si128(x, y);
let cmp_eq = _mm_cmpeq_epi8(y, y);
let cmp_lt = _mm_cmplt_epi8(y, y);

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

Expand All @@ -124,14 +124,14 @@ unsafe fn test_simd() {
test_mm_cvtepi8_epi16();
test_mm_cvtsi128_si64();

// FIXME(#666) implement `#[rustc_arg_required_const(..)]` support
//test_mm_extract_epi8();
test_mm_extract_epi8();
test_mm_insert_epi16();

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)));
assert_eq!(mask1, 1);*/
}*/
assert_eq!(mask1, 1);
}

/*#[target_feature(enable = "sse2")]
#[target_feature(enable = "sse2")]
unsafe fn test_mm_slli_si128() {
#[rustfmt::skip]
let a = _mm_setr_epi8(
Expand All @@ -155,22 +155,9 @@ unsafe fn test_mm_slli_si128() {
);
let r = _mm_slli_si128(a, 16);
assert_eq_m128i(r, _mm_set1_epi8(0));

#[rustfmt::skip]
let a = _mm_setr_epi8(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
);
let r = _mm_slli_si128(a, -1);
assert_eq_m128i(_mm_set1_epi8(0), r);

#[rustfmt::skip]
let a = _mm_setr_epi8(
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
);
let r = _mm_slli_si128(a, -0x80000000);
assert_eq_m128i(r, _mm_set1_epi8(0));
}


#[target_feature(enable = "sse2")]
unsafe fn test_mm_movemask_epi8() {
#[rustfmt::skip]
Expand Down Expand Up @@ -254,10 +241,19 @@ unsafe fn test_mm_extract_epi8() {
8, 9, 10, 11, 12, 13, 14, 15
);
let r1 = _mm_extract_epi8(a, 0);
let r2 = _mm_extract_epi8(a, 19);
let r2 = _mm_extract_epi8(a, 3);
assert_eq!(r1, 0xFF);
assert_eq!(r2, 3);
}*/
}

#[cfg(target_arch = "x86_64")]
#[target_feature(enable = "sse2")]
unsafe fn test_mm_insert_epi16() {
let a = _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7);
let r = _mm_insert_epi16(a, 9, 0);
let e = _mm_setr_epi16(9, 1, 2, 3, 4, 5, 6, 7);
assert_eq_m128i(r, e);
}

#[derive(PartialEq)]
enum LoopState {
Expand Down
199 changes: 0 additions & 199 deletions patches/0024-core-Disable-portable-simd-test.patch
Original file line number Diff line number Diff line change
Expand Up @@ -7,167 +7,6 @@ Subject: [PATCH] [core] Disable portable-simd test
library/core/tests/lib.rs | 1 -
1 file changed, 1 deletion(-)

diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs
index aa1ad93..95fbf55 100644
--- a/library/core/src/lib.rs
+++ b/library/core/src/lib.rs
@@ -398,23 +398,4 @@ pub mod arch {
}
}

-// Pull in the `core_simd` crate directly into libcore. The contents of
-// `core_simd` are in a different repository: rust-lang/portable-simd.
-//
-// `core_simd` depends on libcore, but the contents of this module are
-// set up in such a way that directly pulling it here works such that the
-// crate uses this crate as its libcore.
-#[path = "../../portable-simd/crates/core_simd/src/mod.rs"]
-#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
-#[allow(rustdoc::bare_urls)]
-#[unstable(feature = "portable_simd", issue = "86656")]
-mod core_simd;
-
-#[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
-#[unstable(feature = "portable_simd", issue = "86656")]
-pub mod simd {
- #[unstable(feature = "portable_simd", issue = "86656")]
- pub use crate::core_simd::simd::*;
-}
-
include!("primitive_docs.rs");
diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs
index cd38c3a..ad632dc 100644
--- a/library/core/src/slice/mod.rs
+++ b/library/core/src/slice/mod.rs
@@ -17,6 +17,5 @@ use crate::ptr;
use crate::result::Result;
use crate::result::Result::{Err, Ok};
-use crate::simd::{self, Simd};
use crate::slice;

#[unstable(
@@ -3475,121 +3474,6 @@ impl<T> [T] {
}
}

- /// Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.
- ///
- /// This is a safe wrapper around [`slice::align_to`], so has the same weak
- /// postconditions as that method. You're only assured that
- /// `self.len() == prefix.len() + middle.len() * LANES + suffix.len()`.
- ///
- /// Notably, all of the following are possible:
- /// - `prefix.len() >= LANES`.
- /// - `middle.is_empty()` despite `self.len() >= 3 * LANES`.
- /// - `suffix.len() >= LANES`.
- ///
- /// That said, this is a safe method, so if you're only writing safe code,
- /// then this can at most cause incorrect logic, not unsoundness.
- ///
- /// # Panics
- ///
- /// This will panic if the size of the SIMD type is different from
- /// `LANES` times that of the scalar.
- ///
- /// At the time of writing, the trait restrictions on `Simd<T, LANES>` keeps
- /// that from ever happening, as only power-of-two numbers of lanes are
- /// supported. It's possible that, in the future, those restrictions might
- /// be lifted in a way that would make it possible to see panics from this
- /// method for something like `LANES == 3`.
- ///
- /// # Examples
- ///
- /// ```
- /// #![feature(portable_simd)]
- ///
- /// let short = &[1, 2, 3];
- /// let (prefix, middle, suffix) = short.as_simd::<4>();
- /// assert_eq!(middle, []); // Not enough elements for anything in the middle
- ///
- /// // They might be split in any possible way between prefix and suffix
- /// let it = prefix.iter().chain(suffix).copied();
- /// assert_eq!(it.collect::<Vec<_>>(), vec![1, 2, 3]);
- ///
- /// fn basic_simd_sum(x: &[f32]) -> f32 {
- /// use std::ops::Add;
- /// use std::simd::f32x4;
- /// let (prefix, middle, suffix) = x.as_simd();
- /// let sums = f32x4::from_array([
- /// prefix.iter().copied().sum(),
- /// 0.0,
- /// 0.0,
- /// suffix.iter().copied().sum(),
- /// ]);
- /// let sums = middle.iter().copied().fold(sums, f32x4::add);
- /// sums.reduce_sum()
- /// }
- ///
- /// let numbers: Vec<f32> = (1..101).map(|x| x as _).collect();
- /// assert_eq!(basic_simd_sum(&numbers[1..99]), 4949.0);
- /// ```
- #[unstable(feature = "portable_simd", issue = "86656")]
- pub fn as_simd<const LANES: usize>(&self) -> (&[T], &[Simd<T, LANES>], &[T])
- where
- Simd<T, LANES>: AsRef<[T; LANES]>,
- T: simd::SimdElement,
- simd::LaneCount<LANES>: simd::SupportedLaneCount,
- {
- // These are expected to always match, as vector types are laid out like
- // arrays per <https://llvm.org/docs/LangRef.html#vector-type>, but we
- // might as well double-check since it'll optimize away anyhow.
- assert_eq!(mem::size_of::<Simd<T, LANES>>(), mem::size_of::<[T; LANES]>());
-
- // SAFETY: The simd types have the same layout as arrays, just with
- // potentially-higher alignment, so the de-facto transmutes are sound.
- unsafe { self.align_to() }
- }
-
- /// Split a slice into a prefix, a middle of aligned SIMD types, and a suffix.
- ///
- /// This is a safe wrapper around [`slice::align_to_mut`], so has the same weak
- /// postconditions as that method. You're only assured that
- /// `self.len() == prefix.len() + middle.len() * LANES + suffix.len()`.
- ///
- /// Notably, all of the following are possible:
- /// - `prefix.len() >= LANES`.
- /// - `middle.is_empty()` despite `self.len() >= 3 * LANES`.
- /// - `suffix.len() >= LANES`.
- ///
- /// That said, this is a safe method, so if you're only writing safe code,
- /// then this can at most cause incorrect logic, not unsoundness.
- ///
- /// This is the mutable version of [`slice::as_simd`]; see that for examples.
- ///
- /// # Panics
- ///
- /// This will panic if the size of the SIMD type is different from
- /// `LANES` times that of the scalar.
- ///
- /// At the time of writing, the trait restrictions on `Simd<T, LANES>` keeps
- /// that from ever happening, as only power-of-two numbers of lanes are
- /// supported. It's possible that, in the future, those restrictions might
- /// be lifted in a way that would make it possible to see panics from this
- /// method for something like `LANES == 3`.
- #[unstable(feature = "portable_simd", issue = "86656")]
- pub fn as_simd_mut<const LANES: usize>(&mut self) -> (&mut [T], &mut [Simd<T, LANES>], &mut [T])
- where
- Simd<T, LANES>: AsMut<[T; LANES]>,
- T: simd::SimdElement,
- simd::LaneCount<LANES>: simd::SupportedLaneCount,
- {
- // These are expected to always match, as vector types are laid out like
- // arrays per <https://llvm.org/docs/LangRef.html#vector-type>, but we
- // might as well double-check since it'll optimize away anyhow.
- assert_eq!(mem::size_of::<Simd<T, LANES>>(), mem::size_of::<[T; LANES]>());
-
- // SAFETY: The simd types have the same layout as arrays, just with
- // potentially-higher alignment, so the de-facto transmutes are sound.
- unsafe { self.align_to_mut() }
- }
-
/// Checks if the elements of this slice are sorted.
///
/// That is, for each element `a` and its following element `b`, `a <= b` must hold. If the
diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs
index 06c7be0..359e2e7 100644
--- a/library/core/tests/lib.rs
Expand All @@ -188,41 +27,3 @@ index 06c7be0..359e2e7 100644
mod slice;
mod str;
mod str_lossy;
diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs
index 5dc586d..b6fc48f 100644
--- a/library/std/src/lib.rs
+++ b/library/std/src/lib.rs
@@ -312,6 +312,5 @@
#![feature(panic_can_unwind)]
#![feature(panic_unwind)]
#![feature(platform_intrinsics)]
-#![feature(portable_simd)]
#![feature(prelude_import)]
#![feature(ptr_as_uninit)]
@@ -508,23 +508,6 @@ pub mod time;
#[unstable(feature = "once_cell", issue = "74465")]
pub mod lazy;

-// Pull in `std_float` crate into libstd. The contents of
-// `std_float` are in a different repository: rust-lang/portable-simd.
-#[path = "../../portable-simd/crates/std_float/src/lib.rs"]
-#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)]
-#[allow(rustdoc::bare_urls)]
-#[unstable(feature = "portable_simd", issue = "86656")]
-mod std_float;
-
-#[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
-#[unstable(feature = "portable_simd", issue = "86656")]
-pub mod simd {
- #[doc(inline)]
- pub use crate::std_float::StdFloat;
- #[doc(inline)]
- pub use core::simd::*;
-}
-
#[stable(feature = "futures_api", since = "1.36.0")]
pub mod task {
//! Types and Traits for working with asynchronous tasks.
--
2.26.2.7.g19db9cfb68

7 changes: 7 additions & 0 deletions prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ source prepare_build.sh

cargo install hyperfine || echo "Skipping hyperfine install"

git clone https://github.com/rust-random/rand.git || echo "rust-random/rand has already been cloned"
pushd rand
git checkout -- .
git checkout 0f933f9c7176e53b2a3c7952ded484e1783f0bf1
git am ../crate_patches/*-rand-*.patch
popd

git clone https://github.com/rust-lang/regex.git || echo "rust-lang/regex has already been cloned"
pushd regex
git checkout -- .
Expand Down
Loading