11 #ifndef API_LIBRARY_INST_HPP__
12 #define API_LIBRARY_INST_HPP__
14 #include <stm/config.h>
45 template <
typename T,
size_t S>
59 T invalid = (T)itastp;
68 T invalid = (T)itaftp;
72 #if defined(STM_BITS_32)
80 return (T)(uintptr_t)thread->tmread(thread, (
void**)addr
85 static void write(T* addr, T val, TxThread* thread)
87 thread->tmwrite(thread, (
void**)addr, (
void*)(uintptr_t)val
94 struct DISPATCH<float, 4>
97 static float read(
float* addr, TxThread* thread)
99 union {
float f;
void* v; } v;
100 v.v = thread->tmread(thread, (
void**)addr STM_MASK(~0x0));
105 static void write(
float* addr,
float val, TxThread* thread)
107 union {
float f;
void* v; } v;
109 thread->tmwrite(thread, (
void**)addr, v.v STM_MASK(~0x0));
115 struct DISPATCH<const float, 4>
118 static float read(
const float* addr, TxThread* thread)
120 union {
float f;
void* v; } v;
121 v.v = thread->tmread(thread, (
void**)addr STM_MASK(~0x0));
126 static void write(
const float*,
float, TxThread*)
133 template <
typename T>
134 struct DISPATCH<T, 8>
137 static T
read(T* addr, TxThread* thread)
140 void** addr2 = (
void**)((
long)addr + 4);
143 struct {
void* v1;
void* v2; } v;
146 v.v.v1 = thread->tmread(thread, (
void**)addr STM_MASK(~0x0));
147 v.v.v2 = thread->tmread(thread, addr2 STM_MASK(~0x0));
152 static void write(T* addr, T val, TxThread* thread)
155 void** addr1 = (
void**)addr;
156 void** addr2 = (
void**)((
long)addr + 4);
160 struct {
void* v1;
void* v2; } v;
164 thread->tmwrite(thread, addr1, v.v.v1 STM_MASK(~0x0));
165 thread->tmwrite(thread, addr2, v.v.v2 STM_MASK(~0x0));
174 struct DISPATCH<double, 8>
177 static double read(
double* addr, TxThread* thread)
180 void** addr2 = (
void**)((
long)addr + 4);
183 struct {
void* v1;
void* v2; } v;
186 v.v.v1 = thread->tmread(thread, (
void**)addr STM_MASK(~0x0));
187 v.v.v2 = thread->tmread(thread, addr2 STM_MASK(~0x0));
192 static void write(
double* addr,
double val, TxThread* thread)
195 void** addr1 = (
void**) addr;
196 void** addr2 = (
void**) ((
long)addr + 4);
200 struct {
void* v1;
void* v2; } v;
204 thread->tmwrite(thread, addr1, v.v.v1 STM_MASK(~0x0));
205 thread->tmwrite(thread, addr2, v.v.v2 STM_MASK(~0x0));
211 struct DISPATCH<const double, 8>
214 static double read(
const double* addr, TxThread* thread)
217 void** addr2 = (
void**)((
long)addr + 4);
220 struct {
void* v1;
void* v2; } v;
223 v.v.v1 = thread->tmread(thread, (
void**)addr STM_MASK(~0x0));
224 v.v.v2 = thread->tmread(thread, addr2 STM_MASK(~0x0));
229 static void write(
const double*,
double, TxThread*)
242 template <
typename T>
243 struct DISPATCH<T, 1>
246 static T
read(T* addr, TxThread* thread)
252 union {
char v[4];
void* v2; } v;
253 void** a = (
void**)(((
long)addr) & ~3);
254 long offset = ((long)addr) & 3;
255 v.v2 = thread->tmread(thread, a STM_MASK(0xFF << (8 * offset)));
256 return (T)v.v[offset];
260 static void write(T* addr, T val, TxThread* thread)
264 union { T v[4];
void* v2; } v;
265 void** a = (
void**)(((
long)addr) & ~3);
266 long offset = ((long)addr) & 3;
268 v.v2 = thread->tmread(thread, a STM_MASK(0xFF << (8 * offset)));
270 thread->tmwrite(thread, a, v.v2 STM_MASK(0xFF << (8 * offset)));
274 #elif defined(STM_BITS_64)
276 template <
typename T>
277 struct DISPATCH<T, 8>
280 static T
read(T* addr, TxThread* thread)
282 return (T)(uintptr_t)thread->tmread(thread, (
void**)addr
287 static void write(T* addr, T val, TxThread* thread)
289 thread->tmwrite(thread, (
void**)addr, (
void*)(uintptr_t)val
296 struct DISPATCH<double, 8>
299 static double read(
double* addr, TxThread* thread)
301 union {
double d;
void* v; } v;
302 v.v = thread->tmread(thread, (
void**)addr STM_MASK(~0x0));
307 static void write(
double* addr,
double val, TxThread* thread)
309 union {
double d;
void* v; } v;
311 thread->tmwrite(thread, (
void**)addr, v.v STM_MASK(~0x0));
317 struct DISPATCH<const double, 8>
320 static double read(
const double* addr, TxThread* thread)
322 union {
double d;
void* v; } v;
323 v.v = thread->tmread(thread, (
void**)addr STM_MASK(~0x0));
328 static void write(
const double*,
double, TxThread*)
336 struct DISPATCH<long double, 16>
339 static double read(
double* addr, TxThread* thread)
342 void** addr2 = (
void**)((
long)addr + 4);
345 struct {
void* v1;
void* v2; } v;
348 v.v.v1 = thread->tmread(thread, (
void**)addr STM_MASK(~0x0));
349 v.v.v2 = thread->tmread(thread, addr2 STM_MASK(~0x0));
354 static void write(
double* addr,
double val, TxThread* thread)
357 void** addr1 = (
void**) addr;
358 void** addr2 = (
void**) ((
long)addr + 4);
362 struct {
void* v1;
void* v2; } v;
366 thread->tmwrite(thread, addr1, v.v.v1 STM_MASK(~0x0));
367 thread->tmwrite(thread, addr2, v.v.v2 STM_MASK(~0x0));
384 template <
typename T>
385 struct DISPATCH<T, 4>
388 static T
read(T* addr, TxThread* thread)
393 union {
int v[2];
void* v2; } v;
394 void** a = (
void**)(((intptr_t)addr) & ~7ul);
395 long offset = (((intptr_t)addr)>>2)&1;
396 v.v2 = thread->tmread(thread, a
397 STM_MASK(0xffffffff << (32 * offset)));
398 return (T)v.v[offset];
402 static void write(T* addr, T val, TxThread* thread)
406 union { T v[2];
void* v2; } v;
407 void** a = (
void**)(((intptr_t)addr) & ~7ul);
408 int offset = (((intptr_t)addr)>>2) & 1;
410 v.v2 = thread->tmread(thread, a
411 STM_MASK(0xffffffff << (32 * offset)));
413 thread->tmwrite(thread, a, v.v2
414 STM_MASK(0xffffffff << (32 * offset)));
420 struct DISPATCH<float, 4>
423 static float read(
float* addr, TxThread* thread)
426 union {
float v[2];
void* v2; } v;
427 void** a = (
void**)(((intptr_t)addr)&~7ul);
428 long offset = (((intptr_t)addr)>>2)&1;
429 v.v2 = thread->tmread(thread, a
430 STM_MASK(0xffffffff << (32 * offset)));
435 static void write(
float* addr,
float val, TxThread* thread)
438 union {
float v[2];
void* v2; } v;
439 void**a = (
void**)(((intptr_t)addr) & ~7ul);
440 int offset = (((intptr_t)addr)>>2) & 1;
442 v.v2 = thread->tmread(thread, a
443 STM_MASK(0xffffffff << (32 * offset)));
445 thread->tmwrite(thread, a, v.v2
446 STM_MASK(0xffffffff << (32 * offset)));
452 struct DISPATCH<const float, 4>
455 static float read(
const float* addr, TxThread* thread)
458 union {
float v[2];
void* v2; } v;
459 void** a = (
void**)(((intptr_t)addr)&~7ul);
460 long offset = (((intptr_t)addr)>>2)&1;
461 v.v2 = thread->tmread(thread, a
462 STM_MASK(0xffffffff << (32 * offset)));
467 static void write(
const float*,
float, TxThread*)
473 template <
typename T>
474 struct DISPATCH<T, 1>
477 static T
read(T* addr, TxThread* thread)
483 union {
char v[8];
void* v2; } v;
484 void** a = (
void**)(((
long)addr) & ~7);
485 long offset = ((long)addr) & 7;
486 v.v2 = thread->tmread(thread, a
487 STM_MASK(0xffffffff << (8 * offset)));
488 return (T)v.v[offset];
492 static void write(T* addr, T val, TxThread* thread)
496 union { T v[8];
void* v2; } v;
497 void** a = (
void**)(((
long)addr) & ~7);
498 long offset = ((long)addr) & 7;
500 v.v2 = thread->tmread(thread, a
501 STM_MASK(0xffffffff << (8 * offset)));
503 thread->tmwrite(thread, a, v.v2
504 STM_MASK(0xffffffff << (8 * offset)));
509 #error Cannot figure out the right dispatch mechanism
514 #endif // API_LIBRARY_INST_HPP__
static TM_INLINE void write(T *addr, T val, TxThread *thread)
Definition: library_inst.hpp:65
Definition: stm_fraser.c:61
static TM_INLINE T read(T *addr, TxThread *thread)
Definition: library_inst.hpp:56
Definition: my_thread.hpp:41
Definition: library_inst.hpp:49
Definition: library_inst.hpp:46
Definition: txthread.hpp:47
void NORETURN UNRECOVERABLE(const char *)
Definition: txthread.cpp:155
bool set_op int op_size set_t * l
Definition: stmskip.cc:240