Skip to content

Commit d7ae8a8

Browse files
authored
Rollup merge of #153675 - RalfJung:simd-overflow, r=scottmcm
simd_add/sub/mul/neg: document overflow behavior `simd_neg` had an odd comment about overflow not being UB, without saying what the behavior is instead. Replace that by just saying this uses wrapping arithmetic, and add the same for add/sub/mul. div/rem are already documented to cause UB on div-by-zero and min-div-by-minus-one, and shl/shr cause UB on too large shift amounts.
2 parents d7c9df9 + d7923d4 commit d7ae8a8

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

library/core/src/intrinsics/simd.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,23 @@ pub const unsafe fn simd_splat<T, U>(value: U) -> T;
6262
/// Adds two simd vectors elementwise.
6363
///
6464
/// `T` must be a vector of integers or floats.
65+
/// For integers, wrapping arithmetic is used.
6566
#[rustc_intrinsic]
6667
#[rustc_nounwind]
6768
pub const unsafe fn simd_add<T>(x: T, y: T) -> T;
6869

6970
/// Subtracts `rhs` from `lhs` elementwise.
7071
///
7172
/// `T` must be a vector of integers or floats.
73+
/// For integers, wrapping arithmetic is used.
7274
#[rustc_intrinsic]
7375
#[rustc_nounwind]
7476
pub const unsafe fn simd_sub<T>(lhs: T, rhs: T) -> T;
7577

7678
/// Multiplies two simd vectors elementwise.
7779
///
7880
/// `T` must be a vector of integers or floats.
81+
/// For integers, wrapping arithmetic is used.
7982
#[rustc_intrinsic]
8083
#[rustc_nounwind]
8184
pub const unsafe fn simd_mul<T>(x: T, y: T) -> T;
@@ -233,8 +236,7 @@ pub const unsafe fn simd_as<T, U>(x: T) -> U;
233236
/// Negates a vector elementwise.
234237
///
235238
/// `T` must be a vector of integers or floats.
236-
///
237-
/// Rust panics for `-<int>::Min` due to overflow, but it is not UB with this intrinsic.
239+
/// For integers, wrapping arithmetic is used.
238240
#[rustc_intrinsic]
239241
#[rustc_nounwind]
240242
pub const unsafe fn simd_neg<T>(x: T) -> T;

0 commit comments

Comments
 (0)