Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 9b10a28

Browse files
committed
Implement IsSuppoored for all ISA classes
1 parent 00e7aa0 commit 9b10a28

File tree

17 files changed

+896
-20
lines changed

17 files changed

+896
-20
lines changed

src/inc/corinfo.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,12 @@ TODO: Talk about initializing strutures before use
213213
#define SELECTANY extern __declspec(selectany)
214214
#endif
215215

216-
SELECTANY const GUID JITEEVersionIdentifier = { /* 76a743cd-8a07-471e-9ac4-cd5806a8ffac */
217-
0x76a743cd,
218-
0x8a07,
219-
0x471e,
220-
{0x9a, 0xc4, 0xcd, 0x58, 0x06, 0xa8, 0xff, 0xac}
216+
// {CFEC7B89-D5FF-4A67-823A-EF99FE0286F4}
217+
SELECTANY const GUID JITEEVersionIdentifier = {
218+
0xcfec7b89,
219+
0xd5ff,
220+
0x4a67,
221+
{ 0x82, 0x3a, 0xef, 0x99, 0xfe, 0x2, 0x86, 0xf4 }
221222
};
222223

223224
//////////////////////////////////////////////////////////////////////////////////////////////////////////

src/inc/corjit.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,38 @@ class CORJIT_FLAGS
155155
CORJIT_FLAG_UNUSED11 = 41,
156156
#endif // !defined(_TARGET_ARM_)
157157

158-
CORJIT_FLAG_NO_INLINING = 42 // JIT should not inline any called method into this method
158+
CORJIT_FLAG_NO_INLINING = 42, // JIT should not inline any called method into this method
159+
160+
#if defined(_TARGET_X86_) || defined(_TARGET_AMD64_)
161+
162+
CORJIT_FLAG_USE_SSE3 = 43,
163+
CORJIT_FLAG_USE_SSSE3 = 44,
164+
CORJIT_FLAG_USE_SSE41 = 45,
165+
CORJIT_FLAG_USE_SSE42 = 46,
166+
CORJIT_FLAG_USE_AES = 47,
167+
CORJIT_FLAG_USE_BMI1 = 48,
168+
CORJIT_FLAG_USE_BMI2 = 49,
169+
CORJIT_FLAG_USE_FMA = 50,
170+
CORJIT_FLAG_USE_LZCNT = 51,
171+
CORJIT_FLAG_USE_PCLMULQDQ = 52,
172+
CORJIT_FLAG_USE_POPCNT = 53
173+
174+
175+
#else // !defined(_TARGET_X86_) && !defined(_TARGET_AMD64_)
176+
177+
CORJIT_FLAG_UNUSED12 = 43,
178+
CORJIT_FLAG_UNUSED13 = 44,
179+
CORJIT_FLAG_UNUSED14 = 45,
180+
CORJIT_FLAG_UNUSED15 = 46,
181+
CORJIT_FLAG_UNUSED16 = 47,
182+
CORJIT_FLAG_UNUSED17 = 48,
183+
CORJIT_FLAG_UNUSED18 = 49,
184+
CORJIT_FLAG_UNUSED19 = 50,
185+
CORJIT_FLAG_UNUSED20 = 51,
186+
CORJIT_FLAG_UNUSED21 = 52,
187+
CORJIT_FLAG_UNUSED22 = 53
188+
189+
#endif // !defined(_TARGET_X86_) && !defined(_TARGET_AMD64_)
159190
};
160191

161192
CORJIT_FLAGS()

src/jit/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ set( JIT_AMD64_SOURCES
100100
simdcodegenxarch.cpp
101101
targetamd64.cpp
102102
unwindamd64.cpp
103+
hwintrinsicxarch.cpp
103104
)
104105

