Skip to content

Commit 70a6abf

Browse files
committed
Add unsigned saturating add/sub intrinsics for aarch64
1 parent 88c2e78 commit 70a6abf

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

example/neon.rs

+21
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,24 @@ unsafe fn test_vpadd_u8() {
180180
assert_eq!(r, e);
181181
}
182182

183+
#[cfg(target_arch = "aarch64")]
184+
unsafe fn test_vqsub_u8() {
185+
let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 0xff]);
186+
let b = u8x8::from([30, 1, 1, 1, 34, 0xff, 36, 37]);
187+
let r: u8x8 = transmute(vqsub_u8(transmute(a), transmute(b)));
188+
let e = u8x8::from([0, 1, 2, 3, 0, 0, 0, 218]);
189+
assert_eq!(r, e);
190+
}
191+
192+
#[cfg(target_arch = "aarch64")]
193+
unsafe fn test_vqadd_u8() {
194+
let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 0xff]);
195+
let b = u8x8::from([30, 1, 1, 1, 34, 0xff, 36, 37]);
196+
let r: u8x8 = transmute(vqadd_u8(transmute(a), transmute(b)));
197+
let e = u8x8::from([31, 3, 4, 5, 39, 0xff, 43, 0xff]);
198+
assert_eq!(r, e);
199+
}
200+
183201
#[cfg(target_arch = "aarch64")]
184202
fn main() {
185203
unsafe {
@@ -204,6 +222,9 @@ fn main() {
204222
test_vpadd_u16();
205223
test_vpadd_u32();
206224
test_vpadd_u8();
225+
226+
test_vqsub_u8();
227+
test_vqadd_u8();
207228
}
208229
}
209230

src/intrinsics/llvm_aarch64.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,19 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>(
4444
});
4545
}
4646

47-
_ if intrinsic.starts_with("llvm.aarch64.neon.sqadd.v") => {
47+
_ if intrinsic.starts_with("llvm.aarch64.neon.sqadd.v")
48+
|| intrinsic.starts_with("llvm.aarch64.neon.uqadd.v") =>
49+
{
4850
intrinsic_args!(fx, args => (x, y); intrinsic);
4951

5052
simd_pair_for_each_lane_typed(fx, x, y, ret, &|fx, x_lane, y_lane| {
5153
crate::num::codegen_saturating_int_binop(fx, BinOp::Add, x_lane, y_lane)
5254
});
5355
}
5456

55-
_ if intrinsic.starts_with("llvm.aarch64.neon.sqsub.v") => {
57+
_ if intrinsic.starts_with("llvm.aarch64.neon.sqsub.v")
58+
|| intrinsic.starts_with("llvm.aarch64.neon.uqsub.v") =>
59+
{
5660
intrinsic_args!(fx, args => (x, y); intrinsic);
5761

5862
simd_pair_for_each_lane_typed(fx, x, y, ret, &|fx, x_lane, y_lane| {

0 commit comments

Comments
 (0)