Fix return types of SInt::Unsigned and SInt::*Divide - #156
Open
alastairreid wants to merge 6 commits into
Open
Conversation
This utility function is useful for things like applying constant folding to types like 'Bits(4+1)'
Apply constant folding to types like 'Bits(4+1)'. Apart from being simpler, this is essential when using the -O0 compilation flag because it requires that bitwidths are literal constants. In particular, this is needed in tests of functions whose return type is of the form 'Bits(x * y)', 'Bits(x + 1)', etc.
This was incorrectly calculating bounds such as {3..3}
when calculating the bounds of an expression like 'Log2(x) + 3'
This was wrong because the result of Log2 has type {0..}
so the most accurate bounds we could calculate should be {3..} (with no upper bound)
This was incorrectly saying that Bits(N) can be stored in an N-bit signed value. Obviously, we need an (N+1)-bit signed value to represent an unsigned N-bit number.
This had been added to the runtime but, for some reason, it had not been added to the standard library.
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.
The return types of Std::SInt::Unsigned and Std::SInt::*Divide need one more bit to represent the result than the size of the input.
More specifically:
Also adds support for compiling Std::SInt::Ceiling_Divide.
This has been supported in the runtime_*.ml files for a while but we had not added support in the C backend.
To be able to write tests that use -O0 for these operations, I had to tweak the typechecker so that it does not infer types like "__sint(8+1)" (which the backend will not accept) and, instead infers the type "__sint(9)".