Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regression test for issue #52025 #86393

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/test/ui/traits/operator-overloading-issue-52025.rs
Original file line number Diff line number Diff line change
@@ -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<Self::Vf32, Output = Self::Vf32> + Add<f32, Output = Self::Vf32>;

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<F32x4> for F32x4 {
type Output = F32x4;

fn add(self, rhs: F32x4) -> F32x4 {
F32x4(unsafe { _mm_add_ps(self.0, rhs.0) })
}
}

impl Add<f32> 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: Simd>() -> 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::<Sse2>() });
}