[cfe-commits] r157733 - in /cfe/trunk: include/clang/Basic/BuiltinsX86.def lib/Basic/Targets.cpp lib/Headers/wmmintrin.h test/CodeGen/pclmul-builtins.c
Craig Topper
craig.topper at gmail.com
Wed May 30 22:18:48 PDT 2012
Author: ctopper
Date: Thu May 31 00:18:48 2012
New Revision: 157733
URL: http://llvm.org/viewvc/llvm-project?rev=157733&view=rev
Log:
Add builtin for pclmulqdq instruction.
Added:
cfe/trunk/test/CodeGen/pclmul-builtins.c
Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Headers/wmmintrin.h
Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=157733&r1=157732&r2=157733&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Thu May 31 00:18:48 2012
@@ -385,6 +385,9 @@
BUILTIN(__builtin_ia32_aesimc128, "V2LLiV2LLi", "")
BUILTIN(__builtin_ia32_aeskeygenassist128, "V2LLiV2LLiIc", "")
+// CLMUL
+BUILTIN(__builtin_ia32_pclmulqdq128, "V2LLiV2LLiV2LLiIc", "")
+
// AVX
BUILTIN(__builtin_ia32_addsubpd256, "V4dV4dV4d", "")
BUILTIN(__builtin_ia32_addsubps256, "V8fV8fV8f", "")
Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=157733&r1=157732&r2=157733&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu May 31 00:18:48 2012
@@ -1238,6 +1238,7 @@
} MMX3DNowLevel;
bool HasAES;
+ bool HasPCLMUL;
bool HasLZCNT;
bool HasBMI;
bool HasBMI2;
@@ -1388,8 +1389,9 @@
public:
X86TargetInfo(const std::string& triple)
: TargetInfo(triple), SSELevel(NoSSE), MMX3DNowLevel(NoMMX3DNow),
- HasAES(false), HasLZCNT(false), HasBMI(false), HasBMI2(false),
- HasPOPCNT(false), HasSSE4a(false), HasFMA4(false), CPU(CK_Generic) {
+ HasAES(false), HasPCLMUL(false), HasLZCNT(false), HasBMI(false),
+ HasBMI2(false), HasPOPCNT(false), HasSSE4a(false), HasFMA4(false),
+ CPU(CK_Generic) {
BigEndian = false;
LongDoubleFormat = &llvm::APFloat::x87DoubleExtended;
}
@@ -1571,6 +1573,7 @@
Features["sse42"] = false;
Features["sse4a"] = false;
Features["aes"] = false;
+ Features["pclmul"] = false;
Features["avx"] = false;
Features["avx2"] = false;
Features["lzcnt"] = false;
@@ -1631,18 +1634,19 @@
case CK_Corei7:
setFeatureEnabled(Features, "mmx", true);
setFeatureEnabled(Features, "sse4", true);
- setFeatureEnabled(Features, "aes", true);
break;
case CK_Corei7AVX:
case CK_CoreAVXi:
setFeatureEnabled(Features, "mmx", true);
setFeatureEnabled(Features, "avx", true);
setFeatureEnabled(Features, "aes", true);
+ setFeatureEnabled(Features, "pclmul", true);
break;
case CK_CoreAVX2:
setFeatureEnabled(Features, "mmx", true);
setFeatureEnabled(Features, "avx2", true);
setFeatureEnabled(Features, "aes", true);
+ setFeatureEnabled(Features, "pclmul", true);
setFeatureEnabled(Features, "lzcnt", true);
setFeatureEnabled(Features, "bmi", true);
setFeatureEnabled(Features, "bmi2", true);
@@ -1695,6 +1699,7 @@
setFeatureEnabled(Features, "avx", true);
setFeatureEnabled(Features, "sse4a", true);
setFeatureEnabled(Features, "aes", true);
+ setFeatureEnabled(Features, "pclmul", true);
break;
case CK_C3_2:
setFeatureEnabled(Features, "mmx", true);
@@ -1740,6 +1745,8 @@
Features["mmx"] = Features["3dnow"] = Features["3dnowa"] = true;
else if (Name == "aes")
Features["aes"] = true;
+ else if (Name == "pclmul")
+ Features["pclmul"] = true;
else if (Name == "avx")
Features["mmx"] = Features["sse"] = Features["sse2"] = Features["sse3"] =
Features["ssse3"] = Features["sse41"] = Features["sse42"] =
@@ -1789,6 +1796,8 @@
Features["3dnowa"] = false;
else if (Name == "aes")
Features["aes"] = false;
+ else if (Name == "pclmul")
+ Features["pclmul"] = false;
else if (Name == "avx")
Features["avx"] = Features["avx2"] = Features["fma4"] = false;
else if (Name == "avx2")
@@ -1826,6 +1835,11 @@
continue;
}
+ if (Feature == "pclmul") {
+ HasPCLMUL = true;
+ continue;
+ }
+
if (Feature == "lzcnt") {
HasLZCNT = true;
continue;
@@ -2038,6 +2052,9 @@
if (HasAES)
Builder.defineMacro("__AES__");
+ if (HasPCLMUL)
+ Builder.defineMacro("__PCLMUL__");
+
if (HasLZCNT)
Builder.defineMacro("__LZCNT__");
@@ -2119,12 +2136,12 @@
.Case("avx2", SSELevel >= AVX2)
.Case("bmi", HasBMI)
.Case("bmi2", HasBMI2)
- .Case("sse4a", HasSSE4a)
.Case("fma4", HasFMA4)
.Case("lzcnt", HasLZCNT)
.Case("mm3dnow", MMX3DNowLevel >= AMD3DNow)
.Case("mm3dnowa", MMX3DNowLevel >= AMD3DNowAthlon)
.Case("mmx", MMX3DNowLevel >= MMX)
+ .Case("pclmul", HasPCLMUL)
.Case("popcnt", HasPOPCNT)
.Case("sse", SSELevel >= SSE1)
.Case("sse2", SSELevel >= SSE2)
@@ -2132,6 +2149,7 @@
.Case("ssse3", SSELevel >= SSSE3)
.Case("sse41", SSELevel >= SSE41)
.Case("sse42", SSELevel >= SSE42)
+ .Case("sse4a", HasSSE4a)
.Case("x86", true)
.Case("x86_32", PointerWidth == 32)
.Case("x86_64", PointerWidth == 64)
Modified: cfe/trunk/lib/Headers/wmmintrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/wmmintrin.h?rev=157733&r1=157732&r2=157733&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/wmmintrin.h (original)
+++ cfe/trunk/lib/Headers/wmmintrin.h Thu May 31 00:18:48 2012
@@ -24,11 +24,13 @@
#ifndef _WMMINTRIN_H
#define _WMMINTRIN_H
-#if !defined (__AES__)
-# error "AES instructions not enabled"
+#include <emmintrin.h>
+
+#if !defined (__AES__) && !defined (__PCLMUL__)
+# error "AES/PCLMUL instructions not enabled"
#else
-#include <xmmintrin.h>
+#ifdef __AES__
static __inline__ __m128i __attribute__((__always_inline__, __nodebug__))
_mm_aesenc_si128(__m128i __V, __m128i __R)
@@ -64,4 +66,14 @@
__builtin_ia32_aeskeygenassist128((C), (R))
#endif /* __AES__ */
+
+#ifdef __PCLMUL__
+
+#define _mm_clmulepi64_si128(__X, __Y, __I) \
+ ((__m128i)__builtin_ia32_pclmulqdq128((__v2di)(__m128i)(__X), \
+ (__v2di)(__m128i)(__Y), (char)(__I)))
+
+#endif /* __PCLMUL__ */
+
+#endif /* __AES__ || __PCLMUL__ */
#endif /* _WMMINTRIN_H */
Added: cfe/trunk/test/CodeGen/pclmul-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pclmul-builtins.c?rev=157733&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/pclmul-builtins.c (added)
+++ cfe/trunk/test/CodeGen/pclmul-builtins.c Thu May 31 00:18:48 2012
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -O3 -triple=x86_64-apple-darwin -target-feature +pclmul -emit-llvm -o - | FileCheck %s
+
+// Don't include mm_malloc.h, it's system specific.
+#define __MM_MALLOC_H
+
+#include <wmmintrin.h>
+
+__m128i test_mm_clmulepi64_si128(__m128i a, __m128i b) {
+ // CHECK: @llvm.x86.pclmulqdq
+ return _mm_clmulepi64_si128(a, b, 0);
+}
More information about the cfe-commits
mailing list