feat(builtins): bulk PCM16LE codec kernels — buf_from_pcm16le/buf_to_pcm16le/buf_deinterleave (#602) - #606
Merged
Merged
Conversation
…pcm16le/buf_deinterleave (#602) DeslanStudio's WAV import measured 10.8 s for a 50 s stereo 48 kHz file on the N3350: the PCM16 byte decode (two buf_gets + two's-complement fold + /32767 per sample, ~4.8 M times) was an interpreted loop, and the write path is the same shape in reverse. These are the byte-codec siblings of the #597 window kernels: - buf_from_pcm16le of [bytes, byte_off, count] — LE s16 window -> NEW float buffer (v = b0 + 256*b1; fold at 32768; v / 32767) - buf_to_pcm16le of [floats, off, count] — float window -> NEW byte buffer (clamp [-1,1], round(x*32767), two's complement via +65536, ds_fmod low byte / floor high byte) - buf_deinterleave of [src, channel, nch, count?] — every nch-th sample from index channel -> NEW buffer (count defaults to the tail) Arithmetic mirrors the consumer's interpreted wavio loops step-for-step (num_guard per VM operation, same evaluation order) so each builtin is bit-identical to the loop it replaces — pinned by the differential leg in tests/test_pcm_codec.eigs (decode+deinterleave vs the fused wav_read loop, encode vs the wav_write loop, round-trip parity, deinterleave vs the stride loop) on seeded pseudo-random data. Loud bounds per the #597 family (value/index_range/type_mismatch; count 0 a valid no-op; count > INT_MAX/2 raises limit before the 2x multiply can overflow). Output allocations charged to the #292 sandbox budget; all three join the sandbox pure-compute allowlist; freestanding-safe (floor/round only). Perf (tests/bench_pcm_codec.eigs, 2.4 M samples, n=5 medians, N3350, pinned to one core): decode 941 ms (JIT) / 2395 ms (interpreter) vs 52.9 ms — ~18x / ~45x; encode 2053 ms / 4295 ms vs 92.8 ms — ~22x / ~46x; stereo split (both channels) 350 ms / 972 ms vs 18.7 ms — ~19x / ~52x. Closes #602 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
InauguralPhysicist
force-pushed
the
feat-pcm-codec-602
branch
from
July 14, 2026 09:55
e67e778 to
bcfa1e6
Compare
Collaborator
Author
|
Rebased onto main with #608 (the #607 module-env race fix) — the tsan gate failure was that pre-existing latent race, deterministically exposed by this PR's +3 builtin registrations shifting the module-env layout. Red-then-green verified locally: 4 TSan warnings on test_concurrent with these builtins and no fix, 0 across 3 runs with #608. |
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.
Closes #602
What
The byte-codec siblings of the #597 window kernels, driven by the measured DAW demand (DeslanStudio WAV import: 10.8 s for a 50 s stereo 48 kHz file on the N3350, dominated by the interpreted per-sample PCM16 decode):
buf_from_pcm16le of [bytes, byte_off, count]— decode a little-endian s16 window into a NEW float buffer (v = b0 + 256*b1; two's-complement fold at 32768;v / 32767)buf_to_pcm16le of [floats, off, count]— encode a float window into a NEW byte buffer (clamp [-1,1],round(x*32767), two's complement via +65536,ds_fmodlow byte /floorhigh byte)buf_deinterleave of [src, channel, nch, count?]— everynch-th sample starting atchannel(interleaved channel split;countdefaults to the available tail)Bit-identical contract: arithmetic mirrors DeslanStudio wavio's interpreted loops step-for-step (
num_guardper VM operation, same evaluation order). The differential suite leg (tests/test_pcm_codec.eigs) pins exact equality on seeded pseudo-random data: decode+deinterleave vs the fused wav_read loop, encode vs the wav_write loop, encode→decode round-trip parity, deinterleave vs the stride loop.Loud bounds per the family (
value/index_range/type_mismatch; count 0 is a valid no-op;count > INT_MAX/2raiseslimitbefore the ×2 can overflow). Output allocations charge the #292 sandbox budget; all three join the sandbox pure-compute allowlist; freestanding-safe.Perf (n=5 medians, N3350,
tests/bench_pcm_codec.eigs, 2.4 M samples, pinned to one core; an unrelated process held the other core — deltas are floor-subtracted per-pass times)Gates
detect_leaks=1: 2888/2889, leak tally 0 — the single failure isexamples/invariant_weak.eigshitting [97]'s 60 s wall guard under ASan (measured 71 s in isolation under ASan on this box — pre-existing marginality, no relation to this diff).🤖 Generated with Claude Code