You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file sketches how the new helpers (TBRANCH/TMUX/TMAJ/TNET, etc.) might be encoded in a future ternary ISA that favors tryte-aligned opcodes and asynchronous control.
4
+
5
+
## Tryte-friendly Opcode Layout
6
+
7
+
Balanced ternary instructions can pack more information per opcode than binary. A 6-trit “tryte” can be divided into:
8
+
9
+
-**2 trits**: data width tag
10
+
-**2 trits**: instruction family (e.g., logic, control, neural)
11
+
-**2 trits**: immediate flags / predicate bits
12
+
13
+
For example, TBRANCH and TMUX can share the same family slot (control) but use different predicate bits to indicate whether the instruction targets code or data. This layout keeps the decoder simple and lets the hardware dispatch a full control triple in one cycle.
14
+
15
+
| Tryte Field | Value (balanced ternary) | Meaning |
A `TBRANCH` instruction can carry three relative offsets/labels plus a flag that enables speculative dispatch, while `TMUX` uses the same control bits to choose among data paths.
22
+
23
+
## Async Control Handshake
24
+
25
+
Following Setun’s clockless transitions, the ternary branch path can be modeled as a handshake:
26
+
27
+
1. A ternary condition trit is produced by the comparison logic.
28
+
2. The arbiter observes the trit and activates one of three ready signals (negative/zero/positive).
29
+
3. The pipeline selects the matching target tag (one of the triple encoded next to the opcode).
30
+
4. Speculative bits indicate whether the branch outcome should be confirmed in a later cycle or aborted.
31
+
32
+
Because ternary conditions expose sign symmetry, `TSIGNJMP`/`TMUX` can reuse the same handshake: the runtime helper returns the chosen target (or data lane) immediately, and an arbiter verifies the trit feeds through to the next cycle before committing.
33
+
34
+
## TNN-Ready Units
35
+
36
+
Vectorized primitives such as `TMAJ` and `TNET` benefit from this encoding because they can receive their operand tag, width, and mask in a single tryte. For example, a `TNET` instruction on a 128-trit register might set the width field to `+1`, the family to `+1` (neural), and use the flags to toggle “fold-over” behavior for training-aware rounding.
37
+
38
+
These sketches guide future ASIC/FPGA work; the runtime helpers and skeleton demos mirror the same semantics in software.
Copy file name to clipboardExpand all lines: MASTER_ISA.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,6 +116,7 @@ focuses on instructions whose semantics *literally require* a three-valued persp
116
116
- Tryte-friendly opcodes: reserve 6 trits per slot (e.g., 2 trits for vector width, 2 trits for the instruction family, 2 trits for immediates/flags). Instructions such as `TBRANCH`, `TMAJ`, and `TMULADD` can live in a single tryte with built-in width tags so the hardware decoder can dispatch without binary prefix tables.
117
117
- Async branch support: follow Setun’s clockless transitions by treating `TBRANCH`/`TSIGNJMP` as micro-instructions that grab a condition trit and target triple simultaneously, avoiding the binary flag expansion. Documenting this early helps map the runtime helpers to future hardware that may signal targets through a branch arbiter rather than the normal program counter updates.
118
118
- Async control handshake: model hardware such that the condition feed (ternary condition register) produces one of three ready signals, and an arbiter selects the matching target label/offset in the same cycle. `TBRANCH` should therefore expose a triple-target field plus a flag that indicates whether the jump is speculative; software helpers can mirror that by returning the chosen target value so forward progress can be verified even before hardware support arrives.
119
+
- For a concrete tryte encoding, see `ENCODING.md`, which lays out the 6-trit fields for family/tag/flags (including how TBRANCH/TMUX/TMAJ/TNET slot into those fields) and explains how the async arbiter consumes the flag field as a readiness handshake.
119
120
120
121
## Next steps
121
122
@@ -124,3 +125,7 @@ focuses on instructions whose semantics *literally require* a three-valued persp
124
125
2. Choose a canonical helper prefix (`__ternary` by default) and append the new operations to that ABI.
125
126
3. Prototype the quantization/branch helpers in `runtime_skeleton/` so plugin tests can depend on them.
126
127
4. Sketch hardware encodings (tryte/6-trit opcodes) once the semantics settle.
128
+
5. Expand t128/runtime coverage (and tests) so the helper list scales beyond t64 and the TMUX/TNET paths used in the skeleton can be verified on larger registers (**Completed**).
129
+
- The reference runtime now defines all t128 helpers (including TMUX/TNET/TEQUIV/TXOR) via `_BitInt(256)` encode/decode helpers and exposes them through `include/ternary_runtime.h`.
130
+
- The runtime skeleton mirrors the same helpers so the minimal implementation delivers the ISA contracts and the TMUX/TNET demo can run across t128 lanes.
131
+
- Focused tests (`tests/test_logic_helpers.c`, `runtime_skeleton/test_runtime_skeleton.c`) cover the t128 helpers and `tools/check_helper_docs.py` keeps documentation in lockstep.
For a minimal out-of-line runtime, use the reference implementation in `runtime/ternary_runtime.c`
202
206
with the public header `include/ternary_runtime.h`. It implements the same packed 2-bit-trit
203
-
semantics as the helpers (t32/t64) and is intended as a starting point for a real ISA-backed
204
-
library. Packed helpers for t128 are not provided in this reference runtime.
207
+
semantics as the helpers (t32/t64) and now surfaces the t128 helpers when `_BitInt(256)`
208
+
support exists so ISA-backed runtimes can prototype on the wider register set.
205
209
206
210
Example build:
207
211
@@ -261,6 +265,17 @@ make test CXX=g++-15 CC=gcc-15
261
265
262
266
`make test` now also compiles `tests/test_literals.c` (ensuring literal helpers + promotions compile) and `test_ternary.c` with `-fplugin-arg-ternary_plugin-dump-gimple` so Phase 3 coverage exercises the dump/trace flags.
263
267
268
+
### Extended helper ABI
269
+
270
+
In addition to the core helper ABI described in `SPECIFICATION.md`, the roadmap now exposes the ternary-only helpers used by the TMUX/TNET/TNN demo and the runtime/reference implementations:
These helpers are exercised by the runtime skeleton demo (`runtime_skeleton/run_tnn_demo.sh`), which now builds and runs a tiny ternary neural network pipeline across t32/t64/t128 helper implementations and TMUX-driven routing logic.
278
+
264
279
## Description
265
280
266
281
This plugin analyzes ternary conditional expressions in the code and can optionally
@@ -304,7 +319,27 @@ For helpers that literally need three-valued semantics (TMIN/TMAX, TIMPL/TLIMP,
304
319
TMAJ, TQUANT, and the TNOT/TINV aliases), see `MASTER_ISA.md`. It documents how
305
320
these instructions propagate “unknown” trits, when to use TINV as an inference
306
321
alias, and the extended control-flow helpers (TBRANCH/TSIGNJMP) you can expose
307
-
through `__ternary_*` before hardware encodings are sketched.
322
+
through `__ternary_*` before hardware encodings are sketched (see `ENCODING.md`
0 commit comments