Skip to content

Commit 70c8947

Browse files
committed
resolve comments:
1. rename flag: avx512f_vl to avx512vl as it now serves across other subsets. 2. handled the ISA flag checks in AOT.
1 parent 70e097e commit 70c8947

File tree

5 files changed

+71
-57
lines changed

5 files changed

+71
-57
lines changed

src/coreclr/tools/Common/Compiler/HardwareIntrinsicHelpers.cs

+22-24
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,13 @@ private static class XArchIntrinsicConstants
7171
public const int AvxVnni = 0x2000;
7272
public const int Movbe = 0x4000;
7373
public const int Avx512f = 0x8000;
74-
public const int Avx512f_vl = 0x10000;
74+
public const int Avx512vl = 0x10000;
7575
public const int Avx512bw = 0x20000;
7676
public const int Avx512cd = 0x40000;
7777
public const int Avx512dq = 0x80000;
7878
public const int Avx512Vbmi = 0x100000;
7979
public const int Serialize = 0x200000;
8080
public const int Avx10v1 = 0x400000;
81-
public const int Avx10v1_v256 = 0x800000;
82-
public const int Avx10v1_v512 = 0x1000000;
8381

8482
public static void AddToBuilder(InstructionSetSupportBuilder builder, int flags)
8583
{
@@ -115,31 +113,31 @@ public static void AddToBuilder(InstructionSetSupportBuilder builder, int flags)
115113
builder.AddSupportedInstructionSet("movbe");
116114
if ((flags & Avx512f) != 0)
117115
builder.AddSupportedInstructionSet("avx512f");
118-
if ((flags & Avx512f_vl) != 0)
116+
if ((flags & Avx512vl) != 0)
119117
builder.AddSupportedInstructionSet("avx512f_vl");
120118
if ((flags & Avx512bw) != 0)
121119
builder.AddSupportedInstructionSet("avx512bw");
122-
if (((flags & Avx512bw) != 0) && ((flags & Avx512f_vl) != 0))
120+
if (((flags & Avx512bw) != 0) && ((flags & Avx512vl) != 0))
123121
builder.AddSupportedInstructionSet("avx512bw_vl");
124122
if ((flags & Avx512cd) != 0)
125123
builder.AddSupportedInstructionSet("avx512cd");
126-
if (((flags & Avx512cd) != 0) && (flags & Avx512f_vl) != 0)
124+
if (((flags & Avx512cd) != 0) && (flags & Avx512vl) != 0)
127125
builder.AddSupportedInstructionSet("avx512cd_vl");
128126
if ((flags & Avx512dq) != 0)
129127
builder.AddSupportedInstructionSet("avx512dq");
130-
if (((flags & Avx512dq) != 0) && (flags & Avx512f_vl) != 0)
128+
if (((flags & Avx512dq) != 0) && (flags & Avx512vl) != 0)
131129
builder.AddSupportedInstructionSet("avx512dq_vl");
132130
if ((flags & Avx512Vbmi) != 0)
133131
builder.AddSupportedInstructionSet("avx512vbmi");
134-
if (((flags & Avx512Vbmi) != 0) && (flags & Avx512f_vl) != 0)
132+
if (((flags & Avx512Vbmi) != 0) && (flags & Avx512vl) != 0)
135133
builder.AddSupportedInstructionSet("avx512vbmi_vl");
136134
if ((flags & Serialize) != 0)
137135
builder.AddSupportedInstructionSet("serialize");
138136
if ((flags & Avx10v1) != 0)
139137
builder.AddSupportedInstructionSet("avx10v1");
140-
if ((flags & Avx10v1_v256) != 0)
138+
if ((flags & Avx10v1) != 0)
141139
builder.AddSupportedInstructionSet("avx10v1_v256");
142-
if ((flags & Avx10v1_v512) != 0)
140+
if (((flags & Avx10v1) != 0) && ((flags & Avx512f) != 0))
143141
builder.AddSupportedInstructionSet("avx10v1_v512");
144142
}
145143

