Skip to content

Fix FP32 log IEEE-754 handling in NEON and SVE - #1326

Open
harshith-roy wants to merge 2 commits into
ARM-software:mainfrom
harshith-roy:fix-log-ieee754-soft-relu-overflow
Open

harshith-roy wants to merge 2 commits into
ARM-software:mainfrom
harshith-roy:fix-log-ieee754-soft-relu-overflow

Conversation

@harshith-roy

Copy link
Copy Markdown

Summary

This change improves IEEE-754 exceptional-value handling and subnormal accuracy in the NEON and SVE FP32 logarithm implementations.

It also fixes an FP16 SOFT_RELU overflow regression exposed by the corrected logarithm behavior.

Changes

  • Add IEEE-754 classification and exceptional-value handling to NEON and SVE FP32 Log.
  • Handle positive FP32 subnormal inputs through normalization.
  • Return appropriate results for zero, negative inputs, infinities and NaNs.
  • Preserve the legacy logarithm implementation for Pow to avoid changing its existing behavior.
  • Fix FP16 SOFT_RELU overflow handling in NEON and SVE.
  • Add regression tests for exceptional logarithm inputs, vector boundaries, subnormal accuracy and SOFT_RELU overflow.

Validation

Validated using AArch64 cross-compilation and QEMU user-mode emulation.

  • NEON ElementwiseLog: 213/213
  • SVE ElementwiseLog: 213/213 at vector lengths 16, 32 and 64 bytes.
  • NEON ActivationLayer: 929/929
  • SVE ActivationLayer: 929/929 at vector lengths 16, 32 and 64 bytes.
  • NEON Softmax and LogSoftmax: 528/528.

Both NEON and SVE builds passed with warnings treated as errors.

Note: Runtime validation was performed under QEMU, not physical ARM hardware.

@ThatKJ

ThatKJ commented Nov 14, 2026

Copy link
Copy Markdown

Independent validation on physical Apple Silicon (NEON)

Thanks for the upstream fix, @harshith-roy. I tested PR #1326 on a physical Apple M5 (macOS 27.2, Apple clang 21.0.0), comparing the unmodified v53.3.1 implementation (ff4646a) against the patched implementation (46d762b).

Correctness

  • Independent native verification harness: 2,771/2,771 cases passed with the patch, compared with 1,879 failing cases on the baseline.
  • Covered signed zero, infinities, negative inputs, qNaN/sNaN, positive subnormals, and vector boundaries from 1 to 65 elements.
  • Lane-isolation checks found no neighboring-lane contamination.
  • Positive subnormal results matched the reference within the tested relative-error tolerance of 1e-6.
  • 580/580 float activation tests passed, including the FP16/FP32 SoftReLU overflow boundary coverage.

Performance — FP32 Log, 1M elements

Threads Baseline Patched Latency ratio
1 269 µs 1,608 µs 5.98×
10 112 µs 351 µs 3.13×

The patch restores correctness in the tested cases, but the performance regression is significant, particularly for the single-threaded workload. It would be worth investigating whether the special-value handling can be optimized further before merging.

Two review findings

  1. macOS sNaN portability: The quiet-NaN-bit assertion in tests/validation/NEON/ElementwiseLog.cpp assumes that scalar std::log(sNaN) quiets the result. Darwin libm can preserve the signaling NaN bit pattern in the scalar remainder path. The current assertion can therefore fail despite a NaN result. I suggest relaxing the scalar-path assertion to require std::isnan(got) rather than a specific quiet bit.
  2. PR scope and CI: The branch includes an additional release/version commit that changes files unrelated to the logarithm fix. The squash check is currently failing; removing the unrelated changes and consolidating the intended patch should help keep review focused.

Scope: All execution testing was native NEON on Apple Silicon. SVE was not executed on physical hardware.

Overall, I can confirm the reported NEON correctness improvement on physical hardware, with the performance regression and Darwin test portability issue noted above.

Thanks again for working on this upstream!

@morgolock morgolock left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address these before merging:

  1. Reduce the NEON log performance regression. In a native Arm microbenchmark (GCC 11.5.0, -O3, one core, 1,048,576 positive normal FP32 inputs), vlogq_f32 takes 2,271 us versus 619 us for the legacy helper: 3.7x slower. The new local static const declarations in NEMath.inl introduce twelve initialization-guard checks per vector call. Replacing those declarations with const reduced the slowdown to 2.4x in an isolated experiment, so please also optimize the ordinary-input path while retaining the exceptional-value handling. These timings measure the helper, not an end-to-end model.

  2. Drop the unrelated release commit ff4646a968. It changes the library version/SONAME from 38.0.0 to 53.3.1 and updates release metadata in SConscript, CMakeLists.txt, README.md, and docs/Doxyfile. These changes should not be part of this fix.

  3. Fix the submission checks. Keep the fix as a single commit, use the required commit-message format, and add the missing Signed-off-by: line. The precommit and squash checks currently fail.

The numerical checks passed: 44 log tests and 755 activation tests on native Arm with SVE128, plus all 8,388,607 positive FP32 subnormal inputs through each of the NEON and SVE log helpers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants