Skip to content

Commit 88c2e78

Browse files
committedNov 4, 2023
Implement aarch64 addp intrinsics
1 parent 1f09bae commit 88c2e78

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
 

‎example/neon.rs

+56
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,55 @@ unsafe fn test_vpmax_f32() {
131131
assert_eq!(r, e);
132132
}
133133

134+
#[cfg(target_arch = "aarch64")]
135+
unsafe fn test_vpadd_s16() {
136+
let a = i16x4::from([1, 2, 3, 4]);
137+
let b = i16x4::from([0, -1, -2, -3]);
138+
let r: i16x4 = transmute(vpadd_s16(transmute(a), transmute(b)));
139+
let e = i16x4::from([3, 7, -1, -5]);
140+
assert_eq!(r, e);
141+
}
142+
#[cfg(target_arch = "aarch64")]
143+
unsafe fn test_vpadd_s32() {
144+
let a = i32x2::from([1, 2]);
145+
let b = i32x2::from([0, -1]);
146+
let r: i32x2 = transmute(vpadd_s32(transmute(a), transmute(b)));
147+
let e = i32x2::from([3, -1]);
148+
assert_eq!(r, e);
149+
}
150+
#[cfg(target_arch = "aarch64")]
151+
unsafe fn test_vpadd_s8() {
152+
let a = i8x8::from([1, 2, 3, 4, 5, 6, 7, 8]);
153+
let b = i8x8::from([0, -1, -2, -3, -4, -5, -6, -7]);
154+
let r: i8x8 = transmute(vpadd_s8(transmute(a), transmute(b)));
155+
let e = i8x8::from([3, 7, 11, 15, -1, -5, -9, -13]);
156+
assert_eq!(r, e);
157+
}
158+
#[cfg(target_arch = "aarch64")]
159+
unsafe fn test_vpadd_u16() {
160+
let a = u16x4::from([1, 2, 3, 4]);
161+
let b = u16x4::from([30, 31, 32, 33]);
162+
let r: u16x4 = transmute(vpadd_u16(transmute(a), transmute(b)));
163+
let e = u16x4::from([3, 7, 61, 65]);
164+
assert_eq!(r, e);
165+
}
166+
#[cfg(target_arch = "aarch64")]
167+
unsafe fn test_vpadd_u32() {
168+
let a = u32x2::from([1, 2]);
169+
let b = u32x2::from([30, 31]);
170+
let r: u32x2 = transmute(vpadd_u32(transmute(a), transmute(b)));
171+
let e = u32x2::from([3, 61]);
172+
assert_eq!(r, e);
173+
}
174+
#[cfg(target_arch = "aarch64")]
175+
unsafe fn test_vpadd_u8() {
176+
let a = u8x8::from([1, 2, 3, 4, 5, 6, 7, 8]);
177+
let b = u8x8::from([30, 31, 32, 33, 34, 35, 36, 37]);
178+
let r: u8x8 = transmute(vpadd_u8(transmute(a), transmute(b)));
179+
let e = u8x8::from([3, 7, 11, 15, 61, 65, 69, 73]);
180+
assert_eq!(r, e);
181+
}
182+
134183
#[cfg(target_arch = "aarch64")]
135184
fn main() {
136185
unsafe {
@@ -148,6 +197,13 @@ fn main() {
148197
test_vpmax_u16();
149198
test_vpmax_u32();
150199
test_vpmax_f32();
200+
201+
test_vpadd_s16();
202+
test_vpadd_s32();
203+
test_vpadd_s8();
204+
test_vpadd_u16();
205+
test_vpadd_u32();
206+
test_vpadd_u8();
151207
}
152208
}
153209

‎src/intrinsics/llvm_aarch64.rs

+12
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,18 @@ pub(crate) fn codegen_aarch64_llvm_intrinsic_call<'tcx>(
228228
);
229229
}
230230

231+
_ if intrinsic.starts_with("llvm.aarch64.neon.addp.v") => {
232+
intrinsic_args!(fx, args => (x, y); intrinsic);
233+
234+
simd_horizontal_pair_for_each_lane(
235+
fx,
236+
x,
237+
y,
238+
ret,
239+
&|fx, _lane_ty, _res_lane_ty, x_lane, y_lane| fx.bcx.ins().iadd(x_lane, y_lane),
240+
);
241+
}
242+
231243
// FIXME generalize vector types
232244
"llvm.aarch64.neon.tbl1.v16i8" => {
233245
intrinsic_args!(fx, args => (t, idx); intrinsic);

0 commit comments

Comments
 (0)