Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(countcomb): make module function correctly #8

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ class CountCombinations(numBits: Int) extends Module {
})

private val three = "b11".U

val areOnes =
VecInit
.tabulate(numBits - 1) { i =>
val currentBits = io.value(i + 1, i)
currentBits === three
};

val utilVec = VecInit(0.U(numBits.W).asBools)
for (i <- 0 until numBits - 1) {
utilVec(i) := (if (i == 0) { areOnes(i) }
else {
!utilVec(i - 1) && areOnes(i)
})
}

io.count :=
PopCount(
VecInit
.tabulate(numBits - 1) { i => (io.value(i + 1, i) === three) }
.asUInt
)
PopCount(utilVec.asUInt)
}

class CountCombinationsTopIO(numDigits: Int, numLeds: Int) extends Bundle {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import chiseltest._
import org.scalatest.flatspec.AnyFlatSpec

class CountCombinationsTester extends AnyFlatSpec with ChiselScalatestTester {
"CountCombinations of 0b11 in 0b11111111" should "be equal to 7" in {
"CountCombinations of 0b11 in 0b11111111" should "be equal to 4" in {
test(new CountCombinations(8)) { dut =>
dut.io.value.poke("b11111111".U)
dut.io.count.expect(7.U)
dut.io.count.expect(4.U)
}
}

Expand All @@ -19,6 +19,19 @@ class CountCombinationsTester extends AnyFlatSpec with ChiselScalatestTester {
dut.io.count.expect(0.U)
}
}

"CountCombinations of 0b11 in 0b00000111" should "be equal to 1" in {
test(new CountCombinations(8)) { dut =>
dut.io.value.poke("b00000111".U)
dut.io.count.expect(1.U)
}
}
"CountCombinations of 0b11 in 0b11100111" should "be equal to 2" in {
test(new CountCombinations(8)) { dut =>
dut.io.value.poke("b11100111".U)
dut.io.count.expect(2.U)
}
}
}

class CountCombinationsTestbench(
Expand Down