From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/traits/operator-overloading-issue-52025.rs | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/test/ui/traits/operator-overloading-issue-52025.rs (limited to 'src/test/ui/traits/operator-overloading-issue-52025.rs') diff --git a/src/test/ui/traits/operator-overloading-issue-52025.rs b/src/test/ui/traits/operator-overloading-issue-52025.rs new file mode 100644 index 000000000..7ce638832 --- /dev/null +++ b/src/test/ui/traits/operator-overloading-issue-52025.rs @@ -0,0 +1,57 @@ +// only-x86_64 +// build-pass + +use std::arch::x86_64::*; +use std::fmt::Debug; +use std::ops::*; + +pub trait Simd { + type Vf32: Copy + Debug + Add + Add; + + unsafe fn set1_ps(a: f32) -> Self::Vf32; + unsafe fn add_ps(a: Self::Vf32, b: Self::Vf32) -> Self::Vf32; +} + +#[derive(Copy, Debug, Clone)] +pub struct F32x4(pub __m128); + +impl Add for F32x4 { + type Output = F32x4; + + fn add(self, rhs: F32x4) -> F32x4 { + F32x4(unsafe { _mm_add_ps(self.0, rhs.0) }) + } +} + +impl Add for F32x4 { + type Output = F32x4; + fn add(self, rhs: f32) -> F32x4 { + F32x4(unsafe { _mm_add_ps(self.0, _mm_set1_ps(rhs)) }) + } +} + +pub struct Sse2; +impl Simd for Sse2 { + type Vf32 = F32x4; + + #[inline(always)] + unsafe fn set1_ps(a: f32) -> Self::Vf32 { + F32x4(_mm_set1_ps(a)) + } + + #[inline(always)] + unsafe fn add_ps(a: Self::Vf32, b: Self::Vf32) -> Self::Vf32 { + F32x4(_mm_add_ps(a.0, b.0)) + } +} + +unsafe fn test() -> S::Vf32 { + let a = S::set1_ps(3.0); + let b = S::set1_ps(2.0); + let result = a + b; + result +} + +fn main() { + println!("{:?}", unsafe { test::() }); +} -- cgit v1.2.3