src/test/scala/chipsldpc/ConvergenceCheckerSpec.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
6import org.scalatest.freespec.AnyFreeSpec
7
8final class ConvergenceCheckerSpec extends AnyFreeSpec with ChiselSim {
9 private val steane = TannerGraph.fromRows(
10 variableCount = 7,
11 rowOnes = Seq(Seq(3, 4, 5, 6), Seq(1, 2, 5, 6), Seq(0, 2, 4, 6)),
12 )
13
14 "the Steane checker exhaustively computes H * estimate + syndrome" in {
15 simulateRaw(new ConvergenceChecker(steane)) { dut =>
16 for {
17 estimate <- 0 until (1 << steane.variableCount)
18 syndrome <- 0 until (1 << steane.checkCount)
19 } {
20 dut.estimate.zipWithIndex.foreach { case (bit, i) => bit.poke(((estimate >> i) & 1).B) }
21 dut.syndrome.zipWithIndex.foreach { case (bit, i) => bit.poke(((syndrome >> i) & 1).B) }
22
23 val expected = steane.rowOnes.zipWithIndex.map { case (row, check) =>
24 row.count(i => ((estimate >> i) & 1) != 0) % 2 != ((syndrome >> check) & 1)
25 }
26 dut.residual.zip(expected).foreach { case (bit, value) => bit.expect(value.B) }
27 dut.converged.expect((!expected.contains(true)).B)
28 }
29 }
30 }
31}