Skip to content

Commit 71a5698

Browse files
committed
Improve simd_bitmask documentation and other minor fixes
1 parent 560ac23 commit 71a5698

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

library/core/src/intrinsics/simd.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ extern "platform-intrinsic" {
199199
///
200200
/// `V` must be a vector of integers with the same length as `T` (but any element size).
201201
///
202+
/// `idx` must be a constant.
203+
///
202204
/// For each pointer in `ptr`, if the corresponding value in `mask` is `!0`, read the pointer.
203205
/// Otherwise if the corresponding value in `mask` is `0`, return the corresponding value from
204206
/// `val`.
@@ -319,15 +321,20 @@ extern "platform-intrinsic" {
319321
/// `T` must be an integer vector.
320322
///
321323
/// `U` must be either the smallest unsigned integer with at least as many bits as the length
324+
/// of `T`, or the smallest array of `u8` with as many bits as the length of `T`.
322325
///
323326
/// Each element is truncated to a single bit and packed into the result.
324327
///
325-
/// The bit order depends on the byte endianness.
326-
/// The bitmask is always packed into the smallest/first bits, but the order is LSB-first for
327-
/// little endian and MSB-first for big endian.
328-
/// In other words, the LSB corresponds to the first vector element for little endian,
329-
/// and the last vector element for big endian.
330-
/// of `T`, or the smallest array of `u8` with as many bits as the length of `T`.
328+
/// No matter whether the output is an array or an unsigned integer, it is treated as a single
329+
/// contiguous list of bits. The bitmask is always packed on the least-significant side of the
330+
/// output, and padded with 0s in the most-significant bits. The order of the bits depends on
331+
/// endianess:
332+
///
333+
/// * On little endian, the least significant bit corresponds to the first vector element.
334+
/// * On big endian, the least significant bit corresponds to the last vector element.
335+
///
336+
/// For example, `[-1, 0, -1, -1]` packs to `0b1101` on little endian and `0b1011` on big
337+
/// endian.
331338
///
332339
/// # Safety
333340
/// `x` must contain only `0` and `!0`.
@@ -349,7 +356,7 @@ extern "platform-intrinsic" {
349356

350357
/// Select elements from a bitmask.
351358
///
352-
/// `M` must be an unsigned integer of type matching `simd_bitmask`.
359+
/// `M` must be an unsigned integer or array of `u8`, matching `simd_bitmask`.
353360
///
354361
/// `T` must be a vector.
355362
///
@@ -360,7 +367,7 @@ extern "platform-intrinsic" {
360367
/// The bitmask bit order matches `simd_bitmask`.
361368
///
362369
/// # Safety
363-
/// `mask` must only contain `0` and `!0`.
370+
/// Padding bits must be all zero.
364371
pub fn simd_select_bitmask<M, T>(m: M, yes: T, no: T) -> T;
365372

366373
/// Elementwise calculates the offset from a pointer vector, potentially wrapping.

0 commit comments

Comments
 (0)