src/main/scala/chipsldpc/CheckNode.scala
Source from the repository checkout used to build these docs. Line numbers link to individual source lines.
1package chipsldpc
2
3import chisel3._
4
5final class CheckNode(config: CheckConfig) extends RawModule {
6 val inputs = IO(Input(Vec(config.degree, new SignMag(config.q.magnitudeBits))))
7 val syndrome = IO(Input(Bool()))
8 val scaleShift = config.scale match {
9 case _: RampScale => Some(IO(Input(UInt(config.scale.controlBits.W))))
10 case _ => None
11 }
12 val result = IO(Output(new CheckResult(config)))
13
14 private val signs = inputs.map(Arithmetic.hardDecision)
15 private val parity = VecInit(signs).asUInt.xorR ^ syndrome
16 private val (first, second) = TwoMinLogic(inputs.map(_.magnitude))
17 private val control = scaleShift.getOrElse(0.U)
18 private val scaledFirst = Arithmetic.scale(first, control, config.scale, config.q.magnitudeBits)
19 private val scaledSecond = Arithmetic.scale(second, control, config.scale, config.q.magnitudeBits)
20
21 result.minima.first := scaledFirst
22 result.minima.second := scaledSecond
23 result.edges.zipWithIndex.foreach { case (edge, i) =>
24 edge.useSecond := inputs(i).magnitude === first
25 edge.sign := parity ^ signs(i)
26 }
27}
28
29final class CheckNodeUnit(config: CheckConfig) extends Module {
30 val io = IO(new Bundle {
31 val valid = Input(Bool())
32 val inputs = Input(Vec(config.degree, new SignMag(config.q.magnitudeBits)))
33 val syndrome = Input(Bool())
34 val scaleShift = Input(UInt(config.scale.controlBits.W))
35 val outValid = Output(Bool())
36 val result = Output(new CheckResult(config))
37 })
38
39 private val core = Module(new CheckNode(config))
40 core.inputs := io.inputs
41 core.syndrome := io.syndrome
42 core.scaleShift.foreach(_ := io.scaleShift)
43
44 private val result = RegInit(0.U.asTypeOf(new CheckResult(config)))
45 when(io.valid) { result := core.result }
46 io.result := result
47 io.outValid := RegNext(io.valid, false.B)
48}