105106
set( JIT_ARM_SOURCES
@@ -127,6 +128,7 @@ set( JIT_I386_SOURCES
127128
simdcodegenxarch.cpp
128129
targetx86.cpp
129130
unwindx86.cpp
131+
hwintrinsicxarch.cpp
130132
)
131133

132134
set( JIT_ARM64_SOURCES

src/jit/compiler.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,72 @@ void Compiler::compSetProcessor()
25602560
#endif // DEBUG
25612561

25622562
#endif // _TARGET_X86_
2563+
2564+
// Instruction set flags fo// Instruction set flags for Intel hardware intrinsics
2565+
#ifdef _TARGET_XARCH_
2566+
opts.compSupportsISA = 0;
2567+
2568+
if (!jitFlags.IsSet(JitFlags::JIT_FLAG_PREJIT))
2569+
{
2570+
if (opts.compCanUseSSE2)
2571+
{
2572+
opts.setSupportedISA(InstructionSet_SSE);
2573+
opts.setSupportedISA(InstructionSet_SSE2);
2574+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_AES))
2575+
{
2576+
opts.setSupportedISA(InstructionSet_AES);
2577+
}
2578+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_AVX))
2579+
{
2580+
opts.setSupportedISA(InstructionSet_AVX);
2581+
}
2582+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_AVX2))
2583+
{
2584+
opts.setSupportedISA(InstructionSet_AVX2);
2585+
}
2586+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_BMI1))
2587+
{
2588+
opts.setSupportedISA(InstructionSet_BMI1);
2589+
}
2590+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_BMI2))
2591+
{
2592+
opts.setSupportedISA(InstructionSet_BMI2);
2593+
}
2594+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_FMA))
2595+
{
2596+
opts.setSupportedISA(InstructionSet_FMA);
2597+
}
2598+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_LZCNT))
2599+
{
2600+
opts.setSupportedISA(InstructionSet_LZCNT);
2601+
}
2602+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_PCLMULQDQ))
2603+
{
2604+
opts.setSupportedISA(InstructionSet_PCLMULQDQ);
2605+
}
2606+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_POPCNT))
2607+
{
2608+
opts.setSupportedISA(InstructionSet_POPCNT);
2609+
}
2610+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE3))
2611+
{
2612+
opts.setSupportedISA(InstructionSet_SSE3);
2613+
}
2614+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE41))
2615+
{
2616+
opts.setSupportedISA(InstructionSet_SSE41);
2617+
}
2618+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSE42))
2619+
{
2620+
opts.setSupportedISA(InstructionSet_SSE42);
2621+
}
2622+
if (jitFlags.IsSet(JitFlags::JIT_FLAG_USE_SSSE3))
2623+
{
2624+
opts.setSupportedISA(InstructionSet_SSSE3);
2625+
}
2626+
}
2627+
}
2628+
#endif
25632629
}
25642630

25652631
#ifdef PROFILING_SUPPORTED

src/jit/compiler.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,6 +3016,28 @@ class Compiler
30163016
CorInfoIntrinsics intrinsicID,
30173017
bool tailCall);
30183018
NamedIntrinsic lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method);
3019+
3020+
#ifdef _TARGET_XARCH_
3021+
InstructionSet lookupHWIntrinsicISA(const char* className);
3022+
NamedIntrinsic lookupHWIntrinsic(const char* methodName, InstructionSet isa);
3023+
InstructionSet isaOfHWIntrinsic(NamedIntrinsic intrinsic);
3024+
GenTree* impX86HWIntrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3025+
GenTree* impSSEIntrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3026+
GenTree* impSSE2Intrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3027+
GenTree* impSSE3Intrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3028+
GenTree* impSSSE3Intrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3029+
GenTree* impSSE41Intrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3030+
GenTree* impSSE42Intrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3031+
GenTree* impAVXIntrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3032+
GenTree* impAVX2Intrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3033+
GenTree* impAESIntrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3034+
GenTree* impBMI1Intrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3035+
GenTree* impBMI2Intrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3036+
GenTree* impFMAIntrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3037+
GenTree* impLZCNTIntrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3038+
GenTree* impPCLMULQDQIntrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3039+
GenTree* impPOPCNTIntrinsic(NamedIntrinsic intrinsic, CORINFO_METHOD_HANDLE method);
3040+
#endif
30193041
GenTreePtr impArrayAccessIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
30203042
CORINFO_SIG_INFO* sig,
30213043
int memberRef,
@@ -7915,6 +7937,19 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
79157937
#endif // FEATURE_AVX_SUPPORT
79167938
#endif // _TARGET_XARCH_
79177939

