Skip to content

Commit adc5814

Browse files
authored
Add vld1q_f32 (#892)
The alignment requirements should match the pointer type. See llvm commit 8beaba13b8a61697008854b82ed3b45377af9d9d
1 parent 05267c1 commit adc5814

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

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

+23
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,19 @@ pub unsafe fn vqtbx4q_p8(a: poly8x16_t, t: poly8x16x4_t, idx: uint8x16_t) -> pol
17991799
))
18001800
}
18011801

1802+
#[inline]
1803+
#[target_feature(enable = "neon")]
1804+
#[cfg_attr(test, assert_instr(ldr))]
1805+
pub unsafe fn vld1q_f32(addr: *const f32) -> float32x4_t {
1806+
use crate::core_arch::simd::f32x4;
1807+
transmute(f32x4::new(
1808+
*addr,
1809+
*addr.offset(1),
1810+
*addr.offset(2),
1811+
*addr.offset(3),
1812+
))
1813+
}
1814+
18021815
#[cfg(test)]
18031816
mod tests {
18041817
use crate::core_arch::aarch64::test_support::*;
@@ -1807,6 +1820,16 @@ mod tests {
18071820
use std::mem::transmute;
18081821
use stdarch_test::simd_test;
18091822

1823+
#[simd_test(enable = "neon")]
1824+
unsafe fn test_vld1q_f32() {
1825+
let e = f32x4::new(1., 2., 3., 4.);
1826+
let f = [0., 1., 2., 3., 4.];
1827+
// do a load that has 4 byte alignment to make sure we're not
1828+
// over aligning it
1829+
let r: f32x4 = transmute(vld1q_f32(f[1..].as_ptr()));
1830+
assert_eq!(r, e);
1831+
}
1832+
18101833
#[simd_test(enable = "neon")]
18111834
unsafe fn test_vpaddq_s16() {
18121835
let a = i16x8::new(1, 2, 3, 4, 5, 6, 7, 8);

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

+23
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ extern "C" {
217217
d: int8x8_t,
218218
e: int8x8_t,
219219
) -> int8x8_t;
220+
#[cfg_attr(target_arch = "arm", link_name = "llvm.arm.neon.vld1.v4f32.p0i8")]
221+
fn vld1q_v4f32(addr: *const u8, align: u32) -> float32x4_t;
220222
}
221223

222224
/// Absolute value (wrapping).
@@ -1767,6 +1769,16 @@ pub unsafe fn vld1q_u8(addr: *const u8) -> uint8x16_t {
17671769
ptr::read(addr as *const uint8x16_t)
17681770
}
17691771

1772+
/// Load multiple single-element structures to one, two, three, or four registers
1773+
#[inline]
1774+
#[cfg(target_arch = "arm")]
1775+
#[target_feature(enable = "neon")]
1776+
#[target_feature(enable = "v7")]
1777+
#[cfg_attr(test, assert_instr("vld1.32"))]
1778+
pub unsafe fn vld1q_f32(addr: *const f32) -> float32x4_t {
1779+
vld1q_v4f32(addr as *const u8, 4)
1780+
}
1781+
17701782
#[cfg(test)]
17711783
mod tests {
17721784
use super::*;
@@ -1791,6 +1803,17 @@ mod tests {
17911803
assert_eq!(r, e);
17921804
}
17931805

1806+
#[cfg(target_arch = "arm")]
1807+
#[simd_test(enable = "neon")]
1808+
unsafe fn test_vld1q_f32() {
1809+
let e = f32x4::new(1., 2., 3., 4.);
1810+
let f = [0., 1., 2., 3., 4.];
1811+
// do a load that has 4 byte alignment to make sure we're not
1812+
// over aligning it
1813+
let r: f32x4 = transmute(vld1q_f32(f[1..].as_ptr()));
1814+
assert_eq!(r, e);
1815+
}
1816+
17941817
#[simd_test(enable = "neon")]
17951818
unsafe fn test_vget_lane_u8() {
17961819
let v = i8x8::new(1, 2, 3, 4, 5, 6, 7, 8);

0 commit comments

Comments
 (0)