Skip to content
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

Updating Unix to save/restore Avx512 state #83784

Merged
merged 17 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions src/coreclr/pal/inc/pal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1315,13 +1315,42 @@ QueueUserAPC(
IN HANDLE hThread,
IN ULONG_PTR dwData);

#ifdef HOST_X86

#if defined(HOST_X86) || defined(HOST_AMD64)
// MSVC directly defines intrinsics for __cpuid and __cpuidex matching the below signatures
// We define matching signatures for use on Unix platforms.

#if __has_builtin(__cpuid)
janvorli marked this conversation as resolved.
Show resolved Hide resolved
extern "C" void __cpuid(int cpuInfo[4], int function_id);
#else
inline void __cpuid(int cpuInfo[4], int function_id)
{
// Based on the Clang implementation provided in cpuid.h:
// https://github.com/llvm/llvm-project/blob/master/clang/lib/Headers/cpuid.h

__asm(" cpuid\n" \
: "=a"(cpuInfo[0]), "=b"(cpuInfo[1]), "=c"(cpuInfo[2]), "=d"(cpuInfo[3]) \
: "0"(function_id)
);
}
#endif // __cpuid

#if __has_builtin(__cpuidex)
extern "C" void __cpuidex(int cpuInfo[4], int function_id, int subFunction_id);
#else
inline void __cpuidex(int cpuInfo[4], int function_id, int subFunction_id)
{
// Based on the Clang implementation provided in cpuid.h:
// https://github.com/llvm/llvm-project/blob/master/clang/lib/Headers/cpuid.h

__asm(" cpuid\n" \
: "=a"(cpuInfo[0]), "=b"(cpuInfo[1]), "=c"(cpuInfo[2]), "=d"(cpuInfo[3]) \
: "0"(function_id), "2"(subFunction_id)
);
}
#endif // __cpuidex
#endif // HOST_X86 || HOST_AMD64

#ifdef HOST_X86

//
// ***********************************************************************************
Expand Down Expand Up @@ -1468,12 +1497,6 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS {

#elif defined(HOST_AMD64)

// MSVC directly defines intrinsics for __cpuid and __cpuidex matching the below signatures
// We define matching signatures for use on Unix platforms.

extern "C" void __cpuid(int cpuInfo[4], int function_id);
extern "C" void __cpuidex(int cpuInfo[4], int function_id, int subFunction_id);

// copied from winnt.h

#define CONTEXT_AMD64 0x100000
Expand Down
28 changes: 0 additions & 28 deletions src/coreclr/pal/src/thread/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,34 +322,6 @@ typedef int __ptrace_request;
Xstate_ExtendedFeature Xstate_ExtendedFeatures[Xstate_ExtendedFeatures_Count];
#endif // XSTATE_SUPPORTED

#if defined(HOST_X86) || defined(HOST_AMD64)
#if !__has_builtin(__cpuid)
void __cpuid(int cpuInfo[4], int function_id)
{
// Based on the Clang implementation provided in cpuid.h:
// https://github.com/llvm/llvm-project/blob/master/clang/lib/Headers/cpuid.h

__asm(" cpuid\n" \
: "=a"(cpuInfo[0]), "=b"(cpuInfo[1]), "=c"(cpuInfo[2]), "=d"(cpuInfo[3]) \
: "0"(function_id)
);
}
#endif

#if !__has_builtin(__cpuidex)
void __cpuidex(int cpuInfo[4], int function_id, int subFunction_id)
{
// Based on the Clang implementation provided in cpuid.h:
// https://github.com/llvm/llvm-project/blob/master/clang/lib/Headers/cpuid.h

__asm(" cpuid\n" \
: "=a"(cpuInfo[0]), "=b"(cpuInfo[1]), "=c"(cpuInfo[2]), "=d"(cpuInfo[3]) \
: "0"(function_id), "2"(subFunction_id)
);
}
#endif
#endif // HOST_x86 || HOST_AMD64

/*++
Function:
CONTEXT_GetRegisters
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/vm/amd64/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ ASMCONSTANTS_C_ASSERT(OFFSETOF__MethodDesc__m_wFlags == offsetof(MethodDesc, m_w
ASMCONSTANTS_C_ASSERT(OFFSETOF__VASigCookie__pNDirectILStub
== offsetof(VASigCookie, pNDirectILStub));

#ifdef UNIX_AMD64_ABI
#if defined(UNIX_AMD64_ABI) && !defined(HOST_WINDOWS)
// Expression is too complicated, is currently:
// (8*6 + 4*2 + 2*6 + 4 + 8*6 + 8*16 + 8 + /*XMM_SAVE_AREA32*/(2*2 + 1*2 + 2 + 4 + 2*2 + 4 + 2*2 + 4*2 + 16*8 + 16*16 + 1*96) + 26*16 + 8 + 8*5 + /*XSTATE*/ + 8 + 8 + /*XSTATE_AVX*/ 16*16 + /*XSTATE_AVX512_KMASK*/ 8*8 + /*XSTATE_AVX512_ZMM_H*/ 32*16 + 8*4 + /*XSTATE_AVX512_ZMM*/ 64*16)
#define SIZEOF__CONTEXT (3136)
#else
// Expression is too complicated, is currently:
// Expression is too complicated, is currently:
// (8*6 + 4*2 + 2*6 + 4 + 8*6 + 8*16 + 8 + /*XMM_SAVE_AREA32*/(2*2 + 1*2 + 2 + 4 + 2*2 + 4 + 2*2 + 4*2 + 16*8 + 16*16 + 1*96) + 26*16 + 8 + 8*5)
#define SIZEOF__CONTEXT (1232)
#endif
Expand Down Expand Up @@ -445,7 +445,7 @@ ASMCONSTANTS_C_ASSERT(OFFSETOF__CONTEXT__Xmm15
ASMCONSTANTS_C_ASSERT(OFFSETOF__CONTEXT__VectorRegister
== offsetof(CONTEXT, VectorRegister[0]));

#ifdef UNIX_AMD64_ABI
#if defined(UNIX_AMD64_ABI) && !defined(HOST_WINDOWS)
#define SIZEOF__FaultingExceptionFrame (0x40 + SIZEOF__CONTEXT)
#else
#define SIZEOF__FaultingExceptionFrame (0x20 + SIZEOF__CONTEXT)
Expand Down