blob: d0f16701d3c15cf8e5e540694993321cdbb21950 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
// SPDX-License-Identifier: Apache-2.0
import chisel3._
import chisel3.util._
import chiseltest._
import chiseltest.formal._
import org.scalatest.flatspec.AnyFlatSpec
import scala.math.min
class ScanLeftOrTestModule(width: Int) extends Module {
val input = IO(Input(UInt(width.W)))
var lsb = false.B
val vec = for (b <- input.asBools) yield {
val cur = b || lsb
lsb = cur
cur
}
val ref = VecInit(vec).asUInt
val testee = scanLeftOr(input)
assert(testee === ref)
}
class ScanRightOrTestModule(width: Int) extends Module {
val input = IO(Input(UInt(width.W)))
val ref = Reverse(scanLeftOr(Reverse(input)))
val testee = scanRightOr(input)
assert(testee === ref)
}
class scanOrTest extends AnyFlatSpec with ChiselScalatestTester with Formal {
"scanLeftOr" should "compute correctly" in {
for (i <- 1 to 16) {
verify(new ScanLeftOrTestModule(i), Seq(BoundedCheck(1)))
}
}
"scanRightOr" should "compute correctly" in {
for (i <- 1 to 16) {
verify(new ScanRightOrTestModule(i), Seq(BoundedCheck(1)))
}
}
}
|