From 25fe3cc69d3f14d3985aa053ed8962cffcbdc842 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 17 Feb 2024 09:14:45 +0100 Subject: [PATCH] intrinsics::simd: add missing functions --- library/core/src/intrinsics/simd.rs | 103 ++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/library/core/src/intrinsics/simd.rs b/library/core/src/intrinsics/simd.rs index 588891ffa4d5..9d70b0833828 100644 --- a/library/core/src/intrinsics/simd.rs +++ b/library/core/src/intrinsics/simd.rs @@ -3,6 +3,24 @@ //! In this module, a "vector" is any `repr(simd)` type. extern "platform-intrinsic" { + /// Insert an element into a vector, returning the updated vector. + /// + /// `T` must be a vector with element type `U`. + /// + /// # Safety + /// + /// `idx` must be in-bounds of the vector. + pub fn simd_insert(x: T, idx: u32, val: U) -> T; + + /// Extract an element from a vector. + /// + /// `T` must be a vector with element type `U`. + /// + /// # Safety + /// + /// `idx` must be in-bounds of the vector. + pub fn simd_extract(x: T, idx: u32) -> U; + /// Add two simd vectors elementwise. /// /// `T` must be a vector of integer or floating point primitive types. @@ -317,6 +335,18 @@ extern "platform-intrinsic" { /// Starting with the value `y`, add the elements of `x` and accumulate. pub fn simd_reduce_add_ordered(x: T, y: U) -> U; + /// Add elements within a vector in arbitrary order, and without regard + /// for signed zeros. + /// + /// `T` must be a vector of integer or floating-point primitive types. + /// + /// `U` must be the element type of `T`. + /// + /// # Safety + /// + /// All input elements must be finite (i.e., not NAN and not +/- INF). + pub fn simd_reduce_add_unordered(x: T) -> U; + /// Multiply elements within a vector from left to right. /// /// `T` must be a vector of integer or floating-point primitive types. @@ -326,6 +356,18 @@ extern "platform-intrinsic" { /// Starting with the value `y`, multiply the elements of `x` and accumulate. pub fn simd_reduce_mul_ordered(x: T, y: U) -> U; + /// Multiply elements within a vector in arbitrary order, and without regard + /// for signed zeros. + /// + /// `T` must be a vector of integer or floating-point primitive types. + /// + /// `U` must be the element type of `T`. + /// + /// # Safety + /// + /// All input elements must be finite (i.e., not NAN and not +/- INF). + pub fn simd_reduce_mul_unordered(x: T) -> U; + /// Check if all mask values are true. /// /// `T` must be a vector of integer primitive types. @@ -351,6 +393,19 @@ extern "platform-intrinsic" { /// For floating-point values, uses IEEE-754 `maxNum`. pub fn simd_reduce_max(x: T) -> U; + /// Return the maximum element of a vector. + /// + /// `T` must be a vector of integer or floating-point primitive types. + /// + /// `U` must be the element type of `T`. + /// + /// For floating-point values, uses IEEE-754 `maxNum`. + /// + /// # Safety + /// + /// All input elements must be finite (i.e., not NAN and not +/- INF). + pub fn simd_reduce_max_nanless(x: T) -> U; + /// Return the minimum element of a vector. /// /// `T` must be a vector of integer or floating-point primitive types. @@ -360,6 +415,19 @@ extern "platform-intrinsic" { /// For floating-point values, uses IEEE-754 `minNum`. pub fn simd_reduce_min(x: T) -> U; + /// Return the minimum element of a vector. + /// + /// `T` must be a vector of integer or floating-point primitive types. + /// + /// `U` must be the element type of `T`. + /// + /// For floating-point values, uses IEEE-754 `minNum`. + /// + /// # Safety + /// + /// All input elements must be finite (i.e., not NAN and not +/- INF). + pub fn simd_reduce_min_nanless(x: T) -> U; + /// Logical "and" all elements together. /// /// `T` must be a vector of integer or floating-point primitive types. @@ -518,4 +586,39 @@ extern "platform-intrinsic" { /// /// `T` must be a vector of floats. pub fn simd_fma(x: T, y: T, z: T) -> T; + + // Computes the sine of each element. + /// + /// `T` must be a vector of floats. + pub fn simd_fsin(a: T) -> T; + + // Computes the cosine of each element. + /// + /// `T` must be a vector of floats. + pub fn simd_fcos(a: T) -> T; + + // Computes the exponential function of each element. + /// + /// `T` must be a vector of floats. + pub fn simd_fexp(a: T) -> T; + + // Computes 2 raised to the power of each element. + /// + /// `T` must be a vector of floats. + pub fn simd_fexp2(a: T) -> T; + + // Computes the base 10 logarithm of each element. + /// + /// `T` must be a vector of floats. + pub fn simd_flog10(a: T) -> T; + + // Computes the base 2 logarithm of each element. + /// + /// `T` must be a vector of floats. + pub fn simd_flog2(a: T) -> T; + + // Computes the natural logarithm of each element. + /// + /// `T` must be a vector of floats. + pub fn simd_flog(a: T) -> T; }