[cfe-commits] r165685 - in /cfe/trunk: include/clang/Basic/BuiltinsX86.def include/clang/Driver/Options.td lib/Basic/Targets.cpp lib/Headers/f16cintrin.h lib/Headers/x86intrin.h test/CodeGen/f16c-builtins.c

Manman Ren mren at apple.com
Wed Oct 10 17:59:55 PDT 2012


Author: mren
Date: Wed Oct 10 19:59:55 2012
New Revision: 165685

URL: http://llvm.org/viewvc/llvm-project?rev=165685&view=rev
Log:
X86: add F16C support in Clang

Support the following intrinsics:
  _mm_cvtph_ps, _mm256_cvtph_ps, _mm_cvtps_ph, _mm256_cvtps_ph

rdar://12407875

Added:
    cfe/trunk/lib/Headers/f16cintrin.h
    cfe/trunk/test/CodeGen/f16c-builtins.c
Modified:
    cfe/trunk/include/clang/Basic/BuiltinsX86.def
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/Basic/Targets.cpp
    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=165685&r1=165684&r2=165685&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Wed Oct 10 19:59:55 2012
@@ -613,6 +613,12 @@
 BUILTIN(__builtin_ia32_gatherq_d, "V4iV4iV4iC*V2LLiV4iIc", "")
 BUILTIN(__builtin_ia32_gatherq_d256, "V4iV4iV4iC*V4LLiV4iIc", "")
 
+// F16C
+BUILTIN(__builtin_ia32_vcvtps2ph, "V8sV4fIi", "")
+BUILTIN(__builtin_ia32_vcvtps2ph256, "V8sV8fIi", "")
+BUILTIN(__builtin_ia32_vcvtph2ps, "V4fV8s", "")
+BUILTIN(__builtin_ia32_vcvtph2ps256, "V8fV8s", "")
+
 // RDRAND
 BUILTIN(__builtin_ia32_rdrand16_step, "UiUs*", "")
 BUILTIN(__builtin_ia32_rdrand32_step, "UiUi*", "")

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=165685&r1=165684&r2=165685&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Oct 10 19:59:55 2012
@@ -823,6 +823,7 @@
 def mno_fma4 : Flag<"-mno-fma4">, Group<m_x86_Features_Group>;
 def mno_fma : Flag<"-mno-fma">, Group<m_x86_Features_Group>;
 def mno_xop : Flag<"-mno-xop">, Group<m_x86_Features_Group>;
+def mno_f16c : Flag<"-mno-f16c">, Group<m_x86_Features_Group>;
 
 def mno_thumb : Flag<"-mno-thumb">, Group<m_Group>;
 def marm : Flag<"-marm">, Alias<mno_thumb>;
@@ -863,6 +864,7 @@
 def mfma4 : Flag<"-mfma4">, Group<m_x86_Features_Group>;
 def mfma : Flag<"-mfma">, Group<m_x86_Features_Group>;
 def mxop : Flag<"-mxop">, Group<m_x86_Features_Group>;
+def mf16c : Flag<"-mf16c">, Group<m_x86_Features_Group>;
 def mips16 : Flag<"-mips16">, Group<m_Group>;
 def mno_mips16 : Flag<"-mno-mips16">, Group<m_Group>;
 def mdsp : Flag<"-mdsp">, Group<m_Group>;

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=165685&r1=165684&r2=165685&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Wed Oct 10 19:59:55 2012
@@ -1360,6 +1360,7 @@
   bool HasFMA4;
   bool HasFMA;
   bool HasXOP;
+  bool HasF16C;
 
   /// \brief Enumeration of all of the X86 CPUs supported by Clang.
   ///
@@ -1506,7 +1507,8 @@
     : TargetInfo(triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow),
       HasAES(false), HasPCLMUL(false), HasLZCNT(false), HasRDRND(false),
       HasBMI(false), HasBMI2(false), HasPOPCNT(false), HasSSE4a(false),
-      HasFMA4(false), HasFMA(false), HasXOP(false), CPU(CK_Generic) {
+      HasFMA4(false), HasFMA(false), HasXOP(false), HasF16C(false),
+      CPU(CK_Generic) {
     BigEndian = false;
     LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
   }
@@ -1712,6 +1714,7 @@
   Features["fma4"] = false;
   Features["fma"] = false;
   Features["xop"] = false;
+  Features["f16c"] = false;
 
   // FIXME: This *really* should not be here.
 
@@ -1922,6 +1925,8 @@
       Features["bmi2"] = true;
     else if (Name == "popcnt")
       Features["popcnt"] = true;
+    else if (Name == "f16c")
+      Features["f16c"] = true;
   } else {
     if (Name == "mmx")
       Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = false;
@@ -1982,6 +1987,8 @@
       Features["fma4"] = Features["xop"] = false;
     else if (Name == "xop")
       Features["xop"] = false;
+    else if (Name == "f16c")
+      Features["f16c"] = false;
   }
 
   return true;
