[cfe-commits] r146855 - in /cfe/trunk: include/clang/Basic/BuiltinsX86.def lib/Headers/CMakeLists.txt lib/Headers/avx2intrin.h lib/Headers/immintrin.h lib/Serialization/ASTReader.cpp lib/Serialization/ASTWriter.cpp test/CodeGen/avx2-builtins.c

Craig Topper craig.topper at gmail.com
Sun Dec 18 21:04:33 PST 2011


Author: ctopper
Date: Sun Dec 18 23:04:33 2011
New Revision: 146855

URL: http://llvm.org/viewvc/llvm-project?rev=146855&view=rev
Log:
Begin adding AVX2 intrinsics. Necessitated increasing the number of bits used to store builtinID when serializing identifier table.

Added:
    cfe/trunk/lib/Headers/avx2intrin.h
    cfe/trunk/test/CodeGen/avx2-builtins.c
Modified:
    cfe/trunk/include/clang/Basic/BuiltinsX86.def
    cfe/trunk/lib/Headers/CMakeLists.txt
    cfe/trunk/lib/Headers/immintrin.h
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=146855&r1=146854&r2=146855&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Sun Dec 18 23:04:33 2011
@@ -220,9 +220,9 @@
 BUILTIN(__builtin_ia32_pmaxsw128, "V8sV8sV8s", "")
 BUILTIN(__builtin_ia32_pminub128, "V16cV16cV16c", "")
 BUILTIN(__builtin_ia32_pminsw128, "V8sV8sV8s", "")
-BUILTIN(__builtin_ia32_packsswb128, "V8sV8sV8s", "")
-BUILTIN(__builtin_ia32_packssdw128, "V4iV4iV4i", "")
-BUILTIN(__builtin_ia32_packuswb128, "V8sV8sV8s", "")
+BUILTIN(__builtin_ia32_packsswb128, "V16cV8sV8s", "")
+BUILTIN(__builtin_ia32_packssdw128, "V8sV4iV4i", "")
+BUILTIN(__builtin_ia32_packuswb128, "V16cV8sV8s", "")
 BUILTIN(__builtin_ia32_pmulhuw128, "V8sV8sV8s", "")
 BUILTIN(__builtin_ia32_addsubps, "V4fV4fV4f", "")
 BUILTIN(__builtin_ia32_addsubpd, "V2dV2dV2d", "")
@@ -481,4 +481,14 @@
 BUILTIN(__builtin_ia32_maskstorepd256, "vV4d*V4dV4d", "")
 BUILTIN(__builtin_ia32_maskstoreps256, "vV8f*V8fV8f", "")
 
+// AVX2
+BUILTIN(__builtin_ia32_mpsadbw256, "V32cV32cV32ci", "")
+BUILTIN(__builtin_ia32_pabsb256, "V32cV32c", "")
+BUILTIN(__builtin_ia32_pabsw256, "V16sV16s", "")
+BUILTIN(__builtin_ia32_pabsd256, "V8iV8i", "")
+BUILTIN(__builtin_ia32_packsswb256, "V32cV16sV16s", "")
+BUILTIN(__builtin_ia32_packssdw256, "V16sV8iV8i", "")
+BUILTIN(__builtin_ia32_packuswb256, "V32cV16sV16s", "")
+BUILTIN(__builtin_ia32_packusdw256, "V16sV8iV8i", "")
+
 #undef BUILTIN