@@ -184,32 +182,32 @@ public static int FromInstructionSet(InstructionSet instructionSet)
184182
InstructionSet.X64_MOVBE_X64 => Movbe,
185183
InstructionSet.X64_AVX512F => Avx512f,
186184
InstructionSet.X64_AVX512F_X64 => Avx512f,
187-
InstructionSet.X64_AVX512F_VL => Avx512f_vl,
188-
InstructionSet.X64_AVX512F_VL_X64 => Avx512f_vl,
185+
InstructionSet.X64_AVX512F_VL => Avx512vl,
186+
InstructionSet.X64_AVX512F_VL_X64 => Avx512vl,
189187
InstructionSet.X64_AVX512BW => Avx512bw,
190188
InstructionSet.X64_AVX512BW_X64 => Avx512bw,
191-
InstructionSet.X64_AVX512BW_VL => (Avx512bw | Avx512f_vl),
192-
InstructionSet.X64_AVX512BW_VL_X64 => (Avx512bw | Avx512f_vl),
189+
InstructionSet.X64_AVX512BW_VL => (Avx512bw | Avx512vl),
190+
InstructionSet.X64_AVX512BW_VL_X64 => (Avx512bw | Avx512vl),
193191
InstructionSet.X64_AVX512CD => Avx512cd,
194192
InstructionSet.X64_AVX512CD_X64 => Avx512cd,
195-
InstructionSet.X64_AVX512CD_VL => (Avx512cd | Avx512f_vl),
196-
InstructionSet.X64_AVX512CD_VL_X64 => (Avx512cd | Avx512f_vl),
193+
InstructionSet.X64_AVX512CD_VL => (Avx512cd | Avx512vl),
194+
InstructionSet.X64_AVX512CD_VL_X64 => (Avx512cd | Avx512vl),
197195
InstructionSet.X64_AVX512DQ => Avx512dq,
198196
InstructionSet.X64_AVX512DQ_X64 => Avx512dq,
199-
InstructionSet.X64_AVX512DQ_VL => (Avx512dq | Avx512f_vl),
200-
InstructionSet.X64_AVX512DQ_VL_X64 => (Avx512dq | Avx512f_vl),
197+
InstructionSet.X64_AVX512DQ_VL => (Avx512dq | Avx512vl),
198+
InstructionSet.X64_AVX512DQ_VL_X64 => (Avx512dq | Avx512vl),
201199
InstructionSet.X64_AVX512VBMI => Avx512Vbmi,
202200
InstructionSet.X64_AVX512VBMI_X64 => Avx512Vbmi,
203-
InstructionSet.X64_AVX512VBMI_VL => (Avx512Vbmi | Avx512f_vl),
204-
InstructionSet.X64_AVX512VBMI_VL_X64 => (Avx512Vbmi | Avx512f_vl),
201+
InstructionSet.X64_AVX512VBMI_VL => (Avx512Vbmi | Avx512vl),
202+
InstructionSet.X64_AVX512VBMI_VL_X64 => (Avx512Vbmi | Avx512vl),
205203
InstructionSet.X64_X86Serialize => Serialize,
206204
InstructionSet.X64_X86Serialize_X64 => Serialize,
207205
InstructionSet.X64_AVX10v1 => Avx10v1,
208206
InstructionSet.X64_AVX10v1_X64 => Avx10v1,
209-
InstructionSet.X64_AVX10v1_V256 => Avx10v1_v256,
210-
InstructionSet.X64_AVX10v1_V256_X64 => Avx10v1_v256,
211-
InstructionSet.X64_AVX10v1_V512 => Avx10v1_v512,
212-
InstructionSet.X64_AVX10v1_V512_X64 => Avx10v1_v512,
207+
InstructionSet.X64_AVX10v1_V256 => Avx10v1,
208+
InstructionSet.X64_AVX10v1_V256_X64 => Avx10v1,
209+
InstructionSet.X64_AVX10v1_V512 => (Avx10v1 | Avx512f),
210+
InstructionSet.X64_AVX10v1_V512_X64 => (Avx10v1 | Avx512f),
213211

214212
// Baseline ISAs - they're always available
215213
InstructionSet.X64_SSE => 0,

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/HardwareIntrinsicHelpers.Aot.cs

