Repository navigation
Fix prefetch hints on clang-cl so prefetchL1 emits prefetcht0 - #654
Closed
MercylinPreethi wants to merge 1 commit into
Closed
MercylinPreethi wants to merge 1 commit into
MercylinPreethi wants to merge 1 commit into
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.
MercylinPreethi
marked this pull request as draft
November 20, 2026 07:30
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
Fix prefetch hints on clang-cl so
prefetchL1()emitsprefetcht0*-windows-msvc),<windows.h>pulls inwinnt.h, which redefines_MM_HINT_T0/T1/T2/NTAto the MSVC values 1/2/3/0 after clang'sxmmintrin.hset them to 3/2/1/0._mm_prefetchreads the hint as a GCC-style locality (hint & 3), soprefetchL1()becameprefetcht2andprefetchL3()becameprefetcht0. Every BVH node and leaf prefetch during traversal was affected.__builtin_prefetchwith an explicit locality for clang + MSVC ABI on x86 only. MSVC, GCC, Linux, macOS and ARM64 still use the existing_mm_prefetchpath. It does not change results.Files:
common/sys/intrinsics.hMeasured
Embree built from upstream
304b5b744, Release, SSE2 to AVX2Prefetch instructions in the AVX2 library (clang-cl 23.1.5):
Test plan
prefetcht0/t1/t2/ntanow matchprefetchL1/L2/L3/NTAon clang-cl.EMBREE_TESTING_INTENSITY=3, clang-cl 21.1.0 on Ryzen 5 9600X: 625/625 passed