__builtin_memcpy for large blocks - #596
Open
xavierleroy wants to merge 9 commits into
Open
xavierleroy wants to merge 9 commits into
xavierleroy wants to merge 9 commits into
Conversation
Previously, a 32-bit move immediate was used to load `sz / 4`, resulting in an overflow if `sz` >= 2^34. Easy fix: use a 64-bit move immediate. TargetPrinter will turn it into a 32-bit move immediate when possible.
On modern x86_64 processors, it's specially optimized in hardware. Keep the previous sequence (`rep movsl` plus corrections) for x86_32 because it's probably faster on older processors.
Use a 64-bit move immediate for `sz / 16` and do the computations in Z, not int.
Use a 64-bit move immediate and do the calculations in Z, not in int. Note: on RV-32, `sz` is at most 2^32-1, and the 64-bit move immediate only uses RV-32 instructions.
Do the size calculations in Z, not in int.
Do the size calculations in Z, not in int
Larger alignments are not allowed by the formal CompCert semantics.
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 expansion of
__builtin_memcpycurrently masks some of the high bits of the size argument off, resulting in partial copies for very large blocks (size >= 2^30, 2^34 or 2^36, depending on the target architecture).This is very unlikely to occur in practice, but this PR fixes this problem, making sure all bits of the size argument are honored.
In passing, it also changes the expansion of
__builtin_memcpyon x86-64 to take advantage of hardware optimizations on recent x86 processors, and reduces the alignment used to at most 8, which is the largest alignment supported by the CompCert back-end.Issue (on x86-64) reported by Christos Papakonstantinou (Cantina Security).