Add Mbool
memory chunk to improve compilation of computations at type _Bool
#513
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.
This PR introduces a new kind of memory chunk,
Mbool
, to be used when compiling loads and stores of values of C type_Bool
.The semantics of a memory load with chunk
Mbool
is as follows:_Bool
has size 1 byte)With this semantics, the result of the load is guaranteed to be a correct value of type
_Bool
, i.e. 0, 1 or Vundef. This is not the case in the current CompCert, where_Bool
values are read using theMint8unsigned
chunk, resulting in any integer in the 0..255 range, or Vundef.Consequently, the value analysis of Boolean computations is more precise, enabling nice optimizations, as in the following examples.
With this PR, all three examples are compiled without any normalization to
_Bool
.The semantics of
Mbool
loads is carefully engineered so that it can be implemented in the final assembly code as a 8-bit unsigned loadMint8unsigned
, producing a "more defined than" result.What's in this PR?
Mbool
memory chunk is added, with the semantics outlined above.Mbool
.Mbool
loads and stores intoMint8unsigned
loads and stores, after all optimizations have been done.Mbool
loads and stores to access l-values of_Bool
type._Bool
are 0, 1 and Vundef.In passing, the PR refactors some code from the various Asmgen/Asmgenproof files into the shared Stacking/Stackingproof files. This was not absolutely necessary, just a good opportunity to do so.