Imported Upstream version 16.11
[deb_dpdk.git] / lib / librte_eal / common / include / arch / x86 / rte_rtm.h
1 #ifndef _RTE_RTM_H_
2 #define _RTE_RTM_H_ 1
3
4 /*
5  * Copyright (c) 2012,2013 Intel Corporation
6  * Author: Andi Kleen
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that: (1) source code distributions
10  * retain the above copyright notice and this paragraph in its entirety, (2)
11  * distributions including binary code include the above copyright notice and
12  * this paragraph in its entirety in the documentation or other materials
13  * provided with the distribution
14  *
15  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
16  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
17  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18  */
19
20 /* Official RTM intrinsics interface matching gcc/icc, but works
21    on older gcc compatible compilers and binutils. */
22
23 #include <rte_common.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29
30 #define RTE_XBEGIN_STARTED              (~0u)
31 #define RTE_XABORT_EXPLICIT             (1 << 0)
32 #define RTE_XABORT_RETRY                (1 << 1)
33 #define RTE_XABORT_CONFLICT             (1 << 2)
34 #define RTE_XABORT_CAPACITY             (1 << 3)
35 #define RTE_XABORT_DEBUG                (1 << 4)
36 #define RTE_XABORT_NESTED               (1 << 5)
37 #define RTE_XABORT_CODE(x)              (((x) >> 24) & 0xff)
38
39 static __attribute__((__always_inline__)) inline
40 unsigned int rte_xbegin(void)
41 {
42         unsigned int ret = RTE_XBEGIN_STARTED;
43
44         asm volatile(".byte 0xc7,0xf8 ; .long 0" : "+a" (ret) :: "memory");
45         return ret;
46 }
47
48 static __attribute__((__always_inline__)) inline
49 void rte_xend(void)
50 {
51          asm volatile(".byte 0x0f,0x01,0xd5" ::: "memory");
52 }
53
54 /* not an inline function to workaround a clang bug with -O0 */
55 #define rte_xabort(status) do { \
56         asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory"); \
57 } while (0)
58
59 static __attribute__((__always_inline__)) inline
60 int rte_xtest(void)
61 {
62         unsigned char out;
63
64         asm volatile(".byte 0x0f,0x01,0xd6 ; setnz %0" :
65                 "=r" (out) :: "memory");
66         return out;
67 }
68
69 #ifdef __cplusplus
70 }
71 #endif
72
73 #endif /* _RTE_RTM_H_ */