Skip to content

stage2: wasm - Improve @mulWithOverflow implementation #11605

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

Merged
merged 4 commits into from
May 7, 2022

Conversation

Luukdegram
Copy link
Contributor

@Luukdegram Luukdegram commented May 7, 2022

This improves the @mulWithOverflow implementation and ensures it passes all tests when bitsize <= 32.
To also support integers with bitsize 64, we will need compiler-rt support as Wasm does not have the same capabilities like the native backends with regards to carry bits, etc.

This PR ensures the Wasm backend will comply with #11316

Luukdegram added 4 commits May 6, 2022 21:58
When a signed integer is negative, the integer will be stored as a two's complement,
rather than its signed value. Instead, we verify the signed bits during arithmetic operations.
This fixes signed cases of `@mulWithOverflow`.
As we now store negative signed integers as two's complement,
we must also ensure that when truncating a float, its value is wrapped
around the integer's size.

This also splits `@mulWithOverflow` into its own function to make
the code more maintainable and reduce branching.
@Luukdegram Luukdegram force-pushed the wasm-mul-overflow branch from 25819ed to a110979 Compare May 7, 2022 18:02
@kubkon kubkon merged commit f161d38 into ziglang:master May 7, 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.

2 participants