1#![expect(
5 missing_docs,
6 reason = "TODO: https://github.com/linebender/fearless_simd/issues/40"
7)]
8
9use fearless_simd::{Level, Simd, SimdBase, WithSimd, dispatch};
10
11struct Foo;
14
15impl WithSimd for Foo {
16 type Output = f32;
17
18 #[inline(always)]
19 fn with_simd<S: Simd>(self, simd: S) -> Self::Output {
20 let a = simd.splat_f32x4(42.0);
21 let b = a + a;
22 b[0]
23 }
24}
25
26#[inline(always)]
27fn foo<S: Simd>(simd: S, x: f32) -> f32 {
28 let n = S::f32s::N;
29 println!("n = {n}");
30 simd.splat_f32x4(x).sqrt()[0]
31}
32
33fn do_something_on_neon(_level: Level) -> f32 {
35 #[cfg(all(feature = "safe_wrappers", target_arch = "aarch64"))]
36 if let Some(neon) = _level.as_neon() {
37 return neon.vectorize(
38 #[inline(always)]
39 || {
40 let v = neon.neon.vdupq_n_f32(42.0);
41 neon.neon.vgetq_lane_f32::<0>(v)
42 },
43 );
44 }
45 0.0
46}
47
48fn main() {
49 let level = Level::new();
50 let x = level.dispatch(Foo);
51 let y = dispatch!(level, simd => foo(simd, 42.0));
52 let z = do_something_on_neon(level);
53
54 println!("level = {level:?}, x = {x}, y = {y}, z = {z}");
55}