Skip to content

fix(js): reuse a 4-byte DataView for F32 bit casts - #1651

Closed
adeerkhan wants to merge 1 commit into
bendlang:mainfrom
adeerkhan:fix/js-f32-bit-casts
Closed

adeerkhan wants to merge 1 commit into
bendlang:mainfrom
adeerkhan:fix/js-f32-bit-casts

Conversation

@adeerkhan

Copy link
Copy Markdown
Contributor

Resolves #1638.

f32_bits and f32_from_bits in the emitted JS runtime each allocated a fresh Float32Array/Uint32Array pair per call. Reuse one private 4-byte DataView for both, removing the per-call allocation on numeric code paths.

Behavior is unchanged: little-endian (matching the previous typed-array view), so signed zero, subnormals, the largest finite F32, and Infinity round-trip identically. NaN-payload guarantees are unchanged (the JS lane does not preserve them, per WONTFIX).

I verified equivalence against the previous implementation for a range of values (signed zero, subnormals, 3.4e38, Infinity, NaN, and arbitrary u32 bit patterns) with a standalone script.

f32_bits and f32_from_bits each allocated a Float32Array/Uint32Array pair
per call. Reuse one private 4-byte DataView for both, removing the per-call
allocation on numeric code paths. Behavior is unchanged (little-endian,
matching the previous typed-array view). Resolves bendlang#1638.
@Lorenzobattistela

Copy link
Copy Markdown
Collaborator

Thanks for the fix! Closing as a duplicate of #1643, which makes the same change for #1638 and is already under review. If you want to help there, note the review asks to reuse bend.ts's existing F32_VIEW helpers rather than adding a second copy in comp.ts.

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.

JS F32 bit casts allocate a fresh buffer and typed views on every call

2 participants