Skip to content

Commit c8c07a5

Browse files
committed
Further explain semantics
1 parent 2d921d8 commit c8c07a5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

library/core/src/intrinsics/simd.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,22 @@ extern "platform-intrinsic" {
8383
/// Otherwise, truncates or extends the value, maintaining the sign for signed integers.
8484
///
8585
/// # Safety
86-
/// Casting floats to integers truncates, but the truncated value must fit in the target type.
86+
/// Casting from integer types is always safe.
87+
/// Casting between two float types is also always safe.
88+
///
89+
/// Casting floats to integers truncates, following the same rules as `to_int_unchecked`.
90+
/// Specifically, each element must:
91+
/// * Not be `NaN`
92+
/// * Not be infinite
93+
/// * Be representable in the return type, after truncating off its fractional part
8794
pub fn simd_cast<T, U>(x: T) -> U;
8895

8996
/// Numerically cast a vector, elementwise.
9097
///
9198
/// `T` and `U` be a vectors of integer or floating point primitive types, and must have the
9299
/// same length.
93100
///
94-
/// Like `simd_cast`, but saturates float-to-integer conversions.
101+
/// Like `simd_cast`, but saturates float-to-integer conversions (NaN becomes 0).
95102
/// This matches regular `as` and is always safe.
96103
///
97104
/// When casting floats to integers, the result is truncated.
@@ -337,6 +344,10 @@ extern "platform-intrinsic" {
337344
/// For example, `[!0, 0, !0, !0]` packs to `0b1101` on little endian and `0b1011` on big
338345
/// endian.
339346
///
347+
/// To consider a larger example, `[!0, 0, 0, 0, 0, 0, 0, 0, !0, !0, 0, 0, 0, 0, !0, 0]` packs
348+
/// to `[0b00000001, 0b01000011]` or `0b0100001100000001` on little endian, and `[0b10000000,
349+
/// 0b11000010]` or `0b1000000011000010` on big endian.
350+
///
340351
/// # Safety
341352
/// `x` must contain only `0` and `!0`.
342353
pub fn simd_bitmask<T, U>(x: T) -> U;

0 commit comments

Comments
 (0)