68 {
69#if defined(__i386__) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
70#if !defined(_MSC_VER) || (defined(_MSC_VER) && defined(__clang__) && !defined(__c2__))
71 static const auto __cpuidex = [](int *cpuInfo, int func1, int func2) {
72 __asm__ __volatile__("cpuid\n\t" : "=a"(cpuInfo[0]), "=b"(cpuInfo[1]), "=c"(cpuInfo[2]), "=d"(cpuInfo[3]) : "a"(func1), "c"(func2));
73 };
74
75 static const auto _mm_clwb = [](const void *addr) { __asm__ __volatile__(".byte 0x66, 0x0f, 0xae, 0x30\n\t" : : "a"(addr)); };
76 static const auto _mm_clflushopt = [](const void *addr) { __asm__ __volatile__("clflushopt (%0)\n\t" : : "r"(addr)); };
77 static const auto _mm_clflush = [](const void *addr) { __asm__ __volatile__("clflush (%0)\n\t" : : "r"(addr)); };
78 static const auto _mm_sfence = []() { __asm__ __volatile__("sfence\n\t"); };
79#endif
80 int nBuff[4];
81 __cpuidex(nBuff, 0x7, 0x0);
82 if(nBuff[1] & (1 << 24))
83 {
86 {
87 while(bytes > 0)
88 {
89 _mm_clwb(addr);
90 addr = (void *) ((uintptr_t) addr + 64);
91 bytes -= 64;
92 }
93 _mm_sfence();
95 }
96 while(bytes > 0)
97 {
98 _mm_clflushopt(addr);
99 addr = (void *) ((uintptr_t) addr + 64);
100 bytes -= 64;
101 }
102 _mm_sfence();
104 };
105 }
106 if(nBuff[1] & (1 << 23))
107 {
109 while(bytes > 0)
110 {
111 _mm_clflushopt(addr);
112 addr = (void *) ((uintptr_t) addr + 64);
113 bytes -= 64;
114 }
115 _mm_sfence();
117 };
118 }
119 else
120 {
121
123 while(bytes > 0)
124 {
125 _mm_clflush(addr);
126 addr = (void *) ((uintptr_t) addr + 64);
127 bytes -= 64;
128 }
130 };
131 }
132#elif defined(__aarch64__) || defined(_M_ARM64)
133#if !defined(_MSC_VER) || (defined(_MSC_VER) && defined(__clang__) && !defined(__c2__))
134 static const auto _dmb_ish = []() { __asm__ __volatile__("dmb ish" : : : "memory"); };
135 static const auto _dc_cvac = [](const void *addr) { __asm__ __volatile__("dc cvac, %0" : : "r"(addr) : "memory"); };
136 static const auto _dc_civac = [](const void *addr) { __asm__ __volatile__("dc civac, %0" : : "r"(addr) : "memory"); };
137#else
138 static const auto _dmb_ish = []() { __dmb(_ARM64_BARRIER_ISH); };
139 static const auto _dc_cvac = [](const void *addr) {
140 (void) addr;
141 abort();
142 };
143 static const auto _dc_civac = [](const void *addr) {
144 (void) addr;
145 abort();
146 };
147#endif
150 {
151 while(bytes > 0)
152 {
153 _dc_cvac(addr);
154 addr = (void *) ((uintptr_t) addr + 64);
155 bytes -= 64;
156 }
157 _dmb_ish();
159 }
160 while(bytes > 0)
161 {
162 _dc_civac(addr);
163 addr = (void *) ((uintptr_t) addr + 64);
164 bytes -= 64;
165 }
166 _dmb_ish();
168 };
169#elif defined(__arm__) || defined(_M_ARM)
170#if !defined(_MSC_VER) || (defined(_MSC_VER) && defined(__clang__) && !defined(__c2__))
171#undef _MoveToCoprocessor
172#define _MoveToCoprocessor(value, coproc, opcode1, crn, crm, opcode2) \
173 __asm__ __volatile__("MCR p" #coproc ", " #opcode1 ", %0, c" #crn ", c" #crm ", " #opcode2 : : "r"(value) : "memory");
174#endif
177 {
178 while(bytes > 0)
179 {
180
181 _MoveToCoprocessor(addr, 15, 0, 7, 10, 1);
182 addr = (void *) ((uintptr_t) addr + 64);
183 bytes -= 64;
184 }
185
186 _MoveToCoprocessor(0, 15, 0, 7, 10, 5);
188 }
189 while(bytes > 0)
190 {
191
192 _MoveToCoprocessor(addr, 15, 0, 7, 14, 1);
193 addr = (void *) ((uintptr_t) addr + 64);
194 bytes -= 64;
195 }
196
197 _MoveToCoprocessor(0, 15, 0, 7, 10, 5);
199 };
200#elif defined(__powerpc__)
201
202
203 static const auto _sync = []() { __asm__ __volatile__("sync" : : : "memory"); };
204 static const auto _dcbst = [](const void *addr) { __asm__ __volatile__("dcbst 0, %0" : : "r"(addr) : "memory"); };
205 static const auto _dcbf = [](const void *addr) { __asm__ __volatile__("dcbf 0, %0" : : "r"(addr) : "memory"); };
208 {
209 while(bytes > 0)
210 {
211 _dcbst(addr);
212 addr = (void *) ((uintptr_t) addr + 64);
213 bytes -= 64;
214 }
215 _sync();
217 }
218 while(bytes > 0)
219 {
220 _dcbf(addr);
221 addr = (void *) ((uintptr_t) addr + 64);
222 bytes -= 64;
223 }
224 _sync();
226 };
227#else
228#error Unsupported platform
229#endif
230 }
constexpr memory_flush memory_flush_retain
Flush modified cache line to memory, but retain as unmodified in cache.
Definition mem_flush_loads_stores.hpp:60
constexpr memory_flush memory_flush_evict
Flush modified cache line to memory, and evict completely from all caches.
Definition mem_flush_loads_stores.hpp:62
memory_flush
The kinds of cache line flushing which can be performed.
Definition mem_flush_loads_stores.hpp:52