Skip to content

Commit a6caa95

Browse files
committed
[compiler-rt] Don't check XCR0 when detecting avx512 on Darwin.
Darwin lazily saves the AVX512 context on first use [1]: instead of checking that it already does to figure out if the OS supports AVX512, trust that the kernel will do the right thing and always assume the context save support is available. [1] https://github.com/apple/darwin-xnu/blob/xnu-4903.221.2/osfmk/i386/fpu.c#L174 Reviewers: ab, RKSimon, craig.topper Reviewed By: craig.topper Subscribers: dberris, JDevlieghere, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D70454 (cherry-picked from a70c3f9)
1 parent b79e912 commit a6caa95

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

compiler-rt/lib/builtins/cpu_model.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,15 @@ static void getAvailableFeatures(unsigned ECX, unsigned EDX, unsigned MaxLeaf,
532532
const unsigned AVXBits = (1 << 27) | (1 << 28);
533533
bool HasAVX = ((ECX & AVXBits) == AVXBits) && !getX86XCR0(&EAX, &EDX) &&
534534
((EAX & 0x6) == 0x6);
535+
#if defined(__APPLE__)
536+
// Darwin lazily saves the AVX512 context on first use: trust that the OS will
537+
// save the AVX512 context if we use AVX512 instructions, even the bit is not
538+
// set right now.
539+
bool HasAVX512Save = true;
540+
#else
541+
// AVX512 requires additional context to be saved by the OS.
535542
bool HasAVX512Save = HasAVX && ((EAX & 0xe0) == 0xe0);
543+
#endif
536544

537545
if (HasAVX)
538546
setFeature(FEATURE_AVX);

0 commit comments

Comments
 (0)