Skip to content

Commit

Permalink
Allow generating HW intrinsics in crossgen (dotnet/coreclr#24689)
Browse files Browse the repository at this point in the history
We currently don't precompile methods that use hardware intrinsics because we don't know the CPU that the generated code will run on. Jitting these methods slows down startup and accounts for 3% of startup time in PowerShell.
With this change, we're going to lift this restriction for CoreLib (the thing that matters for startup) and support generating HW intrinsics for our minimum supported target ISA (SSE/SSE2).

Commit migrated from dotnet/coreclr@d4fadf0
  • Loading branch information
MichalStrehovsky authored May 30, 2019
1 parent d220bcb commit 83ee5e8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/coreclr/src/vm/methodtablebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "ecmakey.h"
#include "customattribute.h"
#include "typestring.h"
#include "compile.h"

//*******************************************************************************
// Helper functions to sort GCdescs by offset (decending order)
Expand Down Expand Up @@ -1517,12 +1518,20 @@ MethodTableBuilder::BuildMethodTableThrowing(
if (hr == S_OK && (strcmp(nameSpace, "System.Runtime.Intrinsics.X86") == 0))
#endif
{
if (IsCompilationProcess())
#if defined(CROSSGEN_COMPILE)
#if defined(_TARGET_X86_) || defined(_TARGET_AMD64_)
if ((!IsNgenPDBCompilationProcess()
&& GetAppDomain()->ToCompilationDomain()->GetTargetModule() != g_pObjectClass->GetModule())
|| (strcmp(className, "Sse") != 0 && strcmp(className, "Sse2") != 0))
#endif // defined(_TARGET_X86_) || defined(_TARGET_AMD64_)
{
// Disable AOT compiling for managed implementation of hardware intrinsics in mscorlib.
// Disable AOT compiling for managed implementation of hardware intrinsics.
// We specially treat them here to ensure correct ISA features are set during compilation
// The only exception to this rule are SSE and SSE2 intrinsics in CoreLib - we can
// safely expand those because we require them to be always available.
COMPlusThrow(kTypeLoadException, IDS_EE_HWINTRINSIC_NGEN_DISALLOWED);
}
#endif // defined(CROSSGEN_COMPILE)
bmtProp->fIsHardwareIntrinsic = true;
}
}
Expand Down Expand Up @@ -9546,16 +9555,21 @@ void MethodTableBuilder::CheckForSystemTypes()
// These __m128 and __m256 types, among other requirements, are special in that they must always
// be aligned properly.

if (IsCompilationProcess())
#ifdef CROSSGEN_COMPILE
// Disable AOT compiling for the SIMD hardware intrinsic types. These types require special
// ABI handling as they represent fundamental data types (__m64, __m128, and __m256) and not
// aggregate or union types. See https://github.com/dotnet/coreclr/issues/15943
//
// Once they are properly handled according to the ABI requirements, we can remove this check
// and allow them to be used in crossgen/AOT scenarios.
//
// We can allow these to AOT compile in CoreLib since CoreLib versions with the runtime.
if (!IsNgenPDBCompilationProcess() &&
GetAppDomain()->ToCompilationDomain()->GetTargetModule() != g_pObjectClass->GetModule())
{
// Disable AOT compiling for the SIMD hardware intrinsic types. These types require special
// ABI handling as they represent fundamental data types (__m64, __m128, and __m256) and not
// aggregate or union types. See https://github.com/dotnet/coreclr/issues/15943
//
// Once they are properly handled according to the ABI requirements, we can remove this check
// and allow them to be used in crossgen/AOT scenarios.
COMPlusThrow(kTypeLoadException, IDS_EE_HWINTRINSIC_NGEN_DISALLOWED);
}
#endif

if (strcmp(name, g_Vector64Name) == 0)
{
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/src/zap/zapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,15 @@ void Zapper::InitializeCompilerFlags(CORCOMPILE_VERSION_INFO * pVersionInfo)

#endif // _TARGET_X86_

#if defined(_TARGET_X86_) || defined(_TARGET_AMD64_) || defined(_TARGET_ARM64_)
// If we're compiling CoreLib, allow RyuJIT to generate SIMD code so that we can expand some
// of the hardware intrinsics.
if (m_pEECompileInfo->GetAssemblyModule(m_hAssembly) == m_pEECompileInfo->GetLoaderModuleForMscorlib())
{
m_pOpt->m_compilerFlags.Set(CORJIT_FLAGS::CORJIT_FLAG_FEATURE_SIMD);
}
#endif // defined(_TARGET_X86_) || defined(_TARGET_AMD64_) || defined(_TARGET_ARM64_)

if ( m_pOpt->m_compilerFlags.IsSet(CORJIT_FLAGS::CORJIT_FLAG_DEBUG_INFO)
&& m_pOpt->m_compilerFlags.IsSet(CORJIT_FLAGS::CORJIT_FLAG_DEBUG_CODE)
&& m_pOpt->m_compilerFlags.IsSet(CORJIT_FLAGS::CORJIT_FLAG_PROF_ENTERLEAVE))
Expand Down

0 comments on commit 83ee5e8

Please sign in to comment.