+40-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,46 @@ public static MethodIL EmitIsSupportedIL(MethodDesc method, FieldDesc isSupporte
4949
var emit = new ILEmitter();
5050
ILCodeStream codeStream = emit.NewCodeStream();
5151

52-
codeStream.Emit(ILOpcode.ldsfld, emit.NewToken(isSupportedField));
53-
codeStream.EmitLdc(flag);
54-
codeStream.Emit(ILOpcode.and);
55-
codeStream.EmitLdc(0);
56-
codeStream.Emit(ILOpcode.cgt_un);
57-
codeStream.Emit(ILOpcode.ret);
52+
switch (instructionSet)
53+
{
54+
case InstructionSet.X64_AVX10v1_V512:
55+
case InstructionSet.X64_AVX10v1_V512_X64:
56+
case InstructionSet.X64_AVX512F_VL:
57+
case InstructionSet.X64_AVX512F_VL_X64:
58+
case InstructionSet.X64_AVX512BW_VL:
59+
case InstructionSet.X64_AVX512BW_VL_X64:
60+
case InstructionSet.X64_AVX512CD_VL:
61+
case InstructionSet.X64_AVX512CD_VL_X64:
62+
case InstructionSet.X64_AVX512DQ_VL:
63+
case InstructionSet.X64_AVX512DQ_VL_X64:
64+
case InstructionSet.X64_AVX512VBMI_VL:
65+
case InstructionSet.X64_AVX512VBMI_VL_X64:
66+
{
67+
// These are the ISAs managed by multiple-bit flags.
68+
// we need to emit different IL to handle the checks.
69+
// (isSupportedField & flag) == flag
70+
codeStream.Emit(ILOpcode.ldsfld, emit.NewToken(isSupportedField));
71+
codeStream.EmitLdc(flag);
72+
codeStream.Emit(ILOpcode.and);
73+
codeStream.EmitLdc(flag);
74+
codeStream.Emit(ILOpcode.beq);
75+
codeStream.Emit(ILOpcode.ret);
76+
break;
77+
}
78+
79+
default:
80+
{
81+
// (isSupportedField & flag) >= (unsinged)0
82+
codeStream.Emit(ILOpcode.ldsfld, emit.NewToken(isSupportedField));
83+
codeStream.EmitLdc(flag);
84+
codeStream.Emit(ILOpcode.and);
85+
codeStream.EmitLdc(0);
86+
codeStream.Emit(ILOpcode.cgt_un);
87+
codeStream.Emit(ILOpcode.ret);
88+
break;
89+
}
90+
91+
}
5892

5993
return emit.Link(method);
6094
}

src/coreclr/vm/codeman.cpp

+7-13
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ void EEJitManager::SetCpuInfo()
13101310
CPUCompileFlags.Set(InstructionSet_AVX512F);
13111311
}
13121312

1313-
if (((cpuFeatures & XArchIntrinsicConstants_Avx512f_vl) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX512F_VL))
1313+
if (((cpuFeatures & XArchIntrinsicConstants_Avx512vl) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX512F_VL))
13141314
{
13151315
CPUCompileFlags.Set(InstructionSet_AVX512F_VL);
13161316
}
@@ -1320,7 +1320,7 @@ void EEJitManager::SetCpuInfo()
13201320
CPUCompileFlags.Set(InstructionSet_AVX512BW);
13211321
}
13221322

1323-
if (((cpuFeatures & XArchIntrinsicConstants_Avx512bw) != 0) && ((cpuFeatures & XArchIntrinsicConstants_Avx512f_vl) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX512BW_VL))
1323+
if (((cpuFeatures & XArchIntrinsicConstants_Avx512bw) != 0) && ((cpuFeatures & XArchIntrinsicConstants_Avx512vl) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX512BW_VL))
13241324
{
13251325
CPUCompileFlags.Set(InstructionSet_AVX512BW_VL);
13261326
}
@@ -1330,7 +1330,7 @@ void EEJitManager::SetCpuInfo()
13301330
CPUCompileFlags.Set(InstructionSet_AVX512CD);
13311331
}
13321332

1333-
if (((cpuFeatures & XArchIntrinsicConstants_Avx512cd) != 0) && ((cpuFeatures & XArchIntrinsicConstants_Avx512f_vl) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX512CD_VL))
1333+
if (((cpuFeatures & XArchIntrinsicConstants_Avx512cd) != 0) && ((cpuFeatures & XArchIntrinsicConstants_Avx512vl) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX512CD_VL))
13341334
{
13351335
CPUCompileFlags.Set(InstructionSet_AVX512CD_VL);
13361336
}
@@ -1340,7 +1340,7 @@ void EEJitManager::SetCpuInfo()
13401340
CPUCompileFlags.Set(InstructionSet_AVX512DQ);
13411341
}
13421342

