[cfe-commits] r147275 - in /cfe/trunk: include/clang/Basic/BuiltinsX86.def lib/Headers/bmi2intrin.h lib/Headers/immintrin.h lib/Headers/x86intrin.h test/CodeGen/bmi2-builtins.c

Craig Topper craig.topper at gmail.com
Sun Dec 25 18:31:11 PST 2011


Author: ctopper
Date: Sun Dec 25 20:31:10 2011
New Revision: 147275

URL: http://llvm.org/viewvc/llvm-project?rev=147275&view=rev
Log:
Add BMI2 intrinsics.

Added:
    cfe/trunk/lib/Headers/bmi2intrin.h
    cfe/trunk/test/CodeGen/bmi2-builtins.c
Modified:
    cfe/trunk/include/clang/Basic/BuiltinsX86.def
    cfe/trunk/lib/Headers/immintrin.h
    cfe/trunk/lib/Headers/x86intrin.h

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=147275&r1=147274&r2=147275&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Sun Dec 25 20:31:10 2011
@@ -604,4 +604,12 @@
 BUILTIN(__builtin_ia32_bextr_u32, "UiUiUi", "")
 BUILTIN(__builtin_ia32_bextr_u64, "ULLiULLiULLi", "")
 
+// BMI2
+BUILTIN(__builtin_ia32_bzhi_si, "UiUiUi", "")
+BUILTIN(__builtin_ia32_bzhi_di, "ULLiULLiULLi", "")
+BUILTIN(__builtin_ia32_pdep_si, "UiUiUi", "")
+BUILTIN(__builtin_ia32_pdep_di, "ULLiULLiULLi", "")
+BUILTIN(__builtin_ia32_pext_si, "UiUiUi", "")
+BUILTIN(__builtin_ia32_pext_di, "ULLiULLiULLi", "")
+
 #undef BUILTIN

Added: cfe/trunk/lib/Headers/bmi2intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/bmi2intrin.h?rev=147275&view=auto
==============================================================================
--- cfe/trunk/lib/Headers/bmi2intrin.h (added)
+++ cfe/trunk/lib/Headers/bmi2intrin.h Sun Dec 25 20:31:10 2011
@@ -0,0 +1,75 @@
+/*===---- bmi2intrin.h - BMI2 intrinsics -----------------------------------===
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#if !defined __X86INTRIN_H && !defined __IMMINTRIN_H
+#error "Never use <bmi2intrin.h> directly; include <x86intrin.h> instead."
+#endif
+
+#ifndef __BMI2__
+# error "BMI2 instruction set not enabled"
+#endif /* __BMI2__ */
+
+#ifndef __BMI2INTRIN_H
+#define __BMI2INTRIN_H
+
+static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
+_bzhi_u32(unsigned int __X, unsigned int __Y)
+{
+  return __builtin_ia32_bzhi_si(__X, __Y);
+}
+
+static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
+_pdep_u32(unsigned int __X, unsigned int __Y)
+{
+  return __builtin_ia32_pdep_si(__X, __Y);
+}
+
+static __inline__ unsigned int __attribute__((__always_inline__, __nodebug__))
+_pext_u32(unsigned int __X, unsigned int __Y)
+{
+  return __builtin_ia32_pext_si(__X, __Y);
+}
+
+#ifdef  __x86_64__
+
+static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
+_bzhi_u64(unsigned long long __X, unsigned long long __Y)
+{
+  return __builtin_ia32_bzhi_di(__X, __Y);
+}
+
+static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
+_pdep_u64(unsigned long long __X, unsigned long long __Y)
+{
+  return __builtin_ia32_pdep_di(__X, __Y);
+}
+
+static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
+_pext_u64(unsigned long long __X, unsigned long long __Y)
+{
+  return __builtin_ia32_pext_di(__X, __Y);
+}
+
+#endif /* !__x86_64__  */
+
+#endif /* __BMI2INTRIN_H */

Modified: cfe/trunk/lib/Headers/immintrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/immintrin.h?rev=147275&r1=147274&r2=147275&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/immintrin.h (original)
+++ cfe/trunk/lib/Headers/immintrin.h Sun Dec 25 20:31:10 2011
@@ -64,6 +64,10 @@
 #include <bmiintrin.h>
 #endif
 
+#ifdef __BMI2__
+#include <bmi2intrin.h>
+#endif
+
 #ifdef __LZCNT__
 #include <lzcntintrin.h>
 #endif

Modified: cfe/trunk/lib/Headers/x86intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/x86intrin.h?rev=147275&r1=147274&r2=147275&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/x86intrin.h (original)
+++ cfe/trunk/lib/Headers/x86intrin.h Sun Dec 25 20:31:10 2011
@@ -30,6 +30,10 @@
 #include <bmiintrin.h>
 #endif
 
+#ifdef __BMI2__
+#include <bmi2intrin.h>
+#endif
+
 #ifdef __LZCNT__
 #include <lzcntintrin.h>
 #endif

Added: cfe/trunk/test/CodeGen/bmi2-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/bmi2-builtins.c?rev=147275&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/bmi2-builtins.c (added)
+++ cfe/trunk/test/CodeGen/bmi2-builtins.c Sun Dec 25 20:31:10 2011
@@ -0,0 +1,36 @@
+// RUN: %clang_cc1 %s -O3 -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s
+
+// Don't include mm_malloc.h, it's system specific.
+#define __MM_MALLOC_H
+
+#include <x86intrin.h>
+
+unsigned int test_bzhi_u32(unsigned int __X, unsigned int __Y) {
+  // CHECK: @llvm.x86.bmi.bzhi.32
+  return _bzhi_u32(__X, __Y);
+}
+
+unsigned int test_pdep_u32(unsigned int __X, unsigned int __Y) {
+  // CHECK: @llvm.x86.bmi.pdep.32
+  return _pdep_u32(__X, __Y);
+}
+
+unsigned int test_pext_u32(unsigned int __X, unsigned int __Y) {
+  // CHECK: @llvm.x86.bmi.pext.32
+  return _pext_u32(__X, __Y);
+}
+
+unsigned long long test_bzhi_u64(unsigned long long __X, unsigned long long __Y) {
+  // CHECK: @llvm.x86.bmi.bzhi.64
+  return _bzhi_u64(__X, __Y);
+}
+
+unsigned long long test_pdep_u64(unsigned long long __X, unsigned long long __Y) {
+  // CHECK: @llvm.x86.bmi.pdep.64
+  return _pdep_u64(__X, __Y);
+}
+
+unsigned long long test_pext_u64(unsigned long long __X, unsigned long long __Y) {
+  // CHECK: @llvm.x86.bmi.pext.64
+  return _pext_u64(__X, __Y);
+}





More information about the cfe-commits mailing list