tlds
Transactional Operations for Linked Data Structures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
intel_defns.h
Go to the documentation of this file.
1 #ifndef __INTEL_DEFNS_H__
2 #define __INTEL_DEFNS_H__
3 
4 #include <pthread.h>
5 #include <sched.h>
6 
7 #ifndef INTEL
8 #define INTEL
9 #endif
10 
11 #if 0
12 #define pthread_mutex_init(_m,_i) \
13 ({ pthread_mutex_init(_m,_i); (_m)->__m_kind = PTHREAD_MUTEX_ADAPTIVE_NP; })
14 #endif
15 
16 
17 /*
18  * I. Compare-and-swap.
19  */
20 
21 /*
22  * This is a strong barrier! Reads cannot be delayed beyond a later store.
23  * Reads cannot be hoisted beyond a LOCK prefix. Stores always in-order.
24  */
25 #define CAS(_a, _o, _n) \
26 ({ __typeof__(_o) __o = _o; \
27  __asm__ __volatile__( \
28  "lock cmpxchg %3,%1" \
29  : "=a" (__o), "=m" (*(volatile unsigned int *)(_a)) \
30  : "0" (__o), "r" (_n) ); \
31  __o; \
32 })
33 
34 #define FAS(_a, _n) \
35 ({ __typeof__(_n) __o; \
36  __asm__ __volatile__( \
37  "lock xchg %0,%1" \
38  : "=r" (__o), "=m" (*(volatile unsigned int *)(_a)) \
39  : "0" (_n) ); \
40  __o; \
41 })
42 
43 #define CAS64(_a, _o, _n) \
44 ({ __typeof__(_o) __o = _o; \
45  __asm__ __volatile__( \
46  "movl %3, %%ecx;" \
47  "movl %4, %%ebx;" \
48  "lock cmpxchg8b %1" \
49  : "=A" (__o), "=m" (*(volatile unsigned long long *)(_a)) \
50  : "0" (__o), "m" (_n >> 32), "m" (_n) \
51  : "ebx", "ecx" ); \
52  __o; \
53 })
54 
55 /* Update Integer location, return Old value. */
56 #define CASIO CAS
57 #define FASIO FAS
58 /* Update Pointer location, return Old value. */
59 #define CASPO CAS
60 #define FASPO FAS
61 /* Update 32/64-bit location, return Old value. */
62 #define CAS32O CAS
63 #define CAS64O CAS64
64 
65 /*
66  * II. Memory barriers.
67  * WMB(): All preceding write operations must commit before any later writes.
68  * RMB(): All preceding read operations must commit before any later reads.
69  * MB(): All preceding memory accesses must commit before any later accesses.
70  *
71  * If the compiler does not observe these barriers (but any sane compiler
72  * will!), then VOLATILE should be defined as 'volatile'.
73  */
74 
75 #define MB() __sync_synchronize()
76 #define WMB() __asm__ __volatile__ ("" : : : "memory")
77 #define RMB() MB()
78 #define VOLATILE /*volatile*/
79 
80 /* On Intel, CAS is a strong barrier, but not a compile barrier. */
81 #define RMB_NEAR_CAS() WMB()
82 #define WMB_NEAR_CAS() WMB()
83 #define MB_NEAR_CAS() WMB()
84 
85 
86 /*
87  * III. Cycle counter access.
88  */
89 
90 typedef unsigned long long tick_t;
91 
92 static inline tick_t __attribute__((always_inline))
93 RDTICK()
94 { tick_t __t;
95  __asm__ __volatile__("rdtsc\n"
96  "shl $32,%%rdx\n"
97  "or %%rdx,%%rax"
98  : "=a"(__t)
99  :
100  : "%rcx", "%rdx");
101  return __t;
102 }
103 
104 
105 
106 
107 /*
108  * IV. Types.
109  */
110 
111 typedef unsigned char _u8;
112 typedef unsigned short _u16;
113 typedef unsigned int _u32;
114 typedef unsigned long long _u64;
115 
116 #endif /* __INTEL_DEFNS_H__ */
unsigned int _u32
Definition: intel_defns.h:113
unsigned char _u8
Definition: intel_defns.h:111
unsigned short _u16
Definition: intel_defns.h:112
unsigned long long _u64
Definition: intel_defns.h:114
static tick_t __attribute__((always_inline)) RDTICK()
Definition: intel_defns.h:92
unsigned long long tick_t
Definition: intel_defns.h:90