Skip to content

Commit 5946cf7

Browse files
folkertdevAmanieu
authored andcommitted
add vec_nabs
1 parent 73dc2ef commit 5946cf7

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

Diff for: crates/core_arch/src/s390x/macros.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,7 @@ macro_rules! impl_neg {
436436
impl crate::ops::Neg for s_t_l!($s) {
437437
type Output = s_t_l!($s);
438438
fn neg(self) -> Self::Output {
439-
let zero = $s::splat($zero);
440-
unsafe { transmute(simd_sub(zero, transmute(self))) }
439+
unsafe { simd_neg(self) }
441440
}
442441
}
443442
};

Diff for: crates/core_arch/src/s390x/vector.rs

+40
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,31 @@ mod sealed {
506506
impl_vec_trait! { [VectorAbs vec_abs] vec_abs_f32 (vector_float) }
507507
impl_vec_trait! { [VectorAbs vec_abs] vec_abs_f64 (vector_double) }
508508

509+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
510+
pub trait VectorNabs {
511+
unsafe fn vec_nabs(self) -> Self;
512+
}
513+
514+
#[inline]
515+
#[target_feature(enable = "vector")]
516+
#[cfg_attr(
517+
all(test, target_feature = "vector-enhancements-1"),
518+
assert_instr(vflnsb)
519+
)]
520+
unsafe fn vec_nabs_f32(a: vector_float) -> vector_float {
521+
simd_neg(simd_fabs(a))
522+
}
523+
524+
#[inline]
525+
#[target_feature(enable = "vector")]
526+
#[cfg_attr(test, assert_instr(vflndb))]
527+
unsafe fn vec_nabs_f64(a: vector_double) -> vector_double {
528+
simd_neg(simd_fabs(a))
529+
}
530+
531+
impl_vec_trait! { [VectorNabs vec_nabs] vec_nabs_f32 (vector_float) }
532+
impl_vec_trait! { [VectorNabs vec_nabs] vec_nabs_f64 (vector_double) }
533+
509534
#[unstable(feature = "stdarch_s390x", issue = "135681")]
510535
pub trait VectorSplats<Output> {
511536
unsafe fn vec_splats(self) -> Output;
@@ -1528,6 +1553,17 @@ where
15281553
a.vec_abs()
15291554
}
15301555

1556+
/// Vector negative abs.
1557+
#[inline]
1558+
#[target_feature(enable = "vector")]
1559+
#[unstable(feature = "stdarch_s390x", issue = "135681")]
1560+
pub unsafe fn vec_nabs<T>(a: T) -> T
1561+
where
1562+
T: sealed::VectorNabs,
1563+
{
1564+
a.vec_nabs()
1565+
}
1566+
15311567
/// Vector splats.
15321568
#[inline]
15331569
#[target_feature(enable = "vector")]
@@ -2351,6 +2387,10 @@ mod tests {
23512387
test_vec_abs! { test_vec_abs_f32, f32x4, -42f32, 42f32 }
23522388
test_vec_abs! { test_vec_abs_f64, f64x2, -42f64, 42f64 }
23532389

2390+
test_vec_1! { test_vec_nabs, vec_nabs, f32x4,
2391+
[core::f32::consts::PI, 1.0, 0.0, -1.0],
2392+
[-core::f32::consts::PI, -1.0, 0.0, -1.0] }
2393+
23542394
test_vec_2! { test_vec_andc, vec_andc, i32x4,
23552395
[0b11001100, 0b11001100, 0b11001100, 0b11001100],
23562396
[0b00110011, 0b11110011, 0b00001100, 0b10000000],

0 commit comments

Comments
 (0)