rust/src/test/ui/simd/simd-generics.rs

40 lines
691 B
Rust
Raw Normal View History

// run-pass
#![allow(non_camel_case_types)]
2014-02-04 08:26:02 +00:00
#![feature(repr_simd, platform_intrinsics)]
2014-02-04 07:04:19 +00:00
use std::ops;
#[repr(simd)]
2015-03-30 13:38:27 +00:00
#[derive(Copy, Clone)]
2015-01-24 21:36:30 +00:00
struct f32x4(f32, f32, f32, f32);
extern "platform-intrinsic" {
fn simd_add<T>(x: T, y: T) -> T;
}
2014-12-31 20:45:13 +00:00
fn add<T: ops::Add<Output=T>>(lhs: T, rhs: T) -> T {
lhs + rhs
}
2014-12-31 20:45:13 +00:00
impl ops::Add for f32x4 {
type Output = f32x4;
2014-12-01 22:33:22 +00:00
fn add(self, rhs: f32x4) -> f32x4 {
unsafe {simd_add(self, rhs)}
}
}
2014-02-04 07:04:19 +00:00
pub fn main() {
let lr = f32x4(1.0f32, 2.0f32, 3.0f32, 4.0f32);
// lame-o
let f32x4(x, y, z, w) = add(lr, lr);
assert_eq!(x, 2.0f32);
assert_eq!(y, 4.0f32);
assert_eq!(z, 6.0f32);
assert_eq!(w, 8.0f32);
}