1343-
if (((cpuFeatures & XArchIntrinsicConstants_Avx512dq) != 0) && ((cpuFeatures & XArchIntrinsicConstants_Avx512f_vl) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX512DQ_VL))
1343+
if (((cpuFeatures & XArchIntrinsicConstants_Avx512dq) != 0) && ((cpuFeatures & XArchIntrinsicConstants_Avx512vl) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX512DQ_VL))
13441344
{
13451345
CPUCompileFlags.Set(InstructionSet_AVX512DQ_VL);
13461346
}
@@ -1350,7 +1350,7 @@ void EEJitManager::SetCpuInfo()
13501350
CPUCompileFlags.Set(InstructionSet_AVX512VBMI);
13511351
}
13521352

1353-
if (((cpuFeatures & XArchIntrinsicConstants_Avx512Vbmi) != 0) && ((cpuFeatures & XArchIntrinsicConstants_Avx512f_vl) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX512VBMI_VL))
1353+
if (((cpuFeatures & XArchIntrinsicConstants_Avx512Vbmi) != 0) && ((cpuFeatures & XArchIntrinsicConstants_Avx512vl) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX512VBMI_VL))
13541354
{
13551355
CPUCompileFlags.Set(InstructionSet_AVX512VBMI_VL);
13561356
}
@@ -1431,16 +1431,10 @@ void EEJitManager::SetCpuInfo()
14311431
// defined in InstructionSetDesc.txt should be explicit, no transitive implication should be assumed.
14321432
if (((cpuFeatures & XArchIntrinsicConstants_Avx10v1) != 0) && CLRConfig::GetConfigValue(CLRConfig::EXTERNAL_EnableAVX10v1))
14331433
{
1434+
// Avx10v1 & Avx10v1_V256 are supposed to appear on any Avx10 machine,
1435+
// Avx10v1_V512 shall be cancelled later if Avx512 does not exist.
14341436
CPUCompileFlags.Set(InstructionSet_AVX10v1);
1435-
}
1436-
1437-
if (((cpuFeatures & XArchIntrinsicConstants_Avx10v1_V256) != 0))
1438-
{
14391437
CPUCompileFlags.Set(InstructionSet_AVX10v1_V256);
1440-
}
1441-
1442-
if (((cpuFeatures & XArchIntrinsicConstants_Avx10v1_V512) != 0))
1443-
{
14441438
CPUCompileFlags.Set(InstructionSet_AVX10v1_V512);
14451439
}
14461440
#elif defined(TARGET_ARM64)

src/native/minipal/cpufeatures.c

+1-11
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int minipal_getcpufeatures(void)
228228

229229
if ((cpuidInfo[CPUID_EBX] & (1 << 31)) != 0) // AVX512F_VL
230230
{
231-
result |= XArchIntrinsicConstants_Avx512f_vl;
231+
result |= XArchIntrinsicConstants_Avx512vl;
232232
}
233233

234234
if ((cpuidInfo[CPUID_EBX] & (1 << 30)) != 0) // AVX512BW
@@ -269,16 +269,6 @@ int minipal_getcpufeatures(void)
269269
{
270270
result |= XArchIntrinsicConstants_Avx10v1;
271271
}
272-
273-
if ((cpuidInfo[CPUID_EBX] & (1 << 17)) != 0)
274-
{
275-
result |= XArchIntrinsicConstants_Avx10v1_V256;
276-
}
277-
278-
if ((cpuidInfo[CPUID_EBX] & (1 << 18)) != 0)
279-
{
280-
result |= XArchIntrinsicConstants_Avx10v1_V512;
281-
}
282272
}
283273
}
284274
}

src/native/minipal/cpufeatures.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ enum XArchIntrinsicConstants
2727
XArchIntrinsicConstants_AvxVnni = 0x2000,
2828
XArchIntrinsicConstants_Movbe = 0x4000,
2929
XArchIntrinsicConstants_Avx512f = 0x8000,
30-
XArchIntrinsicConstants_Avx512f_vl = 0x10000,
30+
XArchIntrinsicConstants_Avx512vl = 0x10000,
3131
XArchIntrinsicConstants_Avx512bw = 0x20000,
3232
XArchIntrinsicConstants_Avx512cd = 0x40000,
3333
XArchIntrinsicConstants_Avx512dq = 0x80000,
3434
XArchIntrinsicConstants_Avx512Vbmi = 0x100000,
3535
XArchIntrinsicConstants_Serialize = 0x200000,
3636
XArchIntrinsicConstants_Avx10v1 = 0x400000,
37-
XArchIntrinsicConstants_Avx10v1_V256 = 0x800000,
38-
XArchIntrinsicConstants_Avx10v1_V512 = 0x1000000,
3937
};
4038
#endif // HOST_X86 || HOST_AMD64
4139

0 commit comments

Comments
 (0)