Modified: cfe/trunk/lib/Headers/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/CMakeLists.txt?rev=146855&r1=146854&r2=146855&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/CMakeLists.txt (original)
+++ cfe/trunk/lib/Headers/CMakeLists.txt Sun Dec 18 23:04:33 2011
@@ -1,6 +1,7 @@
 set(files
   altivec.h
   avxintrin.h
+  avx2intrin.h
   emmintrin.h
   float.h
   immintrin.h

Added: cfe/trunk/lib/Headers/avx2intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx2intrin.h?rev=146855&view=auto
==============================================================================
--- cfe/trunk/lib/Headers/avx2intrin.h (added)
+++ cfe/trunk/lib/Headers/avx2intrin.h Sun Dec 18 23:04:33 2011
@@ -0,0 +1,119 @@
+/*===---- avx2intrin.h - AVX2 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.
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __IMMINTRIN_H
+#error "Never use <avx2intrin.h> directly; include <immintrin.h> instead."
+#endif
+
+/* SSE4 Multiple Packed Sums of Absolute Difference.  */
+#define _mm256_mpsadbw_epu8(X, Y, M) __builtin_ia32_mpsadbw256((X), (Y), (M))
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_abs_epi8(__m256i a)
+{
+    return (__m256i)__builtin_ia32_pabsb256((__v32qi)a);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_abs_epi16(__m256i a)
+{
+    return (__m256i)__builtin_ia32_pabsw256((__v16hi)a);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_abs_epi32(__m256i a)
+{
+    return (__m256i)__builtin_ia32_pabsd256((__v8si)a);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_packs_epi16(__m256i a, __m256i b)
+{
+  return (__m256i)__builtin_ia32_packsswb256((__v16hi)a, (__v16hi)b);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_packs_epi32(__m256i a, __m256i b)
+{
+  return (__m256i)__builtin_ia32_packssdw256((__v8si)a, (__v8si)b);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_packus_epi16(__m256i a, __m256i b)
+{
+  return (__m256i)__builtin_ia32_packuswb256((__v16hi)a, (__v16hi)b);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_packus_epi32(__m256i __V1, __m256i __V2)
+{
+  return (__m256i) __builtin_ia32_packusdw256((__v8si)__V1, (__v8si)__V2);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_add_epi8(__m256i a, __m256i b)
+{
+  return (__m256i)((__v32qi)a + (__v32qi)b);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_add_epi16(__m256i a, __m256i b)
+{
+  return (__m256i)((__v16hi)a + (__v16hi)b);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_add_epi32(__m256i a, __m256i b)
+{
+  return (__m256i)((__v8si)a + (__v8si)b);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_add_epi64(__m256i a, __m256i b)
+{
+  return a + b;
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_sub_epi8(__m256i a, __m256i b)
+{
+  return (__m256i)((__v32qi)a - (__v32qi)b);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_sub_epi16(__m256i a, __m256i b)
+{
+  return (__m256i)((__v16hi)a - (__v16hi)b);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_sub_epi32(__m256i a, __m256i b)
+{
+  return (__m256i)((__v8si)a - (__v8si)b);
+}
+
+static __inline__ __m256i __attribute__((__always_inline__, __nodebug__))
+_mm256_sub_epi64(__m256i a, __m256i b)
+{
+  return a - b;
+}

Modified: cfe/trunk/lib/Headers/immintrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/immintrin.h?rev=146855&r1=146854&r2=146855&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/immintrin.h (original)
+++ cfe/trunk/lib/Headers/immintrin.h Sun Dec 18 23:04:33 2011
@@ -56,4 +56,8 @@
 #include <avxintrin.h>
 #endif
 
+#ifdef __AVX2__
+#include <avx2intrin.h>
+#endif
+
 #endif /* __IMMINTRIN_H */

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=146855&r1=146854&r2=146855&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Sun Dec 18 23:04:33 2011
@@ -529,8 +529,8 @@
   Bits >>= 1;
   bool hasMacroDefinition = Bits & 0x01;
   Bits >>= 1;
-  unsigned ObjCOrBuiltinID = Bits & 0x3FF;
-  Bits >>= 10;
+  unsigned ObjCOrBuiltinID = Bits & 0x7FF;
+  Bits >>= 11;
 
   assert(Bits == 0 && "Extra bits in the identifier?");
   DataLen -= 6;

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=146855&r1=146854&r2=146855&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Sun Dec 18 23:04:33 2011
@@ -2519,6 +2519,7 @@
     uint32_t Bits = 0;
     bool HasMacroDefinition = hasMacroDefinition(II, Macro);
     Bits = (uint32_t)II->getObjCOrBuiltinID();
+    assert((Bits & 0x7ff) == Bits && "ObjCOrBuiltinID too big for ASTReader.");
     Bits = (Bits << 1) | unsigned(HasMacroDefinition);
     Bits = (Bits << 1) | unsigned(II->isExtensionToken());
     Bits = (Bits << 1) | unsigned(II->isPoisoned());

Added: cfe/trunk/test/CodeGen/avx2-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx2-builtins.c?rev=146855&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/avx2-builtins.c (added)
+++ cfe/trunk/test/CodeGen/avx2-builtins.c Sun Dec 18 23:04:33 2011
@@ -0,0 +1,86 @@
+// RUN: %clang_cc1 %s -O3 -triple=x86_64-apple-darwin -target-feature +avx2 -emit-llvm -o - | FileCheck %s
+
+// Don't include mm_malloc.h, it's system specific.
+#define __MM_MALLOC_H
+
+#include <immintrin.h>
+
+__m256 test_mm256_mpsadbw_epu8(__m256 x, __m256 y) {
+  // CHECK: @llvm.x86.avx2.mpsadbw({{.*}}, {{.*}}, i32 3)
+  return _mm256_mpsadbw_epu8(x, y, 3);
+}
+
+__m256 test_mm256_abs_epi8(__m256 a) {
+  // CHECK: @llvm.x86.avx2.pabs.b
+  return _mm256_abs_epi8(a);
+}
+
+__m256 test_mm256_abs_epi16(__m256 a) {
+  // CHECK: @llvm.x86.avx2.pabs.w
+  return _mm256_abs_epi16(a);
+}
+
+__m256 test_mm256_abs_epi32(__m256 a) {
+  // CHECK: @llvm.x86.avx2.pabs.d
+  return _mm256_abs_epi32(a);
+}
+
+__m256 test_mm256_packs_epi16(__m256 a, __m256 b) {
+  // CHECK: @llvm.x86.avx2.packsswb
+  return _mm256_packs_epi16(a, b);
+}
+
+__m256 test_mm256_packs_epi32(__m256 a, __m256 b) {
+  // CHECK: @llvm.x86.avx2.packssdw
+  return _mm256_packs_epi32(a, b);
+}
+
+__m256 test_mm256_packs_epu16(__m256 a, __m256 b) {
+  // CHECK: @llvm.x86.avx2.packuswb
+  return _mm256_packus_epi16(a, b);
+}
+
+__m256 test_mm256_packs_epu32(__m256 a, __m256 b) {
+  // CHECK: @llvm.x86.avx2.packusdw
+  return _mm256_packus_epi32(a, b);
+}
+
+__m256 test_mm256_add_epi8(__m256 a, __m256 b) {
+  // CHECK: add <32 x i8>
+  return _mm256_add_epi8(a, b);
+}
+
+__m256 test_mm256_add_epi16(__m256 a, __m256 b) {
+  // CHECK: add <16 x i16>
+  return _mm256_add_epi16(a, b);
+}
+
+__m256 test_mm256_add_epi32(__m256 a, __m256 b) {
+  // CHECK: add <8 x i32>
+  return _mm256_add_epi32(a, b);
+}
+
+__m256 test_mm256_add_epi64(__m256 a, __m256 b) {
+  // CHECK: add <4 x i64>
+  return _mm256_add_epi64(a, b);
+}
+
+__m256 test_mm256_sub_epi8(__m256 a, __m256 b) {
+  // CHECK: sub <32 x i8>
+  return _mm256_sub_epi8(a, b);
+}
+
+__m256 test_mm256_sub_epi16(__m256 a, __m256 b) {
+  // CHECK: sub <16 x i16>
+  return _mm256_sub_epi16(a, b);
+}
+
+__m256 test_mm256_sub_epi32(__m256 a, __m256 b) {
+  // CHECK: sub <8 x i32>
+  return _mm256_sub_epi32(a, b);
+}
+
+__m256 test_mm256_sub_epi64(__m256 a, __m256 b) {
+  // CHECK: sub <4 x i64>
+  return _mm256_sub_epi64(a, b);
+}





More information about the cfe-commits mailing list