BP decoder

StaticTannerCore is the shared fixed-graph min-sum network. VanillaBpDecoder adds its autonomous early-terminating controller.

Static Tanner network

TannerGraph.fromRows builds the graph from the nonzero column indices of each parity-check row. TannerNodeGraphs.from derives local CNU and VNU ports from its stable, row-major edge identifiers. Rows are sorted by variable index; duplicate or out-of-range entries, empty checks, and unused variables are rejected. The graph representation permits degree-one checks, but StaticTannerCore requires every check to have degree at least two. Variable degree one is valid.

StaticTannerCore instantiates:

  • one StaticCheckStage for each parity check;

  • one StaticVariableStage for each variable;

  • one fixed connection for every graph edge; and

  • one combinational ConvergenceChecker for \(H\hat{\mathbf e} + \boldsymbol\sigma\) over \(\mathrm{GF}(2)\).

An accepted load stores the syndrome and unsigned quantized priors \(\lambda_j\). StaticVariableStage initializes \(M_j=\lambda_j\), \(R_{i,j}=+\lambda_j\), and \(\hat e_j=0\).

An accepted step starts one iteration. All check stages update on the first clock and all variable stages commit on the second. The immediate commit view is used by autonomous controllers; StaticTannerDatapath exposes the registered result view. The phase enables and fixed edge wires are constructed by StaticTannerCore; there is no row-by-row runtime schedule.

From messages to RTL

Check \(i\) and variable \(j\) exchange \(R_{i,j}\) (variable to check) and \(\sigma_{i,j}\) (check to variable). The measured syndrome is \(\boldsymbol\sigma\); \(\mathcal N(i)\) and \(\mathcal N(j)\) denote the neighbors of the indicated node. The QEC background introduces these messages. Here the equations describe the quantized hardware values; the links beside them identify their production implementation.

CNU: shared parity and minima

CNU sign and magnitude paths share a parity reduction and two minima; a result register stores the pair and per-edge sign and selector.

One check’s combinational arithmetic and its static-stage register. The diagram shows one representative edge’s sign and selector; those fields exist for every neighbor. The scaled minimum pair is shared.

Suppress iteration labels within one update. Canonical input signs and the syndrome-adjusted shared parity are

\[b_{i,j}=[R_{i,j}<0],\qquad P_i=\boldsymbol\sigma_i\oplus\bigoplus_{j\in\mathcal N(i)}b_{i,j},\qquad s_{i,j}=P_i\oplus b_{i,j}.\]

Arithmetic.hardDecision canonicalizes input signs, and CheckNode.parity forms the shared XOR. CheckNode.result.edges then XORs each recipient’s sign out of that parity.

Let \(a_{i,1}\le a_{i,2}\) be the two smallest input magnitudes with multiplicity. The CNU scales the pair once and compares each input against the raw first minimum:

\[m_{i,k}=g_t(a_{i,k}),\quad k\in\{1,2\},\qquad c_{i,j}=[|R_{i,j}|=a_{i,1}].\]

TwoMinLogic.apply computes the pair. CheckNode scales it once and assigns the per-edge useSecond comparison.

The VNU reconstructs the exclusive check message using that selector:

\[\begin{split}\sigma_{i,j}=(-1)^{s_{i,j}} \begin{cases} m_{i,2},&c_{i,j}=1,\\ m_{i,1},&c_{i,j}=0. \end{cases}\end{split}\]

VariableLogic.apply selects the magnitude and Arithmetic.fromSignMag interprets its sign. Duplicate minima remain valid: \((2,2,5)\) produces \((2,2)\), so both tied edges can select the second value. A zero magnitude is numerically zero regardless of its metadata sign.

CheckResult stores one MinPair and a vector of EdgeMeta(sign, useSecond): \(2w_m+2d_c\) result bits for check degree \(d_c\), excluding the stored syndrome. CheckMessage is the VNU-side wire view of that pair and one edge’s metadata; it does not imply a separately registered pair on each edge. The static core requires \(d_c\geq2\).

Available scaling policies are:

  • NoScale: preserve the magnitude;

  • VallsScale(a, b): (x >> a) + (x >> b), clipped to the magnitude width;

  • RampScale(maxShift): x - (x >> u) for controls through maxShift, then x.

Arithmetic.scale implements these policies. For RampScale(k), the exact control-dependent rule is

\[\begin{split}g_u(a)=\begin{cases} a-\lfloor a/2^u\rfloor,&0\leq u\leq k,\\ a,&u>k. \end{cases}\end{split}\]

This subtracts a truncated shifted value; it does not round the complete real-valued product downward. The autonomous VanillaBpDecoder and RelayBpDecoder start local iteration \(t\) at one and supply \(u=\min(t,2^{w_u}-1)\). RampScale.controlBits defines \(w_u\); the maintained default is RampScale(4). The manual datapath takes \(u\) directly from step.bits. In particular, \(u=0\) sets both scaled minima to zero; autonomous controllers begin at \(u=1\).

VNU: one total, three outputs

The VNU selects and signs incoming CNU magnitudes, adds them to the bias, and sends the full total to subtraction, saturation, and hard-decision branches.

