feat(math): lower DSP scalar functions statically - #146
Open
iplanwebsites wants to merge 1 commit into
Open
Conversation
|
@iplanwebsites is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
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.
Why
ScriptC can compile a lot of JavaScript directly, but several common
Mathfunctions were still treated as calls that need a JavaScript runtime. That is a problem for small audio and signal-processing programs, where functions such asMath.sinandMath.sqrtare basic building blocks and the compiled program may not have a JavaScript engine available as a fallback.We ran into this while prototyping a hybrid audio engine. The browser manages the audio graph, while a small compiled module handles sample processing. Even a simple oscillator needs sine, and common shaping and level calculations use square root, powers, exponentials, and logarithms.
This PR adds those small, general-purpose math building blocks to ScriptC. It does not add an audio engine or any Web Audio APIs.
What this adds
The C and LLVM backends can now compile these directly:
Math.sinMath.cosMath.sqrtMath.expMath.logMath.powMath.froundMath.PIMath.EIn other words, these operations become normal compiled math operations instead of unsupported dynamic calls.
The change also updates ScriptC surface coverage, diagnostics, manifests, and library profiles so the advertised support matches what the compiler can actually emit.
How it was tested
A differential corpus test runs the same DSP-style math program in Node and as compiled C and LLVM output, then checks that stdout, stderr, and exit status match.
I also ran:
Both full lanes used the repository-pinned Node 24.15.0. The Sandbox image was not configured locally, so I used the documented full local fallback from
AGENTS.md.I kept this PR intentionally focused: no audio application code, experimental reactor work, or project notes are included. Happy to adjust the supported set or implementation shape based on maintainer preference.