From d96f0c382f0e4d22deafdaed11d9aff1fc1d91f0 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 22 Dec 2023 12:31:59 +0100 Subject: [PATCH 1/4] simd intrinsics: add simd_shuffle_generic --- library/core/src/intrinsics/simd.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/library/core/src/intrinsics/simd.rs b/library/core/src/intrinsics/simd.rs index 0fd27974dceca..1483be2a69903 100644 --- a/library/core/src/intrinsics/simd.rs +++ b/library/core/src/intrinsics/simd.rs @@ -190,14 +190,27 @@ extern "platform-intrinsic" { /// /// `T` must be a vector. /// - /// `U` must be a const array of `i32`s. + /// `U` must be a **const** array of `i32`s. This means it must either refer to a named + /// const or be given as an inline const expression (`const { ... }`). /// /// `V` must be a vector with the same element type as `T` and the same length as `U`. /// - /// Concatenates `x` and `y`, then returns a new vector such that each element is selected from - /// the concatenation by the matching index in `idx`. + /// Returns a new vector such that element `i` is selected from `xy[idx[i]]`, where `xy` + /// is the concatenation of `x` and `y`. It is a compile-time error if `idx[i]` is out-of-bounds + /// of `xy`. pub fn simd_shuffle(x: T, y: T, idx: U) -> V; + /// Shuffle two vectors by const indices. + /// + /// `T` must be a vector. + /// + /// `V` must be a vector with the same element type as `T` and the same length as `IDX`. + /// + /// Returns a new vector such that element `i` is selected from `xy[IDX[i]]`, where `xy` + /// is the concatenation of `x` and `y`. It is a compile-time error if `IDX[i]` is out-of-bounds + /// of `xy`. + pub fn simd_shuffle_generic(x: T, y: T) -> U; + /// Read a vector of pointers. /// /// `T` must be a vector. From 5219af6ae0a71c20dc5fa25520ef2b2927e37f7e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 28 Dec 2023 13:21:02 +0100 Subject: [PATCH 2/4] add more missing simd intrinsics --- library/core/src/intrinsics/simd.rs | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/library/core/src/intrinsics/simd.rs b/library/core/src/intrinsics/simd.rs index 1483be2a69903..d52f04bf3e004 100644 --- a/library/core/src/intrinsics/simd.rs +++ b/library/core/src/intrinsics/simd.rs @@ -481,4 +481,36 @@ extern "platform-intrinsic" { /// /// `T` must be a vector of integers. pub fn simd_cttz(x: T) -> T; + + /// Round up each element to the next highest integer. + /// + /// `T` must be a vector of floats. + pub fn simd_ceil(x: T) -> T; + + /// Round down each element to the next lowest integer. + /// + /// `T` must be a vector of floats. + pub fn simd_floor(x: T) -> T; + + /// Round each element to the closest integer. + /// Ties are resolving by rounding away from 0. + /// + /// `T` must be a vector of floats. + pub fn simd_round(x: T) -> T; + + /// Return the integer part of each element. + /// This means that non-integer numbers are always truncated towards zero. + /// + /// `T` must be a vector of floats. + pub fn simd_trunc(x: T) -> T; + + /// Takes the square root of each element. + /// + /// `T` must be a vector of floats. + pub fn simd_fsqrt(x: T) -> T; + + /// Computes `(x*y) + z` for each element, but without any intermediate rounding. + /// + /// `T` must be a vector of floats. + pub fn simd_fma(x: T, y: T, z: T) -> T; } From aa64c73f1413fcf5277075774022d2da44840ae5 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 29 Dec 2023 00:09:11 +0100 Subject: [PATCH 3/4] simd_scatter: mention left-to-right order --- library/core/src/intrinsics/simd.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/core/src/intrinsics/simd.rs b/library/core/src/intrinsics/simd.rs index d52f04bf3e004..97eca28ec054a 100644 --- a/library/core/src/intrinsics/simd.rs +++ b/library/core/src/intrinsics/simd.rs @@ -245,6 +245,9 @@ extern "platform-intrinsic" { /// corresponding value in `val` to the pointer. /// Otherwise if the corresponding value in `mask` is `0`, do nothing. /// + /// The stores happen in left-to-right order. + /// (This is relevant in case two of the stores overlap.) + /// /// # Safety /// Unmasked values in `T` must be writeable as if by `::write` (e.g. aligned to the element /// type). From 3bc490d814b126087d2a5f564688fb6991025b86 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 10 Feb 2024 10:19:57 +0100 Subject: [PATCH 4/4] various docs tweaks --- library/core/src/intrinsics/simd.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/core/src/intrinsics/simd.rs b/library/core/src/intrinsics/simd.rs index 97eca28ec054a..ef4c65639eb4d 100644 --- a/library/core/src/intrinsics/simd.rs +++ b/library/core/src/intrinsics/simd.rs @@ -204,7 +204,7 @@ extern "platform-intrinsic" { /// /// `T` must be a vector. /// - /// `V` must be a vector with the same element type as `T` and the same length as `IDX`. + /// `U` must be a vector with the same element type as `T` and the same length as `IDX`. /// /// Returns a new vector such that element `i` is selected from `xy[IDX[i]]`, where `xy` /// is the concatenation of `x` and `y`. It is a compile-time error if `IDX[i]` is out-of-bounds @@ -485,24 +485,24 @@ extern "platform-intrinsic" { /// `T` must be a vector of integers. pub fn simd_cttz(x: T) -> T; - /// Round up each element to the next highest integer. + /// Round up each element to the next highest integer-valued float. /// /// `T` must be a vector of floats. pub fn simd_ceil(x: T) -> T; - /// Round down each element to the next lowest integer. + /// Round down each element to the next lowest integer-valued float. /// /// `T` must be a vector of floats. pub fn simd_floor(x: T) -> T; - /// Round each element to the closest integer. - /// Ties are resolving by rounding away from 0. + /// Round each element to the closest integer-valued float. + /// Ties are resolved by rounding away from 0. /// /// `T` must be a vector of floats. pub fn simd_round(x: T) -> T; - /// Return the integer part of each element. - /// This means that non-integer numbers are always truncated towards zero. + /// Return the integer part of each element as an integer-valued float. + /// In other words, non-integer values are truncated towards zero. /// /// `T` must be a vector of floats. pub fn simd_trunc(x: T) -> T;