7940+
#ifdef _TARGET_XARCH_
7941+
// only for Intel hardware intrinsics
7942+
uint64_t compSupportsISA;
7943+
void setSupportedISA(InstructionSet isa)
7944+
{
7945+
compSupportsISA |= 1 << isa;
7946+
}
7947+
bool compSupports(InstructionSet isa)
7948+
{
7949+
return (compSupportsISA & (1 << isa)) != 0;
7950+
}
7951+
#endif
7952+
79187953
// optimize maximally and/or favor speed over size?
79197954

79207955
#define DEFAULT_MIN_OPTS_CODE_SIZE 60000

src/jit/hwintrinsiclistxarch.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
/*****************************************************************************/
6+
#ifndef HARDWARE_INTRINSIC
7+
#error Define HARDWARE_INTRINSIC before including this file
8+
#endif
9+
/*****************************************************************************/
10+
11+
// clang-format off
12+
13+
#ifdef _TARGET_XARCH_
14+
// Intrinsic ID Function name ISA
15+
// SSE Intrinsics
16+
HARDWARE_INTRINSIC(SSE_IsSupported, "get_IsSupported", SSE)
17+
18+
// SSE2 Intrinsics
19+
HARDWARE_INTRINSIC(SSE2_IsSupported, "get_IsSupported", SSE2)
20+
21+
// SSE3 Intrinsics
22+
HARDWARE_INTRINSIC(SSE3_IsSupported, "get_IsSupported", SSE3)
23+
24+
// SSSE3 Intrinsics
25+
HARDWARE_INTRINSIC(SSSE3_IsSupported, "get_IsSupported", SSSE3)
26+
27+
// SSE41 Intrinsics
28+
HARDWARE_INTRINSIC(SSE41_IsSupported, "get_IsSupported", SSE41)
29+
30+
// SSE42 Intrinsics
31+
HARDWARE_INTRINSIC(SSE42_IsSupported, "get_IsSupported", SSE42)
32+
33+
// AVX Intrinsics
34+
HARDWARE_INTRINSIC(AVX_IsSupported, "get_IsSupported", AVX)
35+
36+
// AVX2 Intrinsics
37+
HARDWARE_INTRINSIC(AVX2_IsSupported, "get_IsSupported", AVX2)
38+
39+
// AES Intrinsics
40+
HARDWARE_INTRINSIC(AES_IsSupported, "get_IsSupported", AES)
41+
42+
// BMI1 Intrinsics
43+
HARDWARE_INTRINSIC(BMI1_IsSupported, "get_IsSupported", BMI1)
44+
45+
// BMI2 Intrinsics
46+
HARDWARE_INTRINSIC(BMI2_IsSupported, "get_IsSupported", BMI2)
47+
48+
// FMA Intrinsics
49+
HARDWARE_INTRINSIC(FMA_IsSupported, "get_IsSupported", FMA)
50+
51+
// LZCNT Intrinsics
52+
HARDWARE_INTRINSIC(LZCNT_IsSupported, "get_IsSupported", LZCNT)
53+
54+
// PCLMULQDQ Intrinsics
55+
HARDWARE_INTRINSIC(PCLMULQDQ_IsSupported, "get_IsSupported", PCLMULQDQ)
56+
57+
// POPCNT Intrinsics
58+
HARDWARE_INTRINSIC(POPCNT_IsSupported, "get_IsSupported", POPCNT)
59+
#endif
60+
61+
#undef HARDWARE_INTRINSIC
62+
63+
// clang-format on

0 commit comments

Comments
 (0)