[ARM] Implement BitPosition with arm intrinsics (dotnet/coreclr#7819)
authorHanjoung Lee <waterets@gmail.com>
Wed, 2 Nov 2016 13:23:57 +0000 (22:23 +0900)
committerJan Kotas <jkotas@microsoft.com>
Wed, 2 Nov 2016 13:23:57 +0000 (06:23 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/478591ee6c7b09c0c7165d1c85a05463fd070db4

src/coreclr/src/inc/bitposition.h

index 0f3831f..392d9a6 100644 (file)
@@ -25,7 +25,11 @@ inline
 unsigned            BitPosition(unsigned value)
 {
     _ASSERTE((value != 0) && ((value & (value-1)) == 0));
-#ifndef _TARGET_AMD64_
+#if defined(_TARGET_ARM_) && defined(__llvm__)
+    // use intrinsic functions for arm32
+    // this is applied for LLVM only but it may work for some compilers
+    DWORD index = __builtin_clz(__builtin_arm_rbit(value));
+#elif !defined(_TARGET_AMD64_)
     const unsigned PRIME = 37;
 
     static const char hashTable[PRIME] =