Skip to content

The NEON SIMD backend is in the tree but nothing dispatches to it #4286

Closed

Description

@zackees

simd_arm_neon.hpp is referenced by a comment and nothing else

src/platforms/arm/simd_arm_neon.hpp is a full SIMD backend — ~700 lines, the same 66-operation API the other backends implement, using vhaddq_u8, vqmovn_u16 and the rest.

Nothing selects it. src/platforms/simd.h dispatches:

#if   x86/x64                -> simd_x86.hpp
#elif FL_IS_ESP32            -> simd_esp32.hpp
#elif __ARM_FEATURE_DSP == 1 -> simd_arm_dsp.hpp
#else                        -> simd_noop.hpp

There is no __ARM_NEON or __aarch64__ arm. __ARM_FEATURE_DSP is the ARMv7E-M DSP extension (Cortex-M4/M7), which ARMv8-A parts do not define, so every ARMv8-A target falls through to the scalar fallback: Apple Silicon, Raspberry Pi 3/4/5, and any ARM64 board.

The only mention of the file outside itself is a comment in simd_arm_dsp.hpp:

// This is the FastLED-wide SIMD API convention (mirrored across simd_noop,
// simd_x86, simd_arm_neon, simd_xtensa, simd_riscv):

Verified with grep -rn simd_arm_neon src ci tests — one hit, that comment.

How this surfaced

While working out why #4285 failed on the macOS CI runner. That PR adds a differential test which includes the fallback under a second namespace to compare it against the host's selected backend; on Apple Silicon the include collapsed, because the fallback was the selected backend and the PCH had already pulled it in.

Why this is not just a missed optimisation

Two consequences beyond speed:

  1. The macOS CI runner tests the scalar path, not a NEON one. Anyone reading "the ARM SIMD backend is covered by CI" would be wrong.
  2. The backend is unmaintained by construction. It compiles nowhere, so nothing catches drift in it. It has had no chance to be wrong, and equally no chance to be right.

What would need deciding

Wiring it in is not a one-line change to the dispatch, and I have deliberately not made it:

  • Correctness first. test(simd): cover the scalar fallback, and fix three x86 divergences it found (#4216) #4285 lands a differential harness that checks a backend against the fallback across all 66 operations. Pointing that at NEON is the cheap way to find out whether the file is actually correct before it goes live on every ARM64 machine.
  • Which guard. __ARM_NEON is defined on ARMv7-A with NEON as well as ARMv8-A; whether both are wanted is a decision, not a lookup.
  • Interaction with __ARM_FEATURE_DSP. A part could define both. The order of the arms then decides which wins, and that should be deliberate.
  • Blast radius. It changes the compiled code path on Apple Silicon CI and on every Pi-class target at once.

Filed as a finding rather than a fix. Happy to do the wiring once #4285 gives it a check to sit behind, if that is wanted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Activity

  1. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Wired in #4291 — and the first CI run found a real bug in it

    The dispatch arm is in that PR, behind the harness this issue said the wiring should sit behind (#4285, now merged). Reporting what it turned up, because it is the answer to "is this backend actually correct?" — which the issue could only pose, not settle.

    It was not. macOS CI failed at tests/fl/math/simd.cpp:298 on the first run:

    blend_u8_16 multiplied with vmulq_n_s16. diff spans −255..255 and amount spans 0..255, so the product needs 17 signed bits — at a=0, b=255, amount=192 the true value is 48960, which wraps int16 to −16576, shifts to −65, and saturates to 0 where 191 was wanted. The 25% case immediately above it passed only because 255×64 happens to fit.

    The scalar fallback never had the bug: diff * amount promotes to int there.

    Fixed by widening to 32 bits, keeping vshrn_n_s32 so the arithmetic shift the fallback performs is preserved — that matters beyond the overflow, since an arithmetic shift rounds toward negative infinity and a diff of −1 at amount 1 gives −1, not 0. The cheaper absolute-difference form would disagree by one code on every darkening blend.

    Verified without an ARM machine, two ways: the intrinsic sequence modelled exactly and compared against the fallback across every amount and a stride over every (a, b) — 109,300 disagreements before, zero after — and cross-compiled with --target=aarch64-linux-gnu -march=armv8-a so the intrinsics are checked by a real ARM front end rather than by eye.

    The rest of the file was audited for the same class: scale_u8_16 tops out at 255×255 inside a uint16 and is fine, mullo_u16_8 is a wrapping low-half multiply by definition. blend_u8_16 was the only one.

    One thing narrowed rather than fixed

    MSVC advertises _M_ARM64, not __ARM_NEON, so native ARM64 Windows is not covered by the arm — and the _M_ARM64 branches already inside simd_arm_neon.hpp stay unreachable there. Nothing regresses (that target took the fallback before too), but I have not added it: there is no MSVC ARM64 runner here, and the case against enabling a backend nobody can check is the bug above. It is pinned by a dispatch case so it reads as a decision.

    And the dispatch table now has a test

    That is the part that keeps this from recurring. ci/tests/test_simd_dispatch.py evaluates the real chain with the real preprocessor, one case per target family, and requires every simd_*.hpp in the tree to be reachable. Removing the NEON arm again fails three cases including that one.

  2. zackees commented on Sep 10, 2026

    @zackees
    MemberAuthor

    Done in #4291, verified on master, closing

    what evidence on master
    the dispatch arm exists src/platforms/simd.h:56 — #include "platforms/arm/simd_arm_neon.hpp" under __ARM_NEON || __ARM_NEON__
    the backend is correct the int16 overflow in blend_u8_16 is fixed — vmull_n_s16 widening at simd_arm_neon.hpp:157
    it cannot go unreachable again ci/tests/test_simd_dispatch.py requires every simd_*.hpp in the tree to be reachable from the chain

    The thing worth carrying forward from this issue is what enabling the backend immediately found: a real int16 overflow that had been sitting in the file the whole time it was unreachable — 109,300 disagreements against the scalar fallback across the input space, saturating a 75% blend of black-to-white to 0 instead of 191. A backend nothing compiles is not a backend that works; it is one that has never been asked.

    Two things deliberately left, both recorded rather than implied:

    • MSVC ARM64 is not covered. MSVC advertises _M_ARM64 rather than __ARM_NEON, so the arm misses it and the _M_ARM64 branches inside the backend stay unreachable there. That is the status quo, not a regression, and it is pinned by a case in the dispatch test so whoever adds it changes that case on purpose. There is no MSVC ARM64 runner here, and the overflow above is the argument against enabling a backend nobody can check.
    • 32-bit ARMv7-A parts that define both __ARM_FEATURE_DSP and __ARM_NEON keep the DSP backend. Ordering choice, also pinned. Moving them to NEON is likely an improvement with its own targets to check.
  3. moved this from Triage to Done in FastLED Trackeron Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions