void tabort6 (int *mem) { /* Here global + 255 gets reloaded into a reg. Better would be to just reload global or *mem and get the +255 for free as address arithmetic. */ __builtin_tabort (*mem + 255); }
foo (v4si a) { a += (v4si){ 1, 1, 1, 1 }; if (__builtin_tbegin (0) == 0) { a += (v4si){ 1, 1, 1, 1 }; __builtin_tabort (256); __builtin_tend (); } else a -= (v4si){ 1, 1, 1, 1 }; return a; }
int main (void) { #ifdef HAS_ISA_2_07 /* Just get the compiler to generate each of the TM instructions * so we can verify that valgrind recognizes them. * For now, only the tbegin instruction does anything in valgrind. * The rest are just treated as NOPS. */ __builtin_tabort (0); __builtin_tabortdc (0,0,0); __builtin_tabortdci (0,0,0); __builtin_tabortwc (0,0,0); __builtin_tabortwci (0,0,0); __builtin_tbegin (0); __builtin_tend (0); // __builtin_tcheck (0); tcheck not recognized by compiler __builtin_trechkpt (); // not recognized by early HW __builtin_treclaim (0); // not recognized by early HW __builtin_tsr (0); #endif return 0; }
int __lll_trylock_elision (int *futex, short *adapt_count) { __asm__ volatile (".machinemode \"zarch_nohighgprs\"\n\t" ".machine \"all\"" : : : "memory"); /* Implement POSIX semantics by forbiding nesting elided trylocks. Sorry. After the abort the code is re-executed non transactional and if the lock was already locked return an error. */ if (__builtin_tx_nesting_depth () > 0) { /* Note that this abort may terminate an outermost transaction that was created outside glibc. This persistently aborts the current transactions to force them to use the default lock instead of retrying transactions until their try_tbegin is zero. */ __builtin_tabort (_HTM_FIRST_USER_ABORT_CODE | 1); } /* Only try a transaction if it's worth it. */ if (*adapt_count <= 0) { unsigned status; if (__builtin_expect ((status = __builtin_tbegin ((void *)0)) == _HTM_TBEGIN_STARTED, 1)) { if (*futex == 0) return 0; /* Lock was busy. Fall back to normal locking. */ /* Since we are in a non-nested transaction there is no need to abort, which is expensive. */ __builtin_tend (); /* Note: Changing the adapt_count here might abort a transaction on a different cpu, but that could happen anyway when the futex is acquired, so there's no need to check the nesting depth here. */ if (aconf.skip_lock_busy > 0) *adapt_count = aconf.skip_lock_busy; } else { if (status != _HTM_TBEGIN_TRANSIENT) { /* A persistent abort (cc 1 or 3) indicates that a retry is probably futile. Use the normal locking now and for the next couple of calls. Be careful to avoid writing to the lock. */ if (aconf.skip_trylock_internal_abort > 0) *adapt_count = aconf.skip_trylock_internal_abort; } } /* Could do some retries here. */ } else { /* Lost updates are possible, but harmless. Due to races this might lead to *adapt_count becoming less than zero. */ (*adapt_count)--; } return lll_trylock (*futex); }
int foo (void) { return __builtin_tabort (10); }
void tabort8 () { __builtin_tabort (-1); }
void tabort7 () { __builtin_tabort (global + 255); }
void tabort5 () { __builtin_tabort (global); }
void tabort4 (int *mem) { __builtin_tabort (*mem); }
void tabort3 (int reg) { /* { dg-final { scan-assembler-times "tabort\t255" 1 } } */ __builtin_tabort (reg + 255); }
void tabort2 (int reg) { __builtin_tabort (reg); }
void tabort1 () { __builtin_tabort (256); }