Repository navigation
perf(c): compute U32.pow by exponentiation by squaring - #1567
Merged
Merged
Conversation
…JS text in intr_of Drops JS_OPERATIONS and File.ops: intr_of skips an op with no JS text in a JS file, so JS still runs Base's U32.pow. Restores the two comments the first commit cut to fit the cap; on current main comp.ts fits with them.
Lorenzobattistela
force-pushed
the
perf/u32-pow
branch
from
October 15, 2026 11:05
3b1abdb to
94d3758
Compare
Lorenzobattistela
approved these changes
Oct 15, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
U32.pow performs one multiplication per exponent step on the C backend. Use exponentiation by squaring to reduce that work to the exponent's bit length. Keep multiplication modulo 2^32, return one for exponent zero, and retain all 48 bits of the compiled Nat exponent.
Keep the Base definition and generated JavaScript unchanged. This preserves the existing proof reductions and reference backend. Select the backend's intrinsic table once per file so C-only entries do not suppress JavaScript definitions. Add tests for overflow, zero exponents, partial applications, larger exponents, and the symbolic successor equation.
On an Apple M5 Max, 500,000 calls with exponent 4,096 took 1.827 s on main and 1.810 ms with this change. The base changes on every call. For exponent 2, 5,000,000 calls took 9.728 ms and 2.514 ms. All measured exponents from 0 through 4,096 improved on macOS Clang 21 and Linux ARM64 Clang 19. These are focused benchmark results, not application speedups.
Validation:
The maintainer cluster gates have not run. Linux ran in an ARM64 VM on the same physical CPU.