]> granicus.if.org Git - clang/commitdiff
[Clang][bmi][intrinsics] Adding _mm_tzcnt_64 _mm_tzcnt_32 intrinsics to clang.
authorMichael Zuckerman <Michael.zuckerman@intel.com>
Wed, 22 Jun 2016 12:32:43 +0000 (12:32 +0000)
committerMichael Zuckerman <Michael.zuckerman@intel.com>
Wed, 22 Jun 2016 12:32:43 +0000 (12:32 +0000)
Differential Revision: http://reviews.llvm.org/D21373

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273401 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Headers/bmiintrin.h
test/CodeGen/bmi-builtins.c

index d39b04c8c68a665f043c3d1ee99b9f64f518333c..30acfaeb9f3bc2e2122eba0728ee49e44cf0cf44 100644 (file)
@@ -287,6 +287,22 @@ __tzcnt_u32(unsigned int __X)
   return __X ? __builtin_ctz(__X) : 32;
 }
 
+/// \brief Counts the number of trailing zero bits in the operand.
+///
+/// \headerfile <x86intrin.h>
+///
+/// This intrinsic corresponds to the \c TZCNT instruction.
+///
+/// \param __X
+///    An unsigned 32-bit integer whose trailing zeros are to be counted.
+/// \returns An 32-bit integer containing the number of trailing zero
+///    bits in the operand.
+static __inline__ int __RELAXED_FN_ATTRS
+_mm_tzcnt_32(unsigned int __X)
+{
+  return __X ? __builtin_ctz(__X) : 32;
+}
+
 #ifdef __x86_64__
 
 /// \brief Performs a bitwise AND of the second operand with the one's
@@ -508,6 +524,22 @@ __tzcnt_u64(unsigned long long __X)
   return __X ? __builtin_ctzll(__X) : 64;
 }
 
+/// \brief Counts the number of trailing zero bits in the operand.
+///
+/// \headerfile <x86intrin.h>
+///
+/// This intrinsic corresponds to the \c TZCNT instruction.
+///
+/// \param __X
+///    An unsigned 64-bit integer whose trailing zeros are to be counted.
+/// \returns An 64-bit integer containing the number of trailing zero
+///    bits in the operand.
+static __inline__ long long __RELAXED_FN_ATTRS
+_mm_tzcnt_64(unsigned long long __X)
+{
+  return __X ? __builtin_ctzll(__X) : 64;
+}
+
 #endif /* __x86_64__ */
 
 #undef __DEFAULT_FN_ATTRS
index aac491d1a59721cb861cb46c6033296862e77057..b9e22f9b20f50ba84d5eadef8dc37f0cd7ba5ee9 100644 (file)
@@ -64,6 +64,13 @@ unsigned int test__tzcnt_u32(unsigned int __X) {
   return __tzcnt_u32(__X);
 }
 
+int test_mm_tzcnt_32(unsigned int __X) {
+  // CHECK-LABEL: test_mm_tzcnt_32
+  // CHECK: icmp ne i32 %{{.*}}, 0
+  // CHECK: i32 @llvm.cttz.i32(i32 %{{.*}}, i1 true)
+  return _mm_tzcnt_32(__X);
+}
+
 unsigned long long test__andn_u64(unsigned long __X, unsigned long __Y) {
   // CHECK-LABEL: test__andn_u64
   // CHECK: xor i64 %{{.*}}, -1
@@ -105,6 +112,13 @@ unsigned long long test__tzcnt_u64(unsigned long long __X) {
   return __tzcnt_u64(__X);
 }
 
+long long test_mm_tzcnt_64(unsigned long long __X) {
+  // CHECK-LABEL: test_mm_tzcnt_64
+  // CHECK: icmp ne i64 %{{.*}}, 0
+  // CHECK: i64 @llvm.cttz.i64(i64 %{{.*}}, i1 true)
+  return _mm_tzcnt_64(__X);
+}
+
 // Intel intrinsics
 
 unsigned short test_tzcnt_u16(unsigned short __X) {