Skip to content

Commit 8f05090

Browse files
committed
Add multiply add saturated
1 parent 26f591a commit 8f05090

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

coresimd/powerpc/altivec.rs

+22
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ impl_from_bits_!(
362362
extern "C" {
363363
#[ link_name = "llvm.ppc.altivec.vperm" ]
364364
fn vperm(a: vector_signed_int, b: vector_signed_int, c: vector_unsigned_char) -> vector_signed_int;
365+
#[ link_name = "llvm.ppc.altivec.vmhaddshs" ]
366+
fn vmhaddshs(a: vector_signed_short, b: vector_signed_short, c: vector_signed_short) -> vector_signed_short;
365367
}
366368

367369
mod sealed {
@@ -723,6 +725,15 @@ mod endian {
723725
b.vec_vperm(a, c)
724726
}
725727
}
728+
729+
/// Vector Multiply Add Saturated
730+
#[inline]
731+
#[target_feature(enable = "altivec")]
732+
#[cfg_attr(test, assert_instr(vmhaddshs))]
733+
pub unsafe fn vec_madds(a: vector_signed_short, b: vector_signed_short, c: vector_signed_short) -> vector_signed_short {
734+
vmhaddshs(a, b, c)
735+
}
736+
726737
#[cfg(target_endian = "big")]
727738
mod endian {
728739
use super::*;
@@ -837,6 +848,17 @@ mod tests {
837848
0x04, 0x05, 0x06, 0x07, 0x14, 0x15, 0x16, 0x17],
838849
[0.0, 1.0, 1.0, 1.1]}
839850

851+
#[simd_test(enable = "altivec")]
852+
unsafe fn test_vec_madds() {
853+
let a: vector_signed_short = i16x8::new(0 * 256, 1 * 256, 2 * 256, 3 * 256, 4 * 256, 5 * 256, 6 * 256, 7 * 256).into_bits();
854+
let b: vector_signed_short = i16x8::new(256, 256, 256, 256, 256, 256, 256, 256).into_bits();
855+
let c: vector_signed_short = i16x8::new(0, 1, 2, 3, 4, 5, 6, 7).into_bits();
856+
857+
let d = i16x8::new(0, 3, 6, 9, 12, 15, 18, 21);
858+
859+
assert_eq!(d, vec_madds(a, b, c).into_bits());
860+
}
861+
840862
#[simd_test(enable = "altivec")]
841863
unsafe fn vec_add_i32x4_i32x4() {
842864
let x = i32x4::new(1, 2, 3, 4);

0 commit comments

Comments
 (0)