Skip to content

Vectorize Fabric transform multiplication and equality on arm64 - #60538

Open
ide wants to merge 1 commit into
react:mainfrom
expo:@ide/transform-kernels
Open

ide wants to merge 1 commit into
react:mainfrom
expo:@ide/transform-kernels

Conversation

@ide

@ide ide commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Use NEON to multiply and compare Fabric's 4×4 transform matrices on arm64. Keep the scalar implementation on other architectures and with MSVC, which declares its NEON intrinsics in <arm64_neon.h>. Preserve how matrix equality treats signed zero and NaN. During composition, reserve space for both operation lists before copying them in concatenation order. An identity on either side returns the other transform unchanged.

Changelog:

[INTERNAL] [CHANGED] - Vectorize Fabric transform operations on arm64.

Test Plan:

The C++ TransformTest suite passes. The new cases check signed zero and NaN in matrix equality, that an identity on either side keeps infinite entries, and the order of composing transforms across three axes.

In an optimized C++ benchmark on Apple M6, the median falls from 59.03 to 28.53 retired instructions per equality comparison and from 1,255.42 to 450.21 per composition. proc_pid_rusage counts instructions across five interleaved runs. The output checksums match.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 4, 2026
@ide
ide force-pushed the @ide/transform-kernels branch from dfee107 to a08fb01 Compare December 4, 2026 11:32
@ide ide changed the title Vectorize Fabric transform matrix operations on arm64 Vectorize Fabric transform multiplication and equality on arm64 Dec 4, 2026
@ide
ide force-pushed the @ide/transform-kernels branch from a08fb01 to 7d52df4 Compare December 4, 2026 12:35
@ide
ide marked this pull request as ready for review December 4, 2026 14:37
@javache

javache commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for the optimisation and the benchmark numbers. One portability fix before merging: Transform.cpp:13–14 selects <arm_neon.h> when _M_ARM64 is defined, but MSVC provides its NEON intrinsics through <arm64_neon.h>. Could you narrow the guard so MSVC keeps using the scalar path?

Non-blocking: the new right-identity shortcut bypasses multiplication, so it preserves non-finite entries instead of propagating NaNs through 0 * infinity. That seems reasonable; a short comment or test would make the behaviour intentional.

Use NEON to multiply and compare Fabric's 4×4 transform matrices on arm64. Keep the scalar implementation on other architectures and with MSVC, which declares its NEON intrinsics in `<arm64_neon.h>`. Preserve how matrix equality treats signed zero and NaN. During composition, reserve space for both operation lists before copying them in concatenation order. An identity on either side returns the other transform unchanged.

The C++ `TransformTest` suite passes. The new cases check signed zero and NaN in matrix equality, that an identity on either side keeps infinite entries, and the order of composing transforms across three axes.

In an optimized C++ benchmark on Apple M6, the median falls from 59.03 to 28.53 retired instructions per equality comparison and from 1,255.42 to 450.21 per composition. `proc_pid_rusage` counts instructions across five interleaved runs. The output checksums match.

Signed-off-by: James Ide <ide@expo.dev>
@ide
ide force-pushed the @ide/transform-kernels branch from 7d52df4 to e9fcab3 Compare December 4, 2026 20:49
@ide

ide commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Done in e9fcab3: the NEON code is now guarded by __aarch64__ alone, so MSVC, which defines only _M_ARM64, keeps the scalar path. Clang and GCC define __aarch64__ on every arm64 target, so the Apple and Android builds are unchanged. I also added a comment and a TransformTest case: an identity on either side returns the other transform unchanged, infinite entries included. The case fails without the right-identity shortcut.

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

Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants