Moving the x86 lookupHWIntrinsic and lookupHWIntrinsicISA methods to be static method...
authorTanner Gooding <tagoo@outlook.com>
Sat, 2 Jun 2018 16:07:31 +0000 (09:07 -0700)
committerTanner Gooding <tagoo@outlook.com>
Sat, 2 Jun 2018 21:23:38 +0000 (14:23 -0700)
src/jit/compiler.h
src/jit/hwintrinsicxarch.cpp
src/jit/hwintrinsicxarch.h
src/jit/importer.cpp

index 2b054f6c51218b7ca6b516cfbf3baf3a1ba88de4..b3b55741b443fa9713b668e533431e6fa72101cb 100644 (file)
@@ -2964,8 +2964,6 @@ public:
 
 protected:
 #ifdef _TARGET_XARCH_
-    static InstructionSet lookupHWIntrinsicISA(const char* className);
-    static NamedIntrinsic lookupHWIntrinsic(const char* methodName, InstructionSet isa);
     static InstructionSet isaOfHWIntrinsic(NamedIntrinsic intrinsic);
     static bool isIntrinsicAnIsSupportedPropertyGetter(NamedIntrinsic intrinsic);
     static bool isFullyImplmentedISAClass(InstructionSet isa);
index 633a853a42679b23e2032592d6cc2ff70024af8e..84b54896e1cabc73e9313cd619d7b3c3c9aa6478 100644 (file)
@@ -34,117 +34,127 @@ const HWIntrinsicInfo& HWIntrinsicInfo::lookup(NamedIntrinsic id)
 }
 
 //------------------------------------------------------------------------
-// lookupHWIntrinsicISA: map class name to InstructionSet value
+// lookupId: Gets the NamedIntrinsic for a given method name and InstructionSet
 //
 // Arguments:
-//    className -- class name in System.Runtime.Intrinsics.X86
+//    className  -- The name of the class associated with the HWIntrinsic to lookup
+//    methodName -- The name of the method associated with the HWIntrinsic to lookup
 //
 // Return Value:
