RTL
The coordinate primitive in RTL: decode, compose, and distance
1 Decoder definition
The decoder is a pure combinational function over one 16-bit input. Given a code point in [U+AC00, U+D7A3], it produces the three structural axes:
\[offset = code - \text{U+AC00}, \qquad i = offset / 588, \qquad m = (offset \bmod 588) / 28, \qquad f = offset \bmod 28\]
with \(i\) in [0, 18], \(m\) in [0, 20], and \(f\) in [0, 27]. The formula also fixes the order of the codes: the stride of each axis is at least the span of the next, so code order is the axis order, and a range that fixes a prefix of the axes is a contiguous run of codes. That is a property of the definition rather than of any realization, and the memory document builds on it. There are no registers, so the latency is exactly one cycle by construction. Inputs below U+AC00 underflow and are outside the valid domain; inputs in U+D7A4..U+D7AF are structurally invalid filler positions.
2 Division structure
The constant divisions dominate the critical path. Two implementations of the same arithmetic were measured:
| Structure | Implementation | Depth |
|---|---|---|
| Shift-subtract (naive) | Yosys techmap long division | 72 logic levels |
| Multiply-shift (current) | (q4 * 9363) >> 16 for /28, (j * 781) >> 14 for /21 |
33 logic levels |
The multiply-shift constants are exact over the valid domain: division by 28 becomes division by 7 on q4 = offset >> 2 (28 = 4 x 7, q4 at most 2792), and division by 21 applies to j at most 398. Both structures are functionally identical, which the verification pipeline proves rather than assumes.
3 Streaming structure
The decoder above is one combinational unit, so it costs the whole multiply chain per code point. tagma_decoder_pipe keeps the arithmetic and splits it at the constant multiplies, one large multiply per stage, with the two small constants as shift-and-add trees in the last stage.
| Stage | Work |
|---|---|
| 0 | offset = code - 0xAC00 |
| 1 | j = (q4 * 9363) >> 16 |
| 2 | i = (j * 781) >> 14 |
| 3 | m = j - 21 * i, f = offset - 28 * j |
9363 and 781 have no shift-and-add form, so they keep a multiplier each. 21 = 16 + 4 + 1 and 28 = 32 - 4 do, so the last stage is adders. The last stage writes f as offset - 28 * j rather than 4 * (q4 - 7 * j) + r2; the two are equal modulo 2^14, so the low five bits agree on every 16-bit input and not only inside the valid range. Latency is four clocks, throughput is one code point per clock, and the simulation compares the pipeline against the combinational unit at every cycle, which carries the anchors above over to it. Device measurements are in the FPGA document.
4 Compose and distance
The decoder maps an index to the three axes. The primitive needs the inverse and a metric as well, and both are small combinational units in the same tree:
| Unit | Operation | Structure |
|---|---|---|
tagma_compose |
axes to index, the inverse of the decode | two constant multiplies, one validity bound per axis |
tagma_dist |
field-wise absolute difference of two code points | two tagma_decoder cores and three subtractors |
tagma_compose is the decoder read backwards: the same 588 and 28 constants appear as multipliers instead of divisors, and an out-of-range axis triple is reported as valid = 0 with index = 0. tagma_dist decodes each operand with the same core as the standalone decoder, so the two share one decode definition, and returns the three per-axis distances separately, matching Coord::hamming_distance on every valid pair.
5 Cost
The reports in the tree give what each unit costs, so “small” is a measurement rather than a description. Mapped to one library of seven two-input cells, the three units are comparable (synth/yosys/reports/gates_stat.txt, compose_gates_stat.txt, dist_gates_stat.txt):
| Unit | Two-input cells | What it is |
|---|---|---|
tagma_decoder |
588 | the decode |
tagma_compose |
258 | the inverse |
tagma_dist |
1,329 | two decoders and three subtractors |
Before a gate library is chosen the decoder is 478 Yosys cells (generic_stat.json). The gate-library count is higher because that library has no multiplexer and no compound gate, so each of them expands into several two-input cells.
The decoder in a named technology: 201 LUT4 and 41 carry cells on the iCE40 part (ice40_stat.txt), and 388 standard cells covering 2,826 µm² in SkyWater 130 nm high density (sky130_decoder_stat.txt). The sky130 figure carries no sequential elements, which is the definition: the arithmetic is combinational. The block that went through place and route is the registered demo top, the decoder with its three output registers and the validity flag: 410 logic and register cells in 1,920 placed instances, the rest fill and tap, covering 4,430 µm² at 34% utilization. The routed netlist with extracted parasitics reports a worst setup slack of +72.77 ns and a total negative slack of 0.00 at the 12 MHz constraint, with 57.8 µW at the tool’s default input activity and 36.6 µW at one code point per clock, about 3.0 pJ per decode; the absolute power figure is provisional.
Three conditions belong with these numbers. They are one synthesis of one RTL revision, so a different library or a different clock changes them. The 12 MHz constraint is the demonstration board’s clock, and the flow had 72.77 ns of slack left at it, so the area is what that constraint produced rather than the smallest area at which the logic closes. Device measurements, including the pipeline’s register-to-register rate, are in the FPGA document.
The flow’s final GDS is drawn below in monochrome on white, so it holds in print:
met1 through met5, with the power grid the darkest element.
met1 through met3, the signal routing alone.
6 Verification pipeline
The pipeline has a single source of truth: tagma_core in Rust, the reference implementation of the primitive. Every hardware artifact is checked against it. The pipeline is shown in Figure Figure 3.
The components:
| Component | Role |
|---|---|
golden_export.rs |
Exports all 11,172 (offset, i, m, f) vectors from Coord::to_axes into golden_anchors.hex, one packed 29-bit value per line |
| Formula simulation | Recomputes the formula in the testbench and compares the RTL against it |
| Golden simulation | Reads the anchor file and checks the RTL against the Rust reference |
| Gate-level simulation | Runs the synthesized netlist against the same anchor file |
| Formal equivalence | Proves the RTL and the netlist identical over all 2^16 inputs with equiv_simple and equiv_induct |
| Compose and distance channels | Formula and golden simulation for tagma_compose and tagma_dist, plus the same gate-level and equivalence checks |
| Consistency gate | Python check that validates the generated anchor file against the decomposition contract |
7 Results
| Check | Result |
|---|---|
| Exhaustive RTL simulation (formula mode) | PASS: all 11,172 code points |
| Golden anchors (Rust reference mode) | PASS: all 11,172 |
| Gate-level netlist simulation | PASS: all 11,172 |
| Formal equivalence RTL vs netlist | proven, 50 cells, all 2^16 inputs |
| Compose (formula mode) | PASS: all 32,768 axis combinations |
| Compose (golden mode) | PASS: all 11,172 |
| Distance (formula mode) | PASS: 3 x 11,172 over varying operands and both orders |
| Distance (golden mode) | PASS: 3 x 11,172 over varying operands and both orders |
| Compose RTL vs netlist | proven, all 2^15 axis combinations |
| Distance RTL vs netlist | proven, all 2^32 input pairs |
| Streaming pipeline | PASS: 44,689 emitted triples over 4 full sweeps, compared against the combinational unit at every cycle |
The exhaustive tests also found the boundary correction: the last valid code point is U+D7A3, not U+D7AF. The testbench boundary was wrong initially and the failure surfaced only because the full space was enumerated.