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  #elif defined(ARM64)
35  #include <sse2neon.h>
36  #else
37  #define SYSloadFence()
38  #define SYSstoreFence()
39  #define SYSmemoryFence()
40  #endif
41 #endif
42 
43 
45 {
46  /// Any reordering the compiler or hardware chooses to do is okay.
48 
49  /// Prevents any reads by the same thread that follow this in
50  /// program order from occurring before this read, i.e. a
51  /// compiler and CPU load fence is placed after the read.
53 
54  /// Prevents any writes by the same thread that precede this in
55  /// program order from occurring after this write, i.e. a
56  /// compiler and CPU store fence is placed before the write.
58 
59  /// The current operation will be executed before any loads or
60  /// stores that follow it in program order and after any loads
61  /// or stores that precede it. Moreover, sequential consistency
62  /// is assured meaning that all observers will see this operation
63  /// in the same order relative to any other MEMORY_ORDER_SEQ_CST
64  /// operations.
66 };
67 
68 #ifndef SYSloadFence
69 /// Memory load fence:
70 ///
71 /// This forces any memory reads from before this fence to finish before
72 /// any following memory reads, but does not enforce any ordering with
73 /// respect to memory writes.
74 inline void SYSloadFence()
75 {
76 #if defined(ARM64)
77  // sse2neon maps _mm_sfence() to __sync_synchronize(),
78  // which is a full memory barrier for both reads and writes.
79  _mm_sfence();
80 #else
81  _mm_lfence();
82 #endif
83 }
84 #endif
85 
86 #ifndef SYSstoreFence
87 /// Memory store fence:
88 ///
89 /// This forces any memory writes from before this fence to finish before
90 /// any following memory writes, but does not enforce any ordering with
91 /// respect to memory reads.
92 inline void SYSstoreFence()
93 {
94  _mm_sfence();
95 }
96 #endif
97 
98 #ifndef SYSmemoryFence
99 /// Full memory fence:
100 ///
101 /// This forces any memory reads or writes from before this fence to finish before
102 /// any following memory reads or writes.
103 /// NOTE: This is *not* equivalent to a load fence and a store fence, because
104 /// e.g., that would not ensure that any writes have finished before any
105 /// following reads or vice versa.
106 inline void SYSmemoryFence()
107 {
108 #if defined(ARM64)
109  // sse2neon maps _mm_sfence() to __sync_synchronize(),
110  // which is a full memory barrier for both reads and writes.
111  _mm_sfence();
112 #else
113  _mm_mfence();
114 #endif
115 }
116 #endif
117 
118 #endif
#define SYSloadFence()
SYS_MemoryOrder
#define SYSstoreFence()
Any reordering the compiler or hardware chooses to do is okay.
#define SYSmemoryFence()