ISARef Multi-ISA & Silicon Reference
45,419 ISA items · 105,907 timings · 913 microarchs · 15,555 chips · 105 sources
Arch:
Tier:

SEMINIT

T1 tenstorrent alu insn
SEMINIT (Set the Value and Max of some semaphores)
SourceTenstorrent Official Tensix ISA Documentation (Wormhole & Blackhole) (tenstorrent_tt_isa)
Reliability TierT1 — Official Specification
ISA / Silicon ScopeBlackholeA0 / WormholeB0
Tenstorrent Wormhole B0 & Blackhole A0
License & VersionApache-2.0
main
Upstreamhttps://github.com/tenstorrent/tt-isa-documentation
Privilegeuser
ExtensionsTensix, Sync Unit, BlackholeA0, WormholeB0
Note: If the programmer intent is for the semaphore manipulation to happen after some earlier Tensix instruction has _finished_ execution, it may be necessary to insert a STALLWAIT instruction (with block bit B1) somewhere between that earlier instruction and the SEMINIT instruction. If the issuing thread's most recent…

Summary

Various semaphores are selected using a bitmask, and the selected semaphores have their Value and Max set to the provided values. Max is subsequently used by SEMWAIT, and software should not SEMPOST a semaphore whose Value is at or above its Max (current hardware ignores Max in SEMPOST; this is a NonContractualBehavior). Software should also not set a Value above the Max (current hardware stores both as given; this…

Syntax / Encoding

TT_SEMINIT(/* u4 */ NewMax, /* u4 */ NewValue, /* u8 */ SemaphoreMask)

Binary Encodings (1)

WidthFormatBit PatternMask / Match
32Tensix-32b10100011xxxxxxxxxxxxxxxxxxxxxxxx0xff000000 / 0xa3000000

Operands

NameDescription
NewMax
NewValue
SemaphoreMask

Reference Notes

# `SEMINIT` (Set the `Value` and `Max` of some semaphores)

**Summary:** Various semaphores are selected using a bitmask, and the selected semaphores have their `Value` and `Max` set to the provided values. `Max` is subsequently used by [`SEMWAIT`](SEMWAIT.md), and software should not [`SEMPOST`](SEMPOST.md) a semaphore whose `Value` is at or above its `Max` (current hardware ignores `Max` in `SEMPOST`; this is a `NonContractualBehavior`). Software should also not set a `Value` above the `Max` (current hardware stores both as given; this is a `NonContractualBehavior`).

**Backend execution unit:** [Sync Unit](SyncUnit.md)

## Syntax

```c
TT_SEMINIT(/* u4 */ NewMax, /* u4 */ NewValue, /* u8 */ SemaphoreMask)
```

## Encoding

![](../../../Diagrams/Out/Bits32_SEMINIT.svg)

## Functional model

```c
atomic {
  for (unsigned i = 0; i < 8; ++i) {
    if (SemaphoreMask.Bit[i]) {
      if (NewValue > NewMax) {
        NonContractualBehavior {
          // Current silicon stores both as given, as below (not architecturally guaranteed)
        }
      }
      Semaphores[i].Value = NewValue;
      Semaphores[i].Max = NewMax;
    }
  }
}
```

## Instruction scheduling

If the programmer intent is for the semaphore manipulation to happen after some earlier Tensix instruction has _finished_ execution, it may be necessary to insert a [`STALLWAIT`](STALLWAIT.md) instruction (with block bit B1) somewhere between that earlier instruction and the `SEMINIT` instruction.

If the issuing thread's most recent [`SEMWAIT`](SEMWAIT.md) selects a semaphore that this instruction changes, its block mask does not include B1, and no instruction blocked by that mask has been issued by the thread since, then the `SEMWAIT` might still be latched when this instruction executes, and whether it is depends on timing, but the outcome does not, and is NonContractualBehavior: the `SEMWAIT` is evaluated against the semaphores as they were before this instruction, and is forgotten if that evaluation finds its conditions met, else stays latched and sees this instruction's change, as executing the two in program order would (what other threads and RISCV cores do to the semaphores in between still matters, as for any `SEMWAIT`). Software should not rely on this: include B1 in the `SEMWAIT`'s block mask.