Repository navigation
Fix prefetch hints on clang-cl for Windows - #655
Merged
stefanatwork merged 2 commits intoNov 26, 2026
Merged
Conversation
When Embree is built with clang for the MSVC ABI (clang-cl, or clang++ targeting *-windows-msvc), <windows.h> brings in winnt.h, which redefines _MM_HINT_T0/T1/T2/NTA to the MSVC values 1/2/3/0 after clang's xmmintrin.h has set them to 3/2/1/0. Clang's _mm_prefetch reads the hint as a GCC-style locality (hint & 3), so prefetchL1 ended up as prefetcht2 and prefetchL3 as prefetcht0. Every BVH node and leaf prefetch during traversal was affected. Use __builtin_prefetch with an explicit locality for this compiler/ABI combination. MSVC, GCC, Linux, macOS and ARM64 builds still take the existing _mm_prefetch path. Checked on clang-cl 21.1.0 (Ryzen 5 9600X): the AVX2 traversal code goes from 0 prefetcht0 / 5298 prefetcht2 to 5298 prefetcht0 / 0 prefetcht2.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the Windows Clang prefetch-hint change.
No open issues 🎉
What changed in this PR
Corrects prefetch cache hints for Windows Clang builds targeting the MSVC ABI, restoring intended L1 prefetching during Embree’s BVH traversal.
Changes:
- Uses
__builtin_prefetchin the affected builds to avoid Windows header redefinitions of_MM_HINT_*. - Preserves the existing implementation for other compilers, platforms, and ARM64 builds.
| File | Description |
|---|---|
common/sys/intrinsics.h |
Adds Windows Clang-specific prefetch helpers with explicit cache-locality hints. |
Review effort: Balanced
svenwoop
approved these changes
Nov 26, 2026
stefanatwork
approved these changes
Nov 26, 2026
stefanatwork
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, good catch!
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.
Summary
Files changed:
common/sys/intrinsics.hMeasured
Embree built from upstream
304b5b7, Release build, SSE2 to AVX2.Test run: Embree's own
embree_verifyray benchmarks on the AVX2 path (1M triangles, StaticFast, MediumQuality),Accuracy verification
prefetchL1used to compile toprefetcht2(the L2 prefetch) and now compiles toprefetcht0(the L1 prefetch), as intended.ctest, includingembree_verify,embree_tests)