2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
2020-11-08 20:21:28 +10:00
|
|
|
#![allow(non_camel_case_types)]
|
2025-02-24 17:26:56 +01:00
|
|
|
#![feature(repr_simd, core_intrinsics)]
|
2014-02-04 01:04:19 -06:00
|
|
|
|
2025-07-12 02:33:42 -07:00
|
|
|
#[path = "../../auxiliary/minisimd.rs"]
|
|
|
|
|
mod minisimd;
|
|
|
|
|
use minisimd::*;
|
|
|
|
|
|
2025-02-24 17:26:56 +01:00
|
|
|
use std::intrinsics::simd::simd_add;
|
2014-01-21 23:12:41 -06:00
|
|
|
use std::ops;
|
|
|
|
|
|
2025-07-12 02:33:42 -07:00
|
|
|
type A<const N: usize> = Simd<f32, N>;
|
2021-08-03 03:33:09 +00:00
|
|
|
|
2025-07-12 02:33:42 -07:00
|
|
|
type B<T> = Simd<T, 4>;
|
2021-08-03 03:33:09 +00:00
|
|
|
|
2025-07-12 02:33:42 -07:00
|
|
|
type C<T, const N: usize> = Simd<T, N>;
|
2019-07-13 17:16:57 +02:00
|
|
|
|
2025-02-24 17:26:56 +01:00
|
|
|
fn add<T: ops::Add<Output = T>>(lhs: T, rhs: T) -> T {
|
2014-01-21 23:12:41 -06:00
|
|
|
lhs + rhs
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-31 15:45:13 -05:00
|
|
|
impl ops::Add for f32x4 {
|
|
|
|
|
type Output = f32x4;
|
|
|
|
|
|
2014-12-01 17:33:22 -05:00
|
|
|
fn add(self, rhs: f32x4) -> f32x4 {
|
2020-11-08 20:21:28 +10:00
|
|
|
unsafe { simd_add(self, rhs) }
|
2014-01-21 23:12:41 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-08 20:21:28 +10:00
|
|
|
pub fn main() {
|
2021-08-03 03:33:09 +00:00
|
|
|
let x = [1.0f32, 2.0f32, 3.0f32, 4.0f32];
|
|
|
|
|
let y = [2.0f32, 4.0f32, 6.0f32, 8.0f32];
|
2014-01-21 23:12:41 -06:00
|
|
|
|
|
|
|
|
// lame-o
|
2025-07-12 02:33:42 -07:00
|
|
|
let a = f32x4::from_array([1.0f32, 2.0f32, 3.0f32, 4.0f32]);
|
|
|
|
|
let [a0, a1, a2, a3] = add(a, a).into_array();
|
2021-08-03 03:33:09 +00:00
|
|
|
assert_eq!(a0, 2.0f32);
|
|
|
|
|
assert_eq!(a1, 4.0f32);
|
|
|
|
|
assert_eq!(a2, 6.0f32);
|
|
|
|
|
assert_eq!(a3, 8.0f32);
|
|
|
|
|
|
2025-07-12 02:33:42 -07:00
|
|
|
let a = A::from_array(x);
|
|
|
|
|
assert_eq!(add(a, a).into_array(), y);
|
2021-08-03 03:33:09 +00:00
|
|
|
|
2025-07-12 02:33:42 -07:00
|
|
|
let b = B::from_array(x);
|
|
|
|
|
assert_eq!(add(b, b).into_array(), y);
|
2021-08-03 03:33:09 +00:00
|
|
|
|
2025-07-12 02:33:42 -07:00
|
|
|
let c = C::from_array(x);
|
|
|
|
|
assert_eq!(add(c, c).into_array(), y);
|
2020-11-08 20:21:28 +10:00
|
|
|
}
|