[PATCH][X86] Add Clang support for intrinsics __rdtsc and __rdtscp.
Andrea Di Biagio
andrea.dibiagio at gmail.com
Thu Apr 24 11:20:32 PDT 2014
Hi,
This patch:
1. adds a definition for two new Builtinsx86:
__builtin_ia32_rdtsc;
__builtin_ia32_rdtscp.
2. Replaces the already existing definition of intrinsics __rdtsc in
ia32intrin.h with a simple call to the new GCC builtin
'__builtin_ia32_rdtsc()'.
3. Adds a definition for the new intrinsic __rdtscp in ia32intrin.h.
LLVM revision 207127 (
http://llvm.org/viewvc/llvm-project?view=revision&revision=207127)
added the two new x86 builtin intrinsics to the IR.
This patch is simply adding the support for the two new intrinsics to Clang.
Please let me know if ok to submit.
Thanks,
Andrea Di Biagio
SN Systems - Sony Computer Entertainment Group.
-------------- next part --------------
Index: lib/Headers/ia32intrin.h
===================================================================
--- lib/Headers/ia32intrin.h (revision 207131)
+++ lib/Headers/ia32intrin.h (working copy)
@@ -82,11 +82,15 @@
/* __rdtsc */
static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
__rdtsc(void) {
- unsigned int __eax, __edx;
- __asm__ ("rdtsc" : "=a" (__eax), "=d" (__edx));
- return ((unsigned long long)__edx << 32) | __eax;
+ return __builtin_ia32_rdtsc();
}
+/* __rdtscp */
+static __inline__ unsigned long long __attribute__((__always_inline__, __nodebug__))
+__rdtscp(unsigned int *__A) {
+ return __builtin_ia32_rdtscp(__A);
+}
+
#define _rdtsc() __rdtsc()
#endif /* __IA32INTRIN_H */
Index: test/CodeGen/builtins-x86.c
===================================================================
--- test/CodeGen/builtins-x86.c (revision 207131)
+++ test/CodeGen/builtins-x86.c (working copy)
@@ -263,6 +263,9 @@
tmp_V4f = __builtin_ia32_cvtpi2ps(tmp_V4f, tmp_V2i);
tmp_V2i = __builtin_ia32_cvtps2pi(tmp_V4f);
tmp_i = __builtin_ia32_cvtss2si(tmp_V4f);
+
+ tmp_i = __builtin_ia32_rdtsc();
+ tmp_i = __builtin_ia32_rdtscp(&tmp_Ui);
#ifdef USE_64
tmp_LLi = __builtin_ia32_cvtss2si64(tmp_V4f);
#endif
Index: include/clang/Basic/BuiltinsX86.def
===================================================================
--- include/clang/Basic/BuiltinsX86.def (revision 207131)
+++ include/clang/Basic/BuiltinsX86.def (working copy)
@@ -760,5 +760,7 @@
BUILTIN(__builtin_ia32_xend, "v", "")
BUILTIN(__builtin_ia32_xabort, "vIc", "")
BUILTIN(__builtin_ia32_xtest, "i", "")
+BUILTIN(__builtin_ia32_rdtsc, "ULLi", "")
+BUILTIN(__builtin_ia32_rdtscp, "ULLiUi*", "")
#undef BUILTIN
More information about the cfe-commits
mailing list