]> xenbits.xensource.com Git - xtf.git/commitdiff
TSX intrinsics
authorAndrew Cooper <andrew.cooper3@citrix.com>
Sun, 29 Apr 2018 14:55:31 +0000 (15:55 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 15 Jun 2018 14:38:05 +0000 (15:38 +0100)
These are implemented to the GCC API, but are compatible with older
toolchains.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/include/arch/tsx.h [new file with mode: 0644]
arch/x86/include/arch/xtf.h
include/xtf/compiler-gcc.h
include/xtf/lib.h

diff --git a/arch/x86/include/arch/tsx.h b/arch/x86/include/arch/tsx.h
new file mode 100644 (file)
index 0000000..d99ef16
--- /dev/null
@@ -0,0 +1,82 @@
+/**
+ * @file arch/x86/include/arch/tsx.h
+ *
+ * %x86 TSX intrinsics, compatible with the GCC API.
+ *
+ * To use:
+ *
+ * ~~~~~{.c}
+ *
+ *    if ( (xstatus = _xbegin()) == _XBEGIN_STARTED )
+ *    {
+ *        // Inside hardware transaction
+ *        _xend();
+ *    }
+ *    else
+ *        // Abort occured
+ *
+ * ~~~~~
+ */
+#ifndef XTF_X86_TSX_H
+#define XTF_X86_TSX_H
+
+#include <xtf/compiler.h>
+
+#define _XBEGIN_STARTED  (~0u)
+#define _XABORT_EXPLICIT (1u << 0)
+#define _XABORT_RETRY    (1u << 1)
+#define _XABORT_CONFLICT (1u << 2)
+#define _XABORT_CAPACITY (1u << 3)
+#define _XABORT_DEBUG    (1u << 4)
+#define _XABORT_NESTED   (1u << 5)
+#define _XABORT_CODE(x)  (((x) >> 24) & 0xff)
+
+static inline unsigned int _xbegin(void)
+{
+    unsigned int ret = _XBEGIN_STARTED;
+
+    asm volatile (".byte 0xc7, 0xf8, 0, 0, 0, 0" /* xbegin 1f; 1: */
+                  : "+a" (ret) :: "memory");
+
+    return ret;
+}
+
+static inline int _xtest(void)
+{
+    int rc;
+
+    asm volatile (".byte 0x0f, 0x01, 0xd6" /* xtest */
+                  ASM_FLAG_OUT(, "; setnz %[rc]")
+                  : ASM_FLAG_OUT("=@ccnz", [rc] "=rm") (rc));
+
+    return rc;
+}
+
+/*
+ * N.B. Should be static inline, but clang can't cope with 'code' being
+ * propagated through a function parameter.
+ */
+#define _xabort(code)                                           \
+    do {                                                        \
+        asm volatile (".byte 0xc6, 0xf8, %c0" /* xabort %0 */   \
+                      :: "N" (code) : "memory");                \
+        unreachable();                                          \
+    } while ( 0 )
+
+static inline void _xend(void)
+{
+    asm volatile (".byte 0x0f, 0x01, 0xd6" /* xend */
+                  ::: "memory");
+}
+
+#endif /* XTF_X86_TSX_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
index 6cedf08e81cec850ecd017b83e47f71da3e5ee41..8c951cd13a5f7611ee1c06a3df3eb54d77f3b22f 100644 (file)
@@ -13,6 +13,7 @@
 #include <arch/pagetable.h>
 #include <arch/symbolic-const.h>
 #include <arch/test.h>
+#include <arch/tsx.h>
 #include <arch/x86-dbg-reg.h>
 
 extern char _end[];
index f6f76c46ce23407cdf2f12a7e51969b029b0de80..25b2fd2716bc6da75066719923582c7df951ba56 100644 (file)
 #define __has_extension(x) GCC_HAS_ ## x
 #endif /* __has_extension */
 
+#ifdef __GCC_ASM_FLAG_OUTPUTS__
+# define ASM_FLAG_OUT(yes, no) yes
+#else
+# define ASM_FLAG_OUT(yes, no) no
+#endif
+
 #endif /* XTF_COMPILER_GCC_H */
 
 /*
index abf8f2534417db76ece8c8781fb726ce3235b81e..3348464b7069894687dba701bf59a4b1877b920b 100644 (file)
@@ -54,12 +54,6 @@ void __noreturn panic(const char *fmt, ...) __printf(1, 2);
 
 #define ROUNDUP(x, a) (((x) + (a) - 1) & ~((a) - 1))
 
-#ifdef __GCC_ASM_FLAG_OUTPUTS__
-# define ASM_FLAG_OUT(yes, no) yes
-#else
-# define ASM_FLAG_OUT(yes, no) no
-#endif
-
 void heapsort(void *base, size_t nmemb, size_t size,
               int (*compar)(const void *, const void *),
               void (*swap)(void *, void *));