]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/operator-overloading-issue-52025.rs
Rollup merge of #99742 - sigaloid:master, r=thomcc
[rust.git] / src / test / ui / traits / operator-overloading-issue-52025.rs
1 // only-x86_64
2 // build-pass
3
4 use std::arch::x86_64::*;
5 use std::fmt::Debug;
6 use std::ops::*;
7
8 pub trait Simd {
9     type Vf32: Copy + Debug + Add<Self::Vf32, Output = Self::Vf32> + Add<f32, Output = Self::Vf32>;
10
11     unsafe fn set1_ps(a: f32) -> Self::Vf32;
12     unsafe fn add_ps(a: Self::Vf32, b: Self::Vf32) -> Self::Vf32;
13 }
14
15 #[derive(Copy, Debug, Clone)]
16 pub struct F32x4(pub __m128);
17
18 impl Add<F32x4> for F32x4 {
19     type Output = F32x4;
20
21     fn add(self, rhs: F32x4) -> F32x4 {
22         F32x4(unsafe { _mm_add_ps(self.0, rhs.0) })
23     }
24 }
25
26 impl Add<f32> for F32x4 {
27     type Output = F32x4;
28     fn add(self, rhs: f32) -> F32x4 {
29         F32x4(unsafe { _mm_add_ps(self.0, _mm_set1_ps(rhs)) })
30     }
31 }
32
33 pub struct Sse2;
34 impl Simd for Sse2 {
35     type Vf32 = F32x4;
36
37     #[inline(always)]
38     unsafe fn set1_ps(a: f32) -> Self::Vf32 {
39         F32x4(_mm_set1_ps(a))
40     }
41
42     #[inline(always)]
43     unsafe fn add_ps(a: Self::Vf32, b: Self::Vf32) -> Self::Vf32 {
44         F32x4(_mm_add_ps(a.0, b.0))
45     }
46 }
47
48 unsafe fn test<S: Simd>() -> S::Vf32 {
49     let a = S::set1_ps(3.0);
50     let b = S::set1_ps(2.0);
51     let result = a + b;
52     result
53 }
54
55 fn main() {
56     println!("{:?}", unsafe { test::<Sse2>() });
57 }