Skip to content

Commit cfa8500

Browse files
committed
RiscV64 doesn't have public types for its intrinsics.
Document definearch command in instructionsetdesc.txt Drive the "intrinsic namespace" logic for `LookupPlatformIntrinsicInstructionSet` from the newly added field in definearch. Fix the ARM64 intrinsics namespace.
1 parent 2ed8d9c commit cfa8500

File tree

3 files changed

+51
-49
lines changed

3 files changed

+51
-49
lines changed

src/coreclr/tools/Common/JitInterface/CorInfoInstructionSet.cs

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,10 +1020,10 @@ public static IEnumerable<InstructionSetInfo> ArchitectureToValidInstructionSets
10201020
break;
10211021

10221022
case TargetArchitecture.RiscV64:
1023-
yield return new InstructionSetInfo("base", "RiscV64Base", InstructionSet.RiscV64_RiscV64Base, true);
1024-
yield return new InstructionSetInfo("zba", "Zba", InstructionSet.RiscV64_Zba, true);
1025-
yield return new InstructionSetInfo("zbb", "Zbb", InstructionSet.RiscV64_Zbb, true);
1026-
yield return new InstructionSetInfo("zbs", "Zbs", InstructionSet.RiscV64_Zbs, true);
1023+
yield return new InstructionSetInfo("base", "", InstructionSet.RiscV64_RiscV64Base, true);
1024+
yield return new InstructionSetInfo("zba", "", InstructionSet.RiscV64_Zba, true);
1025+
yield return new InstructionSetInfo("zbb", "", InstructionSet.RiscV64_Zbb, true);
1026+
yield return new InstructionSetInfo("zbs", "", InstructionSet.RiscV64_Zbs, true);
10271027
break;
10281028

