Skip to content
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

pub use std::simd::StdFloat; #93146

Merged
merged 24 commits into from
Feb 3, 2022
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b6d0eec
Wrap bitshifts in ops.rs
workingjubilee Dec 9, 2021
8aef340
Refactor bitops with `#[must_use]`
workingjubilee Dec 9, 2021
049e8ca
Refactor float arith with `#[must_use]`
workingjubilee Dec 9, 2021
5dcd397
Finish refactoring ints in ops.rs
workingjubilee Dec 9, 2021
bc326a2
Refactor ops.rs with a recursive macro
workingjubilee Dec 22, 2021
a424205
Use Mask::any in div check
workingjubilee Dec 24, 2021
4bbef26
Merge portable-simd#210 - ./wrap-shifts
workingjubilee Dec 30, 2021
ecc00ef
impl std::simd::StdFloat
workingjubilee Dec 21, 2021
af26e3b
Tear down and rewrite support for float testing
workingjubilee Dec 21, 2021
09fa72a
Merge portable-simd#219 - ./std-float
workingjubilee Dec 31, 2021
65cb2c9
Fix mask alias
calebzulawski Jan 9, 2022
138b9cf
Use intrinsic for min/max
calebzulawski Jan 13, 2022
41db153
Merge pull request #224 from rust-lang/feature/min-max-intrinsic
calebzulawski Jan 14, 2022
a4f5f01
Use intrinsics for Mask::{to,from}_array
workingjubilee Nov 13, 2021
56566d8
Annotate signed type in int_divrem_guard
workingjubilee Jan 20, 2022
4fc62c2
fix documentation typo
AlecGoncharow Jan 23, 2022
36cca22
Update crates/core_simd/src/vector/float.rs
calebzulawski Jan 25, 2022
cad7434
Merge pull request #231 from AlecGoncharow/patch-1
calebzulawski Jan 25, 2022
a991d48
Add Simd::cast
workingjubilee Jan 27, 2022
0031b02
Add core_simd/tests/cast.rs
workingjubilee Jan 27, 2022
7072c22
Merge portable-simd#232 - ./feat/typecast
workingjubilee Jan 27, 2022
03f6fbb
Omit Simd::cast during bootstrap
workingjubilee Jan 27, 2022
cde7bdc
Sync rust-lang/portable-simd@03f6fbb21e6050da2a05b3ce8f480c020b384916
workingjubilee Jan 27, 2022
e96159e
pub use std::simd::StdFloat;
workingjubilee Jan 27, 2022
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 library/portable-simd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -2,5 +2,6 @@

members = [
"crates/core_simd",
"crates/std_float",
"crates/test_helpers",
]
3 changes: 3 additions & 0 deletions library/portable-simd/crates/core_simd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -26,3 +26,6 @@ features = ["alloc"]

[dev-dependencies.test_helpers]
path = "../test_helpers"

[dev-dependencies]
std_float = { path = "../std_float/", features = ["as_crate"] }
10 changes: 5 additions & 5 deletions library/portable-simd/crates/core_simd/examples/nbody.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#![cfg_attr(feature = "std", feature(portable_simd))]
#![feature(portable_simd)]
extern crate std_float;

/// Benchmarks game nbody code
/// Taken from the `packed_simd` crate
/// Run this benchmark with `cargo test --example nbody`
#[cfg(feature = "std")]
mod nbody {
use core_simd::*;
use core_simd::simd::*;
#[allow(unused)] // False positive?
use std_float::StdFloat;

use std::f64::consts::PI;
const SOLAR_MASS: f64 = 4.0 * PI * PI;
@@ -167,7 +169,6 @@ mod nbody {
}
}

