Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stdlib): Add Conv.wasmI32ToNumber function #978

Merged
merged 3 commits into from
Oct 11, 2021

Conversation

cician
Copy link
Contributor

@cician cician commented Oct 10, 2021

This PR adds a function to convert WasmI32 to Number. This differs from tagSimpleNumber in runtime/dataStructures in that it's safe to use for any value of WasmI32, not just the range allowed in Simple numbers.

Btw there's also tagSimple in runtime/numbes that duplicates exactly the code from tagSimpleNumber, or the other way around. Maybe one can become reexport of the other.

I tried to optimize it so that we can possibly just replace most uses of tagSimpleNumber/tagSimple without fearing performance regressions.

Copy link
Member

@peblair peblair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful! Thank you!

Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com>
Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com>
Copy link
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

// the same. This may sound counter intuitive, but for numbers that fit into
// the range it is faster than performing the check with WasmI32.geS and
// WasmI32.leS by about 20%. An additional ~33% is gained by avoiding a
// call to tagSimpleNumber and instead doing it inline. For the case of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got some branches in the works that makes Binaryen inlining of these calls work, so no worries about that in the future 🙂

@ospencer ospencer merged commit c93ade8 into grain-lang:main Oct 11, 2021
@github-actions github-actions bot mentioned this pull request May 31, 2022
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.

4 participants