10291029
case TargetArchitecture.X64:
@@ -1335,6 +1335,9 @@ public static InstructionSet LookupPlatformIntrinsicInstructionSet(TargetArchite
13351335
break;
13361336

13371337
case TargetArchitecture.X64:
1338+
platformIntrinsicNamespace = "System.Runtime.Intrinsics.X86";
1339+
break;
1340+
13381341
case TargetArchitecture.X86:
13391342
platformIntrinsicNamespace = "System.Runtime.Intrinsics.X86";
13401343
break;
@@ -1413,28 +1416,16 @@ public static InstructionSet LookupPlatformIntrinsicInstructionSet(TargetArchite
14131416
else
14141417
{ return InstructionSet.ARM64_Sve2; }
14151418

1419+
default:
1420+
return InstructionSet.ILLEGAL;
14161421
}
1417-
break;
1418-
14191422
case TargetArchitecture.RiscV64:
14201423
switch (typeName)
14211424
{
14221425

1423-
case "RiscV64Base":
1424-
{ return InstructionSet.RiscV64_RiscV64Base; }
1425-
1426-
case "Zba":
1427-
{ return InstructionSet.RiscV64_Zba; }
1428-
1429-
case "Zbb":
1430-
{ return InstructionSet.RiscV64_Zbb; }
1431-
1432-
case "Zbs":
1433-
{ return InstructionSet.RiscV64_Zbs; }
1434-
1426+
default:
1427+
return InstructionSet.ILLEGAL;
14351428
}
1436-
break;
1437-
14381429
case TargetArchitecture.X64:
14391430
switch (typeName)
14401431
{
@@ -1763,9 +1754,9 @@ public static InstructionSet LookupPlatformIntrinsicInstructionSet(TargetArchite
17631754
else
17641755
{ return InstructionSet.X64_AVXVNNIINT; }
17651756

1757+
default:
1758+
return InstructionSet.ILLEGAL;
17661759
}
1767-
break;
1768-
17691760
case TargetArchitecture.X86:
17701761
switch (typeName)
17711762
{
@@ -1947,9 +1938,9 @@ public static InstructionSet LookupPlatformIntrinsicInstructionSet(TargetArchite
19471938
else
19481939
{ return InstructionSet.X86_AVXVNNIINT; }
19491940

1941+
default:
1942+
return InstructionSet.ILLEGAL;
19501943
}
1951-
break;
1952-
19531944
}
19541945
return InstructionSet.ILLEGAL;
19551946
}
@@ -1961,7 +1952,7 @@ public static IEnumerable<MetadataType> LookupPlatformIntrinsicTypes(TypeSystemC
19611952
case (InstructionSet.ARM64_ArmBase, TargetArchitecture.ARM64):
19621953
case (InstructionSet.ARM64_ArmBase_Arm64, TargetArchitecture.ARM64):
19631954
{
1964-
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm64"u8, "ArmBase"u8, true);
1955+
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm"u8, "ArmBase"u8, true);
19651956
yield return type;
19661957
if (instructionSet == InstructionSet.ARM64_ArmBase_Arm64)
19671958
{
@@ -1973,7 +1964,7 @@ public static IEnumerable<MetadataType> LookupPlatformIntrinsicTypes(TypeSystemC
19731964
case (InstructionSet.ARM64_AdvSimd, TargetArchitecture.ARM64):
19741965
case (InstructionSet.ARM64_AdvSimd_Arm64, TargetArchitecture.ARM64):
19751966
{
1976-
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm64"u8, "AdvSimd"u8, true);
1967+
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm"u8, "AdvSimd"u8, true);
19771968
yield return type;
19781969
if (instructionSet == InstructionSet.ARM64_AdvSimd_Arm64)
19791970
{
@@ -1985,7 +1976,7 @@ public static IEnumerable<MetadataType> LookupPlatformIntrinsicTypes(TypeSystemC
19851976
case (InstructionSet.ARM64_Aes, TargetArchitecture.ARM64):
19861977
case (InstructionSet.ARM64_Aes_Arm64, TargetArchitecture.ARM64):
19871978
{
1988-
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm64"u8, "Aes"u8, true);
1979+
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm"u8, "Aes"u8, true);
19891980
yield return type;
19901981
if (instructionSet == InstructionSet.ARM64_Aes_Arm64)
19911982
{
@@ -1997,7 +1988,7 @@ public static IEnumerable<MetadataType> LookupPlatformIntrinsicTypes(TypeSystemC
19971988
case (InstructionSet.ARM64_Crc32, TargetArchitecture.ARM64):
19981989
case (InstructionSet.ARM64_Crc32_Arm64, TargetArchitecture.ARM64):
19991990
{
2000-
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm64"u8, "Crc32"u8, true);
1991+
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm"u8, "Crc32"u8, true);
20011992
yield return type;
20021993
if (instructionSet == InstructionSet.ARM64_Crc32_Arm64)
20031994
{
@@ -2009,7 +2000,7 @@ public static IEnumerable<MetadataType> LookupPlatformIntrinsicTypes(TypeSystemC
20092000
case (InstructionSet.ARM64_Dp, TargetArchitecture.ARM64):
20102001
case (InstructionSet.ARM64_Dp_Arm64, TargetArchitecture.ARM64):
20112002
{
2012-
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm64"u8, "Dp"u8, true);
2003+
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm"u8, "Dp"u8, true);
20132004
yield return type;
20142005
if (instructionSet == InstructionSet.ARM64_Dp_Arm64)
20152006
{
@@ -2021,7 +2012,7 @@ public static IEnumerable<MetadataType> LookupPlatformIntrinsicTypes(TypeSystemC
20212012
case (InstructionSet.ARM64_Rdm, TargetArchitecture.ARM64):
20222013
case (InstructionSet.ARM64_Rdm_Arm64, TargetArchitecture.ARM64):
20232014
{
2024-
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm64"u8, "Rdm"u8, true);
2015+
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm"u8, "Rdm"u8, true);
20252016
yield return type;
20262017
if (instructionSet == InstructionSet.ARM64_Rdm_Arm64)
20272018
{
@@ -2033,7 +2024,7 @@ public static IEnumerable<MetadataType> LookupPlatformIntrinsicTypes(TypeSystemC
20332024
case (InstructionSet.ARM64_Sha1, TargetArchitecture.ARM64):
20342025
case (InstructionSet.ARM64_Sha1_Arm64, TargetArchitecture.ARM64):
20352026
{
2036-
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm64"u8, "Sha1"u8, true);
2027+
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm"u8, "Sha1"u8, true);
20372028
yield return type;
20382029
if (instructionSet == InstructionSet.ARM64_Sha1_Arm64)
20392030
{
@@ -2045,7 +2036,7 @@ public static IEnumerable<MetadataType> LookupPlatformIntrinsicTypes(TypeSystemC
20452036
case (InstructionSet.ARM64_Sha256, TargetArchitecture.ARM64):
20462037
case (InstructionSet.ARM64_Sha256_Arm64, TargetArchitecture.ARM64):
20472038
{
2048-
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm64"u8, "Sha256"u8, true);
2039+
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm"u8, "Sha256"u8, true);
20492040
yield return type;
20502041
if (instructionSet == InstructionSet.ARM64_Sha256_Arm64)
20512042
{
@@ -2057,7 +2048,7 @@ public static IEnumerable<MetadataType> LookupPlatformIntrinsicTypes(TypeSystemC
20572048
case (InstructionSet.ARM64_Sve, TargetArchitecture.ARM64):
20582049
case (InstructionSet.ARM64_Sve_Arm64, TargetArchitecture.ARM64):
20592050
{
2060-
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm64"u8, "Sve"u8, true);
2051+
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm"u8, "Sve"u8, true);
20612052
yield return type;
20622053
if (instructionSet == InstructionSet.ARM64_Sve_Arm64)
20632054
{
@@ -2069,7 +2060,7 @@ public static IEnumerable<MetadataType> LookupPlatformIntrinsicTypes(TypeSystemC
20692060
case (InstructionSet.ARM64_Sve2, TargetArchitecture.ARM64):
20702061
case (InstructionSet.ARM64_Sve2_Arm64, TargetArchitecture.ARM64):
20712062
{
2072-
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm64"u8, "Sve2"u8, true);
2063+
var type = context.SystemModule.GetType("System.Runtime.Intrinsics.Arm"u8, "Sve2"u8, true);
20732064
yield return type;
20742065
if (instructionSet == InstructionSet.ARM64_Sve2_Arm64)
20752066
{

src/coreclr/tools/Common/JitInterface/ThunkGenerator/InstructionSetDesc.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
; Define the set of instruction sets available on a platform
22
; Format is
33
;
4+
; Define an architecture
5+
; definearch,<architecture>,<bitness>,<64bit variant JIT name>,<64bit variant managed name>,<managed namespace>
6+
;
47
; Add new instruction set
58
; instructionset,<architecture>,<managed name>,<r2r name if different>,<R2R numeric value>, <jit instruction set name>, <public name>
69
;
@@ -203,7 +206,7 @@ definearch ,X64 ,64Bit ,X64, X64, X86
203206
copyinstructionsets,X86 ,X64
204207

205208
; Definition of Arm64 instruction sets
206-
definearch ,ARM64 ,64Bit ,Arm64, Arm64, Arm64
209+
definearch ,ARM64 ,64Bit ,Arm64, Arm64, Arm
207210

208211
instructionset ,ARM64 ,ArmBase , ,16 ,ArmBase ,base
209212
instructionset ,ARM64 ,AdvSimd , ,17 ,AdvSimd ,neon
@@ -253,10 +256,10 @@ implication ,ARM64 ,Sve2 ,Sve
253256
; Definition of Riscv64 instruction sets
254257
definearch ,RiscV64 ,64Bit ,RiscV64, RiscV64,
255258

256-
instructionset ,RiscV64 ,RiscV64Base , ,56 ,RiscV64Base ,base
257-
instructionset ,RiscV64 ,Zba , ,57 ,Zba ,zba
258-
instructionset ,RiscV64 ,Zbb , ,58 ,Zbb ,zbb
259-
instructionset ,RiscV64 ,Zbs , ,84 ,Zbs ,zbs
259+
instructionset ,RiscV64 , ,RiscV64Base ,56 ,RiscV64Base ,base
260+
instructionset ,RiscV64 , ,Zba ,57 ,Zba ,zba
261+
instructionset ,RiscV64 , ,Zbb ,58 ,Zbb ,zbb
262+
instructionset ,RiscV64 , ,Zbs ,84 ,Zbs ,zbs
260263

261264
implication ,RiscV64 ,Zbb ,RiscV64Base
262265
implication ,RiscV64 ,Zba ,RiscV64Base

src/coreclr/tools/Common/JitInterface/ThunkGenerator/InstructionSetGenerator.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -824,20 +824,28 @@ public static InstructionSet LookupPlatformIntrinsicInstructionSet(TargetArchite
824824
string platformIntrinsicNamespace;
825825
826826
switch (targetArch)
827+
{");
828+
829+
830+
foreach (string architecture in _architectures)
827831
{
828-
case TargetArchitecture.ARM64:
829-
platformIntrinsicNamespace = ""System.Runtime.Intrinsics.Arm"";
830-
break;
832+
if (!_architectureManagedNamespace.ContainsKey(architecture))
833+
continue;
831834

832-
case TargetArchitecture.X64:
833-
case TargetArchitecture.X86:
834-
platformIntrinsicNamespace = ""System.Runtime.Intrinsics.X86"";
835+
string ns = _architectureManagedNamespace[architecture];
836+
tr.Write($@"
837+
case TargetArchitecture.{architecture}:
838+
platformIntrinsicNamespace = ""{ns}"";
835839
break;
840+
");
841+
}
836842

843+
tr.Write(@"
837844
default:
838845
return InstructionSet.ILLEGAL;
839846
}
840-
847+
");
848+
tr.Write(@"
841849
if (namespaceName != platformIntrinsicNamespace)
842850
return InstructionSet.ILLEGAL;
843851
@@ -899,9 +907,9 @@ public static InstructionSet LookupPlatformIntrinsicInstructionSet(TargetArchite
899907
");
900908
}
901909
tr.Write($@"
902-
}}
903-
break;
904-
");
910+
default:
911+
return InstructionSet.ILLEGAL;
912+
}}");
905913
}
906914

907915
tr.Write(@"

0 commit comments

Comments
 (0)