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 (struct __htm_tdb* tdb, int reg, int *mem, uint64_t *mem64) { int cc; int n; __builtin_tbegin ((void *)0); __builtin_tbegin ((void *)-99999); __builtin_tbegin ((void *)99999); while (__builtin_tbegin ((void *)0) != 0) { } cc = __builtin_tbegin ((void *)0x12345678); cc = __builtin_tbegin (tdb); cc = __builtin_tbegin (&global_tdb); cc = __builtin_tbegin ((void *)(long long)(reg + 0x12345678)); cc = __builtin_tbegin ((void *)(long long)(reg)); __builtin_tbegin_nofloat ((void *)0); __builtin_tbegin_nofloat ((void *)-99999); __builtin_tbegin_nofloat ((void *)99999); cc = __builtin_tbegin_nofloat ((void *)0x12345678); cc = __builtin_tbegin_nofloat (tdb); cc = __builtin_tbegin_nofloat (&global_tdb); cc = __builtin_tbegin_nofloat ((void *)(long long)(reg + 0x12345678)); cc = __builtin_tbegin_nofloat ((void *)(long long)(reg)); __builtin_tbegin_retry ((void *)0, 0); cc = __builtin_tbegin_retry ((void *)0, 1); cc = __builtin_tbegin_retry ((void *)0, -1); cc = __builtin_tbegin_retry ((void *)0, 42); cc = __builtin_tbegin_retry ((void *)0, reg); cc = __builtin_tbegin_retry ((void *)0, *mem); cc = __builtin_tbegin_retry ((void *)0, global); cc = __builtin_tbegin_retry (tdb, 42); cc = __builtin_tbegin_retry (&global_tdb, 42); cc = __builtin_tbegin_retry ((void *)0x12345678, global); cc = __builtin_tbegin_retry ( (void *)(long long) (reg + 0x12345678), global + 1); cc = __builtin_tbegin_retry ( (void *)(long long)(reg), global - 1); __builtin_tbegin_retry_nofloat ((void *)0, 0); cc = __builtin_tbegin_retry_nofloat ((void *)0, 1); cc = __builtin_tbegin_retry_nofloat ((void *)0, -1); cc = __builtin_tbegin_retry_nofloat ((void *)0, 42); cc = __builtin_tbegin_retry_nofloat ((void *)0, reg); cc = __builtin_tbegin_retry_nofloat ((void *)0, *mem); cc = __builtin_tbegin_retry_nofloat ((void *)0, global); cc = __builtin_tbegin_retry_nofloat (tdb, 42); cc = __builtin_tbegin_retry_nofloat (&global_tdb, 42); cc = __builtin_tbegin_retry_nofloat ((void *)0x12345678, global); cc = __builtin_tbegin_retry_nofloat ( (void *)(long long) (reg + 0x12345678), global + 1); cc = __builtin_tbegin_retry_nofloat ( (void *)(long long)(reg), global - 1); __builtin_tbeginc (); __builtin_tx_nesting_depth (); n = __builtin_tx_nesting_depth (); __builtin_non_tx_store (mem64, 0); { const uint64_t val_var = 0x1122334455667788; __builtin_non_tx_store (mem64, val_var); } __builtin_non_tx_store (mem64, (uint64_t)reg); __builtin_non_tx_store (mem64, g); __builtin_non_tx_store ((uint64_t *)0, 0); __builtin_non_tx_store ((uint64_t *)0x12345678, 0); __builtin_non_tx_store (&g, 23); __builtin_non_tx_store (&g, reg); __builtin_non_tx_store (&g, *mem); __builtin_non_tx_store (&g, global); __builtin_tend(); __builtin_tx_assist (0); __builtin_tx_assist (1); __builtin_tx_assist (reg); __builtin_tx_assist (*mem); __builtin_tx_assist (global); }