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!

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.

2 participants