-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[clang][X86] Add __cpuidex function to cpuid.h (#97785)
MSVC has a __cpuidex function implemented to call the underlying cpuid instruction which accepts a leaf, subleaf, and data array that the output data is written into. This patch adds this functionality into clang under the cpuid.h header. This also makes clang match GCC's behavior. GCC has had __cpuidex in its cpuid.h since 2020. This is another attempt to land https://reviews.llvm.org/D158348.
- Loading branch information
1 parent
ce4aada
commit 1cafde2
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Make sure that __cpuidex in cpuid.h doesn't conflict with the MS | ||
// extensions built in by ensuring compilation succeeds: | ||
// RUN: %clang_cc1 %s -ffreestanding -fms-extensions -fms-compatibility \ | ||
// RUN: -fms-compatibility-version=19.00 -triple x86_64-pc-windows-msvc -emit-llvm -o - | ||
// %clang_cc1 %s -ffreestanding -triple x86_64-w64-windows-gnu -fms-extensions -emit-llvm -o - | ||
// RUN: %clang_cc1 %s -ffreestanding -fopenmp -fopenmp-is-target-device -aux-triple x86_64-unknown-linux-gnu | ||
|
||
typedef __SIZE_TYPE__ size_t; | ||
|
||
// We declare __cpuidex here as where the buitlin should be exposed (MSVC), the | ||
// declaration is in <intrin.h>, but <intrin.h> is not available from all the | ||
// targets that are being tested here. | ||
void __cpuidex (int[4], int, int); | ||
|
||
#include <cpuid.h> | ||
|
||
int cpuid_info[4]; | ||
|
||
void test_cpuidex(unsigned level, unsigned count) { | ||
__cpuidex(cpuid_info, level, count); | ||
} | ||
|
This file contains 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