From 0e21891eb04d0545495f8adb85954f8857871818 Mon Sep 17 00:00:00 2001
From: Eric Christopher <echristo@gmail.com>
Date: Wed, 17 Jun 2015 18:42:07 +0000
Subject: [PATCH] Move xtest to its own file to match the gcc header
 organization.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239926 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Headers/CMakeLists.txt |  1 +
 lib/Headers/immintrin.h    | 10 +---------
 lib/Headers/xtestintrin.h  | 41 ++++++++++++++++++++++++++++++++++++++
 test/Headers/x86intrin-2.c |  4 ++++
 4 files changed, 47 insertions(+), 9 deletions(-)
 create mode 100644 lib/Headers/xtestintrin.h

diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt
index 29a738e7a81..5f8857c41b4 100644
--- a/lib/Headers/CMakeLists.txt
+++ b/lib/Headers/CMakeLists.txt
@@ -62,6 +62,7 @@ set(files
   x86intrin.h
   xmmintrin.h
   xopintrin.h
+  xtestintrin.h
   )
 
 set(output_dir ${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}/include)
diff --git a/lib/Headers/immintrin.h b/lib/Headers/immintrin.h
index 4194eb5910a..4af407dfc7e 100644
--- a/lib/Headers/immintrin.h
+++ b/lib/Headers/immintrin.h
@@ -136,15 +136,7 @@ _writegsbase_u64(unsigned long long __V)
 
 #include <rtmintrin.h>
 
-/* xtest returns non-zero if the instruction is executed within an RTM or active
- * HLE region. */
-/* FIXME: This can be an either or for RTM/HLE. Deal with this when HLE is
- * supported. */
-static __inline__ int __attribute__((__always_inline__, __nodebug__, __target__("rtm")))
-_xtest(void)
-{
-  return __builtin_ia32_xtest();
-}
+#include <xtestintrin.h>
 
 #include <shaintrin.h>
 
diff --git a/lib/Headers/xtestintrin.h b/lib/Headers/xtestintrin.h
new file mode 100644
index 00000000000..9d3378fd1ee
--- /dev/null
+++ b/lib/Headers/xtestintrin.h
@@ -0,0 +1,41 @@
+/*===---- xtestintrin.h - XTEST intrinsic ---------------------------------===
+ *
+ * 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 <xtestintrin.h> directly; include <immintrin.h> instead."
+#endif
+
+#ifndef __XTESTINTRIN_H
+#define __XTESTINTRIN_H
+
+/* xtest returns non-zero if the instruction is executed within an RTM or active
+ * HLE region. */
+/* FIXME: This can be an either or for RTM/HLE. Deal with this when HLE is
+ * supported. */
+static __inline__ int
+    __attribute__((__always_inline__, __nodebug__, __target__("rtm")))
+    _xtest(void) {
+  return __builtin_ia32_xtest();
+}
+
+#endif
diff --git a/test/Headers/x86intrin-2.c b/test/Headers/x86intrin-2.c
index 825321da17f..f98fdbd13a8 100644
--- a/test/Headers/x86intrin-2.c
+++ b/test/Headers/x86intrin-2.c
@@ -130,4 +130,8 @@ __m128 __attribute__((__target__("f16c"))) mm_cvtph_ps_wrap(__m128i a) {
   return _mm_cvtph_ps(a);
 }
 
+int __attribute__((__target__("rtm"))) xtest_wrap(void) {
+  return _xtest();
+}
+
 #endif
-- 
GitLab