The full-width total feeds every output branch. Per-edge subtraction bypasses the stored marginal’s saturation. The drawing shows an ordinary iteration; at a Relay leg transition the edge-message register instead reloads the prior, as described below.

Where the RTL contract differs from ideal arithmetic

VariableLogic.apply reconstructs signed check messages, adds the bias, and reuses one total for the marginal, hard decision, and every outgoing extrinsic message:

(1)\[\begin{split}\begin{aligned} T_j&=B_j+\sum_{i\in\mathcal N(j)}\sigma_{i,j},\\ M_j&=\operatorname{sat}_{w_a}(T_j),\qquad \hat e_j=[T_j<0],\\ R_{i,j}&=\operatorname{pack}_{w_m}(T_j-\sigma_{i,j}). \end{aligned}\end{split}\]

Here \(T_j\) is the full working-width sum and \(M_j\) the stored signed marginal. Arithmetic.clipSigned implements sat on \([-2^{w_a-1},2^{w_a-1}-1]\); Arithmetic.toSignMag implements pack, clipping magnitude to \(2^{w_m}-1\) and canonicalizing zero. Subtraction and decision occur before clipping the stored marginal. Arithmetic.hardDecision selects zero for \(T_j=0\).

Arithmetic.sum uses a balanced tree padded to \(w_a+\max(1,\operatorname{bitlength}(|\mathcal N(j)|))\) bits, as derived by VariableConfig.workBits. Quantization requires \(w_a\geq w_m+1\). A bias lies in the signed \(w_a\)-bit range, while each check message has magnitude at most \(2^{w_m}-1\). These bounds fit both the working sum and the subsequent recipient subtraction without arithmetic wrap.

Vanilla drives \(B_j\) from the immutable prior; Relay computes \(B_j\) from the prior and the previous stored marginal. StaticVariableStage connects this bias to the leaf port named VariableNode.prior; that port is the current bias, not necessarily the immutable frame prior.

On a normal VNU commit, the stage stores all three calculated outputs. When Relay asserts restartMessages at a leg boundary, StaticVariableStage still stores the newly calculated \(M_j\) and \(\hat e_j\), but stores \(R_{i,j}=+\lambda_j\) for the next leg instead of the calculated extrinsic message. The immutable prior is not reloaded from the external input at that boundary.

Clock and initialization boundaries

The arithmetic leaves are combinational RawModules. StaticCheckStage stores the syndrome on load and the CNU result on step.fire. StaticVariableStage commits the next marginal, decision, and edge messages on the following VNU phase, subject to the Relay restart override above. The autonomous controllers first test convergence after a completed iteration, including when the loaded syndrome is zero.

For the manually stepped StaticTannerDatapath, load and step use ready/valid handshakes. Before the first accepted load, step.ready is false. A pending load.valid has priority over a step; neither request can be accepted during the VNU phase. Its result is a one-cycle Valid pulse, with no ready signal or output backpressure. Consumers must sample the registered snapshot while result.valid is high.

StaticTannerCore.commit uses the combinational next VNU decisions for convergence on the VNU phase; result exposes the registered snapshot afterward. The two-clock schedule describes decoder computation, not input/output transport latency or an achieved FPGA clock frequency.

For the published CNU and VNU datapath schematics, see Maurer et al., Sec. 4.1, Fig. 3(a–b). The diagrams above make the current chipsLDPC bundle and register boundaries explicit; the linked Scala sources define their implemented behavior.

Autonomous vanilla BP

VanillaBpConfig requires a positive iteration limit and fixes the graph, quantization, and check scaling. RelayDefaults.q supplies four magnitude bits and seven signed marginal bits; RelayDefaults.scale supplies the default ramp policy.

VanillaBpDecoder accepts StaticDecoderInput through io.in. It runs until the residual is zero or the frame limit is reached, then holds a BpDecoderResult on io.out until accepted. The result contains:

  • success and correction bits;

  • final signed marginals and residual;

  • completed iterations; and

  • legsExecuted = 1 and solutionsFound equal to the success flag.

When runtimeIterationLimit is elaborated, the optional limit port may select any positive prefix of the configured capacity; it is sampled on io.in.fire. For \(N\) completed iterations, io.out.valid first becomes high immediately after the \(2N\)th rising clock edge following the accepted input edge. This excludes the edge that accepts the result through io.out.fire. Output backpressure extends interface latency but does not alter the reported iteration count. A new input cannot be accepted until the current output has been accepted and the controller has returned to its idle state.

Inspect and test

./scripts/emit.sh static-steane
./scripts/emit.sh vanilla-steane
./mill chipsLDPC.test.testOnly chipsldpc.TwoMinSpec chipsldpc.CheckNodeSpec chipsldpc.VariableNodeSpec
./mill chipsLDPC.test.testOnly chipsldpc.StaticTannerDatapathSpec
./mill chipsLDPC.test.testOnly chipsldpc.BpDecodersSpec

The maintained large experiment is in examples/BivariateBicycle144BpOnly/. Relay control is described in Relay BP.