Enable software prefetching on MSVC and clang-cl x86 and x86_64#13238
Merged
nojb merged 2 commits intoocaml:trunkfrom Jun 17, 2024
Merged
Enable software prefetching on MSVC and clang-cl x86 and x86_64#13238nojb merged 2 commits intoocaml:trunkfrom
nojb merged 2 commits intoocaml:trunkfrom
Conversation
ghost
reviewed
Jun 17, 2024
32a7fa6 to
9d4a838
Compare
ghost
reviewed
Jun 17, 2024
9d4a838 to
cc1a463
Compare
ghost
approved these changes
Jun 17, 2024
cc1a463 to
0e151d6
Compare
nojb
approved these changes
Jun 17, 2024
Contributor
nojb
left a comment
There was a problem hiding this comment.
LGTM (on behalf of @dustanddreams)
Reorders a bit the macros tests as clang-cl doesn't define __GNUC__ and warns if -Wundef is enabled. It has the side-effect of enabling the built-in functions to perform arithmetic with overflow checking under clang-cl too.
Both GCC and MSVC emit the prefetcht0 instruction. Prefer clang's builtin instead of the intrinsic. With MSVC, call the intrinsic directly in order not to have to pull winnt.h via windows.h for PreFetchCacheLine.
0e151d6 to
99f2e84
Compare
NickBarnes
reviewed
Jun 17, 2024
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.
Chasing the last bits of the MSVC/clang-cl restore, re-enable software prefetching hints to help the garbage collector on MSVC and clang-cl.
Both GCC and MSVC emit the
prefetcht0instruction (check on godbolt).Prefer clang's builtin instead of the intrinsic, I find it a bit cleaner and it's one fewer header.
With MSVC, call the intrinsic directly in order not to have to pull
winnt.hviawindows.h(forPreFetchCacheLine). I'm using the same definition asPreFetchCacheLine.An ad-hoc benchmark using hyperfine's defaults on Stephen Dolan's markbench regression test for software prefetching gives:
Half the time, twice the fun!
The first commit aligns compiler builtin detection with compiler attributes detection, and reorders a bit the macros tests as clang-cl doesn't define
__GNUC__and warns if-Wundefis enabled. It has the side-effect of enabling the built-in functions to perform arithmetic with overflow checking under clang-cl too.