Merge pull request #2006 from eduardosm/unsafe-tests

Avoid `unsafe fn` in aarch64, powerpc and s390x tests
This commit is contained in:
Folkert de Vries 2026-01-29 13:37:01 +00:00 committed by GitHub
commit 9eaf7fa384
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 536 additions and 425 deletions

View file

@ -569,47 +569,46 @@ mod tests {
use crate::core_arch::aarch64::test_support::*;
use crate::core_arch::arm_shared::test_support::*;
use crate::core_arch::{aarch64::neon::*, aarch64::*, simd::*};
use std::mem::transmute;
use stdarch_test::simd_test;
#[simd_test(enable = "neon")]
unsafe fn test_vadd_f64() {
let a = 1.;
let b = 8.;
let e = 9.;
let r: f64 = transmute(vadd_f64(transmute(a), transmute(b)));
fn test_vadd_f64() {
let a = f64x1::from_array([1.]);
let b = f64x1::from_array([8.]);
let e = f64x1::from_array([9.]);
let r = f64x1::from(vadd_f64(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vaddq_f64() {
fn test_vaddq_f64() {
let a = f64x2::new(1., 2.);
let b = f64x2::new(8., 7.);
let e = f64x2::new(9., 9.);
let r: f64x2 = transmute(vaddq_f64(transmute(a), transmute(b)));
let r = f64x2::from(vaddq_f64(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vadd_s64() {
let a = 1_i64;
let b = 8_i64;
let e = 9_i64;
let r: i64 = transmute(vadd_s64(transmute(a), transmute(b)));
fn test_vadd_s64() {
let a = i64x1::from_array([1]);
let b = i64x1::from_array([8]);
let e = i64x1::from_array([9]);
let r = i64x1::from(vadd_s64(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vadd_u64() {
let a = 1_u64;
let b = 8_u64;
let e = 9_u64;
let r: u64 = transmute(vadd_u64(transmute(a), transmute(b)));
fn test_vadd_u64() {
let a = u64x1::from_array([1]);
let b = u64x1::from_array([8]);
let e = u64x1::from_array([9]);
let r = u64x1::from(vadd_u64(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vaddd_s64() {
fn test_vaddd_s64() {
let a = 1_i64;
let b = 8_i64;
let e = 9_i64;
@ -618,7 +617,7 @@ mod tests {
}
#[simd_test(enable = "neon")]
unsafe fn test_vaddd_u64() {
fn test_vaddd_u64() {
let a = 1_u64;
let b = 8_u64;
let e = 9_u64;
@ -627,25 +626,25 @@ mod tests {
}
#[simd_test(enable = "neon")]
unsafe fn test_vext_p64() {
let a: i64x1 = i64x1::new(0);
let b: i64x1 = i64x1::new(1);
let e: i64x1 = i64x1::new(0);
let r: i64x1 = transmute(vext_p64::<0>(transmute(a), transmute(b)));
fn test_vext_p64() {
let a = u64x1::new(0);
let b = u64x1::new(1);
let e = u64x1::new(0);
let r = u64x1::from(vext_p64::<0>(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vext_f64() {
let a: f64x1 = f64x1::new(0.);
let b: f64x1 = f64x1::new(1.);
let e: f64x1 = f64x1::new(0.);
let r: f64x1 = transmute(vext_f64::<0>(transmute(a), transmute(b)));
fn test_vext_f64() {
let a = f64x1::new(0.);
let b = f64x1::new(1.);
let e = f64x1::new(0.);
let r = f64x1::from(vext_f64::<0>(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vshld_n_s64() {
fn test_vshld_n_s64() {
let a: i64 = 1;
let e: i64 = 4;
let r: i64 = vshld_n_s64::<2>(a);
@ -653,7 +652,7 @@ mod tests {
}
#[simd_test(enable = "neon")]
unsafe fn test_vshld_n_u64() {
fn test_vshld_n_u64() {
let a: u64 = 1;
let e: u64 = 4;
let r: u64 = vshld_n_u64::<2>(a);
@ -661,7 +660,7 @@ mod tests {
}
#[simd_test(enable = "neon")]
unsafe fn test_vshrd_n_s64() {
fn test_vshrd_n_s64() {
let a: i64 = 4;
let e: i64 = 1;
let r: i64 = vshrd_n_s64::<2>(a);
@ -669,7 +668,7 @@ mod tests {
}
#[simd_test(enable = "neon")]
unsafe fn test_vshrd_n_u64() {
fn test_vshrd_n_u64() {
let a: u64 = 4;
let e: u64 = 1;
let r: u64 = vshrd_n_u64::<2>(a);
@ -677,7 +676,7 @@ mod tests {
}
#[simd_test(enable = "neon")]
unsafe fn test_vsrad_n_s64() {
fn test_vsrad_n_s64() {
let a: i64 = 1;
let b: i64 = 4;
let e: i64 = 2;
@ -686,7 +685,7 @@ mod tests {
}
#[simd_test(enable = "neon")]
unsafe fn test_vsrad_n_u64() {
fn test_vsrad_n_u64() {
let a: u64 = 1;
let b: u64 = 4;
let e: u64 = 2;
@ -695,293 +694,300 @@ mod tests {
}
#[simd_test(enable = "neon")]
unsafe fn test_vdup_n_f64() {
fn test_vdup_n_f64() {
let a: f64 = 3.3;
let e = f64x1::new(3.3);
let r: f64x1 = transmute(vdup_n_f64(a));
let r = f64x1::from(vdup_n_f64(a));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vdup_n_p64() {
fn test_vdup_n_p64() {
let a: u64 = 3;
let e = u64x1::new(3);
let r: u64x1 = transmute(vdup_n_p64(a));
let r = u64x1::from(vdup_n_p64(a));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vdupq_n_f64() {
fn test_vdupq_n_f64() {
let a: f64 = 3.3;
let e = f64x2::new(3.3, 3.3);
let r: f64x2 = transmute(vdupq_n_f64(a));
let r = f64x2::from(vdupq_n_f64(a));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vdupq_n_p64() {
fn test_vdupq_n_p64() {
let a: u64 = 3;
let e = u64x2::new(3, 3);
let r: u64x2 = transmute(vdupq_n_p64(a));
let r = u64x2::from(vdupq_n_p64(a));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vmov_n_p64() {
fn test_vmov_n_p64() {
let a: u64 = 3;
let e = u64x1::new(3);
let r: u64x1 = transmute(vmov_n_p64(a));
let r = u64x1::from(vmov_n_p64(a));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vmov_n_f64() {
fn test_vmov_n_f64() {
let a: f64 = 3.3;
let e = f64x1::new(3.3);
let r: f64x1 = transmute(vmov_n_f64(a));
let r = f64x1::from(vmov_n_f64(a));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vmovq_n_p64() {
fn test_vmovq_n_p64() {
let a: u64 = 3;
let e = u64x2::new(3, 3);
let r: u64x2 = transmute(vmovq_n_p64(a));
let r = u64x2::from(vmovq_n_p64(a));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vmovq_n_f64() {
fn test_vmovq_n_f64() {
let a: f64 = 3.3;
let e = f64x2::new(3.3, 3.3);
let r: f64x2 = transmute(vmovq_n_f64(a));
let r = f64x2::from(vmovq_n_f64(a));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vget_high_f64() {
fn test_vget_high_f64() {
let a = f64x2::new(1.0, 2.0);
let e = f64x1::new(2.0);
let r: f64x1 = transmute(vget_high_f64(transmute(a)));
let r = f64x1::from(vget_high_f64(a.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vget_high_p64() {
fn test_vget_high_p64() {
let a = u64x2::new(1, 2);
let e = u64x1::new(2);
let r: u64x1 = transmute(vget_high_p64(transmute(a)));
let r = u64x1::from(vget_high_p64(a.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vget_low_f64() {
fn test_vget_low_f64() {
let a = f64x2::new(1.0, 2.0);
let e = f64x1::new(1.0);
let r: f64x1 = transmute(vget_low_f64(transmute(a)));
let r = f64x1::from(vget_low_f64(a.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vget_low_p64() {
fn test_vget_low_p64() {
let a = u64x2::new(1, 2);
let e = u64x1::new(1);
let r: u64x1 = transmute(vget_low_p64(transmute(a)));
let r = u64x1::from(vget_low_p64(a.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vget_lane_f64() {
fn test_vget_lane_f64() {
let v = f64x1::new(1.0);
let r = vget_lane_f64::<0>(transmute(v));
let r = vget_lane_f64::<0>(v.into());
assert_eq!(r, 1.0);
}
#[simd_test(enable = "neon")]
unsafe fn test_vgetq_lane_f64() {
fn test_vgetq_lane_f64() {
let v = f64x2::new(0.0, 1.0);
let r = vgetq_lane_f64::<1>(transmute(v));
let r = vgetq_lane_f64::<1>(v.into());
assert_eq!(r, 1.0);
let r = vgetq_lane_f64::<0>(transmute(v));
let r = vgetq_lane_f64::<0>(v.into());
assert_eq!(r, 0.0);
}
#[simd_test(enable = "neon")]
unsafe fn test_vcopy_lane_s64() {
let a: i64x1 = i64x1::new(1);
let b: i64x1 = i64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let e: i64x1 = i64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let r: i64x1 = transmute(vcopy_lane_s64::<0, 0>(transmute(a), transmute(b)));
fn test_vcopy_lane_s64() {
let a = i64x1::new(1);
let b = i64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let e = i64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let r = i64x1::from(vcopy_lane_s64::<0, 0>(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vcopy_lane_u64() {
let a: u64x1 = u64x1::new(1);
let b: u64x1 = u64x1::new(0xFF_FF_FF_FF_FF_FF_FF_FF);
let e: u64x1 = u64x1::new(0xFF_FF_FF_FF_FF_FF_FF_FF);
let r: u64x1 = transmute(vcopy_lane_u64::<0, 0>(transmute(a), transmute(b)));
fn test_vcopy_lane_u64() {
let a = u64x1::new(1);
let b = u64x1::new(0xFF_FF_FF_FF_FF_FF_FF_FF);
let e = u64x1::new(0xFF_FF_FF_FF_FF_FF_FF_FF);
let r = u64x1::from(vcopy_lane_u64::<0, 0>(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vcopy_lane_p64() {
let a: i64x1 = i64x1::new(1);
let b: i64x1 = i64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let e: i64x1 = i64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let r: i64x1 = transmute(vcopy_lane_p64::<0, 0>(transmute(a), transmute(b)));
fn test_vcopy_lane_p64() {
let a = u64x1::new(1);
let b = u64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let e = u64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let r = u64x1::from(vcopy_lane_p64::<0, 0>(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vcopy_lane_f64() {
let a: f64 = 1.;
let b: f64 = 0.;
let e: f64 = 0.;
let r: f64 = transmute(vcopy_lane_f64::<0, 0>(transmute(a), transmute(b)));
fn test_vcopy_lane_f64() {
let a = f64x1::from_array([1.]);
let b = f64x1::from_array([0.]);
let e = f64x1::from_array([0.]);
let r = f64x1::from(vcopy_lane_f64::<0, 0>(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vcopy_laneq_s64() {
let a: i64x1 = i64x1::new(1);
let b: i64x2 = i64x2::new(0, 0x7F_FF_FF_FF_FF_FF_FF_FF);
let e: i64x1 = i64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let r: i64x1 = transmute(vcopy_laneq_s64::<0, 1>(transmute(a), transmute(b)));
fn test_vcopy_laneq_s64() {
let a = i64x1::new(1);
let b = i64x2::new(0, 0x7F_FF_FF_FF_FF_FF_FF_FF);
let e = i64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let r = i64x1::from(vcopy_laneq_s64::<0, 1>(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vcopy_laneq_u64() {
let a: u64x1 = u64x1::new(1);
let b: u64x2 = u64x2::new(0, 0xFF_FF_FF_FF_FF_FF_FF_FF);
let e: u64x1 = u64x1::new(0xFF_FF_FF_FF_FF_FF_FF_FF);
let r: u64x1 = transmute(vcopy_laneq_u64::<0, 1>(transmute(a), transmute(b)));
fn test_vcopy_laneq_u64() {
let a = u64x1::new(1);
let b = u64x2::new(0, 0xFF_FF_FF_FF_FF_FF_FF_FF);
let e = u64x1::new(0xFF_FF_FF_FF_FF_FF_FF_FF);
let r = u64x1::from(vcopy_laneq_u64::<0, 1>(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vcopy_laneq_p64() {
let a: i64x1 = i64x1::new(1);
let b: i64x2 = i64x2::new(0, 0x7F_FF_FF_FF_FF_FF_FF_FF);
let e: i64x1 = i64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let r: i64x1 = transmute(vcopy_laneq_p64::<0, 1>(transmute(a), transmute(b)));
fn test_vcopy_laneq_p64() {
let a = u64x1::new(1);
let b = u64x2::new(0, 0x7F_FF_FF_FF_FF_FF_FF_FF);
let e = u64x1::new(0x7F_FF_FF_FF_FF_FF_FF_FF);
let r = u64x1::from(vcopy_laneq_p64::<0, 1>(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vcopy_laneq_f64() {
let a: f64 = 1.;
let b: f64x2 = f64x2::new(0., 0.5);
let e: f64 = 0.5;
let r: f64 = transmute(vcopy_laneq_f64::<0, 1>(transmute(a), transmute(b)));
fn test_vcopy_laneq_f64() {
let a = f64x1::from_array([1.]);
let b = f64x2::from_array([0., 0.5]);
let e = f64x1::from_array([0.5]);
let r = f64x1::from(vcopy_laneq_f64::<0, 1>(a.into(), b.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vbsl_f64() {
fn test_vbsl_f64() {
let a = u64x1::new(0x8000000000000000);
let b = f64x1::new(-1.23f64);
let c = f64x1::new(2.34f64);
let e = f64x1::new(-2.34f64);
let r: f64x1 = transmute(vbsl_f64(transmute(a), transmute(b), transmute(c)));
let r = f64x1::from(vbsl_f64(a.into(), b.into(), c.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vbsl_p64() {
fn test_vbsl_p64() {
let a = u64x1::new(1);
let b = u64x1::new(u64::MAX);
let c = u64x1::new(u64::MIN);
let e = u64x1::new(1);
let r: u64x1 = transmute(vbsl_p64(transmute(a), transmute(b), transmute(c)));
let r = u64x1::from(vbsl_p64(a.into(), b.into(), c.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vbslq_f64() {
fn test_vbslq_f64() {
let a = u64x2::new(1, 0x8000000000000000);
let b = f64x2::new(f64::MAX, -1.23f64);
let c = f64x2::new(f64::MIN, 2.34f64);
let e = f64x2::new(f64::MIN, -2.34f64);
let r: f64x2 = transmute(vbslq_f64(transmute(a), transmute(b), transmute(c)));
let r = f64x2::from(vbslq_f64(a.into(), b.into(), c.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vbslq_p64() {
fn test_vbslq_p64() {
let a = u64x2::new(u64::MAX, 1);
let b = u64x2::new(u64::MAX, u64::MAX);
let c = u64x2::new(u64::MIN, u64::MIN);
let e = u64x2::new(u64::MAX, 1);
let r: u64x2 = transmute(vbslq_p64(transmute(a), transmute(b), transmute(c)));
let r = u64x2::from(vbslq_p64(a.into(), b.into(), c.into()));
assert_eq!(r, e);
}
#[simd_test(enable = "neon")]
unsafe fn test_vld1_f64() {
fn test_vld1_f64() {
let a: [f64; 2] = [0., 1.];
let e = f64x1::new(1.);
let r: f64x1 = transmute(vld1_f64(a[1..].as_ptr()));
let r = unsafe { f64x1::from(vld1_f64(a[1..].as_ptr())) };
assert_eq!(r, e)
}
#[simd_test(enable = "neon")]
unsafe fn test_vld1q_f64() {
fn test_vld1q_f64() {
let a: [f64; 3] = [0., 1., 2.];
let e = f64x2::new(1., 2.);
let r: f64x2 = transmute(vld1q_f64(a[1..].as_ptr()));
let r = unsafe { f64x2::from(vld1q_f64(a[1..].as_ptr())) };
assert_eq!(r, e)
}
#[simd_test(enable = "neon")]
unsafe fn test_vld1_dup_f64() {
fn test_vld1_dup_f64() {
let a: [f64; 2] = [1., 42.];
let e = f64x1::new(42.);
let r: f64x1 = transmute(vld1_dup_f64(a[1..].as_ptr()));
let r = unsafe { f64x1::from(vld1_dup_f64(a[1..].as_ptr())) };
assert_eq!(r, e)
}
#[simd_test(enable = "neon")]
unsafe fn test_vld1q_dup_f64() {
fn test_vld1q_dup_f64() {
let elem: f64 = 42.;
let e = f64x2::new(42., 42.);
let r: f64x2 = transmute(vld1q_dup_f64(&elem));
let r = unsafe { f64x2::from(vld1q_dup_f64(&elem)) };
assert_eq!(r, e)
}
#[simd_test(enable = "neon")]
unsafe fn test_vld1_lane_f64() {
fn test_vld1_lane_f64() {
let a = f64x1::new(0.);
let elem: f64 = 42.;
let e = f64x1::new(42.);
let r: f64x1 = transmute(vld1_lane_f64::<0>(&elem, transmute(a)));
let r = unsafe { f64x1::from(vld1_lane_f64::<0>(&elem, a.into())) };
assert_eq!(r, e)
}
#[simd_test(enable = "neon")]
unsafe fn test_vld1q_lane_f64() {
fn test_vld1q_lane_f64() {
let a = f64x2::new(0., 1.);
let elem: f64 = 42.;
let e = f64x2::new(0., 42.);
let r: f64x2 = transmute(vld1q_lane_f64::<1>(&elem, transmute(a)));
let r = unsafe { f64x2::from(vld1q_lane_f64::<1>(&elem, a.into())) };
assert_eq!(r, e)
}
#[simd_test(enable = "neon")]
unsafe fn test_vst1_f64() {
fn test_vst1_f64() {
let mut vals = [0_f64; 2];
let a = f64x1::new(1.);
vst1_f64(vals[1..].as_mut_ptr(), transmute(a));
unsafe {
vst1_f64(vals[1..].as_mut_ptr(), a.into());
}
assert_eq!(vals[0], 0.);
assert_eq!(vals[1], 1.);
}
#[simd_test(enable = "neon")]
unsafe fn test_vst1q_f64() {
fn test_vst1q_f64() {
let mut vals = [0_f64; 3];
let a = f64x2::new(1., 2.);
vst1q_f64(vals[1..].as_mut_ptr(), transmute(a));
unsafe {
vst1q_f64(vals[1..].as_mut_ptr(), a.into());
}
assert_eq!(vals[0], 0.);
assert_eq!(vals[1], 1.);

View file

@ -47,6 +47,54 @@ types! {
pub struct vector_float(4 x f32);
}
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
impl From<m8x16> for vector_bool_char {
#[inline]
fn from(value: m8x16) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
impl From<vector_bool_char> for m8x16 {
#[inline]
fn from(value: vector_bool_char) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
impl From<m16x8> for vector_bool_short {
#[inline]
fn from(value: m16x8) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
impl From<vector_bool_short> for m16x8 {
#[inline]
fn from(value: vector_bool_short) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
impl From<m32x4> for vector_bool_int {
#[inline]
fn from(value: m32x4) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
impl From<vector_bool_int> for m32x4 {
#[inline]
fn from(value: vector_bool_int) -> Self {
unsafe { transmute(value) }
}
}
#[allow(improper_ctypes)]
unsafe extern "C" {
#[link_name = "llvm.ppc.altivec.lvx"]
@ -4653,22 +4701,22 @@ mod tests {
};
{ $name: ident, $fn:ident, $ty: ident -> $ty_out: ident, [$($a:expr),+], [$($b:expr),+], [$($d:expr),+] } => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a: s_t_l!($ty) = transmute($ty::new($($a),+));
let b: s_t_l!($ty) = transmute($ty::new($($b),+));
fn $name() {
let a: s_t_l!($ty) = $ty::new($($a),+).into();
let b: s_t_l!($ty) = $ty::new($($b),+).into();
let d = $ty_out::new($($d),+);
let r : $ty_out = transmute($fn(a, b));
let r = $ty_out::from(unsafe { $fn(a, b) });
assert_eq!(d, r);
}
};
{ $name: ident, $fn:ident, $ty: ident -> $ty_out: ident, [$($a:expr),+], [$($b:expr),+], $d:expr } => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a: s_t_l!($ty) = transmute($ty::new($($a),+));
let b: s_t_l!($ty) = transmute($ty::new($($b),+));
fn $name() {
let a: s_t_l!($ty) = $ty::new($($a),+).into();
let b: s_t_l!($ty) = $ty::new($($b),+).into();
let r : $ty_out = transmute($fn(a, b));
let r = $ty_out::from(unsafe { $fn(a, b) });
assert_eq!($d, r);
}
}
@ -4677,11 +4725,11 @@ mod tests {
macro_rules! test_vec_1 {
{ $name: ident, $fn:ident, f32x4, [$($a:expr),+], ~[$($d:expr),+] } => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a: vector_float = transmute(f32x4::new($($a),+));
fn $name() {
let a = vector_float::from(f32x4::new($($a),+));
let d: vector_float = transmute(f32x4::new($($d),+));
let r = transmute(vec_cmple(vec_abs(vec_sub($fn(a), d)), vec_splats(f32::EPSILON)));
let d = vector_float::from(f32x4::new($($d),+));
let r = m32x4::from(unsafe { vec_cmple(vec_abs(vec_sub($fn(a), d)), vec_splats(f32::EPSILON)) });
let e = m32x4::new(true, true, true, true);
assert_eq!(e, r);
}
@ -4691,18 +4739,18 @@ mod tests {
};
{ $name: ident, $fn:ident, $ty: ident -> $ty_out: ident, [$($a:expr),+], [$($d:expr),+] } => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a: s_t_l!($ty) = transmute($ty::new($($a),+));
fn $name() {
let a: s_t_l!($ty) = $ty::new($($a),+).into();
let d = $ty_out::new($($d),+);
let r : $ty_out = transmute($fn(a));
let r = $ty_out::from(unsafe { $fn(a) });
assert_eq!(d, r);
}
}
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_ld() {
fn test_vec_ld() {
let pat = [
u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15),
u8x16::new(
@ -4711,14 +4759,14 @@ mod tests {
];
for off in 0..16 {
let v: u8x16 = transmute(vec_ld(0, (pat.as_ptr() as *const u8).offset(off)));
let v = u8x16::from(unsafe { vec_ld(0, (pat.as_ptr() as *const u8).offset(off)) });
assert_eq!(
v,
u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
);
}
for off in 16..32 {
let v: u8x16 = transmute(vec_ld(0, (pat.as_ptr() as *const u8).offset(off)));
let v = u8x16::from(unsafe { vec_ld(0, (pat.as_ptr() as *const u8).offset(off)) });
assert_eq!(
v,
u8x16::new(
@ -4729,7 +4777,7 @@ mod tests {
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_xl() {
fn test_vec_xl() {
let pat = [
u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15),
u8x16::new(
@ -4738,7 +4786,7 @@ mod tests {
];
for off in 0..16 {
let val: u8x16 = transmute(vec_xl(0, (pat.as_ptr() as *const u8).offset(off)));
let val = u8x16::from(unsafe { vec_xl(0, (pat.as_ptr() as *const u8).offset(off)) });
for i in 0..16 {
let v = val.extract_dyn(i);
assert_eq!(off as usize + i, v as usize);
@ -4747,14 +4795,16 @@ mod tests {
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_xst() {
let v: vector_unsigned_char = transmute(u8x16::new(
fn test_vec_xst() {
let v = vector_unsigned_char::from(u8x16::new(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
));
for off in 0..16 {
let mut buf = [0u8; 32];
vec_xst(v, 0, (buf.as_mut_ptr() as *mut u8).offset(off));
unsafe {
vec_xst(v, 0, (buf.as_mut_ptr() as *mut u8).offset(off));
}
for i in 0..16 {
assert_eq!(i as u8, buf[off as usize..][i]);
}
@ -4762,7 +4812,7 @@ mod tests {
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_ldl() {
fn test_vec_ldl() {
let pat = [
u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15),
u8x16::new(
@ -4771,14 +4821,14 @@ mod tests {
];
for off in 0..16 {
let v: u8x16 = transmute(vec_ldl(0, (pat.as_ptr() as *const u8).offset(off)));
let v = u8x16::from(unsafe { vec_ldl(0, (pat.as_ptr() as *const u8).offset(off)) });
assert_eq!(
v,
u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)
);
}
for off in 16..32 {
let v: u8x16 = transmute(vec_ldl(0, (pat.as_ptr() as *const u8).offset(off)));
let v = u8x16::from(unsafe { vec_ldl(0, (pat.as_ptr() as *const u8).offset(off)) });
assert_eq!(
v,
u8x16::new(
@ -4789,30 +4839,30 @@ mod tests {
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_lde_u8() {
fn test_vec_lde_u8() {
let pat = [u8x16::new(
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
)];
for off in 0..16 {
let v: u8x16 = transmute(vec_lde(off, pat.as_ptr() as *const u8));
let v = u8x16::from(unsafe { vec_lde(off, pat.as_ptr() as *const u8) });
assert_eq!(off as u8, v.extract_dyn(off as _));
}
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_lde_u16() {
fn test_vec_lde_u16() {
let pat = [u16x8::new(0, 1, 2, 3, 4, 5, 6, 7)];
for off in 0..8 {
let v: u16x8 = transmute(vec_lde(off * 2, pat.as_ptr() as *const u16));
let v = u16x8::from(unsafe { vec_lde(off * 2, pat.as_ptr() as *const u16) });
assert_eq!(off as u16, v.extract_dyn(off as _));
}
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_lde_u32() {
fn test_vec_lde_u32() {
let pat = [u32x4::new(0, 1, 2, 3)];
for off in 0..4 {
let v: u32x4 = transmute(vec_lde(off * 4, pat.as_ptr() as *const u32));
let v = u32x4::from(unsafe { vec_lde(off * 4, pat.as_ptr() as *const u32) });
assert_eq!(off as u32, v.extract_dyn(off as _));
}
}
@ -5818,9 +5868,9 @@ mod tests {
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_cmpb() {
let a: vector_float = transmute(f32x4::new(0.1, 0.5, 0.6, 0.9));
let b: vector_float = transmute(f32x4::new(-0.1, 0.5, -0.6, 0.9));
fn test_vec_cmpb() {
let a = vector_float::from(f32x4::new(0.1, 0.5, 0.6, 0.9));
let b = vector_float::from(f32x4::new(-0.1, 0.5, -0.6, 0.9));
let d = i32x4::new(
-0b10000000000000000000000000000000,
0,
@ -5828,15 +5878,15 @@ mod tests {
0,
);
assert_eq!(d, transmute(vec_cmpb(a, b)));
assert_eq!(d, i32x4::from(unsafe { vec_cmpb(a, b) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_ceil() {
let a: vector_float = transmute(f32x4::new(0.1, 0.5, 0.6, 0.9));
fn test_vec_ceil() {
let a = vector_float::from(f32x4::new(0.1, 0.5, 0.6, 0.9));
let d = f32x4::new(1.0, 1.0, 1.0, 1.0);
assert_eq!(d, transmute(vec_ceil(a)));
assert_eq!(d, f32x4::from(unsafe { vec_ceil(a) }));
}
test_vec_2! { test_vec_andc, vec_andc, i32x4,
@ -5926,11 +5976,11 @@ mod tests {
macro_rules! test_vec_abs {
{ $name: ident, $ty: ident, $a: expr, $d: expr } => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a = vec_splats($a);
let a: s_t_l!($ty) = vec_abs(a);
fn $name() {
let a = unsafe { vec_splats($a) };
let a: s_t_l!($ty) = unsafe { vec_abs(a) };
let d = $ty::splat($d);
assert_eq!(d, transmute(a));
assert_eq!(d, $ty::from(a));
}
}
}
@ -5943,11 +5993,11 @@ mod tests {
macro_rules! test_vec_abss {
{ $name: ident, $ty: ident, $a: expr, $d: expr } => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a = vec_splats($a);
let a: s_t_l!($ty) = vec_abss(a);
fn $name() {
let a = unsafe { vec_splats($a) };
let a: s_t_l!($ty) = unsafe { vec_abss(a) };
let d = $ty::splat($d);
assert_eq!(d, transmute(a));
assert_eq!(d, $ty::from(a));
}
}
}
@ -5959,10 +6009,10 @@ mod tests {
macro_rules! test_vec_splats {
{ $name: ident, $ty: ident, $a: expr } => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a: s_t_l!($ty) = vec_splats($a);
fn $name() {
let a: s_t_l!($ty) = unsafe { vec_splats($a) };
let d = $ty::splat($a);
assert_eq!(d, transmute(a));
assert_eq!(d, $ty::from(a));
}
}
}
@ -5978,10 +6028,10 @@ mod tests {
macro_rules! test_vec_splat {
{ $name: ident, $fun: ident, $ty: ident, $a: expr, $b: expr} => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a = $fun::<$a>();
fn $name() {
let a = unsafe { $fun::<$a>() };
let d = $ty::splat($b);
assert_eq!(d, transmute(a));
assert_eq!(d, $ty::from(a));
}
}
}
@ -6073,12 +6123,12 @@ mod tests {
macro_rules! test_vec_min {
{ $name: ident, $ty: ident, [$($a:expr),+], [$($b:expr),+], [$($d:expr),+] } => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a: s_t_l!($ty) = transmute($ty::new($($a),+));
let b: s_t_l!($ty) = transmute($ty::new($($b),+));
fn $name() {
let a: s_t_l!($ty) = $ty::new($($a),+).into();
let b: s_t_l!($ty) = $ty::new($($b),+).into();
let d = $ty::new($($d),+);
let r : $ty = transmute(vec_min(a, b));
let r = $ty::from(unsafe { vec_min(a, b) });
assert_eq!(d, r);
}
}
@ -6117,12 +6167,12 @@ mod tests {
macro_rules! test_vec_max {
{ $name: ident, $ty: ident, [$($a:expr),+], [$($b:expr),+], [$($d:expr),+] } => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a: s_t_l!($ty) = transmute($ty::new($($a),+));
let b: s_t_l!($ty) = transmute($ty::new($($b),+));
fn $name() {
let a: s_t_l!($ty) = $ty::new($($a),+).into();
let b: s_t_l!($ty) = $ty::new($($b),+).into();
let d = $ty::new($($d),+);
let r : $ty = transmute(vec_max(a, b));
let r = $ty::from(unsafe { vec_max(a, b) });
assert_eq!(d, r);
}
}
@ -6163,13 +6213,13 @@ mod tests {
$shorttype:ident, $longtype:ident,
[$($a:expr),+], [$($b:expr),+], [$($c:expr),+], [$($d:expr),+]} => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a: $longtype = transmute($shorttype::new($($a),+));
let b: $longtype = transmute($shorttype::new($($b),+));
let c: vector_unsigned_char = transmute(u8x16::new($($c),+));
fn $name() {
let a = $longtype::from($shorttype::new($($a),+));
let b = $longtype::from($shorttype::new($($b),+));
let c = vector_unsigned_char::from(u8x16::new($($c),+));
let d = $shorttype::new($($d),+);
let r: $shorttype = transmute(vec_perm(a, b, c));
let r = $shorttype::from(unsafe { vec_perm(a, b, c) });
assert_eq!(d, r);
}
}
@ -6249,8 +6299,8 @@ mod tests {
[0.0, 1.0, 1.0, 1.1]}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_madds() {
let a: vector_signed_short = transmute(i16x8::new(
fn test_vec_madds() {
let a = vector_signed_short::from(i16x8::new(
0 * 256,
1 * 256,
2 * 256,
@ -6260,19 +6310,19 @@ mod tests {
6 * 256,
7 * 256,
));
let b: vector_signed_short = transmute(i16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c: vector_signed_short = transmute(i16x8::new(0, 1, 2, 3, 4, 5, 6, 7));
let b = vector_signed_short::from(i16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c = vector_signed_short::from(i16x8::new(0, 1, 2, 3, 4, 5, 6, 7));
let d = i16x8::new(0, 3, 6, 9, 12, 15, 18, 21);
assert_eq!(d, transmute(vec_madds(a, b, c)));
assert_eq!(d, i16x8::from(unsafe { vec_madds(a, b, c) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_madd_float() {
let a: vector_float = transmute(f32x4::new(0.1, 0.2, 0.3, 0.4));
let b: vector_float = transmute(f32x4::new(0.1, 0.2, 0.3, 0.4));
let c: vector_float = transmute(f32x4::new(0.1, 0.2, 0.3, 0.4));
fn test_vec_madd_float() {
let a = vector_float::from(f32x4::new(0.1, 0.2, 0.3, 0.4));
let b = vector_float::from(f32x4::new(0.1, 0.2, 0.3, 0.4));
let c = vector_float::from(f32x4::new(0.1, 0.2, 0.3, 0.4));
let d = f32x4::new(
0.1 * 0.1 + 0.1,
0.2 * 0.2 + 0.2,
@ -6280,26 +6330,26 @@ mod tests {
0.4 * 0.4 + 0.4,
);
assert_eq!(d, transmute(vec_madd(a, b, c)));
assert_eq!(d, f32x4::from(unsafe { vec_madd(a, b, c) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_nmsub_float() {
let a: vector_float = transmute(f32x4::new(0.1, 0.2, 0.3, 0.4));
let b: vector_float = transmute(f32x4::new(0.1, 0.2, 0.3, 0.4));
let c: vector_float = transmute(f32x4::new(0.1, 0.2, 0.3, 0.4));
fn test_vec_nmsub_float() {
let a = vector_float::from(f32x4::new(0.1, 0.2, 0.3, 0.4));
let b = vector_float::from(f32x4::new(0.1, 0.2, 0.3, 0.4));
let c = vector_float::from(f32x4::new(0.1, 0.2, 0.3, 0.4));
let d = f32x4::new(
-(0.1 * 0.1 - 0.1),
-(0.2 * 0.2 - 0.2),
-(0.3 * 0.3 - 0.3),
-(0.4 * 0.4 - 0.4),
);
assert_eq!(d, transmute(vec_nmsub(a, b, c)));
assert_eq!(d, f32x4::from(unsafe { vec_nmsub(a, b, c) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_mradds() {
let a: vector_signed_short = transmute(i16x8::new(
fn test_vec_mradds() {
let a = vector_signed_short::from(i16x8::new(
0 * 256,
1 * 256,
2 * 256,
@ -6309,25 +6359,25 @@ mod tests {
6 * 256,
7 * 256,
));
let b: vector_signed_short = transmute(i16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c: vector_signed_short = transmute(i16x8::new(0, 1, 2, 3, 4, 5, 6, i16::MAX - 1));
let b = vector_signed_short::from(i16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c = vector_signed_short::from(i16x8::new(0, 1, 2, 3, 4, 5, 6, i16::MAX - 1));
let d = i16x8::new(0, 3, 6, 9, 12, 15, 18, i16::MAX);
assert_eq!(d, transmute(vec_mradds(a, b, c)));
assert_eq!(d, i16x8::from(unsafe { vec_mradds(a, b, c) }));
}
macro_rules! test_vec_mladd {
{$name:ident, $sa:ident, $la:ident, $sbc:ident, $lbc:ident, $sd:ident,
[$($a:expr),+], [$($b:expr),+], [$($c:expr),+], [$($d:expr),+]} => {
#[simd_test(enable = "altivec")]
unsafe fn $name() {
let a: $la = transmute($sa::new($($a),+));
let b: $lbc = transmute($sbc::new($($b),+));
let c = transmute($sbc::new($($c),+));
fn $name() {
let a = $la::from($sa::new($($a),+));
let b = $lbc::from($sbc::new($($b),+));
let c = $sbc::new($($c),+).into();
let d = $sd::new($($d),+);
assert_eq!(d, transmute(vec_mladd(a, b, c)));
assert_eq!(d, $sd::from(unsafe { vec_mladd(a, b, c) }));
}
}
}
@ -6335,24 +6385,24 @@ mod tests {
test_vec_mladd! { test_vec_mladd_u16x8_u16x8, u16x8, vector_unsigned_short, u16x8, vector_unsigned_short, u16x8,
[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 2, 6, 12, 20, 30, 42, 56]
}
test_vec_mladd! { test_vec_mladd_u16x8_i16x8, u16x8, vector_unsigned_short, i16x8, vector_unsigned_short, i16x8,
test_vec_mladd! { test_vec_mladd_u16x8_i16x8, u16x8, vector_unsigned_short, i16x8, vector_signed_short, i16x8,
[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 2, 6, 12, 20, 30, 42, 56]
}
test_vec_mladd! { test_vec_mladd_i16x8_u16x8, i16x8, vector_signed_short, u16x8, vector_unsigned_short, i16x8,
[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 2, 6, 12, 20, 30, 42, 56]
}
test_vec_mladd! { test_vec_mladd_i16x8_i16x8, i16x8, vector_signed_short, i16x8, vector_unsigned_short, i16x8,
test_vec_mladd! { test_vec_mladd_i16x8_i16x8, i16x8, vector_signed_short, i16x8, vector_signed_short, i16x8,
[0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7], [0, 2, 6, 12, 20, 30, 42, 56]
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_msum_unsigned_char() {
let a: vector_unsigned_char =
transmute(u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7));
let b: vector_unsigned_char = transmute(u8x16::new(
fn test_vec_msum_unsigned_char() {
let a =
vector_unsigned_char::from(u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7));
let b = vector_unsigned_char::from(u8x16::new(
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
));
let c: vector_unsigned_int = transmute(u32x4::new(0, 1, 2, 3));
let c = vector_unsigned_int::from(u32x4::new(0, 1, 2, 3));
let d = u32x4::new(
(0 + 1 + 2 + 3) * 255 + 0,
(4 + 5 + 6 + 7) * 255 + 1,
@ -6360,17 +6410,17 @@ mod tests {
(4 + 5 + 6 + 7) * 255 + 3,
);
assert_eq!(d, transmute(vec_msum(a, b, c)));
assert_eq!(d, u32x4::from(unsafe { vec_msum(a, b, c) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_msum_signed_char() {
let a: vector_signed_char = transmute(i8x16::new(
fn test_vec_msum_signed_char() {
let a = vector_signed_char::from(i8x16::new(
0, -1, 2, -3, 1, -1, 1, -1, 0, 1, 2, 3, 4, -5, -6, -7,
));
let b: vector_unsigned_char =
transmute(i8x16::new(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1));
let c: vector_signed_int = transmute(u32x4::new(0, 1, 2, 3));
let b =
vector_unsigned_char::from(u8x16::new(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1));
let c = vector_signed_int::from(i32x4::new(0, 1, 2, 3));
let d = i32x4::new(
(0 - 1 + 2 - 3) + 0,
(0) + 1,
@ -6378,11 +6428,12 @@ mod tests {
(4 - 5 - 6 - 7) + 3,
);
assert_eq!(d, transmute(vec_msum(a, b, c)));
assert_eq!(d, i32x4::from(unsafe { vec_msum(a, b, c) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_msum_unsigned_short() {
let a: vector_unsigned_short = transmute(u16x8::new(
fn test_vec_msum_unsigned_short() {
let a = vector_unsigned_short::from(u16x8::new(
0 * 256,
1 * 256,
2 * 256,
@ -6392,9 +6443,8 @@ mod tests {
6 * 256,
7 * 256,
));
let b: vector_unsigned_short =
transmute(u16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c: vector_unsigned_int = transmute(u32x4::new(0, 1, 2, 3));
let b = vector_unsigned_short::from(u16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c = vector_unsigned_int::from(u32x4::new(0, 1, 2, 3));
let d = u32x4::new(
(0 + 1) * 256 * 256 + 0,
(2 + 3) * 256 * 256 + 1,
@ -6402,12 +6452,12 @@ mod tests {
(6 + 7) * 256 * 256 + 3,
);
assert_eq!(d, transmute(vec_msum(a, b, c)));
assert_eq!(d, u32x4::from(unsafe { vec_msum(a, b, c) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_msum_signed_short() {
let a: vector_signed_short = transmute(i16x8::new(
fn test_vec_msum_signed_short() {
let a = vector_signed_short::from(i16x8::new(
0 * 256,
-1 * 256,
2 * 256,
@ -6417,8 +6467,8 @@ mod tests {
6 * 256,
-7 * 256,
));
let b: vector_signed_short = transmute(i16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c: vector_signed_int = transmute(i32x4::new(0, 1, 2, 3));
let b = vector_signed_short::from(i16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c = vector_signed_int::from(i32x4::new(0, 1, 2, 3));
let d = i32x4::new(
(0 - 1) * 256 * 256 + 0,
(2 - 3) * 256 * 256 + 1,
@ -6426,12 +6476,12 @@ mod tests {
(6 - 7) * 256 * 256 + 3,
);
assert_eq!(d, transmute(vec_msum(a, b, c)));
assert_eq!(d, i32x4::from(unsafe { vec_msum(a, b, c) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_msums_unsigned() {
let a: vector_unsigned_short = transmute(u16x8::new(
fn test_vec_msums_unsigned() {
let a = vector_unsigned_short::from(u16x8::new(
0 * 256,
1 * 256,
2 * 256,
@ -6441,9 +6491,8 @@ mod tests {
6 * 256,
7 * 256,
));
let b: vector_unsigned_short =
transmute(u16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c: vector_unsigned_int = transmute(u32x4::new(0, 1, 2, 3));
let b = vector_unsigned_short::from(u16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c = vector_unsigned_int::from(u32x4::new(0, 1, 2, 3));
let d = u32x4::new(
(0 + 1) * 256 * 256 + 0,
(2 + 3) * 256 * 256 + 1,
@ -6451,12 +6500,12 @@ mod tests {
(6 + 7) * 256 * 256 + 3,
);
assert_eq!(d, transmute(vec_msums(a, b, c)));
assert_eq!(d, u32x4::from(unsafe { vec_msums(a, b, c) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_msums_signed() {
let a: vector_signed_short = transmute(i16x8::new(
fn test_vec_msums_signed() {
let a = vector_signed_short::from(i16x8::new(
0 * 256,
-1 * 256,
2 * 256,
@ -6466,8 +6515,8 @@ mod tests {
6 * 256,
-7 * 256,
));
let b: vector_signed_short = transmute(i16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c: vector_signed_int = transmute(i32x4::new(0, 1, 2, 3));
let b = vector_signed_short::from(i16x8::new(256, 256, 256, 256, 256, 256, 256, 256));
let c = vector_signed_int::from(i32x4::new(0, 1, 2, 3));
let d = i32x4::new(
(0 - 1) * 256 * 256 + 0,
(2 - 3) * 256 * 256 + 1,
@ -6475,23 +6524,23 @@ mod tests {
(6 - 7) * 256 * 256 + 3,
);
assert_eq!(d, transmute(vec_msums(a, b, c)));
assert_eq!(d, i32x4::from(unsafe { vec_msums(a, b, c) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_sum2s() {
let a: vector_signed_int = transmute(i32x4::new(0, 1, 2, 3));
let b: vector_signed_int = transmute(i32x4::new(0, 1, 2, 3));
fn test_vec_sum2s() {
let a = vector_signed_int::from(i32x4::new(0, 1, 2, 3));
let b = vector_signed_int::from(i32x4::new(0, 1, 2, 3));
let d = i32x4::new(0, 0 + 1 + 1, 0, 2 + 3 + 3);
assert_eq!(d, transmute(vec_sum2s(a, b)));
assert_eq!(d, i32x4::from(unsafe { vec_sum2s(a, b) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_sum4s_unsigned_char() {
let a: vector_unsigned_char =
transmute(u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7));
let b: vector_unsigned_int = transmute(u32x4::new(0, 1, 2, 3));
fn test_vec_sum4s_unsigned_char() {
let a =
vector_unsigned_char::from(u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7));
let b = vector_unsigned_int::from(u32x4::new(0, 1, 2, 3));
let d = u32x4::new(
0 + 1 + 2 + 3 + 0,
4 + 5 + 6 + 7 + 1,
@ -6499,13 +6548,13 @@ mod tests {
4 + 5 + 6 + 7 + 3,
);
assert_eq!(d, transmute(vec_sum4s(a, b)));
assert_eq!(d, u32x4::from(unsafe { vec_sum4s(a, b) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_sum4s_signed_char() {
let a: vector_signed_char =
transmute(i8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7));
let b: vector_signed_int = transmute(i32x4::new(0, 1, 2, 3));
fn test_vec_sum4s_signed_char() {
let a =
vector_signed_char::from(i8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7));
let b = vector_signed_int::from(i32x4::new(0, 1, 2, 3));
let d = i32x4::new(
0 + 1 + 2 + 3 + 0,
4 + 5 + 6 + 7 + 1,
@ -6513,109 +6562,110 @@ mod tests {
4 + 5 + 6 + 7 + 3,
);
assert_eq!(d, transmute(vec_sum4s(a, b)));
assert_eq!(d, i32x4::from(unsafe { vec_sum4s(a, b) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_sum4s_signed_short() {
let a: vector_signed_short = transmute(i16x8::new(0, 1, 2, 3, 4, 5, 6, 7));
let b: vector_signed_int = transmute(i32x4::new(0, 1, 2, 3));
fn test_vec_sum4s_signed_short() {
let a = vector_signed_short::from(i16x8::new(0, 1, 2, 3, 4, 5, 6, 7));
let b = vector_signed_int::from(i32x4::new(0, 1, 2, 3));
let d = i32x4::new(0 + 1 + 0, 2 + 3 + 1, 4 + 5 + 2, 6 + 7 + 3);
assert_eq!(d, transmute(vec_sum4s(a, b)));
assert_eq!(d, i32x4::from(unsafe { vec_sum4s(a, b) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_mule_unsigned_char() {
let a: vector_unsigned_char =
transmute(u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7));
fn test_vec_mule_unsigned_char() {
let a =
vector_unsigned_char::from(u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7));
let d = u16x8::new(0 * 0, 2 * 2, 4 * 4, 6 * 6, 0 * 0, 2 * 2, 4 * 4, 6 * 6);
assert_eq!(d, transmute(vec_mule(a, a)));
assert_eq!(d, u16x8::from(unsafe { vec_mule(a, a) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_mule_signed_char() {
let a: vector_signed_char = transmute(i8x16::new(
fn test_vec_mule_signed_char() {
let a = vector_signed_char::from(i8x16::new(
0, 1, -2, 3, -4, 5, -6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
));
let d = i16x8::new(0 * 0, 2 * 2, 4 * 4, 6 * 6, 0 * 0, 2 * 2, 4 * 4, 6 * 6);
assert_eq!(d, transmute(vec_mule(a, a)));
assert_eq!(d, i16x8::from(unsafe { vec_mule(a, a) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_mule_unsigned_short() {
let a: vector_unsigned_short = transmute(u16x8::new(0, 1, 2, 3, 4, 5, 6, 7));
fn test_vec_mule_unsigned_short() {
let a = vector_unsigned_short::from(u16x8::new(0, 1, 2, 3, 4, 5, 6, 7));
let d = u32x4::new(0 * 0, 2 * 2, 4 * 4, 6 * 6);
assert_eq!(d, transmute(vec_mule(a, a)));
assert_eq!(d, u32x4::from(unsafe { vec_mule(a, a) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_mule_signed_short() {
let a: vector_signed_short = transmute(i16x8::new(0, 1, -2, 3, -4, 5, -6, 7));
fn test_vec_mule_signed_short() {
let a = vector_signed_short::from(i16x8::new(0, 1, -2, 3, -4, 5, -6, 7));
let d = i32x4::new(0 * 0, 2 * 2, 4 * 4, 6 * 6);
assert_eq!(d, transmute(vec_mule(a, a)));
assert_eq!(d, i32x4::from(unsafe { vec_mule(a, a) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_mulo_unsigned_char() {
let a: vector_unsigned_char =
transmute(u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7));
fn test_vec_mulo_unsigned_char() {
let a =
vector_unsigned_char::from(u8x16::new(0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7));
let d = u16x8::new(1 * 1, 3 * 3, 5 * 5, 7 * 7, 1 * 1, 3 * 3, 5 * 5, 7 * 7);
assert_eq!(d, transmute(vec_mulo(a, a)));
assert_eq!(d, u16x8::from(unsafe { vec_mulo(a, a) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_mulo_signed_char() {
let a: vector_signed_char = transmute(i8x16::new(
fn test_vec_mulo_signed_char() {
let a = vector_signed_char::from(i8x16::new(
0, 1, -2, 3, -4, 5, -6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
));
let d = i16x8::new(1 * 1, 3 * 3, 5 * 5, 7 * 7, 1 * 1, 3 * 3, 5 * 5, 7 * 7);
assert_eq!(d, transmute(vec_mulo(a, a)));
assert_eq!(d, i16x8::from(unsafe { vec_mulo(a, a) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_mulo_unsigned_short() {
let a: vector_unsigned_short = transmute(u16x8::new(0, 1, 2, 3, 4, 5, 6, 7));
fn test_vec_mulo_unsigned_short() {
let a = vector_unsigned_short::from(u16x8::new(0, 1, 2, 3, 4, 5, 6, 7));
let d = u32x4::new(1 * 1, 3 * 3, 5 * 5, 7 * 7);
assert_eq!(d, transmute(vec_mulo(a, a)));
assert_eq!(d, u32x4::from(unsafe { vec_mulo(a, a) }));
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_mulo_signed_short() {
let a: vector_signed_short = transmute(i16x8::new(0, 1, -2, 3, -4, 5, -6, 7));
fn test_vec_mulo_signed_short() {
let a = vector_signed_short::from(i16x8::new(0, 1, -2, 3, -4, 5, -6, 7));
let d = i32x4::new(1 * 1, 3 * 3, 5 * 5, 7 * 7);
assert_eq!(d, transmute(vec_mulo(a, a)));
assert_eq!(d, i32x4::from(unsafe { vec_mulo(a, a) }));
}
#[simd_test(enable = "altivec")]
unsafe fn vec_add_i32x4_i32x4() {
fn vec_add_i32x4_i32x4() {
let x = i32x4::new(1, 2, 3, 4);
let y = i32x4::new(4, 3, 2, 1);
let x: vector_signed_int = transmute(x);
let y: vector_signed_int = transmute(y);
let z = vec_add(x, y);
assert_eq!(i32x4::splat(5), transmute(z));
let x = vector_signed_int::from(x);
let y = vector_signed_int::from(y);
let z = unsafe { vec_add(x, y) };
assert_eq!(i32x4::splat(5), i32x4::from(z));
}
#[simd_test(enable = "altivec")]
unsafe fn vec_ctf_u32() {
let v: vector_unsigned_int = transmute(u32x4::new(u32::MIN, u32::MAX, u32::MAX, 42));
let v2 = vec_ctf::<1, _>(v);
let r2: vector_float = transmute(f32x4::new(0.0, 2147483600.0, 2147483600.0, 21.0));
let v4 = vec_ctf::<2, _>(v);
let r4: vector_float = transmute(f32x4::new(0.0, 1073741800.0, 1073741800.0, 10.5));
let v8 = vec_ctf::<3, _>(v);
let r8: vector_float = transmute(f32x4::new(0.0, 536870900.0, 536870900.0, 5.25));
fn vec_ctf_u32() {
let v = vector_unsigned_int::from(u32x4::new(u32::MIN, u32::MAX, u32::MAX, 42));
let v2 = unsafe { vec_ctf::<1, _>(v) };
let r2 = vector_float::from(f32x4::new(0.0, 2147483600.0, 2147483600.0, 21.0));
let v4 = unsafe { vec_ctf::<2, _>(v) };
let r4 = vector_float::from(f32x4::new(0.0, 1073741800.0, 1073741800.0, 10.5));
let v8 = unsafe { vec_ctf::<3, _>(v) };
let r8 = vector_float::from(f32x4::new(0.0, 536870900.0, 536870900.0, 5.25));
let check = |a, b| {
let r = transmute(vec_cmple(vec_abs(vec_sub(a, b)), vec_splats(f32::EPSILON)));
let r =
m32x4::from(unsafe { vec_cmple(vec_abs(vec_sub(a, b)), vec_splats(f32::EPSILON)) });
let e = m32x4::new(true, true, true, true);
assert_eq!(e, r);
};
@ -6626,26 +6676,32 @@ mod tests {
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_ctu() {
fn test_vec_ctu() {
let v = u32x4::new(u32::MIN, u32::MAX, u32::MAX, 42);
let v2: u32x4 = transmute(vec_ctu::<1>(transmute(f32x4::new(
0.0,
2147483600.0,
2147483600.0,
21.0,
))));
let v4: u32x4 = transmute(vec_ctu::<2>(transmute(f32x4::new(
0.0,
1073741800.0,
1073741800.0,
10.5,
))));
let v8: u32x4 = transmute(vec_ctu::<3>(transmute(f32x4::new(
0.0,
536870900.0,
536870900.0,
5.25,
))));
let v2 = u32x4::from(unsafe {
vec_ctu::<1>(vector_float::from(f32x4::new(
0.0,
2147483600.0,
2147483600.0,
21.0,
)))
});
let v4 = u32x4::from(unsafe {
vec_ctu::<2>(vector_float::from(f32x4::new(
0.0,
1073741800.0,
1073741800.0,
10.5,
)))
});
let v8 = u32x4::from(unsafe {
vec_ctu::<3>(vector_float::from(f32x4::new(
0.0,
536870900.0,
536870900.0,
5.25,
)))
});
assert_eq!(v2, v);
assert_eq!(v4, v);
@ -6653,18 +6709,18 @@ mod tests {
}
#[simd_test(enable = "altivec")]
unsafe fn vec_ctf_i32() {
let v: vector_signed_int = transmute(i32x4::new(i32::MIN, i32::MAX, i32::MAX - 42, 42));
let v2 = vec_ctf::<1, _>(v);
let r2: vector_float =
transmute(f32x4::new(-1073741800.0, 1073741800.0, 1073741800.0, 21.0));
let v4 = vec_ctf::<2, _>(v);
let r4: vector_float = transmute(f32x4::new(-536870900.0, 536870900.0, 536870900.0, 10.5));
let v8 = vec_ctf::<3, _>(v);
let r8: vector_float = transmute(f32x4::new(-268435460.0, 268435460.0, 268435460.0, 5.25));
fn vec_ctf_i32() {
let v = vector_signed_int::from(i32x4::new(i32::MIN, i32::MAX, i32::MAX - 42, 42));
let v2 = unsafe { vec_ctf::<1, _>(v) };
let r2 = vector_float::from(f32x4::new(-1073741800.0, 1073741800.0, 1073741800.0, 21.0));
let v4 = unsafe { vec_ctf::<2, _>(v) };
let r4 = vector_float::from(f32x4::new(-536870900.0, 536870900.0, 536870900.0, 10.5));
let v8 = unsafe { vec_ctf::<3, _>(v) };
let r8 = vector_float::from(f32x4::new(-268435460.0, 268435460.0, 268435460.0, 5.25));
let check = |a, b| {
let r = transmute(vec_cmple(vec_abs(vec_sub(a, b)), vec_splats(f32::EPSILON)));
let r =
m32x4::from(unsafe { vec_cmple(vec_abs(vec_sub(a, b)), vec_splats(f32::EPSILON)) });
println!("{:?} {:?}", a, b);
let e = m32x4::new(true, true, true, true);
assert_eq!(e, r);
@ -6676,26 +6732,32 @@ mod tests {
}
#[simd_test(enable = "altivec")]
unsafe fn test_vec_cts() {
fn test_vec_cts() {
let v = i32x4::new(i32::MIN, i32::MAX, i32::MAX, 42);
let v2: i32x4 = transmute(vec_cts::<1>(transmute(f32x4::new(
-1073741800.0,
1073741800.0,
1073741800.0,
21.0,
))));
let v4: i32x4 = transmute(vec_cts::<2>(transmute(f32x4::new(
-536870900.0,
536870900.0,
536870900.0,
10.5,
))));
let v8: i32x4 = transmute(vec_cts::<3>(transmute(f32x4::new(
-268435460.0,
268435460.0,
268435460.0,
5.25,
))));
let v2 = i32x4::from(unsafe {
vec_cts::<1>(transmute(f32x4::new(
-1073741800.0,
1073741800.0,
1073741800.0,
21.0,
)))
});
let v4 = i32x4::from(unsafe {
vec_cts::<2>(transmute(f32x4::new(
-536870900.0,
536870900.0,
536870900.0,
10.5,
)))
});
let v8 = i32x4::from(unsafe {
vec_cts::<3>(transmute(f32x4::new(
-268435460.0,
268435460.0,
268435460.0,
5.25,
)))
});
assert_eq!(v2, v);
assert_eq!(v4, v);

View file

@ -9,6 +9,7 @@
#![allow(non_camel_case_types)]
use crate::core_arch::powerpc::*;
use crate::core_arch::simd::*;
#[cfg(test)]
use stdarch_test::assert_instr;
@ -34,6 +35,22 @@ types! {
// pub struct vector_unsigned___int128 = i128x1;
}
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
impl From<m64x2> for vector_bool_long {
#[inline]
fn from(value: m64x2) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
impl From<vector_bool_long> for m64x2 {
#[inline]
fn from(value: vector_bool_long) -> Self {
unsafe { transmute(value) }
}
}
#[allow(improper_ctypes)]
unsafe extern "C" {
#[link_name = "llvm.ppc.altivec.vperm"]
@ -46,7 +63,6 @@ unsafe extern "C" {
mod sealed {
use super::*;
use crate::core_arch::simd::*;
#[unstable(feature = "stdarch_powerpc", issue = "111145")]
pub trait VectorPermDI {
@ -221,14 +237,16 @@ mod tests {
macro_rules! test_vec_xxpermdi {
{$name:ident, $shorttype:ident, $longtype:ident, [$($a:expr),+], [$($b:expr),+], [$($c:expr),+], [$($d:expr),+]} => {
#[simd_test(enable = "vsx")]
unsafe fn $name() {
let a: $longtype = transmute($shorttype::new($($a),+, $($b),+));
let b = transmute($shorttype::new($($c),+, $($d),+));
fn $name() {
let a = $longtype::from($shorttype::new($($a),+, $($b),+));
let b = $longtype::from($shorttype::new($($c),+, $($d),+));
assert_eq!($shorttype::new($($a),+, $($c),+), transmute(vec_xxpermdi::<_, 0>(a, b)));
assert_eq!($shorttype::new($($b),+, $($c),+), transmute(vec_xxpermdi::<_, 1>(a, b)));
assert_eq!($shorttype::new($($a),+, $($d),+), transmute(vec_xxpermdi::<_, 2>(a, b)));
assert_eq!($shorttype::new($($b),+, $($d),+), transmute(vec_xxpermdi::<_, 3>(a, b)));
unsafe {
assert_eq!($shorttype::new($($a),+, $($c),+), $shorttype::from(vec_xxpermdi::<_, 0>(a, b)));
assert_eq!($shorttype::new($($b),+, $($c),+), $shorttype::from(vec_xxpermdi::<_, 1>(a, b)));
assert_eq!($shorttype::new($($a),+, $($d),+), $shorttype::from(vec_xxpermdi::<_, 2>(a, b)));
assert_eq!($shorttype::new($($b),+, $($d),+), $shorttype::from(vec_xxpermdi::<_, 3>(a, b)));
}
}
}
}

View file

@ -51,6 +51,54 @@ types! {
pub struct vector_double(2 x f64);
}
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl From<m8x16> for vector_bool_char {
#[inline]
fn from(value: m8x16) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl From<vector_bool_char> for m8x16 {
#[inline]
fn from(value: vector_bool_char) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl From<m16x8> for vector_bool_short {
#[inline]
fn from(value: m16x8) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl From<vector_bool_short> for m16x8 {
#[inline]
fn from(value: vector_bool_short) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl From<m32x4> for vector_bool_int {
#[inline]
fn from(value: m32x4) -> Self {
unsafe { transmute(value) }
}
}
#[unstable(feature = "stdarch_s390x", issue = "135681")]
impl From<vector_bool_int> for m32x4 {
#[inline]
fn from(value: vector_bool_int) -> Self {
unsafe { transmute(value) }
}
}
#[repr(C, packed)]
struct PackedTuple<T, U> {
x: T,
@ -6051,27 +6099,16 @@ mod tests {
}
macro_rules! test_vec_1 {
{ $name: ident, $fn:ident, f32x4, [$($a:expr),+], ~[$($d:expr),+] } => {
#[simd_test(enable = "vector")]
unsafe fn $name() {
let a: vector_float = transmute(f32x4::new($($a),+));
let d: vector_float = transmute(f32x4::new($($d),+));
let r = transmute(vec_cmple(vec_abs(vec_sub($fn(a), d)), vec_splats(f32::EPSILON)));
let e = m32x4::new(true, true, true, true);
assert_eq!(e, r);
}
};
{ $name: ident, $fn:ident, $ty: ident, [$($a:expr),+], [$($d:expr),+] } => {
test_vec_1! { $name, $fn, $ty -> $ty, [$($a),+], [$($d),+] }
};
{ $name: ident, $fn:ident, $ty: ident -> $ty_out: ident, [$($a:expr),+], [$($d:expr),+] } => {
#[simd_test(enable = "vector")]
unsafe fn $name() {
let a: s_t_l!($ty) = transmute($ty::new($($a),+));
fn $name() {
let a: s_t_l!($ty) = $ty::new($($a),+).into();
let d = $ty_out::new($($d),+);
let r : $ty_out = transmute($fn(a));
let r = $ty_out::from(unsafe { $fn(a) });
assert_eq!(d, r);
}
}
@ -6086,35 +6123,23 @@ mod tests {
};
{ $name: ident, $fn:ident, $ty1: ident, $ty2: ident -> $ty_out: ident, [$($a:expr),+], [$($b:expr),+], [$($d:expr),+] } => {
#[simd_test(enable = "vector")]
unsafe fn $name() {
let a: s_t_l!($ty1) = transmute($ty1::new($($a),+));
let b: s_t_l!($ty2) = transmute($ty2::new($($b),+));
fn $name() {
let a: s_t_l!($ty1) = $ty1::new($($a),+).into();
let b: s_t_l!($ty2) = $ty2::new($($b),+).into();
let d = $ty_out::new($($d),+);
let r : $ty_out = transmute($fn(a, b));
let r = $ty_out::from(unsafe { $fn(a, b) });
assert_eq!(d, r);
}
};
{ $name: ident, $fn:ident, $ty: ident -> $ty_out: ident, [$($a:expr),+], [$($b:expr),+], $d:expr } => {
#[simd_test(enable = "vector")]
unsafe fn $name() {
let a: s_t_l!($ty) = transmute($ty::new($($a),+));
let b: s_t_l!($ty) = transmute($ty::new($($b),+));
let r : $ty_out = transmute($fn(a, b));
assert_eq!($d, r);
}
}
}
#[simd_test(enable = "vector")]
unsafe fn vec_add_i32x4_i32x4() {
let x = i32x4::new(1, 2, 3, 4);
let y = i32x4::new(4, 3, 2, 1);
let x: vector_signed_int = transmute(x);
let y: vector_signed_int = transmute(y);
let z = vec_add(x, y);
assert_eq!(i32x4::splat(5), transmute(z));
fn vec_add_i32x4_i32x4() {
let x = vector_signed_int::from(i32x4::new(1, 2, 3, 4));
let y = vector_signed_int::from(i32x4::new(4, 3, 2, 1));
let z = unsafe { vec_add(x, y) };
assert_eq!(i32x4::splat(5), i32x4::from(z));
}
macro_rules! test_vec_sub {
@ -6232,11 +6257,11 @@ mod tests {
macro_rules! test_vec_abs {
{ $name: ident, $ty: ident, $a: expr, $d: expr } => {
#[simd_test(enable = "vector")]
unsafe fn $name() {
let a: s_t_l!($ty) = vec_splats($a);
let a: s_t_l!($ty) = vec_abs(a);
fn $name() {
let a: s_t_l!($ty) = unsafe { vec_splats($a) };
let a: s_t_l!($ty) = unsafe { vec_abs(a) };
let d = $ty::splat($d);
assert_eq!(d, transmute(a));
assert_eq!(d, $ty::from(a));
}
}
}
@ -6386,7 +6411,7 @@ mod tests {
[0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 16],
[4, 2, 1, 8] }
test_vec_2! { test_vec_sral_pos, vec_sral, u32x4, u8x16 -> i32x4,
test_vec_2! { test_vec_sral_pos, vec_sral, u32x4, u8x16 -> u32x4,
[0b1000, 0b1000, 0b1000, 0b1000],
[0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 16],
[4, 2, 1, 8] }
@ -6423,13 +6448,13 @@ mod tests {
$shorttype:ident, $longtype:ident,
[$($a:expr),+], [$($b:expr),+], [$($c:expr),+], [$($d:expr),+]} => {
#[simd_test(enable = "vector")]
unsafe fn $name() {
let a: $longtype = transmute($shorttype::new($($a),+));
let b: $longtype = transmute($shorttype::new($($b),+));
let c: vector_unsigned_char = transmute(u8x16::new($($c),+));
fn $name() {
let a = $longtype::from($shorttype::new($($a),+));
let b = $longtype::from($shorttype::new($($b),+));
let c = vector_unsigned_char::from(u8x16::new($($c),+));
let d = $shorttype::new($($d),+);
let r: $shorttype = transmute(vec_perm(a, b, c));
let r = $shorttype::from(unsafe { vec_perm(a, b, c) });
assert_eq!(d, r);
}
}
@ -6512,46 +6537,46 @@ mod tests {
[core::f32::consts::PI, 1.0, 25.0, 2.0],
[core::f32::consts::PI.sqrt(), 1.0, 5.0, core::f32::consts::SQRT_2] }
test_vec_2! { test_vec_find_any_eq, vec_find_any_eq, i32x4, i32x4 -> u32x4,
test_vec_2! { test_vec_find_any_eq, vec_find_any_eq, i32x4, i32x4 -> i32x4,
[1, -2, 3, -4],
[-5, 3, -7, 8],
[0, 0, 0xFFFFFFFF, 0]
[0, 0, !0, 0]
}
test_vec_2! { test_vec_find_any_ne, vec_find_any_ne, i32x4, i32x4 -> u32x4,
test_vec_2! { test_vec_find_any_ne, vec_find_any_ne, i32x4, i32x4 -> i32x4,
[1, -2, 3, -4],
[-5, 3, -7, 8],
[0xFFFFFFFF, 0xFFFFFFFF, 0, 0xFFFFFFFF]
[!0, !0, 0, !0]
}
test_vec_2! { test_vec_find_any_eq_idx_1, vec_find_any_eq_idx, i32x4, i32x4 -> u32x4,
test_vec_2! { test_vec_find_any_eq_idx_1, vec_find_any_eq_idx, i32x4, i32x4 -> i32x4,
[1, 2, 3, 4],
[5, 3, 7, 8],
[0, 8, 0, 0]
}
test_vec_2! { test_vec_find_any_eq_idx_2, vec_find_any_eq_idx, i32x4, i32x4 -> u32x4,
test_vec_2! { test_vec_find_any_eq_idx_2, vec_find_any_eq_idx, i32x4, i32x4 -> i32x4,
[1, 2, 3, 4],
[5, 6, 7, 8],
[0, 16, 0, 0]
}
test_vec_2! { test_vec_find_any_ne_idx_1, vec_find_any_ne_idx, i32x4, i32x4 -> u32x4,
test_vec_2! { test_vec_find_any_ne_idx_1, vec_find_any_ne_idx, i32x4, i32x4 -> i32x4,
[1, 2, 3, 4],
[1, 5, 3, 4],
[0, 4, 0, 0]
}
test_vec_2! { test_vec_find_any_ne_idx_2, vec_find_any_ne_idx, i32x4, i32x4 -> u32x4,
test_vec_2! { test_vec_find_any_ne_idx_2, vec_find_any_ne_idx, i32x4, i32x4 -> i32x4,
[1, 2, 3, 4],
[1, 2, 3, 4],
[0, 16, 0, 0]
}
test_vec_2! { test_vec_find_any_eq_or_0_idx_1, vec_find_any_eq_or_0_idx, i32x4, i32x4 -> u32x4,
test_vec_2! { test_vec_find_any_eq_or_0_idx_1, vec_find_any_eq_or_0_idx, i32x4, i32x4 -> i32x4,
[1, 2, 0, 4],
[5, 6, 7, 8],
[0, 8, 0, 0]
}
test_vec_2! { test_vec_find_any_ne_or_0_idx_1, vec_find_any_ne_or_0_idx, i32x4, i32x4 -> u32x4,
test_vec_2! { test_vec_find_any_ne_or_0_idx_1, vec_find_any_ne_or_0_idx, i32x4, i32x4 -> i32x4,
[1, 2, 0, 4],
[1, 2, 3, 4],
[0, 8, 0, 0]