@@ -2053,6 +2060,11 @@
       continue;
     }
 
+    if (Feature == "f16c") {
+      HasF16C = true;
+      continue;
+    }
+
     assert(Features[i][0] == '+' && "Invalid target feature!");
     X86SSEEnum Level = llvm::StringSwitch<X86SSEEnum>(Feature)
       .Case("avx2", AVX2)
@@ -2261,6 +2273,9 @@
   if (HasXOP)
     Builder.defineMacro("__XOP__");
 
+  if (HasF16C)
+    Builder.defineMacro("__F16C__");
+
   // Each case falls through to the previous one here.
   switch (SSELevel) {
   case AVX2:
@@ -2344,6 +2359,7 @@
       .Case("x86_32", PointerWidth == 32)
       .Case("x86_64", PointerWidth == 64)
       .Case("xop", HasXOP)
+      .Case("f16c", HasF16C)
       .Default(false);
 }
 

Added: cfe/trunk/lib/Headers/f16cintrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/f16cintrin.h?rev=165685&view=auto
==============================================================================
--- cfe/trunk/lib/Headers/f16cintrin.h (added)
+++ cfe/trunk/lib/Headers/f16cintrin.h Wed Oct 10 19:59:55 2012
@@ -0,0 +1,58 @@
+/*===---- f16cintrin.h - F16C 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 <f16cintrin.h> directly; include <x86intrin.h> instead."
+#endif
+
+#ifndef __F16C__
+# error "F16C instruction is not enabled"
+#endif /* __F16C__ */
+
+#ifndef __F16CINTRIN_H
+#define __F16CINTRIN_H
+
+typedef float __v8sf __attribute__ ((__vector_size__ (32)));
+typedef float __m256 __attribute__ ((__vector_size__ (32)));
+
+#define _mm_cvtps_ph(a, imm) __extension__ ({ \
+  __m128 __a = (a); \
+ (__m128i)__builtin_ia32_vcvtps2ph((__v4sf)__a, (imm)); })
+
+#define _mm256_cvtps_ph(a, imm) __extension__ ({ \
+  __m256 __a = (a); \
+ (__m128i)__builtin_ia32_vcvtps2ph256((__v8sf)__a, (imm)); })
+
+static __inline __m128 __attribute__((__always_inline__, __nodebug__))
+_mm_cvtph_ps(__m128i a)
+{
+  return (__m128)__builtin_ia32_vcvtph2ps((__v8hi)a);
+}
+
+static __inline __m256 __attribute__((__always_inline__, __nodebug__))
+_mm256_cvtph_ps(__m128i a)
+{
+  return (__m256)__builtin_ia32_vcvtph2ps256((__v8hi)a);
+}
+
+#endif /* __F16CINTRIN_H */

Modified: cfe/trunk/lib/Headers/x86intrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/x86intrin.h?rev=165685&r1=165684&r2=165685&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/x86intrin.h (original)
+++ cfe/trunk/lib/Headers/x86intrin.h Wed Oct 10 19:59:55 2012
@@ -58,6 +58,10 @@
 #include <xopintrin.h>
 #endif
 
+#ifdef __F16C__
+#include <f16cintrin.h>
+#endif
+
 // FIXME: LWP
 
 #endif /* __X86INTRIN_H */

Added: cfe/trunk/test/CodeGen/f16c-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/f16c-builtins.c?rev=165685&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/f16c-builtins.c (added)
+++ cfe/trunk/test/CodeGen/f16c-builtins.c Wed Oct 10 19:59:55 2012
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -O3 -triple=x86_64-apple-darwin -target-feature +f16c -emit-llvm -o - | FileCheck %s
+
+// Don't include mm_malloc.h, it's system specific.
+#define __MM_MALLOC_H
+
+#include <x86intrin.h>
+
+__m128 test_mm_cvtph_ps(__m128i a) {
+  // CHECK: @llvm.x86.vcvtph2ps.128
+  return _mm_cvtph_ps(a);
+}
+
+__m256 test_mm256_cvtph_ps(__m128i a) {
+  // CHECK: @llvm.x86.vcvtph2ps.256
+  return _mm256_cvtph_ps(a);
+}
+
+__m128i test_mm_cvtps_ph(__m128 a) {
+  // CHECK: @llvm.x86.vcvtps2ph.128
+  return _mm_cvtps_ph(a, 0);
+}
+
+__m128i test_mm256_cvtps_ph(__m256 a) {
+  // CHECK: @llvm.x86.vcvtps2ph.256
+  return _mm256_cvtps_ph(a, 0);
+}





More information about the cfe-commits mailing list