Skip to content

Commit 886ff38

Browse files
committed
Add vector multiply round and add saturated
1 parent f9f649a commit 886ff38

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

coresimd/powerpc/altivec.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,10 @@ extern "C" {
357357
fn vmhaddshs(
358358
a: vector_signed_short, b: vector_signed_short, c: vector_signed_short,
359359
) -> vector_signed_short;
360+
#[link_name = "llvm.ppc.altivec.vmhraddshs"]
361+
fn vmhraddshs(
362+
a: vector_signed_short, b: vector_signed_short, c: vector_signed_short,
363+
) -> vector_signed_short;
360364
}
361365

362366
mod sealed {
@@ -732,6 +736,16 @@ pub unsafe fn vec_madds(
732736
vmhaddshs(a, b, c)
733737
}
734738

739+
/// Vector Multiply Round and Add Saturated
740+
#[inline]
741+
#[target_feature(enable = "altivec")]
742+
#[cfg_attr(test, assert_instr(vmhraddshs))]
743+
pub unsafe fn vec_mradds(
744+
a: vector_signed_short, b: vector_signed_short, c: vector_signed_short,
745+
) -> vector_signed_short {
746+
vmhraddshs(a, b, c)
747+
}
748+
735749
#[cfg(target_endian = "big")]
736750
mod endian {
737751
use super::*;
@@ -868,6 +882,28 @@ mod tests {
868882
assert_eq!(d, vec_madds(a, b, c).into_bits());
869883
}
870884

885+
#[simd_test(enable = "altivec")]
886+
unsafe fn test_vec_mradds() {
887+
let a: vector_signed_short = i16x8::new(
888+
0 * 256,
889+
1 * 256,
890+
2 * 256,
891+
3 * 256,
892+
4 * 256,
893+
5 * 256,
894+
6 * 256,
895+
7 * 256,
896+
).into_bits();
897+
let b: vector_signed_short =
898+
i16x8::new(256, 256, 256, 256, 256, 256, 256, 256).into_bits();
899+
let c: vector_signed_short =
900+
i16x8::new(0, 1, 2, 3, 4, 5, 6, i16::max_value() - 1).into_bits();
901+
902+
let d = i16x8::new(0, 3, 6, 9, 12, 15, 18, i16::max_value());
903+
904+
assert_eq!(d, vec_madds(a, b, c).into_bits());
905+
}
906+
871907
#[simd_test(enable = "altivec")]
872908
unsafe fn vec_add_i32x4_i32x4() {
873909
let x = i32x4::new(1, 2, 3, 4);

0 commit comments

Comments
 (0)