HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SYS_MemoryOrder.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: SYS_MemoryOrder.h ( UT Library, C++)
7  *
8  * COMMENTS: Enumerated type for memory order of atomic operations.
9  */
10 
11 #ifndef __SYS_MemoryOrder__
12 #define __SYS_MemoryOrder__
13 
14 #include "SYS_Compiler.h"
15 
16 #if defined(FORCE_NON_SIMD)
17  #define SYSloadFence()
18  #define SYSstoreFence()
19  #define SYSmemoryFence()
20 #else
21  #if defined(LINUX) && SYS_IS_GCC_GE(3, 4) && defined(__SSE2__)
22  #include <emmintrin.h>
23  #include <xmmintrin.h>
24  #elif defined(LINUX) && SYS_IS_GCC_GE(3, 4) && defined(__SSE__)
25  #include <xmmintrin.h>
26  #define SYSloadFence()
27  #define SYSmemoryFence()
28  #elif defined(WIN32)
29  #include <emmintrin.h>
30  #include <xmmintrin.h>
31  #elif defined(MBSD_INTEL)
32  #include <emmintrin.h>
33  #include <xmmintrin.h>
34  #else
35  #define SYSloadFence()
36  #define SYSstoreFence()
37  #define SYSmemoryFence()
38  #endif
39 #endif
40 
41 
43 {
44  /// Any reordering the compiler or hardware chooses to do is okay.
46 
47  /// Prevents any reads by the same thread that follow this in
48  /// program order from occurring before this read, i.e. a
49  /// compiler and CPU load fence is placed after the read.
51 
52  /// Prevents any writes by the same thread that precede this in
53  /// program order from occurring after this write, i.e. a
54  /// compiler and CPU store fence is placed before the write.
56 
57  /// The current operation will be executed before any loads or
58  /// stores that follow it in program order and after any loads
59  /// or stores that precede it. Moreover, sequential consistency
60  /// is assured meaning that all observers will see this operation
61  /// in the same order relative to any other MEMORY_ORDER_SEQ_CST
62  /// operations.
64 };
65 
66 #ifndef SYSloadFence
67 /// Memory load fence:
68 ///
69 /// This forces any memory reads from before this fence to finish before
70 /// any following memory reads, but does not enforce any ordering with
71 /// respect to memory writes.
72 inline void SYSloadFence()
73 {
74  _mm_lfence();
75 }
76 #endif
77 
78 #ifndef SYSstoreFence
79 /// Memory store fence:
80 ///
81 /// This forces any memory writes from before this fence to finish before
82 /// any following memory writes, but does not enforce any ordering with
83 /// respect to memory reads.
84 inline void SYSstoreFence()
85 {
86  _mm_sfence();
87 }
88 #endif
89 
90 #ifndef SYSmemoryFence
91 /// Full memory fence:
92 ///
93 /// This forces any memory reads or writes from before this fence to finish before
94 /// any following memory reads or writes.
95 /// NOTE: This is *not* equivalent to a load fence and a store fence, because
96 /// e.g., that would not ensure that any writes have finished before any
97 /// following reads or vice versa.
98 inline void SYSmemoryFence()
99 {
100  _mm_mfence();
101 }
102 #endif
103 
104 #endif
#define SYSloadFence()
SYS_MemoryOrder
#define SYSstoreFence()
Any reordering the compiler or hardware chooses to do is okay.
#define SYSmemoryFence()