diff --git a/fearless_simd/src/generated/avx2.rs b/fearless_simd/src/generated/avx2.rs index 4a0bd797..ec2711f9 100644 --- a/fearless_simd/src/generated/avx2.rs +++ b/fearless_simd/src/generated/avx2.rs @@ -1021,6 +1021,14 @@ impl Simd for Avx2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i8x16(self, a: i8x16) -> i8x16 { + self.neg_i8x16(self.max_i8x16(a, self.splat_i8x16(const { i8::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i8x16(self, a: i8x16) -> i8x16 { + self.abs_i8x16(self.max_i8x16(a, self.splat_i8x16(const { i8::MIN + 1 }))) + } + #[inline(always)] fn mul_i8x16(self, a: i8x16, b: i8x16) -> i8x16 { crate::kernel!( #[inline(always)] @@ -2746,6 +2754,14 @@ impl Simd for Avx2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i16x8(self, a: i16x8) -> i16x8 { + self.neg_i16x8(self.max_i16x8(a, self.splat_i16x8(const { i16::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i16x8(self, a: i16x8) -> i16x8 { + self.abs_i16x8(self.max_i16x8(a, self.splat_i16x8(const { i16::MIN + 1 }))) + } + #[inline(always)] fn mul_i16x8(self, a: i16x8, b: i16x8) -> i16x8 { crate::kernel!( #[inline(always)] @@ -4372,6 +4388,14 @@ impl Simd for Avx2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i32x4(self, a: i32x4) -> i32x4 { + self.neg_i32x4(self.max_i32x4(a, self.splat_i32x4(const { i32::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i32x4(self, a: i32x4) -> i32x4 { + self.abs_i32x4(self.max_i32x4(a, self.splat_i32x4(const { i32::MIN + 1 }))) + } + #[inline(always)] fn mul_i32x4(self, a: i32x4, b: i32x4) -> i32x4 { crate::kernel!( #[inline(always)] @@ -6640,6 +6664,18 @@ impl Simd for Avx2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i64x2(self, a: i64x2) -> i64x2 { + let t = self.neg_i64x2(a); + let mask = self.simd_eq_i64x2(t, self.splat_i64x2(i64::MIN)); + self.xor_i64x2(t, self.to_vector_mask64x2(mask)) + } + #[inline(always)] + fn saturating_abs_i64x2(self, a: i64x2) -> i64x2 { + let t = self.abs_i64x2(a); + let mask = self.simd_eq_i64x2(t, self.splat_i64x2(i64::MIN)); + self.xor_i64x2(t, self.to_vector_mask64x2(mask)) + } + #[inline(always)] fn mul_i64x2(self, a: i64x2, b: i64x2) -> i64x2 { crate::kernel!( #[inline(always)] @@ -8775,6 +8811,14 @@ impl Simd for Avx2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i8x32(self, a: i8x32) -> i8x32 { + self.neg_i8x32(self.max_i8x32(a, self.splat_i8x32(const { i8::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i8x32(self, a: i8x32) -> i8x32 { + self.abs_i8x32(self.max_i8x32(a, self.splat_i8x32(const { i8::MIN + 1 }))) + } + #[inline(always)] fn mul_i8x32(self, a: i8x32, b: i8x32) -> i8x32 { crate::kernel!( #[inline(always)] @@ -10588,6 +10632,14 @@ impl Simd for Avx2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i16x16(self, a: i16x16) -> i16x16 { + self.neg_i16x16(self.max_i16x16(a, self.splat_i16x16(const { i16::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i16x16(self, a: i16x16) -> i16x16 { + self.abs_i16x16(self.max_i16x16(a, self.splat_i16x16(const { i16::MIN + 1 }))) + } + #[inline(always)] fn mul_i16x16(self, a: i16x16, b: i16x16) -> i16x16 { crate::kernel!( #[inline(always)] @@ -12209,6 +12261,14 @@ impl Simd for Avx2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i32x8(self, a: i32x8) -> i32x8 { + self.neg_i32x8(self.max_i32x8(a, self.splat_i32x8(const { i32::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i32x8(self, a: i32x8) -> i32x8 { + self.abs_i32x8(self.max_i32x8(a, self.splat_i32x8(const { i32::MIN + 1 }))) + } + #[inline(always)] fn mul_i32x8(self, a: i32x8, b: i32x8) -> i32x8 { crate::kernel!( #[inline(always)] @@ -14476,6 +14536,18 @@ impl Simd for Avx2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i64x4(self, a: i64x4) -> i64x4 { + let t = self.neg_i64x4(a); + let mask = self.simd_eq_i64x4(t, self.splat_i64x4(i64::MIN)); + self.xor_i64x4(t, self.to_vector_mask64x4(mask)) + } + #[inline(always)] + fn saturating_abs_i64x4(self, a: i64x4) -> i64x4 { + let t = self.abs_i64x4(a); + let mask = self.simd_eq_i64x4(t, self.splat_i64x4(i64::MIN)); + self.xor_i64x4(t, self.to_vector_mask64x4(mask)) + } + #[inline(always)] fn mul_i64x4(self, a: i64x4, b: i64x4) -> i64x4 { crate::kernel!( #[inline(always)] diff --git a/fearless_simd/src/generated/avx512.rs b/fearless_simd/src/generated/avx512.rs index 5a880cf3..8b52d0c9 100644 --- a/fearless_simd/src/generated/avx512.rs +++ b/fearless_simd/src/generated/avx512.rs @@ -1336,6 +1336,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i8x16(self, a: i8x16) -> i8x16 { + self.neg_i8x16(self.max_i8x16(a, self.splat_i8x16(const { i8::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i8x16(self, a: i8x16) -> i8x16 { + self.abs_i8x16(self.max_i8x16(a, self.splat_i8x16(const { i8::MIN + 1 }))) + } + #[inline(always)] fn mul_i8x16(self, a: i8x16, b: i8x16) -> i8x16 { crate::kernel!( #[inline(always)] @@ -3017,6 +3025,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i16x8(self, a: i16x8) -> i16x8 { + self.neg_i16x8(self.max_i16x8(a, self.splat_i16x8(const { i16::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i16x8(self, a: i16x8) -> i16x8 { + self.abs_i16x8(self.max_i16x8(a, self.splat_i16x8(const { i16::MIN + 1 }))) + } + #[inline(always)] fn mul_i16x8(self, a: i16x8, b: i16x8) -> i16x8 { crate::kernel!( #[inline(always)] @@ -4594,6 +4610,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i32x4(self, a: i32x4) -> i32x4 { + self.neg_i32x4(self.max_i32x4(a, self.splat_i32x4(const { i32::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i32x4(self, a: i32x4) -> i32x4 { + self.abs_i32x4(self.max_i32x4(a, self.splat_i32x4(const { i32::MIN + 1 }))) + } + #[inline(always)] fn mul_i32x4(self, a: i32x4, b: i32x4) -> i32x4 { crate::kernel!( #[inline(always)] @@ -6856,6 +6880,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i64x2(self, a: i64x2) -> i64x2 { + self.neg_i64x2(self.max_i64x2(a, self.splat_i64x2(const { i64::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i64x2(self, a: i64x2) -> i64x2 { + self.abs_i64x2(self.max_i64x2(a, self.splat_i64x2(const { i64::MIN + 1 }))) + } + #[inline(always)] fn mul_i64x2(self, a: i64x2, b: i64x2) -> i64x2 { crate::kernel!( #[inline(always)] @@ -8973,6 +9005,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i8x32(self, a: i8x32) -> i8x32 { + self.neg_i8x32(self.max_i8x32(a, self.splat_i8x32(const { i8::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i8x32(self, a: i8x32) -> i8x32 { + self.abs_i8x32(self.max_i8x32(a, self.splat_i8x32(const { i8::MIN + 1 }))) + } + #[inline(always)] fn mul_i8x32(self, a: i8x32, b: i8x32) -> i8x32 { crate::kernel!( #[inline(always)] @@ -10633,6 +10673,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i16x16(self, a: i16x16) -> i16x16 { + self.neg_i16x16(self.max_i16x16(a, self.splat_i16x16(const { i16::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i16x16(self, a: i16x16) -> i16x16 { + self.abs_i16x16(self.max_i16x16(a, self.splat_i16x16(const { i16::MIN + 1 }))) + } + #[inline(always)] fn mul_i16x16(self, a: i16x16, b: i16x16) -> i16x16 { crate::kernel!( #[inline(always)] @@ -12209,6 +12257,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i32x8(self, a: i32x8) -> i32x8 { + self.neg_i32x8(self.max_i32x8(a, self.splat_i32x8(const { i32::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i32x8(self, a: i32x8) -> i32x8 { + self.abs_i32x8(self.max_i32x8(a, self.splat_i32x8(const { i32::MIN + 1 }))) + } + #[inline(always)] fn mul_i32x8(self, a: i32x8, b: i32x8) -> i32x8 { crate::kernel!( #[inline(always)] @@ -14423,6 +14479,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i64x4(self, a: i64x4) -> i64x4 { + self.neg_i64x4(self.max_i64x4(a, self.splat_i64x4(const { i64::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i64x4(self, a: i64x4) -> i64x4 { + self.abs_i64x4(self.max_i64x4(a, self.splat_i64x4(const { i64::MIN + 1 }))) + } + #[inline(always)] fn mul_i64x4(self, a: i64x4, b: i64x4) -> i64x4 { crate::kernel!( #[inline(always)] @@ -16523,6 +16587,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i8x64(self, a: i8x64) -> i8x64 { + self.neg_i8x64(self.max_i8x64(a, self.splat_i8x64(const { i8::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i8x64(self, a: i8x64) -> i8x64 { + self.abs_i8x64(self.max_i8x64(a, self.splat_i8x64(const { i8::MIN + 1 }))) + } + #[inline(always)] fn mul_i8x64(self, a: i8x64, b: i8x64) -> i8x64 { crate::kernel!( #[inline(always)] @@ -18154,6 +18226,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i16x32(self, a: i16x32) -> i16x32 { + self.neg_i16x32(self.max_i16x32(a, self.splat_i16x32(const { i16::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i16x32(self, a: i16x32) -> i16x32 { + self.abs_i16x32(self.max_i16x32(a, self.splat_i16x32(const { i16::MIN + 1 }))) + } + #[inline(always)] fn mul_i16x32(self, a: i16x32, b: i16x32) -> i16x32 { crate::kernel!( #[inline(always)] @@ -19755,6 +19835,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i32x16(self, a: i32x16) -> i32x16 { + self.neg_i32x16(self.max_i32x16(a, self.splat_i32x16(const { i32::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i32x16(self, a: i32x16) -> i32x16 { + self.abs_i32x16(self.max_i32x16(a, self.splat_i32x16(const { i32::MIN + 1 }))) + } + #[inline(always)] fn mul_i32x16(self, a: i32x16, b: i32x16) -> i32x16 { crate::kernel!( #[inline(always)] @@ -22015,6 +22103,14 @@ impl Simd for Avx512 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i64x8(self, a: i64x8) -> i64x8 { + self.neg_i64x8(self.max_i64x8(a, self.splat_i64x8(const { i64::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i64x8(self, a: i64x8) -> i64x8 { + self.abs_i64x8(self.max_i64x8(a, self.splat_i64x8(const { i64::MIN + 1 }))) + } + #[inline(always)] fn mul_i64x8(self, a: i64x8, b: i64x8) -> i64x8 { crate::kernel!( #[inline(always)] diff --git a/fearless_simd/src/generated/fallback.rs b/fearless_simd/src/generated/fallback.rs index 2c96eb24..c99fe71d 100644 --- a/fearless_simd/src/generated/fallback.rs +++ b/fearless_simd/src/generated/fallback.rs @@ -908,6 +908,50 @@ impl Simd for Fallback { .simd_into(self) } #[inline(always)] + fn saturating_neg_i8x16(self, a: i8x16) -> i8x16 { + [ + i8::saturating_neg(a[0usize]), + i8::saturating_neg(a[1usize]), + i8::saturating_neg(a[2usize]), + i8::saturating_neg(a[3usize]), + i8::saturating_neg(a[4usize]), + i8::saturating_neg(a[5usize]), + i8::saturating_neg(a[6usize]), + i8::saturating_neg(a[7usize]), + i8::saturating_neg(a[8usize]), + i8::saturating_neg(a[9usize]), + i8::saturating_neg(a[10usize]), + i8::saturating_neg(a[11usize]), + i8::saturating_neg(a[12usize]), + i8::saturating_neg(a[13usize]), + i8::saturating_neg(a[14usize]), + i8::saturating_neg(a[15usize]), + ] + .simd_into(self) + } + #[inline(always)] + fn saturating_abs_i8x16(self, a: i8x16) -> i8x16 { + [ + i8::saturating_abs(a[0usize]), + i8::saturating_abs(a[1usize]), + i8::saturating_abs(a[2usize]), + i8::saturating_abs(a[3usize]), + i8::saturating_abs(a[4usize]), + i8::saturating_abs(a[5usize]), + i8::saturating_abs(a[6usize]), + i8::saturating_abs(a[7usize]), + i8::saturating_abs(a[8usize]), + i8::saturating_abs(a[9usize]), + i8::saturating_abs(a[10usize]), + i8::saturating_abs(a[11usize]), + i8::saturating_abs(a[12usize]), + i8::saturating_abs(a[13usize]), + i8::saturating_abs(a[14usize]), + i8::saturating_abs(a[15usize]), + ] + .simd_into(self) + } + #[inline(always)] fn mul_i8x16(self, a: i8x16, b: i8x16) -> i8x16 { [ i8::wrapping_mul(a[0usize], b[0usize]), @@ -3468,6 +3512,34 @@ impl Simd for Fallback { .simd_into(self) } #[inline(always)] + fn saturating_neg_i16x8(self, a: i16x8) -> i16x8 { + [ + i16::saturating_neg(a[0usize]), + i16::saturating_neg(a[1usize]), + i16::saturating_neg(a[2usize]), + i16::saturating_neg(a[3usize]), + i16::saturating_neg(a[4usize]), + i16::saturating_neg(a[5usize]), + i16::saturating_neg(a[6usize]), + i16::saturating_neg(a[7usize]), + ] + .simd_into(self) + } + #[inline(always)] + fn saturating_abs_i16x8(self, a: i16x8) -> i16x8 { + [ + i16::saturating_abs(a[0usize]), + i16::saturating_abs(a[1usize]), + i16::saturating_abs(a[2usize]), + i16::saturating_abs(a[3usize]), + i16::saturating_abs(a[4usize]), + i16::saturating_abs(a[5usize]), + i16::saturating_abs(a[6usize]), + i16::saturating_abs(a[7usize]), + ] + .simd_into(self) + } + #[inline(always)] fn mul_i16x8(self, a: i16x8, b: i16x8) -> i16x8 { [ i16::wrapping_mul(a[0usize], b[0usize]), @@ -5230,6 +5302,26 @@ impl Simd for Fallback { .simd_into(self) } #[inline(always)] + fn saturating_neg_i32x4(self, a: i32x4) -> i32x4 { + [ + i32::saturating_neg(a[0usize]), + i32::saturating_neg(a[1usize]), + i32::saturating_neg(a[2usize]), + i32::saturating_neg(a[3usize]), + ] + .simd_into(self) + } + #[inline(always)] + fn saturating_abs_i32x4(self, a: i32x4) -> i32x4 { + [ + i32::saturating_abs(a[0usize]), + i32::saturating_abs(a[1usize]), + i32::saturating_abs(a[2usize]), + i32::saturating_abs(a[3usize]), + ] + .simd_into(self) + } + #[inline(always)] fn mul_i32x4(self, a: i32x4, b: i32x4) -> i32x4 { [ i32::wrapping_mul(a[0usize], b[0usize]), @@ -6850,6 +6942,22 @@ impl Simd for Fallback { .simd_into(self) } #[inline(always)] + fn saturating_neg_i64x2(self, a: i64x2) -> i64x2 { + [ + i64::saturating_neg(a[0usize]), + i64::saturating_neg(a[1usize]), + ] + .simd_into(self) + } + #[inline(always)] + fn saturating_abs_i64x2(self, a: i64x2) -> i64x2 { + [ + i64::saturating_abs(a[0usize]), + i64::saturating_abs(a[1usize]), + ] + .simd_into(self) + } + #[inline(always)] fn mul_i64x2(self, a: i64x2, b: i64x2) -> i64x2 { [ i64::wrapping_mul(a[0usize], b[0usize]), diff --git a/fearless_simd/src/generated/neon.rs b/fearless_simd/src/generated/neon.rs index 4b8fcf03..9026e7d1 100644 --- a/fearless_simd/src/generated/neon.rs +++ b/fearless_simd/src/generated/neon.rs @@ -898,6 +898,26 @@ impl Simd for Neon { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i8x16(self, a: i8x16) -> i8x16 { + crate::kernel!( + #[inline(always)] + fn kernel(token: Neon, a: i8x16) -> i8x16 { + vqnegq_s8(a.into()).simd_into(token) + } + ); + kernel(self, a) + } + #[inline(always)] + fn saturating_abs_i8x16(self, a: i8x16) -> i8x16 { + crate::kernel!( + #[inline(always)] + fn kernel(token: Neon, a: i8x16) -> i8x16 { + vqabsq_s8(a.into()).simd_into(token) + } + ); + kernel(self, a) + } + #[inline(always)] fn mul_i8x16(self, a: i8x16, b: i8x16) -> i8x16 { crate::kernel!( #[inline(always)] @@ -2351,6 +2371,26 @@ impl Simd for Neon { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i16x8(self, a: i16x8) -> i16x8 { + crate::kernel!( + #[inline(always)] + fn kernel(token: Neon, a: i16x8) -> i16x8 { + vqnegq_s16(a.into()).simd_into(token) + } + ); + kernel(self, a) + } + #[inline(always)] + fn saturating_abs_i16x8(self, a: i16x8) -> i16x8 { + crate::kernel!( + #[inline(always)] + fn kernel(token: Neon, a: i16x8) -> i16x8 { + vqabsq_s16(a.into()).simd_into(token) + } + ); + kernel(self, a) + } + #[inline(always)] fn mul_i16x8(self, a: i16x8, b: i16x8) -> i16x8 { crate::kernel!( #[inline(always)] @@ -3775,6 +3815,26 @@ impl Simd for Neon { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i32x4(self, a: i32x4) -> i32x4 { + crate::kernel!( + #[inline(always)] + fn kernel(token: Neon, a: i32x4) -> i32x4 { + vqnegq_s32(a.into()).simd_into(token) + } + ); + kernel(self, a) + } + #[inline(always)] + fn saturating_abs_i32x4(self, a: i32x4) -> i32x4 { + crate::kernel!( + #[inline(always)] + fn kernel(token: Neon, a: i32x4) -> i32x4 { + vqabsq_s32(a.into()).simd_into(token) + } + ); + kernel(self, a) + } + #[inline(always)] fn mul_i32x4(self, a: i32x4, b: i32x4) -> i32x4 { crate::kernel!( #[inline(always)] @@ -5838,6 +5898,26 @@ impl Simd for Neon { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i64x2(self, a: i64x2) -> i64x2 { + crate::kernel!( + #[inline(always)] + fn kernel(token: Neon, a: i64x2) -> i64x2 { + vqnegq_s64(a.into()).simd_into(token) + } + ); + kernel(self, a) + } + #[inline(always)] + fn saturating_abs_i64x2(self, a: i64x2) -> i64x2 { + crate::kernel!( + #[inline(always)] + fn kernel(token: Neon, a: i64x2) -> i64x2 { + vqabsq_s64(a.into()).simd_into(token) + } + ); + kernel(self, a) + } + #[inline(always)] fn mul_i64x2(self, a: i64x2, b: i64x2) -> i64x2 { [ i64::wrapping_mul(a[0usize], b[0usize]), diff --git a/fearless_simd/src/generated/simd_trait.rs b/fearless_simd/src/generated/simd_trait.rs index aa4ac8b4..869ab81b 100644 --- a/fearless_simd/src/generated/simd_trait.rs +++ b/fearless_simd/src/generated/simd_trait.rs @@ -557,6 +557,10 @@ pub trait Simd: fn sub_i8x16(self, a: i8x16, b: i8x16) -> i8x16; #[doc = "Subtract two vectors element-wise, saturating on overflow.\n\n\"Saturating\" means that if the result is not representable, the closest representable value (either `Element::MAX` or `Element::MIN`) is returned.\n\nOn x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86."] fn saturating_sub_i8x16(self, a: i8x16, b: i8x16) -> i8x16; + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + fn saturating_neg_i8x16(self, a: i8x16) -> i8x16; + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + fn saturating_abs_i8x16(self, a: i8x16) -> i8x16; #[doc = "Multiply two vectors element-wise, wrapping on overflow."] fn mul_i8x16(self, a: i8x16, b: i8x16) -> i8x16; #[doc = "Compute the bitwise AND of two vectors."] @@ -722,6 +726,17 @@ pub trait Simd: fn sub_u8x16(self, a: u8x16, b: u8x16) -> u8x16; #[doc = "Subtract two vectors element-wise, saturating on overflow.\n\n\"Saturating\" means that if the result is not representable, the closest representable value (either `Element::MAX` or `Element::MIN`) is returned.\n\nOn x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86."] fn saturating_sub_u8x16(self, a: u8x16, b: u8x16) -> u8x16; + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u8x16(self, a: u8x16) -> u8x16 { + let _ = a; + self.splat_u8x16(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u8x16(self, a: u8x16) -> u8x16 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] fn mul_u8x16(self, a: u8x16, b: u8x16) -> u8x16; #[doc = "Compute the bitwise AND of two vectors."] @@ -963,6 +978,10 @@ pub trait Simd: fn sub_i16x8(self, a: i16x8, b: i16x8) -> i16x8; #[doc = "Subtract two vectors element-wise, saturating on overflow.\n\n\"Saturating\" means that if the result is not representable, the closest representable value (either `Element::MAX` or `Element::MIN`) is returned.\n\nOn x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86."] fn saturating_sub_i16x8(self, a: i16x8, b: i16x8) -> i16x8; + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + fn saturating_neg_i16x8(self, a: i16x8) -> i16x8; + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + fn saturating_abs_i16x8(self, a: i16x8) -> i16x8; #[doc = "Multiply two vectors element-wise, wrapping on overflow."] fn mul_i16x8(self, a: i16x8, b: i16x8) -> i16x8; #[doc = "Compute the bitwise AND of two vectors."] @@ -1157,6 +1176,17 @@ pub trait Simd: fn sub_u16x8(self, a: u16x8, b: u16x8) -> u16x8; #[doc = "Subtract two vectors element-wise, saturating on overflow.\n\n\"Saturating\" means that if the result is not representable, the closest representable value (either `Element::MAX` or `Element::MIN`) is returned.\n\nOn x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86."] fn saturating_sub_u16x8(self, a: u16x8, b: u16x8) -> u16x8; + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u16x8(self, a: u16x8) -> u16x8 { + let _ = a; + self.splat_u16x8(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u16x8(self, a: u16x8) -> u16x8 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] fn mul_u16x8(self, a: u16x8, b: u16x8) -> u16x8; #[doc = "Compute the bitwise AND of two vectors."] @@ -1406,6 +1436,10 @@ pub trait Simd: fn sub_i32x4(self, a: i32x4, b: i32x4) -> i32x4; #[doc = "Subtract two vectors element-wise, saturating on overflow.\n\n\"Saturating\" means that if the result is not representable, the closest representable value (either `Element::MAX` or `Element::MIN`) is returned.\n\nOn x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86."] fn saturating_sub_i32x4(self, a: i32x4, b: i32x4) -> i32x4; + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + fn saturating_neg_i32x4(self, a: i32x4) -> i32x4; + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + fn saturating_abs_i32x4(self, a: i32x4) -> i32x4; #[doc = "Multiply two vectors element-wise, wrapping on overflow."] fn mul_i32x4(self, a: i32x4, b: i32x4) -> i32x4; #[doc = "Compute the bitwise AND of two vectors."] @@ -1602,6 +1636,17 @@ pub trait Simd: fn sub_u32x4(self, a: u32x4, b: u32x4) -> u32x4; #[doc = "Subtract two vectors element-wise, saturating on overflow.\n\n\"Saturating\" means that if the result is not representable, the closest representable value (either `Element::MAX` or `Element::MIN`) is returned.\n\nOn x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86."] fn saturating_sub_u32x4(self, a: u32x4, b: u32x4) -> u32x4; + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u32x4(self, a: u32x4) -> u32x4 { + let _ = a; + self.splat_u32x4(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u32x4(self, a: u32x4) -> u32x4 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] fn mul_u32x4(self, a: u32x4, b: u32x4) -> u32x4; #[doc = "Compute the bitwise AND of two vectors."] @@ -2068,6 +2113,10 @@ pub trait Simd: fn sub_i64x2(self, a: i64x2, b: i64x2) -> i64x2; #[doc = "Subtract two vectors element-wise, saturating on overflow.\n\n\"Saturating\" means that if the result is not representable, the closest representable value (either `Element::MAX` or `Element::MIN`) is returned.\n\nOn x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86."] fn saturating_sub_i64x2(self, a: i64x2, b: i64x2) -> i64x2; + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + fn saturating_neg_i64x2(self, a: i64x2) -> i64x2; + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + fn saturating_abs_i64x2(self, a: i64x2) -> i64x2; #[doc = "Multiply two vectors element-wise, wrapping on overflow."] fn mul_i64x2(self, a: i64x2, b: i64x2) -> i64x2; #[doc = "Compute the bitwise AND of two vectors."] @@ -2254,6 +2303,17 @@ pub trait Simd: fn sub_u64x2(self, a: u64x2, b: u64x2) -> u64x2; #[doc = "Subtract two vectors element-wise, saturating on overflow.\n\n\"Saturating\" means that if the result is not representable, the closest representable value (either `Element::MAX` or `Element::MIN`) is returned.\n\nOn x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86."] fn saturating_sub_u64x2(self, a: u64x2, b: u64x2) -> u64x2; + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u64x2(self, a: u64x2) -> u64x2 { + let _ = a; + self.splat_u64x2(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u64x2(self, a: u64x2) -> u64x2 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] fn mul_u64x2(self, a: u64x2, b: u64x2) -> u64x2; #[doc = "Compute the bitwise AND of two vectors."] @@ -3032,6 +3092,18 @@ pub trait Simd: self.saturating_sub_i8x16(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_i8x32(self, a: i8x32) -> i8x32 { + let (a0, a1) = self.split_i8x32(a); + self.combine_i8x16(self.saturating_neg_i8x16(a0), self.saturating_neg_i8x16(a1)) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_i8x32(self, a: i8x32) -> i8x32 { + let (a0, a1) = self.split_i8x32(a); + self.combine_i8x16(self.saturating_abs_i8x16(a0), self.saturating_abs_i8x16(a1)) + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_i8x32(self, a: i8x32, b: i8x32) -> i8x32 { @@ -3436,6 +3508,17 @@ pub trait Simd: self.saturating_sub_u8x16(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u8x32(self, a: u8x32) -> u8x32 { + let _ = a; + self.splat_u8x32(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u8x32(self, a: u8x32) -> u8x32 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_u8x32(self, a: u8x32, b: u8x32) -> u8x32 { @@ -3991,6 +4074,18 @@ pub trait Simd: self.saturating_sub_i16x8(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_i16x16(self, a: i16x16) -> i16x16 { + let (a0, a1) = self.split_i16x16(a); + self.combine_i16x8(self.saturating_neg_i16x8(a0), self.saturating_neg_i16x8(a1)) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_i16x16(self, a: i16x16) -> i16x16 { + let (a0, a1) = self.split_i16x16(a); + self.combine_i16x8(self.saturating_abs_i16x8(a0), self.saturating_abs_i16x8(a1)) + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_i16x16(self, a: i16x16, b: i16x16) -> i16x16 { @@ -4441,6 +4536,17 @@ pub trait Simd: self.saturating_sub_u16x8(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u16x16(self, a: u16x16) -> u16x16 { + let _ = a; + self.splat_u16x16(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u16x16(self, a: u16x16) -> u16x16 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_u16x16(self, a: u16x16, b: u16x16) -> u16x16 { @@ -5026,6 +5132,18 @@ pub trait Simd: self.saturating_sub_i32x4(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_i32x8(self, a: i32x8) -> i32x8 { + let (a0, a1) = self.split_i32x8(a); + self.combine_i32x4(self.saturating_neg_i32x4(a0), self.saturating_neg_i32x4(a1)) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_i32x8(self, a: i32x8) -> i32x8 { + let (a0, a1) = self.split_i32x8(a); + self.combine_i32x4(self.saturating_abs_i32x4(a0), self.saturating_abs_i32x4(a1)) + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_i32x8(self, a: i32x8, b: i32x8) -> i32x8 { @@ -5478,6 +5596,17 @@ pub trait Simd: self.saturating_sub_u32x4(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u32x8(self, a: u32x8) -> u32x8 { + let _ = a; + self.splat_u32x8(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u32x8(self, a: u32x8) -> u32x8 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_u32x8(self, a: u32x8, b: u32x8) -> u32x8 { @@ -6568,6 +6697,18 @@ pub trait Simd: self.saturating_sub_i64x2(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_i64x4(self, a: i64x4) -> i64x4 { + let (a0, a1) = self.split_i64x4(a); + self.combine_i64x2(self.saturating_neg_i64x2(a0), self.saturating_neg_i64x2(a1)) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_i64x4(self, a: i64x4) -> i64x4 { + let (a0, a1) = self.split_i64x4(a); + self.combine_i64x2(self.saturating_abs_i64x2(a0), self.saturating_abs_i64x2(a1)) + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_i64x4(self, a: i64x4, b: i64x4) -> i64x4 { @@ -6969,6 +7110,17 @@ pub trait Simd: self.saturating_sub_u64x2(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u64x4(self, a: u64x4) -> u64x4 { + let _ = a; + self.splat_u64x4(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u64x4(self, a: u64x4) -> u64x4 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_u64x4(self, a: u64x4, b: u64x4) -> u64x4 { @@ -7990,6 +8142,18 @@ pub trait Simd: self.saturating_sub_i8x32(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_i8x64(self, a: i8x64) -> i8x64 { + let (a0, a1) = self.split_i8x64(a); + self.combine_i8x32(self.saturating_neg_i8x32(a0), self.saturating_neg_i8x32(a1)) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_i8x64(self, a: i8x64) -> i8x64 { + let (a0, a1) = self.split_i8x64(a); + self.combine_i8x32(self.saturating_abs_i8x32(a0), self.saturating_abs_i8x32(a1)) + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_i8x64(self, a: i8x64, b: i8x64) -> i8x64 { @@ -8392,6 +8556,17 @@ pub trait Simd: self.saturating_sub_u8x32(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u8x64(self, a: u8x64) -> u8x64 { + let _ = a; + self.splat_u8x64(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u8x64(self, a: u8x64) -> u8x64 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_u8x64(self, a: u8x64, b: u8x64) -> u8x64 { @@ -8943,6 +9118,24 @@ pub trait Simd: self.saturating_sub_i16x16(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_i16x32(self, a: i16x32) -> i16x32 { + let (a0, a1) = self.split_i16x32(a); + self.combine_i16x16( + self.saturating_neg_i16x16(a0), + self.saturating_neg_i16x16(a1), + ) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_i16x32(self, a: i16x32) -> i16x32 { + let (a0, a1) = self.split_i16x32(a); + self.combine_i16x16( + self.saturating_abs_i16x16(a0), + self.saturating_abs_i16x16(a1), + ) + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_i16x32(self, a: i16x32, b: i16x32) -> i16x32 { @@ -9397,6 +9590,17 @@ pub trait Simd: self.saturating_sub_u16x16(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u16x32(self, a: u16x32) -> u16x32 { + let _ = a; + self.splat_u16x32(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u16x32(self, a: u16x32) -> u16x32 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_u16x32(self, a: u16x32, b: u16x32) -> u16x32 { @@ -9991,6 +10195,18 @@ pub trait Simd: self.saturating_sub_i32x8(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_i32x16(self, a: i32x16) -> i32x16 { + let (a0, a1) = self.split_i32x16(a); + self.combine_i32x8(self.saturating_neg_i32x8(a0), self.saturating_neg_i32x8(a1)) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_i32x16(self, a: i32x16) -> i32x16 { + let (a0, a1) = self.split_i32x16(a); + self.combine_i32x8(self.saturating_abs_i32x8(a0), self.saturating_abs_i32x8(a1)) + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_i32x16(self, a: i32x16, b: i32x16) -> i32x16 { @@ -10445,6 +10661,17 @@ pub trait Simd: self.saturating_sub_u32x8(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u32x16(self, a: u32x16) -> u32x16 { + let _ = a; + self.splat_u32x16(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u32x16(self, a: u32x16) -> u32x16 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_u32x16(self, a: u32x16, b: u32x16) -> u32x16 { @@ -11529,6 +11756,18 @@ pub trait Simd: self.saturating_sub_i64x4(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_i64x8(self, a: i64x8) -> i64x8 { + let (a0, a1) = self.split_i64x8(a); + self.combine_i64x4(self.saturating_neg_i64x4(a0), self.saturating_neg_i64x4(a1)) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_i64x8(self, a: i64x8) -> i64x8 { + let (a0, a1) = self.split_i64x8(a); + self.combine_i64x4(self.saturating_abs_i64x4(a0), self.saturating_abs_i64x4(a1)) + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_i64x8(self, a: i64x8, b: i64x8) -> i64x8 { @@ -11928,6 +12167,17 @@ pub trait Simd: self.saturating_sub_u64x4(a1, b1), ) } + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_neg_u64x8(self, a: u64x8) -> u64x8 { + let _ = a; + self.splat_u64x8(0) + } + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + #[inline(always)] + fn saturating_abs_u64x8(self, a: u64x8) -> u64x8 { + a + } #[doc = "Multiply two vectors element-wise, wrapping on overflow."] #[inline(always)] fn mul_u64x8(self, a: u64x8, b: u64x8) -> u64x8 { @@ -13281,6 +13531,10 @@ pub trait SimdInt: fn saturating_add(self, rhs: impl SimdInto) -> Self; #[doc = "Subtract two vectors element-wise, saturating on overflow.\n\n\"Saturating\" means that if the result is not representable, the closest representable value (either `Element::MAX` or `Element::MIN`) is returned.\n\nOn x86 it is implemented in hardware only for 8-bit and 16-bit elements. For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86."] fn saturating_sub(self, rhs: impl SimdInto) -> Self; + #[doc = "Negate each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`."] + fn saturating_neg(self) -> Self; + #[doc = "Compute the absolute value of each element of the vector, saturating on overflow.\n\nFor unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`."] + fn saturating_abs(self) -> Self; } #[doc = r" Functionality implemented by SIMD masks."] #[doc = r""] diff --git a/fearless_simd/src/generated/simd_types.rs b/fearless_simd/src/generated/simd_types.rs index 9891b00e..7b6703cc 100644 --- a/fearless_simd/src/generated/simd_types.rs +++ b/fearless_simd/src/generated/simd_types.rs @@ -780,6 +780,14 @@ impl crate::SimdInt for i8x16 { self.simd .saturating_sub_i8x16(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i8x16(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i8x16(self) + } } impl SimdWiden for i8x16 { type Widened = i16x8; @@ -1169,6 +1177,14 @@ impl crate::SimdInt for u8x16 { self.simd .saturating_sub_u8x16(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u8x16(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u8x16(self) + } } impl SimdWiden for u8x16 { type Widened = u16x8; @@ -1693,6 +1709,14 @@ impl crate::SimdInt for i16x8 { self.simd .saturating_sub_i16x8(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i16x8(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i16x8(self) + } } impl SimdWiden for i16x8 { type Widened = i32x4; @@ -2089,6 +2113,14 @@ impl crate::SimdInt for u16x8 { self.simd .saturating_sub_u16x8(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u16x8(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u16x8(self) + } } impl SimdWiden for u16x8 { type Widened = u32x4; @@ -2623,6 +2655,14 @@ impl crate::SimdInt for i32x4 { self.simd .saturating_sub_i32x4(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i32x4(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i32x4(self) + } } impl SimdCvtTruncate> for i32x4 { #[doc = "Convert each floating-point element to a signed 32-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results."] @@ -3019,6 +3059,14 @@ impl crate::SimdInt for u32x4 { self.simd .saturating_sub_u32x4(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u32x4(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u32x4(self) + } } impl SimdCvtTruncate> for u32x4 { #[doc = "Convert each floating-point element to an unsigned 32-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results.\n\nOn x86 platforms below AVX-512, this operation will still be slower than converting to `i32`, because there is no native instruction for converting to `u32`.\nIf you know your values fit within range of an `i32`, you should convert to an `i32` and cast to your desired datatype afterwards."] @@ -3995,6 +4043,14 @@ impl crate::SimdInt for i64x2 { self.simd .saturating_sub_i64x2(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i64x2(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i64x2(self) + } } impl SimdCvtTruncate> for i64x2 { #[doc = "Convert each floating-point element to a signed 64-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results."] @@ -4365,6 +4421,14 @@ impl crate::SimdInt for u64x2 { self.simd .saturating_sub_u64x2(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u64x2(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u64x2(self) + } } impl SimdCvtTruncate> for u64x2 { #[doc = "Convert each floating-point element to an unsigned 64-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results."] @@ -5336,6 +5400,14 @@ impl crate::SimdInt for i8x32 { self.simd .saturating_sub_i8x32(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i8x32(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i8x32(self) + } } impl SimdWiden for i8x32 { type Widened = i16x16; @@ -5736,6 +5808,14 @@ impl crate::SimdInt for u8x32 { self.simd .saturating_sub_u8x32(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u8x32(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u8x32(self) + } } impl SimdWiden for u8x32 { type Widened = u16x16; @@ -6257,6 +6337,14 @@ impl crate::SimdInt for i16x16 { self.simd .saturating_sub_i16x16(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i16x16(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i16x16(self) + } } impl SimdWiden for i16x16 { type Widened = i32x8; @@ -6659,6 +6747,14 @@ impl crate::SimdInt for u16x16 { self.simd .saturating_sub_u16x16(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u16x16(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u16x16(self) + } } impl SimdWiden for u16x16 { type Widened = u32x8; @@ -7202,6 +7298,14 @@ impl crate::SimdInt for i32x8 { self.simd .saturating_sub_i32x8(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i32x8(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i32x8(self) + } } impl SimdCvtTruncate> for i32x8 { #[doc = "Convert each floating-point element to a signed 32-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results."] @@ -7605,6 +7709,14 @@ impl crate::SimdInt for u32x8 { self.simd .saturating_sub_u32x8(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u32x8(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u32x8(self) + } } impl SimdCvtTruncate> for u32x8 { #[doc = "Convert each floating-point element to an unsigned 32-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results.\n\nOn x86 platforms below AVX-512, this operation will still be slower than converting to `i32`, because there is no native instruction for converting to `u32`.\nIf you know your values fit within range of an `i32`, you should convert to an `i32` and cast to your desired datatype afterwards."] @@ -8578,6 +8690,14 @@ impl crate::SimdInt for i64x4 { self.simd .saturating_sub_i64x4(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i64x4(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i64x4(self) + } } impl SimdCvtTruncate> for i64x4 { #[doc = "Convert each floating-point element to a signed 64-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results."] @@ -8943,6 +9063,14 @@ impl crate::SimdInt for u64x4 { self.simd .saturating_sub_u64x4(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u64x4(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u64x4(self) + } } impl SimdCvtTruncate> for u64x4 { #[doc = "Convert each floating-point element to an unsigned 64-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results."] @@ -9952,6 +10080,14 @@ impl crate::SimdInt for i8x64 { self.simd .saturating_sub_i8x64(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i8x64(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i8x64(self) + } } impl SimdWiden for i8x64 { type Widened = i16x32; @@ -10378,6 +10514,14 @@ impl crate::SimdInt for u8x64 { self.simd .saturating_sub_u8x64(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u8x64(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u8x64(self) + } } impl SimdWiden for u8x64 { type Widened = u16x32; @@ -10902,6 +11046,14 @@ impl crate::SimdInt for i16x32 { self.simd .saturating_sub_i16x32(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i16x32(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i16x32(self) + } } impl SimdWiden for i16x32 { type Widened = i32x16; @@ -11314,6 +11466,14 @@ impl crate::SimdInt for u16x32 { self.simd .saturating_sub_u16x32(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u16x32(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u16x32(self) + } } impl SimdWiden for u16x32 { type Widened = u32x16; @@ -11853,6 +12013,14 @@ impl crate::SimdInt for i32x16 { self.simd .saturating_sub_i32x16(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i32x16(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i32x16(self) + } } impl SimdCvtTruncate> for i32x16 { #[doc = "Convert each floating-point element to a signed 32-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results."] @@ -12261,6 +12429,14 @@ impl crate::SimdInt for u32x16 { self.simd .saturating_sub_u32x16(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u32x16(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u32x16(self) + } } impl SimdCvtTruncate> for u32x16 { #[doc = "Convert each floating-point element to an unsigned 32-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results.\n\nOn x86 platforms below AVX-512, this operation will still be slower than converting to `i32`, because there is no native instruction for converting to `u32`.\nIf you know your values fit within range of an `i32`, you should convert to an `i32` and cast to your desired datatype afterwards."] @@ -13248,6 +13424,14 @@ impl crate::SimdInt for i64x8 { self.simd .saturating_sub_i64x8(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_i64x8(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_i64x8(self) + } } impl SimdCvtTruncate> for i64x8 { #[doc = "Convert each floating-point element to a signed 64-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results."] @@ -13619,6 +13803,14 @@ impl crate::SimdInt for u64x8 { self.simd .saturating_sub_u64x8(self, rhs.simd_into(self.simd)) } + #[inline(always)] + fn saturating_neg(self) -> Self { + self.simd.saturating_neg_u64x8(self) + } + #[inline(always)] + fn saturating_abs(self) -> Self { + self.simd.saturating_abs_u64x8(self) + } } impl SimdCvtTruncate> for u64x8 { #[doc = "Convert each floating-point element to an unsigned 64-bit integer, truncating towards zero.\n\nOut-of-range values or NaN will produce implementation-defined results."] diff --git a/fearless_simd/src/generated/sse2.rs b/fearless_simd/src/generated/sse2.rs index 13701067..a7ee5e80 100644 --- a/fearless_simd/src/generated/sse2.rs +++ b/fearless_simd/src/generated/sse2.rs @@ -1076,6 +1076,18 @@ impl Simd for Sse2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i8x16(self, a: i8x16) -> i8x16 { + let t = self.neg_i8x16(a); + let mask = self.simd_eq_i8x16(t, self.splat_i8x16(i8::MIN)); + self.xor_i8x16(t, self.to_vector_mask8x16(mask)) + } + #[inline(always)] + fn saturating_abs_i8x16(self, a: i8x16) -> i8x16 { + let t = self.abs_i8x16(a); + let mask = self.simd_eq_i8x16(t, self.splat_i8x16(i8::MIN)); + self.xor_i8x16(t, self.to_vector_mask8x16(mask)) + } + #[inline(always)] fn mul_i8x16(self, a: i8x16, b: i8x16) -> i8x16 { crate::kernel!( #[inline(always)] @@ -3015,6 +3027,14 @@ impl Simd for Sse2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i16x8(self, a: i16x8) -> i16x8 { + self.neg_i16x8(self.max_i16x8(a, self.splat_i16x8(const { i16::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i16x8(self, a: i16x8) -> i16x8 { + self.abs_i16x8(self.max_i16x8(a, self.splat_i16x8(const { i16::MIN + 1 }))) + } + #[inline(always)] fn mul_i16x8(self, a: i16x8, b: i16x8) -> i16x8 { crate::kernel!( #[inline(always)] @@ -4685,6 +4705,18 @@ impl Simd for Sse2 { .simd_into(self) } #[inline(always)] + fn saturating_neg_i32x4(self, a: i32x4) -> i32x4 { + let t = self.neg_i32x4(a); + let mask = self.simd_eq_i32x4(t, self.splat_i32x4(i32::MIN)); + self.xor_i32x4(t, self.to_vector_mask32x4(mask)) + } + #[inline(always)] + fn saturating_abs_i32x4(self, a: i32x4) -> i32x4 { + let t = self.abs_i32x4(a); + let mask = self.simd_eq_i32x4(t, self.splat_i32x4(i32::MIN)); + self.xor_i32x4(t, self.to_vector_mask32x4(mask)) + } + #[inline(always)] fn mul_i32x4(self, a: i32x4, b: i32x4) -> i32x4 { [ i32::wrapping_mul(a[0usize], b[0usize]), @@ -6950,6 +6982,18 @@ impl Simd for Sse2 { .simd_into(self) } #[inline(always)] + fn saturating_neg_i64x2(self, a: i64x2) -> i64x2 { + let t = self.neg_i64x2(a); + let mask = self.simd_eq_i64x2(t, self.splat_i64x2(i64::MIN)); + self.xor_i64x2(t, self.to_vector_mask64x2(mask)) + } + #[inline(always)] + fn saturating_abs_i64x2(self, a: i64x2) -> i64x2 { + let t = self.abs_i64x2(a); + let mask = self.simd_eq_i64x2(t, self.splat_i64x2(i64::MIN)); + self.xor_i64x2(t, self.to_vector_mask64x2(mask)) + } + #[inline(always)] fn mul_i64x2(self, a: i64x2, b: i64x2) -> i64x2 { crate::kernel!( #[inline(always)] diff --git a/fearless_simd/src/generated/sse4_2.rs b/fearless_simd/src/generated/sse4_2.rs index e22afd37..7afa7c28 100644 --- a/fearless_simd/src/generated/sse4_2.rs +++ b/fearless_simd/src/generated/sse4_2.rs @@ -1015,6 +1015,14 @@ impl Simd for Sse4_2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i8x16(self, a: i8x16) -> i8x16 { + self.neg_i8x16(self.max_i8x16(a, self.splat_i8x16(const { i8::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i8x16(self, a: i8x16) -> i8x16 { + self.abs_i8x16(self.max_i8x16(a, self.splat_i8x16(const { i8::MIN + 1 }))) + } + #[inline(always)] fn mul_i8x16(self, a: i8x16, b: i8x16) -> i8x16 { crate::kernel!( #[inline(always)] @@ -2729,6 +2737,14 @@ impl Simd for Sse4_2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i16x8(self, a: i16x8) -> i16x8 { + self.neg_i16x8(self.max_i16x8(a, self.splat_i16x8(const { i16::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i16x8(self, a: i16x8) -> i16x8 { + self.abs_i16x8(self.max_i16x8(a, self.splat_i16x8(const { i16::MIN + 1 }))) + } + #[inline(always)] fn mul_i16x8(self, a: i16x8, b: i16x8) -> i16x8 { crate::kernel!( #[inline(always)] @@ -4335,6 +4351,14 @@ impl Simd for Sse4_2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i32x4(self, a: i32x4) -> i32x4 { + self.neg_i32x4(self.max_i32x4(a, self.splat_i32x4(const { i32::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i32x4(self, a: i32x4) -> i32x4 { + self.abs_i32x4(self.max_i32x4(a, self.splat_i32x4(const { i32::MIN + 1 }))) + } + #[inline(always)] fn mul_i32x4(self, a: i32x4, b: i32x4) -> i32x4 { crate::kernel!( #[inline(always)] @@ -6530,6 +6554,18 @@ impl Simd for Sse4_2 { kernel(self, a, b) } #[inline(always)] + fn saturating_neg_i64x2(self, a: i64x2) -> i64x2 { + let t = self.neg_i64x2(a); + let mask = self.simd_eq_i64x2(t, self.splat_i64x2(i64::MIN)); + self.xor_i64x2(t, self.to_vector_mask64x2(mask)) + } + #[inline(always)] + fn saturating_abs_i64x2(self, a: i64x2) -> i64x2 { + let t = self.abs_i64x2(a); + let mask = self.simd_eq_i64x2(t, self.splat_i64x2(i64::MIN)); + self.xor_i64x2(t, self.to_vector_mask64x2(mask)) + } + #[inline(always)] fn mul_i64x2(self, a: i64x2, b: i64x2) -> i64x2 { crate::kernel!( #[inline(always)] diff --git a/fearless_simd/src/generated/wasm.rs b/fearless_simd/src/generated/wasm.rs index e843e416..1e841ec6 100644 --- a/fearless_simd/src/generated/wasm.rs +++ b/fearless_simd/src/generated/wasm.rs @@ -669,6 +669,14 @@ impl Simd for WasmSimd128 { i8x16_sub_sat(a.into(), b.into()).simd_into(self) } #[inline(always)] + fn saturating_neg_i8x16(self, a: i8x16) -> i8x16 { + self.neg_i8x16(self.max_i8x16(a, self.splat_i8x16(const { i8::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i8x16(self, a: i8x16) -> i8x16 { + self.abs_i8x16(self.max_i8x16(a, self.splat_i8x16(const { i8::MIN + 1 }))) + } + #[inline(always)] fn mul_i8x16(self, a: i8x16, b: i8x16) -> i8x16 { let low = i16x8_extmul_low_i8x16(a.into(), b.into()); let high = i16x8_extmul_high_i8x16(a.into(), b.into()); @@ -1854,6 +1862,14 @@ impl Simd for WasmSimd128 { i16x8_sub_sat(a.into(), b.into()).simd_into(self) } #[inline(always)] + fn saturating_neg_i16x8(self, a: i16x8) -> i16x8 { + self.neg_i16x8(self.max_i16x8(a, self.splat_i16x8(const { i16::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i16x8(self, a: i16x8) -> i16x8 { + self.abs_i16x8(self.max_i16x8(a, self.splat_i16x8(const { i16::MIN + 1 }))) + } + #[inline(always)] fn mul_i16x8(self, a: i16x8, b: i16x8) -> i16x8 { i16x8_mul(a.into(), b.into()).simd_into(self) } @@ -2785,6 +2801,14 @@ impl Simd for WasmSimd128 { v128_bitselect(saturation, wrapped, overflow_mask).simd_into(self) } #[inline(always)] + fn saturating_neg_i32x4(self, a: i32x4) -> i32x4 { + self.neg_i32x4(self.max_i32x4(a, self.splat_i32x4(const { i32::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i32x4(self, a: i32x4) -> i32x4 { + self.abs_i32x4(self.max_i32x4(a, self.splat_i32x4(const { i32::MIN + 1 }))) + } + #[inline(always)] fn mul_i32x4(self, a: i32x4, b: i32x4) -> i32x4 { i32x4_mul(a.into(), b.into()).simd_into(self) } @@ -4112,6 +4136,14 @@ impl Simd for WasmSimd128 { v128_bitselect(saturation, wrapped, overflow_mask).simd_into(self) } #[inline(always)] + fn saturating_neg_i64x2(self, a: i64x2) -> i64x2 { + self.neg_i64x2(self.max_i64x2(a, self.splat_i64x2(const { i64::MIN + 1 }))) + } + #[inline(always)] + fn saturating_abs_i64x2(self, a: i64x2) -> i64x2 { + self.abs_i64x2(self.max_i64x2(a, self.splat_i64x2(const { i64::MIN + 1 }))) + } + #[inline(always)] fn mul_i64x2(self, a: i64x2, b: i64x2) -> i64x2 { i64x2_mul(a.into(), b.into()).simd_into(self) } diff --git a/fearless_simd_gen/src/arch/fallback.rs b/fearless_simd_gen/src/arch/fallback.rs index a2a637c9..fc8ea9c8 100644 --- a/fearless_simd_gen/src/arch/fallback.rs +++ b/fearless_simd_gen/src/arch/fallback.rs @@ -14,6 +14,7 @@ pub(crate) fn translate_op(op: &str, is_float: bool) -> Option<&'static str> { "wrapping_abs" } } + "saturating_abs" => "saturating_abs", "copysign" => "copysign", "neg" => { if is_float { @@ -22,6 +23,7 @@ pub(crate) fn translate_op(op: &str, is_float: bool) -> Option<&'static str> { "wrapping_neg" } } + "saturating_neg" => "saturating_neg", "floor" => "floor", "ceil" => "ceil", "round_ties_even" => "round_ties_even", diff --git a/fearless_simd_gen/src/level.rs b/fearless_simd_gen/src/level.rs index bfceab7d..7bc0aa6e 100644 --- a/fearless_simd_gen/src/level.rs +++ b/fearless_simd_gen/src/level.rs @@ -162,7 +162,8 @@ pub(crate) trait Level { continue; } // Unsigned absolute value uses the identity default at every width. - if (op.method == "abs" && vec_ty.scalar == ScalarType::Unsigned) + if (matches!(op.method, "abs" | "saturating_abs" | "saturating_neg") + && vec_ty.scalar == ScalarType::Unsigned) || op.method == "simd_ne" || op.sig.should_route_swizzle_through_bytes(vec_ty) || op.reversed_compare_method().is_some() diff --git a/fearless_simd_gen/src/mk_neon.rs b/fearless_simd_gen/src/mk_neon.rs index 0334d002..d6441401 100644 --- a/fearless_simd_gen/src/mk_neon.rs +++ b/fearless_simd_gen/src/mk_neon.rs @@ -341,6 +341,21 @@ impl Level for Neon { }); } + if method == "saturating_neg" { + assert_eq!(vec_ty.scalar, ScalarType::Int); + let sat_neg = format_ident!("vqnegq_s{}", vec_ty.scalar_bits); + return self.kernel_method(op, vec_ty, |token| { + quote! { #sat_neg(a.into()).simd_into(#token) } + }); + } + if method == "saturating_abs" { + assert_eq!(vec_ty.scalar, ScalarType::Int); + let sat_abs = format_ident!("vqabsq_s{}", vec_ty.scalar_bits); + return self.kernel_method(op, vec_ty, |token| { + quote! { #sat_abs(a.into()).simd_into(#token) } + }); + } + if matches!(method, "to_degrees" | "to_radians") { return generic_to_degrees_radians(method_sig, method, vec_ty); } diff --git a/fearless_simd_gen/src/mk_simd_trait.rs b/fearless_simd_gen/src/mk_simd_trait.rs index 942f2aa4..0dbda470 100644 --- a/fearless_simd_gen/src/mk_simd_trait.rs +++ b/fearless_simd_gen/src/mk_simd_trait.rs @@ -28,7 +28,9 @@ pub(crate) fn mk_simd_trait() -> TokenStream { let doc_alias = op .doc_alias() .map(|alias| quote! { #[doc(alias = #alias)] }); - if op.method == "abs" && vec_ty.scalar == ScalarType::Unsigned { + if matches!(op.method, "abs" | "saturating_abs") + && vec_ty.scalar == ScalarType::Unsigned + { methods.extend(quote! { #[doc = #doc] #[inline(always)] @@ -36,6 +38,16 @@ pub(crate) fn mk_simd_trait() -> TokenStream { a } }); + } else if op.method == "saturating_neg" && vec_ty.scalar == ScalarType::Unsigned { + let splat_op = generic_op_name("splat", vec_ty); + methods.extend(quote! { + #[doc = #doc] + #[inline(always)] + #method_sig { + let _ = a; + self.#splat_op(0) + } + }); } else if op.method == "simd_ne" { let eq = generic_op_name("simd_eq", vec_ty); let not = generic_op_name("not", &vec_ty.mask_ty()); diff --git a/fearless_simd_gen/src/mk_wasm.rs b/fearless_simd_gen/src/mk_wasm.rs index f7f5326f..b2ef192f 100644 --- a/fearless_simd_gen/src/mk_wasm.rs +++ b/fearless_simd_gen/src/mk_wasm.rs @@ -554,6 +554,28 @@ impl Level for WasmSimd128 { }; } + if matches!(method, "saturating_neg" | "saturating_abs") { + assert_eq!(vec_ty.scalar, ScalarType::Int); + + // WASM doesn't have saturating neg/abs, so we emulate using + // saturating_neg(x) = wrapping_neg(max(x, MIN+1)) + // saturating_abs(x) = wrapping_abs(max(x, MIN+1)) + + let wrapping_op = generic_op_name(&method["saturating_".len()..], vec_ty); + let max_op = generic_op_name("max", vec_ty); + let splat_op = generic_op_name("splat", vec_ty); + let min_value = { + let scalar = vec_ty.scalar_rust(); + quote! { #scalar::MIN } + }; + + return quote! { + #method_sig { + self.#wrapping_op(self.#max_op(a, self.#splat_op(const { #min_value + 1 }))) + } + }; + } + if method == "round" { return generic_round(method_sig, vec_ty); } diff --git a/fearless_simd_gen/src/mk_x86.rs b/fearless_simd_gen/src/mk_x86.rs index 5fb6eda2..37cd787b 100644 --- a/fearless_simd_gen/src/mk_x86.rs +++ b/fearless_simd_gen/src/mk_x86.rs @@ -2777,6 +2777,56 @@ impl X86 { } } + if matches!(method, "saturating_neg" | "saturating_abs") { + assert_eq!(vec_ty.scalar, ScalarType::Int); + + // x86 doesn't have saturating neg/abs, so we emulate using + // saturating_neg(x) = wrapping_neg(max(x, MIN+1)) + // saturating_abs(x) = wrapping_abs(max(x, MIN+1)) + + let wrapping_op = generic_op_name(&method["saturating_".len()..], vec_ty); + let splat_op = generic_op_name("splat", vec_ty); + let min_value = { + let scalar = vec_ty.scalar_rust(); + quote! { #scalar::MIN } + }; + + // Unfortunately, the max-family of instructions have requirements: + // - SSE2: i16 available + // - SSE4.1, AVX2: i8, i16, i32 available + // - AVX512: i8, i16, i32, i64 available + let has_native_max = match self { + Self::Sse2 => vec_ty.scalar_bits == 16, + Self::Sse4_2 | Self::Avx2 => matches!(vec_ty.scalar_bits, 8 | 16 | 32), + Self::Avx512 => matches!(vec_ty.scalar_bits, 8 | 16 | 32 | 64), + }; + if has_native_max { + let max_op = generic_op_name("max", vec_ty); + return quote! { + #method_sig { + self.#wrapping_op(self.#max_op(a, self.#splat_op(const { #min_value + 1 }))) + } + }; + } + + // When native max isn't available, we use the following alternative formulations: + // saturating_neg(x) = { let t = wrapping_neg(x); t ^ eq(t, MIN) } + // saturating_abs(x) = { let t = wrapping_abs(x); t ^ eq(t, MIN) } + // This works because t == MIN iff the operation wraps. So we use xor to bitwise negate t, which maps MIN to MAX. + // This is one (or more) instructions slower, so it's only the fallback. + let eq_op = generic_op_name("simd_eq", vec_ty); + let mask_to_int_op = generic_op_name("to_vector", &vec_ty.mask_ty()); + let xor_op = generic_op_name("xor", vec_ty); + + return quote! { + #method_sig { + let t = self.#wrapping_op(a); + let mask = self.#eq_op(t, self.#splat_op(#min_value)); + self.#xor_op(t, self.#mask_to_int_op(mask)) + } + }; + } + if method == "reverse" { if vec_ty.scalar == ScalarType::Mask { if *self == Self::Avx512 { diff --git a/fearless_simd_gen/src/ops.rs b/fearless_simd_gen/src/ops.rs index 413c4c54..7d900cec 100644 --- a/fearless_simd_gen/src/ops.rs +++ b/fearless_simd_gen/src/ops.rs @@ -1371,6 +1371,20 @@ assert_eq!(*i.reverse_bits(), [0xE6_A2_C4_80, 0xF7_B3_D5_91, 0xD0_50_90_10, 0xF0 On x86 it is implemented in hardware only for 8-bit and 16-bit elements. \ For 32-bit and 64-bit vectors this operation is slower than wrapping subtraction on x86.", ), + Op::new( + "saturating_neg", + OpKind::VecTraitMethod, + OpSig::Unary, + "Negate each element of the vector, saturating on overflow.\n\n\ + For unsigned integers, this will always return zero. For signed integers, this returns the same as `-self`, except when negating the minimum value. For example, `saturating_neg(-128i8)` returns `127i8`.", + ), + Op::new( + "saturating_abs", + OpKind::VecTraitMethod, + OpSig::Unary, + "Compute the absolute value of each element of the vector, saturating on overflow.\n\n\ + For unsigned integers, this will always return the same value. For signed integers, this returns the same as `self.abs()`, except when applied to the minimum value. For example, `saturating_abs(-128i8)` returns `127i8`.", + ), Op::new( "mul", OpKind::Overloaded(CoreOpTrait::Mul), diff --git a/fearless_simd_gen/src/types.rs b/fearless_simd_gen/src/types.rs index 31d525a9..aecb71dd 100644 --- a/fearless_simd_gen/src/types.rs +++ b/fearless_simd_gen/src/types.rs @@ -86,6 +86,10 @@ impl VecType { format!("[{}; {}]", self.scalar.rust(self.scalar_bits), self.len) } + pub(crate) fn scalar_rust(&self) -> TokenStream { + self.scalar.rust(self.scalar_bits) + } + /// Returns the name of the `Aligned{128/256/512}` wrapper for this vector type, used to wrap native vector types or /// arrays of them. pub(crate) fn aligned_wrapper(&self) -> TokenStream { diff --git a/fearless_simd_tests/tests/harness/ops/mod.rs b/fearless_simd_tests/tests/harness/ops/mod.rs index 3478d066..c2673d2e 100644 --- a/fearless_simd_tests/tests/harness/ops/mod.rs +++ b/fearless_simd_tests/tests/harness/ops/mod.rs @@ -80,7 +80,9 @@ mod rotate_elements_left; mod rotate_elements_right; mod round; mod round_ties_even; +mod saturating_abs; mod saturating_add; +mod saturating_neg; mod saturating_sub; mod select; mod set; diff --git a/fearless_simd_tests/tests/harness/ops/saturating_abs.rs b/fearless_simd_tests/tests/harness/ops/saturating_abs.rs new file mode 100644 index 00000000..693b12d5 --- /dev/null +++ b/fearless_simd_tests/tests/harness/ops/saturating_abs.rs @@ -0,0 +1,359 @@ +// Copyright 2026 the Fearless_SIMD Authors +// SPDX-License-Identifier: Apache-2.0 OR MIT + +use fearless_simd::*; +use fearless_simd_dev_macros::simd_test; + +#[simd_test] +fn saturating_abs_i8x16(simd: S) { + let data: [i8; 16] = [ + i8::MIN, + i8::MAX, + i8::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + ]; + let a = i8x16::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i8::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i8x32(simd: S) { + let data: [i8; 32] = [ + i8::MIN, + i8::MAX, + i8::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + 7, + -7, + 8, + -8, + 9, + -9, + 10, + -10, + 11, + -11, + 12, + -12, + 13, + -13, + 14, + -14, + ]; + let a = i8x32::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i8::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i8x64(simd: S) { + let data: [i8; 64] = [ + i8::MIN, + i8::MAX, + i8::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + 7, + -7, + 8, + -8, + 9, + -9, + 10, + -10, + 11, + -11, + 12, + -12, + 13, + -13, + 14, + -14, + i8::MIN, + i8::MAX, + i8::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + 7, + -7, + 8, + -8, + 9, + -9, + 10, + -10, + 11, + -11, + 12, + -12, + 13, + -13, + 14, + -14, + ]; + let a = i8x64::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i8::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i16x8(simd: S) { + let data: [i16; 8] = [i16::MIN, i16::MAX, i16::MIN + 1, 0, 1, -1, 2, -2]; + let a = i16x8::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i16::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i16x16(simd: S) { + let data: [i16; 16] = [ + i16::MIN, + i16::MAX, + i16::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + ]; + let a = i16x16::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i16::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i16x32(simd: S) { + let data: [i16; 32] = [ + i16::MIN, + i16::MAX, + i16::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + 7, + -7, + 8, + -8, + 9, + -9, + 10, + -10, + 11, + -11, + 12, + -12, + 13, + -13, + 14, + -14, + ]; + let a = i16x32::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i16::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i32x4(simd: S) { + let data: [i32; 4] = [i32::MIN, i32::MAX, i32::MIN + 1, 0]; + let a = i32x4::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i32::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i32x8(simd: S) { + let data: [i32; 8] = [i32::MIN, i32::MAX, i32::MIN + 1, 0, 1, -1, 2, -2]; + let a = i32x8::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i32::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i32x16(simd: S) { + let data: [i32; 16] = [ + i32::MIN, + i32::MAX, + i32::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + ]; + let a = i32x16::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i32::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i64x2(simd: S) { + let data: [i64; 2] = [i64::MIN, i64::MAX]; + let a = i64x2::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i64::saturating_abs)); + + let data: [i64; 2] = [i64::MIN + 1, 0]; + let a = i64x2::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i64::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i64x4(simd: S) { + let data: [i64; 4] = [i64::MIN, i64::MAX, i64::MIN + 1, 0]; + let a = i64x4::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i64::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_i64x8(simd: S) { + let data: [i64; 8] = [i64::MIN, i64::MAX, i64::MIN + 1, 0, 1, -1, 2, -2]; + let a = i64x8::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data.map(i64::saturating_abs)); +} + +#[simd_test] +fn saturating_abs_u8x16(simd: S) { + let data: [u8; 16] = std::array::from_fn(|i| i as _); + let a = u8x16::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u8x32(simd: S) { + let data: [u8; 32] = std::array::from_fn(|i| i as _); + let a = u8x32::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u8x64(simd: S) { + let data: [u8; 64] = std::array::from_fn(|i| i as _); + let a = u8x64::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u16x8(simd: S) { + let data: [u16; 8] = std::array::from_fn(|i| i as _); + let a = u16x8::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u16x16(simd: S) { + let data: [u16; 16] = std::array::from_fn(|i| i as _); + let a = u16x16::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u16x32(simd: S) { + let data: [u16; 32] = std::array::from_fn(|i| i as _); + let a = u16x32::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u32x4(simd: S) { + let data: [u32; 4] = std::array::from_fn(|i| i as _); + let a = u32x4::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u32x8(simd: S) { + let data: [u32; 8] = std::array::from_fn(|i| i as _); + let a = u32x8::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u32x16(simd: S) { + let data: [u32; 16] = std::array::from_fn(|i| i as _); + let a = u32x16::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u64x2(simd: S) { + let data: [u64; 2] = std::array::from_fn(|i| i as _); + let a = u64x2::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u64x4(simd: S) { + let data: [u64; 4] = std::array::from_fn(|i| i as _); + let a = u64x4::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} + +#[simd_test] +fn saturating_abs_u64x8(simd: S) { + let data: [u64; 8] = std::array::from_fn(|i| i as _); + let a = u64x8::from_slice(simd, &data); + assert_eq!(*a.saturating_abs(), data); +} diff --git a/fearless_simd_tests/tests/harness/ops/saturating_neg.rs b/fearless_simd_tests/tests/harness/ops/saturating_neg.rs new file mode 100644 index 00000000..3f38b678 --- /dev/null +++ b/fearless_simd_tests/tests/harness/ops/saturating_neg.rs @@ -0,0 +1,362 @@ +// Copyright 2026 the Fearless_SIMD Authors +// SPDX-License-Identifier: Apache-2.0 OR MIT + +use fearless_simd::*; +use fearless_simd_dev_macros::simd_test; + +// Saturating negation: for unsigned integers always returns zero, +// for signed integers negates normally except MIN maps to MAX. + +#[simd_test] +fn saturating_neg_i8x16(simd: S) { + let data: [i8; 16] = [ + i8::MIN, + i8::MAX, + i8::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + ]; + let a = i8x16::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i8::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i8x32(simd: S) { + let data: [i8; 32] = [ + i8::MIN, + i8::MAX, + i8::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + 7, + -7, + 8, + -8, + 9, + -9, + 10, + -10, + 11, + -11, + 12, + -12, + 13, + -13, + 14, + -14, + ]; + let a = i8x32::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i8::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i8x64(simd: S) { + let data: [i8; 64] = [ + i8::MIN, + i8::MAX, + i8::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + 7, + -7, + 8, + -8, + 9, + -9, + 10, + -10, + 11, + -11, + 12, + -12, + 13, + -13, + 14, + -14, + i8::MIN, + i8::MAX, + i8::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + 7, + -7, + 8, + -8, + 9, + -9, + 10, + -10, + 11, + -11, + 12, + -12, + 13, + -13, + 14, + -14, + ]; + let a = i8x64::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i8::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i16x8(simd: S) { + let data: [i16; 8] = [i16::MIN, i16::MAX, i16::MIN + 1, 0, 1, -1, 2, -2]; + let a = i16x8::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i16::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i16x16(simd: S) { + let data: [i16; 16] = [ + i16::MIN, + i16::MAX, + i16::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + ]; + let a = i16x16::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i16::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i16x32(simd: S) { + let data: [i16; 32] = [ + i16::MIN, + i16::MAX, + i16::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + 7, + -7, + 8, + -8, + 9, + -9, + 10, + -10, + 11, + -11, + 12, + -12, + 13, + -13, + 14, + -14, + ]; + let a = i16x32::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i16::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i32x4(simd: S) { + let data: [i32; 4] = [i32::MIN, i32::MAX, i32::MIN + 1, 0]; + let a = i32x4::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i32::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i32x8(simd: S) { + let data: [i32; 8] = [i32::MIN, i32::MAX, i32::MIN + 1, 0, 1, -1, 2, -2]; + let a = i32x8::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i32::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i32x16(simd: S) { + let data: [i32; 16] = [ + i32::MIN, + i32::MAX, + i32::MIN + 1, + 0, + 1, + -1, + 2, + -2, + 3, + -3, + 4, + -4, + 5, + -5, + 6, + -6, + ]; + let a = i32x16::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i32::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i64x2(simd: S) { + let data: [i64; 2] = [i64::MIN, i64::MAX]; + let a = i64x2::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i64::saturating_neg)); + + let data: [i64; 2] = [i64::MIN + 1, 0]; + let a = i64x2::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i64::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i64x4(simd: S) { + let data: [i64; 4] = [i64::MIN, i64::MAX, i64::MIN + 1, 0]; + let a = i64x4::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i64::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_i64x8(simd: S) { + let data: [i64; 8] = [i64::MIN, i64::MAX, i64::MIN + 1, 0, 1, -1, 2, -2]; + let a = i64x8::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), data.map(i64::saturating_neg)); +} + +#[simd_test] +fn saturating_neg_u8x16(simd: S) { + let data: [u8; 16] = std::array::from_fn(|i| i as _); + let a = u8x16::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 16]); +} + +#[simd_test] +fn saturating_neg_u8x32(simd: S) { + let data: [u8; 32] = std::array::from_fn(|i| i as _); + let a = u8x32::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 32]); +} + +#[simd_test] +fn saturating_neg_u8x64(simd: S) { + let data: [u8; 64] = std::array::from_fn(|i| i as _); + let a = u8x64::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 64]); +} + +#[simd_test] +fn saturating_neg_u16x8(simd: S) { + let data: [u16; 8] = std::array::from_fn(|i| i as _); + let a = u16x8::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 8]); +} + +#[simd_test] +fn saturating_neg_u16x16(simd: S) { + let data: [u16; 16] = std::array::from_fn(|i| i as _); + let a = u16x16::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 16]); +} + +#[simd_test] +fn saturating_neg_u16x32(simd: S) { + let data: [u16; 32] = std::array::from_fn(|i| i as _); + let a = u16x32::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 32]); +} + +#[simd_test] +fn saturating_neg_u32x4(simd: S) { + let data: [u32; 4] = std::array::from_fn(|i| i as _); + let a = u32x4::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 4]); +} + +#[simd_test] +fn saturating_neg_u32x8(simd: S) { + let data: [u32; 8] = std::array::from_fn(|i| i as _); + let a = u32x8::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 8]); +} + +#[simd_test] +fn saturating_neg_u32x16(simd: S) { + let data: [u32; 16] = std::array::from_fn(|i| i as _); + let a = u32x16::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 16]); +} + +#[simd_test] +fn saturating_neg_u64x2(simd: S) { + let data: [u64; 2] = std::array::from_fn(|i| i as _); + let a = u64x2::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 2]); +} + +#[simd_test] +fn saturating_neg_u64x4(simd: S) { + let data: [u64; 4] = std::array::from_fn(|i| i as _); + let a = u64x4::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 4]); +} + +#[simd_test] +fn saturating_neg_u64x8(simd: S) { + let data: [u64; 8] = std::array::from_fn(|i| i as _); + let a = u64x8::from_slice(simd, &data); + assert_eq!(*a.saturating_neg(), [0; 8]); +}