#[cfg(feature = "std")]
#[cfg(test)]
mod tests {
// Good enough for demonstration purposes, not going for strictness here.
@@ -184,7 +185,6 @@ mod tests {
}

fn main() {
#[cfg(feature = "std")]
{
let (energy_before, energy_after) = nbody::run(1000);
println!("Energy before: {}", energy_before);
34 changes: 8 additions & 26 deletions library/portable-simd/crates/core_simd/src/intrinsics.rs
Original file line number Diff line number Diff line change
@@ -39,13 +39,21 @@ extern "platform-intrinsic" {

/// fptoui/fptosi/uitofp/sitofp
pub(crate) fn simd_cast<T, U>(x: T) -> U;
/// follows Rust's `T as U` semantics, including saturating float casts
/// which amounts to the same as `simd_cast` for many cases
#[cfg(not(bootstrap))]
pub(crate) fn simd_as<T, U>(x: T) -> U;

/// neg/fneg
pub(crate) fn simd_neg<T>(x: T) -> T;

/// fabs
pub(crate) fn simd_fabs<T>(x: T) -> T;

// minnum/maxnum
pub(crate) fn simd_fmin<T>(x: T, y: T) -> T;
pub(crate) fn simd_fmax<T>(x: T, y: T) -> T;

pub(crate) fn simd_eq<T, U>(x: T, y: T) -> U;
pub(crate) fn simd_ne<T, U>(x: T, y: T) -> U;
pub(crate) fn simd_lt<T, U>(x: T, y: T) -> U;
@@ -87,29 +95,3 @@ extern "platform-intrinsic" {
#[allow(unused)]
pub(crate) fn simd_select_bitmask<M, T>(m: M, a: T, b: T) -> T;
}

#[cfg(feature = "std")]
mod std {
extern "platform-intrinsic" {
// ceil
pub(crate) fn simd_ceil<T>(x: T) -> T;

// floor
pub(crate) fn simd_floor<T>(x: T) -> T;

// round
pub(crate) fn simd_round<T>(x: T) -> T;

// trunc
pub(crate) fn simd_trunc<T>(x: T) -> T;

// fsqrt
pub(crate) fn simd_fsqrt<T>(x: T) -> T;

// fma
pub(crate) fn simd_fma<T>(x: T, y: T, z: T) -> T;
}
}

#[cfg(feature = "std")]
pub(crate) use crate::simd::intrinsics::std::*;
42 changes: 30 additions & 12 deletions library/portable-simd/crates/core_simd/src/masks.rs
Original file line number Diff line number Diff line change
@@ -12,9 +12,10 @@
)]
mod mask_impl;

use crate::simd::intrinsics;
use crate::simd::{LaneCount, Simd, SimdElement, SupportedLaneCount};
use core::cmp::Ordering;
use core::fmt;
use core::{fmt, mem};

mod sealed {
use super::*;
@@ -105,22 +106,39 @@ where
Self(mask_impl::Mask::splat(value))
}

/// Converts an array to a SIMD vector.
/// Converts an array of bools to a SIMD mask.
pub fn from_array(array: [bool; LANES]) -> Self {
let mut vector = Self::splat(false);
for (i, v) in array.iter().enumerate() {
vector.set(i, *v);
// SAFETY: Rust's bool has a layout of 1 byte (u8) with a value of
// true: 0b_0000_0001
// false: 0b_0000_0000
// Thus, an array of bools is also a valid array of bytes: [u8; N]
// This would be hypothetically valid as an "in-place" transmute,
// but these are "dependently-sized" types, so copy elision it is!
unsafe {
let bytes: [u8; LANES] = mem::transmute_copy(&array);
let bools: Simd<i8, LANES> =
intrinsics::simd_ne(Simd::from_array(bytes), Simd::splat(0u8));
Mask::from_int_unchecked(intrinsics::simd_cast(bools))
}
vector
}

/// Converts a SIMD vector to an array.
/// Converts a SIMD mask to an array of bools.
pub fn to_array(self) -> [bool; LANES] {
let mut array = [false; LANES];
for (i, v) in array.iter_mut().enumerate() {
*v = self.test(i);
// This follows mostly the same logic as from_array.
// SAFETY: Rust's bool has a layout of 1 byte (u8) with a value of
// true: 0b_0000_0001
// false: 0b_0000_0000
// Thus, an array of bools is also a valid array of bytes: [u8; N]
// Since our masks are equal to integers where all bits are set,
// we can simply convert them to i8s, and then bitand them by the
// bitpattern for Rust's "true" bool.
// This would be hypothetically valid as an "in-place" transmute,
// but these are "dependently-sized" types, so copy elision it is!
unsafe {
let mut bytes: Simd<i8, LANES> = intrinsics::simd_cast(self.to_int());
bytes &= Simd::splat(1i8);
mem::transmute_copy(&bytes)
}
array
}

/// Converts a vector of integers to a mask, where 0 represents `false` and -1
@@ -516,7 +534,7 @@ pub type mask16x8 = Mask<i16, 8>;
pub type mask16x16 = Mask<i16, 16>;

/// Vector of 32 16-bit masks
pub type mask16x32 = Mask<i32, 32>;
pub type mask16x32 = Mask<i16, 32>;

/// Vector of two 32-bit masks
pub type mask32x2 = Mask<i32, 2>;
Loading