[cfe-commits] r160118 - in /cfe/trunk: include/clang/Basic/BuiltinsX86.def lib/CodeGen/CGBuiltin.cpp lib/Headers/immintrin.h test/CodeGen/rdrand-builtins.c
Benjamin Kramer
benny.kra at googlemail.com
Thu Jul 12 02:33:03 PDT 2012
Author: d0k
Date: Thu Jul 12 04:33:03 2012
New Revision: 160118
URL: http://llvm.org/viewvc/llvm-project?rev=160118&view=rev
Log:
Add _rdrand{16,32,64}_step intrinsics to immintrin.h
Added:
cfe/trunk/test/CodeGen/rdrand-builtins.c
Modified:
cfe/trunk/include/clang/Basic/BuiltinsX86.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Headers/immintrin.h
Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=160118&r1=160117&r2=160118&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Thu Jul 12 04:33:03 2012
@@ -614,6 +614,11 @@
BUILTIN(__builtin_ia32_gatherq_d, "V4iV4iV4iC*V2LLiV4iIc", "")
BUILTIN(__builtin_ia32_gatherq_d256, "V4iV4iV4iC*V4LLiV4iIc", "")
+// RDRAND
+BUILTIN(__builtin_ia32_rdrand16_step, "UiUs*", "")
+BUILTIN(__builtin_ia32_rdrand32_step, "UiUi*", "")
+BUILTIN(__builtin_ia32_rdrand64_step, "UiULLi*", "")
+
// BMI
BUILTIN(__builtin_ia32_bextr_u32, "UiUiUi", "")
BUILTIN(__builtin_ia32_bextr_u64, "ULLiULLiULLi", "")
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=160118&r1=160117&r2=160118&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Jul 12 04:33:03 2012
@@ -2447,6 +2447,27 @@
llvm::Function *F = CGM.getIntrinsic(ID);
return Builder.CreateCall(F, Ops, name);
}
+ case X86::BI__builtin_ia32_rdrand16_step:
+ case X86::BI__builtin_ia32_rdrand32_step:
+ case X86::BI__builtin_ia32_rdrand64_step: {
+ Intrinsic::ID ID;
+ switch (BuiltinID) {
+ default: llvm_unreachable("Unsupported intrinsic!");
+ case X86::BI__builtin_ia32_rdrand16_step:
+ ID = Intrinsic::x86_rdrand_16;
+ break;
+ case X86::BI__builtin_ia32_rdrand32_step:
+ ID = Intrinsic::x86_rdrand_32;
+ break;
+ case X86::BI__builtin_ia32_rdrand64_step:
+ ID = Intrinsic::x86_rdrand_64;
+ break;
+ }
+
+ Value *Call = Builder.CreateCall(CGM.getIntrinsic(ID));
+ Builder.CreateStore(Builder.CreateExtractValue(Call, 0), Ops[0]);
+ return Builder.CreateExtractValue(Call, 1);
+ }
}
}
Modified: cfe/trunk/lib/Headers/immintrin.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/immintrin.h?rev=160118&r1=160117&r2=160118&view=diff
==============================================================================
--- cfe/trunk/lib/Headers/immintrin.h (original)
+++ cfe/trunk/lib/Headers/immintrin.h Thu Jul 12 04:33:03 2012
@@ -76,4 +76,26 @@
#include <fmaintrin.h>
#endif
+#ifdef __RDRND__
+static __inline__ int __attribute__((__always_inline__, __nodebug__))
+_rdrand16_step(unsigned short *__p)
+{
+ return __builtin_ia32_rdrand16_step(__p);
+}
+
+static __inline__ int __attribute__((__always_inline__, __nodebug__))
+_rdrand32_step(unsigned int *__p)
+{
+ return __builtin_ia32_rdrand32_step(__p);
+}
+
+#ifdef __x86_64__
+static __inline__ int __attribute__((__always_inline__, __nodebug__))
+_rdrand64_step(unsigned long long *__p)
+{
+ return __builtin_ia32_rdrand64_step(__p);
+}
+#endif
+#endif /* __RDRND__ */
+
#endif /* __IMMINTRIN_H */
Added: cfe/trunk/test/CodeGen/rdrand-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/rdrand-builtins.c?rev=160118&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/rdrand-builtins.c (added)
+++ cfe/trunk/test/CodeGen/rdrand-builtins.c Thu Jul 12 04:33:03 2012
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -target-feature +rdrnd -emit-llvm -S -emit-llvm -o - %s | FileCheck %s
+#include <immintrin.h>
+
+int rdrand16(unsigned short *p) {
+ return _rdrand16_step(p);
+// CHECK: @rdrand16
+// CHECK: call { i16, i32 } @llvm.x86.rdrand.16
+// CHECK: store i16
+}
+
+int rdrand32(unsigned *p) {
+ return _rdrand32_step(p);
+// CHECK: @rdrand32
+// CHECK: call { i32, i32 } @llvm.x86.rdrand.32
+// CHECK: store i32
+}
+
+int rdrand64(unsigned long long *p) {
+ return _rdrand64_step(p);
+// CHECK: @rdrand64
+// CHECK: call { i64, i32 } @llvm.x86.rdrand.64
+// CHECK: store i64
+}
More information about the cfe-commits
mailing list