Skip to content

Commit 15babf5

Browse files
authored
Enable constant parameters in the code generator and add vext instructions (#1106)
1 parent 8a5da46 commit 15babf5

File tree

6 files changed

+1078
-285
lines changed

6 files changed

+1078
-285
lines changed

crates/core_arch/src/aarch64/neon/generated.rs

+46
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,34 @@ pub unsafe fn vcvtpq_u64_f64(a: float64x2_t) -> uint64x2_t {
16641664
vcvtpq_u64_f64_(a)
16651665
}
16661666

1667+
/// Extract vector from pair of vectors
1668+
#[inline]
1669+
#[target_feature(enable = "neon")]
1670+
#[cfg_attr(test, assert_instr(ext, N = 1))]
1671+
#[rustc_legacy_const_generics(2)]
1672+
pub unsafe fn vextq_p64<const N: i32>(a: poly64x2_t, b: poly64x2_t) -> poly64x2_t {
1673+
static_assert_imm1!(N);
1674+
match N & 0b1 {
1675+
0 => simd_shuffle2(a, b, [0, 1]),
1676+
1 => simd_shuffle2(a, b, [1, 2]),
1677+
_ => unreachable_unchecked(),
1678+
}
1679+
}
1680+
1681+
/// Extract vector from pair of vectors
1682+
#[inline]
1683+
#[target_feature(enable = "neon")]
1684+
#[cfg_attr(test, assert_instr(ext, N = 1))]
1685+
#[rustc_legacy_const_generics(2)]
1686+
pub unsafe fn vextq_f64<const N: i32>(a: float64x2_t, b: float64x2_t) -> float64x2_t {
1687+
static_assert_imm1!(N);
1688+
match N & 0b1 {
1689+
0 => simd_shuffle2(a, b, [0, 1]),
1690+
1 => simd_shuffle2(a, b, [1, 2]),
1691+
_ => unreachable_unchecked(),
1692+
}
1693+
}
1694+
16671695
/// Floating-point multiply-add to accumulator
16681696
#[inline]
16691697
#[target_feature(enable = "neon")]
@@ -5614,6 +5642,24 @@ mod test {
56145642
assert_eq!(r, e);
56155643
}
56165644

5645+
#[simd_test(enable = "neon")]
5646+
unsafe fn test_vextq_p64() {
5647+
let a: i64x2 = i64x2::new(0, 8);
5648+
let b: i64x2 = i64x2::new(9, 11);
5649+
let e: i64x2 = i64x2::new(8, 9);
5650+
let r: i64x2 = transmute(vextq_p64::<1>(transmute(a), transmute(b)));
5651+
assert_eq!(r, e);
5652+
}
5653+
5654+
#[simd_test(enable = "neon")]
5655+
unsafe fn test_vextq_f64() {
5656+
let a: f64x2 = f64x2::new(0., 2.);
5657+
let b: f64x2 = f64x2::new(3., 4.);
5658+
let e: f64x2 = f64x2::new(2., 3.);
5659+
let r: f64x2 = transmute(vextq_f64::<1>(transmute(a), transmute(b)));
5660+
assert_eq!(r, e);
5661+
}
5662+
56175663
#[simd_test(enable = "neon")]
56185664
unsafe fn test_vmla_f64() {
56195665
let a: f64 = 0.;

crates/core_arch/src/aarch64/neon/mod.rs

+42
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
};
1616
#[cfg(test)]
1717
use stdarch_test::assert_instr;
18+
use core::hint::unreachable_unchecked;
1819

1920
types! {
2021
/// ARM-specific 64-bit wide vector of one packed `f64`.
@@ -1427,6 +1428,29 @@ pub unsafe fn vpmaxq_f64(a: float64x2_t, b: float64x2_t) -> float64x2_t {
14271428
vpmaxq_f64_(a, b)
14281429
}
14291430

1431+
/// Extract vector from pair of vectors
1432+
#[inline]
1433+
#[target_feature(enable = "neon")]
1434+
#[cfg_attr(test, assert_instr(str, N = 0))]
1435+
#[rustc_legacy_const_generics(2)]
1436+
pub unsafe fn vext_p64<const N: i32>(a: poly64x1_t, _b: poly64x1_t) -> poly64x1_t {
1437+
if N != 0 {
1438+
unreachable_unchecked()
1439+
}
1440+
a
1441+
}
1442+
1443+
/// Extract vector from pair of vectors
1444+
#[inline]
1445+
#[target_feature(enable = "neon")]
1446+
#[cfg_attr(test, assert_instr(str, N = 0))]
1447+
#[rustc_legacy_const_generics(2)]
1448+
pub unsafe fn vext_f64<const N: i32>(a: float64x1_t, _b: float64x1_t) -> float64x1_t {
1449+
if N != 0 {
1450+
unreachable_unchecked()
1451+
}
1452+
a
1453+
}
14301454
/// Vector combine
14311455
#[inline]
14321456
#[target_feature(enable = "neon")]
@@ -3470,6 +3494,24 @@ mod tests {
34703494
assert_eq!(r, e);
34713495
}
34723496

3497+
#[simd_test(enable = "neon")]
3498+
unsafe fn test_vext_p64() {
3499+
let a: i64x1 = i64x1::new(0);
3500+
let b: i64x1 = i64x1::new(1);
3501+
let e: i64x1 = i64x1::new(0);
3502+
let r: i64x1 = transmute(vext_p64::<0>(transmute(a), transmute(b)));
3503+
assert_eq!(r, e);
3504+
}
3505+
3506+
#[simd_test(enable = "neon")]
3507+
unsafe fn test_vext_f64() {
3508+
let a: f64x1 = f64x1::new(0.);
3509+
let b: f64x1 = f64x1::new(1.);
3510+
let e: f64x1 = f64x1::new(0.);
3511+
let r: f64x1 = transmute(vext_f64::<0>(transmute(a), transmute(b)));
3512+
assert_eq!(r, e);
3513+
}
3514+
34733515
macro_rules! test_vcombine {
34743516
($test_id:ident => $fn_id:ident ([$($a:expr),*], [$($b:expr),*])) => {
34753517
#[allow(unused_assignments)]

0 commit comments

Comments
 (0)