-//    Id for the ISA class.
-//
-InstructionSet Compiler::lookupHWIntrinsicISA(const char* className)
+//    The NamedIntrinsic associated with methodName and isa
+NamedIntrinsic HWIntrinsicInfo::lookupId(const char* className, const char* methodName)
 {
-    if (className != nullptr)
+    // TODO-Throughput: replace sequential search by binary search
+
+    InstructionSet isa = lookupIsa(className);
+    assert(isa != InstructionSet_ILLEGAL);
+
+    assert(methodName != nullptr);
+
+    for (int i = 0; i < (NI_HW_INTRINSIC_END - NI_HW_INTRINSIC_START - 1); i++)
     {
-        if (className[0] == 'A')
+        if (isa != hwIntrinsicInfoArray[i].isa)
         {
-            if (strcmp(className, "Aes") == 0)
-            {
-                return InstructionSet_AES;
-            }
-            else if (strcmp(className, "Avx") == 0)
-            {
-                return InstructionSet_AVX;
-            }
-            else if (strcmp(className, "Avx2") == 0)
-            {
-                return InstructionSet_AVX2;
-            }
+            continue;
         }
-        if (className[0] == 'S')
+
+        if (strcmp(methodName, hwIntrinsicInfoArray[i].name) == 0)
         {
-            if (strcmp(className, "Sse") == 0)
-            {
-                return InstructionSet_SSE;
-            }
-            else if (strcmp(className, "Sse2") == 0)
-            {
-                return InstructionSet_SSE2;
-            }
-            else if (strcmp(className, "Sse3") == 0)
-            {
-                return InstructionSet_SSE3;
-            }
-            else if (strcmp(className, "Ssse3") == 0)
-            {
-                return InstructionSet_SSSE3;
-            }
-            else if (strcmp(className, "Sse41") == 0)
-            {
-                return InstructionSet_SSE41;
-            }
-            else if (strcmp(className, "Sse42") == 0)
-            {
-                return InstructionSet_SSE42;
-            }
+            return hwIntrinsicInfoArray[i].id;
         }
+    }
 
-        if (strcmp(className, "Bmi1") == 0)
+    unreached();
+    return NI_Illegal;
+}
+
+//------------------------------------------------------------------------
+// lookupIsa: Gets the InstructionSet for a given class name
+//
+// Arguments:
+//    className -- The name of the class associated with the InstructionSet to lookup
+//
+// Return Value:
+//    The InstructionSet associated with className
+InstructionSet HWIntrinsicInfo::lookupIsa(const char* className)
+{
+    assert(className != nullptr);
+
+    if (className[0] == 'A')
+    {
+        if (strcmp(className, "Aes") == 0)
         {
-            return InstructionSet_BMI1;
+            return InstructionSet_AES;
         }
-        else if (strcmp(className, "Bmi2") == 0)
+        if (strcmp(className, "Avx") == 0)
         {
-            return InstructionSet_BMI2;
+            return InstructionSet_AVX;
         }
-        else if (strcmp(className, "Fma") == 0)
+        if (strcmp(className, "Avx2") == 0)
         {
-            return InstructionSet_FMA;
+            return InstructionSet_AVX2;
         }
-        else if (strcmp(className, "Lzcnt") == 0)
+    }
+    else if (className[0] == 'S')
+    {
+        if (strcmp(className, "Sse") == 0)
         {
-            return InstructionSet_LZCNT;
+            return InstructionSet_SSE;
         }
-        else if (strcmp(className, "Pclmulqdq") == 0)
+        if (strcmp(className, "Sse2") == 0)
         {
-            return InstructionSet_PCLMULQDQ;
+            return InstructionSet_SSE2;
         }
-        else if (strcmp(className, "Popcnt") == 0)
+        if (strcmp(className, "Sse3") == 0)
         {
-            return InstructionSet_POPCNT;
+            return InstructionSet_SSE3;
+        }
+        if (strcmp(className, "Ssse3") == 0)
+        {
+            return InstructionSet_SSSE3;
+        }
+        if (strcmp(className, "Sse41") == 0)
+        {
+            return InstructionSet_SSE41;
+        }
+        if (strcmp(className, "Sse42") == 0)
+        {
+            return InstructionSet_SSE42;
         }
     }
-
-    JITDUMP("Unsupported ISA.\n");
-    return InstructionSet_ILLEGAL;
-}
-
-//------------------------------------------------------------------------
-// lookupHWIntrinsic: map intrinsic name to named intrinsic value
-//
-// Arguments:
-//    methodName -- name of the intrinsic function.
-//    isa        -- instruction set of the intrinsic.
-//
-// Return Value:
-//    Id for the hardware intrinsic
-//
-// TODO-Throughput: replace sequential search by binary search
-NamedIntrinsic Compiler::lookupHWIntrinsic(const char* methodName, InstructionSet isa)
-{
-    NamedIntrinsic result = NI_Illegal;
-    if (isa != InstructionSet_ILLEGAL)
+    else if (className[0] == 'B')
     {
-        for (int i = 0; i < NI_HW_INTRINSIC_END - NI_HW_INTRINSIC_START - 1; i++)
+        if (strcmp(className, "Bmi1") == 0)
         {
-            if (isa == hwIntrinsicInfoArray[i].isa && strcmp(methodName, hwIntrinsicInfoArray[i].name) == 0)
-            {
-                result = hwIntrinsicInfoArray[i].id;
-                break;
-            }
+            return InstructionSet_BMI1;
+        }
+        if (strcmp(className, "Bmi2") == 0)
+        {
+            return InstructionSet_BMI2;
+        }
+    }
+    else if (className[0] == 'P')
+    {
+        if (strcmp(className, "Pclmulqdq") == 0)
+        {
+            return InstructionSet_PCLMULQDQ;
         }
+        if (strcmp(className, "Popcnt") == 0)
+        {
+            return InstructionSet_POPCNT;
+        }
+    }
+    else if (strcmp(className, "Fma") == 0)
+    {
+        return InstructionSet_FMA;
+    }
+    else if (strcmp(className, "Lzcnt") == 0)
+    {
+        return InstructionSet_LZCNT;
     }
-    return result;
+
+    unreached();
+    return InstructionSet_ILLEGAL;
 }
 
 //------------------------------------------------------------------------
index 820f12d1ac788d1cabebe2cb3c88ec3e1c6e93eb..67e2526ef2adc116d9520e15ebf01ee8c02218c6 100644 (file)
@@ -138,6 +138,8 @@ struct HWIntrinsicInfo
     HWIntrinsicFlag         flags;
 
     static const HWIntrinsicInfo& lookup(NamedIntrinsic id);
+    static NamedIntrinsic lookupId(const char* className, const char* methodName);
+    static InstructionSet lookupIsa(const char* className);
 
     static const char* lookupName(NamedIntrinsic id)
     {
index ef5798f86e5d0d6a3863014d54f5c889a7b67358..0fb27f215868014998517533fae1a336e42f5d0a 100644 (file)
@@ -4081,13 +4081,12 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
 
 #ifdef FEATURE_HW_INTRINSICS
 #if defined(_TARGET_XARCH_)
-    if ((namespaceName != nullptr) && strcmp(namespaceName, "System.Runtime.Intrinsics.X86") == 0)
+    if (strcmp(namespaceName, "System.Runtime.Intrinsics.X86") == 0)
     {
-        InstructionSet isa = lookupHWIntrinsicISA(className);
-        result             = lookupHWIntrinsic(methodName, isa);
+        result = HWIntrinsicInfo::lookupId(className, methodName);
     }
 #elif defined(_TARGET_ARM64_)
-    if ((namespaceName != nullptr) && strcmp(namespaceName, "System.Runtime.Intrinsics.Arm.Arm64") == 0)
+    if (strcmp(namespaceName, "System.Runtime.Intrinsics.Arm.Arm64") == 0)
     {
         result = lookupHWIntrinsic(className, methodName);
     }
@@ -4095,6 +4094,7 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
 #error Unsupported platform
 #endif // !defined(_TARGET_XARCH_) && !defined(_TARGET_ARM64_)
 #endif // FEATURE_HW_INTRINSICS
+
     return result;
 }