-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Adding support for X86Base.CpuId #40167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5169d59
3651229
f5c4138
473940b
5295ffa
45354fe
23ae81d
68daefc
b520e82
6560b88
d8f1eb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace System.Runtime.Intrinsics.X86 | ||
| { | ||
| public abstract partial class X86Base | ||
| { | ||
| [DllImport(RuntimeHelpers.QCall)] | ||
| private static extern unsafe void __cpuidex(int* cpuInfo, int functionId, int subFunctionId); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,21 +95,22 @@ inline void GetSpecificCpuInfo(CORINFO_CPU * cpuInfo) | |
| #endif // !TARGET_X86 | ||
|
|
||
| #if (defined(TARGET_X86) || defined(TARGET_AMD64)) && !defined(CROSSGEN_COMPILE) | ||
| extern "C" DWORD __stdcall getcpuid(DWORD arg, unsigned char result[16]); | ||
| extern "C" DWORD __stdcall getextcpuid(DWORD arg1, DWORD arg2, unsigned char result[16]); | ||
| #ifdef TARGET_UNIX | ||
| // MSVC directly defines intrinsics for __cpuid and __cpuidex matching the below signatures | ||
| // We define matching signatures for use on Unix platforms. | ||
|
|
||
| extern "C" void __stdcall __cpuid(int cpuInfo[4], int function_id); | ||
| extern "C" void __stdcall __cpuidex(int cpuInfo[4], int function_id, int subFunction_id); | ||
| #endif // TARGET_UNIX | ||
| extern "C" DWORD __stdcall xmmYmmStateSupport(); | ||
| #endif | ||
|
|
||
| inline bool TargetHasAVXSupport() | ||
| { | ||
| #if (defined(TARGET_X86) || defined(TARGET_AMD64)) && !defined(CROSSGEN_COMPILE) | ||
| unsigned char buffer[16]; | ||
| // All x86/AMD64 targets support cpuid. | ||
| (void) getcpuid(1, buffer); | ||
| // getcpuid executes cpuid with eax set to its first argument, and ecx cleared. | ||
| // It returns the resulting eax, ebx, ecx and edx (in that order) in buffer[]. | ||
| // The AVX feature is ECX bit 28. | ||
| return ((buffer[11] & 0x10) != 0); | ||
| int cpuInfo[4]; | ||
| __cpuid(cpuInfo, 0x00000001); // All x86/AMD64 targets support cpuid. | ||
| return ((cpuInfo[3] & (1 << 28)) != 0); // The AVX feature is ECX bit 28. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. Looks like this one wasn't fixed in https://github.com/dotnet/runtime/pull/40615/files#diff-94f1f3dca4c0e81211037e26674aac43 |
||
| #endif // (defined(TARGET_X86) || defined(TARGET_AMD64)) && !defined(CROSSGEN_COMPILE) | ||
| return false; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.