Skip to content

Commit e451716

Browse files
authored
Add vminq_f32 and vmaxq_f32 (#905)
1 parent 016eff9 commit e451716

File tree

1 file changed

+43
-0
lines changed
  • crates/core_arch/src/arm/neon

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,13 @@ extern "C" {
188188
#[cfg_attr(target_arch = "arm", link_name = "llvm.arm.neon.vpadd.v16i8")]
189189
#[cfg_attr(target_arch = "aarch64", link_name = "llvm.aarch64.neon.addp.v16i8")]
190190
fn vpaddq_s8_(a: int8x16_t, b: int8x16_t) -> int8x16_t;
191+
192+
#[cfg_attr(target_arch = "arm", link_name = "llvm.arm.neon.vmaxs.v4f32")]
193+
#[cfg_attr(target_arch = "aarch64", link_name = "llvm.aarch64.neon.fmax.v4f32")]
194+
fn vmaxq_f32_(a: float32x4_t, b: float32x4_t) -> float32x4_t;
195+
#[cfg_attr(target_arch = "arm", link_name = "llvm.arm.neon.vmins.v4f32")]
196+
#[cfg_attr(target_arch = "aarch64", link_name = "llvm.aarch64.neon.fmin.v4f32")]
197+
fn vminq_f32_(a: float32x4_t, b: float32x4_t) -> float32x4_t;
191198
}
192199

193200
#[cfg(target_arch = "arm")]
@@ -1836,6 +1843,26 @@ pub unsafe fn vcvtq_u32_f32(a: float32x4_t) -> uint32x4_t {
18361843
transmute(simd_cast::<_, u32x4>(transmute::<_, f32x4>(a)))
18371844
}
18381845

1846+
/// Floating-point minimum (vector).
1847+
#[inline]
1848+
#[target_feature(enable = "neon")]
1849+
#[cfg_attr(target_arch = "arm", target_feature(enable = "v7"))]
1850+
#[cfg_attr(all(test, target_arch = "arm"), assert_instr("vmin.f32"))]
1851+
#[cfg_attr(all(test, target_arch = "aarch64"), assert_instr(fmin))]
1852+
pub unsafe fn vminq_f32(a: float32x4_t, b: float32x4_t) -> float32x4_t {
1853+
vminq_f32_(a, b)
1854+
}
1855+
1856+
/// Floating-point maxmimum (vector).
1857+
#[inline]
1858+
#[target_feature(enable = "neon")]
1859+
#[cfg_attr(target_arch = "arm", target_feature(enable = "v7"))]
1860+
#[cfg_attr(all(test, target_arch = "arm"), assert_instr("vmax.f32"))]
1861+
#[cfg_attr(all(test, target_arch = "aarch64"), assert_instr(fmax))]
1862+
pub unsafe fn vmaxq_f32(a: float32x4_t, b: float32x4_t) -> float32x4_t {
1863+
vmaxq_f32_(a, b)
1864+
}
1865+
18391866
#[cfg(test)]
18401867
mod tests {
18411868
use super::*;
@@ -4314,6 +4341,22 @@ mod tests {
43144341
let e = u8x8::new(3, 7, 11, 15, 61, 65, 69, 73);
43154342
assert_eq!(r, e);
43164343
}
4344+
#[simd_test(enable = "neon")]
4345+
unsafe fn test_vminq_f32() {
4346+
let a = f32x4::new(1., -2., 3., -4.);
4347+
let b = f32x4::new(0., 3., 2., 8.);
4348+
let e = f32x4::new(0., -2., 2., -4.);
4349+
let r: f32x4 = transmute(vminq_f32(transmute(a), transmute(b)));
4350+
assert_eq!(r, e);
4351+
}
4352+
#[simd_test(enable = "neon")]
4353+
unsafe fn test_vmaxq_f32() {
4354+
let a = f32x4::new(1., -2., 3., -4.);
4355+
let b = f32x4::new(0., 3., 2., 8.);
4356+
let e = f32x4::new(1., 3., 3., 8.);
4357+
let r: f32x4 = transmute(vmaxq_f32(transmute(a), transmute(b)));
4358+
assert_eq!(r, e);
4359+
}
43174360
}
43184361

43194362
#[cfg(test)]

0 commit comments

Comments
 (0)