src/test/scala/chipsldpc/StaticTannerDatapathSpec.scala

Source from the repository checkout used to build these docs. Line numbers link to individual source lines.

 1package chipsldpc
 2
 3import chisel3._
 4import chisel3.simulator.scalatest.ChiselSim
 5import chipsldpc.graph.{TannerGraph, TannerNodeGraphs}
 6import org.scalatest.freespec.AnyFreeSpec
 7
 8final class StaticTannerDatapathSpec extends AnyFreeSpec with ChiselSim {
 9  private val graph = TannerGraph.fromRows(
10    7,
11    Seq(Seq(3, 4, 5, 6), Seq(1, 2, 5, 6), Seq(0, 2, 4, 6)),
12  )
13  private val nodes = TannerNodeGraphs.from(graph)
14  private val q = RelayDefaults.q
15  private val priors = Vector(1, 2, 3, 4, 5, 6, 7)
16
17  private def load(
18      dut: StaticTannerDatapath,
19      syndrome: Seq[Boolean],
20  ): Reference.DecoderState = {
21    syndrome.zipWithIndex.foreach { case (bit, i) => dut.io.load.bits.syndrome(i).poke(bit.B) }
22    priors.zipWithIndex.foreach { case (prior, i) => dut.io.load.bits.prior(i).poke(prior.U) }
23    dut.io.load.valid.poke(true.B)
24    dut.io.load.ready.expect(true.B)
25    dut.clock.step()
26    dut.io.load.valid.poke(false.B)
27    dut.io.result.valid.expect(false.B)
28    Reference.initialize(nodes, priors, q)
29  }
30
31  private def step(
32      dut: StaticTannerDatapath,
33      iteration: Int,
34      expected: Reference.DecoderState,
35      syndrome: Seq[Boolean],
36  ): Unit = {
37    dut.io.step.bits.poke(iteration.U)
38    dut.io.step.valid.poke(true.B)
39    dut.io.step.ready.expect(true.B)
40    dut.clock.step()
41    dut.io.step.valid.poke(false.B)
42    dut.io.result.valid.expect(false.B)
43    dut.clock.step()
44    dut.io.result.valid.expect(true.B)
45
46    expected.marginal.zipWithIndex.foreach { case (value, i) =>
47      dut.io.result.bits.marginal(i).expect(value.S)
48      dut.io.result.bits.decision(i).expect(expected.decision(i).B)
49    }
50    val residual = Reference.residual(nodes, expected, syndrome)
51    residual.zipWithIndex.foreach { case (bit, i) => dut.io.result.bits.residual(i).expect(bit.B) }
52    dut.io.result.bits.converged.expect((!residual.contains(true)).B)
53  }
54
55  "the reference model initializes each edge from its variable prior" in {
56    val state = Reference.initialize(nodes, priors, q)
57    assert(state.v2c == graph.edges.map(edge => Reference.SignMag(false, priors(edge.variable))))
58  }
59
60  "the static Steane graph matches the reference every two cycles" in {
61    simulate(new StaticTannerDatapath(nodes)) { dut =>
62      dut.io.load.valid.poke(false.B)
63      dut.io.step.valid.poke(false.B)
64      dut.io.step.bits.poke(0.U)
65      dut.reset.poke(true.B)
66      dut.clock.step()
67      dut.reset.poke(false.B)
68
69      dut.io.step.valid.poke(true.B)
70      dut.io.step.ready.expect(false.B)
71      dut.io.step.valid.poke(false.B)
72
73      for (word <- 0 until 8) {
74        val syndrome = Vector.tabulate(graph.checkCount)(i => ((word >> i) & 1) != 0)
75        var expected = load(dut, syndrome)
76        for (iteration <- 1 to 4) {
77          expected = Reference.iterate(nodes, expected, syndrome, priors, iteration, q, RelayDefaults.scale)
78          step(dut, iteration, expected, syndrome)
79        }
80      }
81    }
82  }
83}