ATRELM
tenstorrent_tt_isa)Tenstorrent Wormhole B0 & Blackhole A0
main
userTensix, Sync Unit, BlackholeA0, WormholeB0Summary
Atomically release a Tensix mutex held by the current thread. The thread should have previously used ATGETM to acquire the mutex.
Syntax / Encoding
TT_ATRELM(/* u16 */ Index)
Binary Encodings (1)
| Width | Format | Bit Pattern | Mask / Match |
|---|---|---|---|
| 32 | Tensix-32b | 10100001xxxxxxxxxxxxxxxxxxxxxxxx | 0xff000000 / 0xa1000000 |
Operands
| Name | Description |
|---|---|
Index |
Reference Notes
# `ATRELM` (Release a Tensix mutex)
**Summary:** Atomically release a Tensix mutex held by the current thread. The thread should have previously used [`ATGETM`](ATGETM.md) to acquire the mutex.
**Backend execution unit:** [Sync Unit](SyncUnit.md)
## Syntax
```c
TT_ATRELM(/* u16 */ Index)
```
## Encoding

## Functional model
This instruction will, if necessary, spend time waiting at the Wait Gate for a chance to release the mutex:
```c
if (Index == 1 || Index > 7) {
// No mutex has this index, so the instruction never leaves the Wait Gate and the thread hangs.
UndefinedBehavior();
}
// Maybe wait for a cycle or two. These waits can happen if other threads
// are also trying to either acquire or release the mutex in question.
if (maybe) wait;
if (maybe) wait;
```
Once the wait is complete, if the current thread already holds the mutex, it proceeds to release it:
```c
if (Mutex[Index].HeldBy == CurrentThread) {
Mutex[Index].HeldBy = Nobody;
} else {
NonContractualBehavior {
// Current silicon completes the instruction and changes no state (not architecturally guaranteed)
}
}
```
If a mutex is released by thread `i`, and _both_ of the other threads are trying to acquire it using [`ATGETM`](ATGETM.md), then thread `(i + 1) % 3` is always chosen to be the acquirer. This ensures round-robin fairness when all threads are trying to acquire the same mutex.