blob: 2f5c49e46592118f44c0032837798011a303d043 (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// See LICENSE for license details.
package chiselTests
import org.scalatest._
import chisel3._
import chisel3.testers.BasicTester
import chisel3.util._
class WhenTester() extends BasicTester {
val cnt = Counter(4)
when(Bool(true)) { cnt.inc() }
val out = Wire(UInt.width(3))
when(cnt.value === UInt.Lit(0)) {
out := UInt.Lit(1)
} .elsewhen (cnt.value === UInt.Lit(1)) {
out := UInt.Lit(2)
} .elsewhen (cnt.value === UInt.Lit(2)) {
out := UInt.Lit(3)
} .otherwise {
out := UInt.Lit(0)
}
assert(out === cnt.value + UInt.Lit(1))
when(cnt.value === UInt.Lit(3)) {
stop()
}
}
class OverlappedWhenTester() extends BasicTester {
val cnt = Counter(4)
when(Bool(true)) { cnt.inc() }
val out = Wire(UInt.width(3))
when(cnt.value <= UInt.Lit(0)) {
out := UInt.Lit(1)
} .elsewhen (cnt.value <= UInt.Lit(1)) {
out := UInt.Lit(2)
} .elsewhen (cnt.value <= UInt.Lit(2)) {
out := UInt.Lit(3)
} .otherwise {
out := UInt.Lit(0)
}
assert(out === cnt.value + UInt.Lit(1))
when(cnt.value === UInt.Lit(3)) {
stop()
}
}
class WhenSpec extends ChiselFlatSpec {
"When, elsewhen, and otherwise with orthogonal conditions" should "work" in {
assertTesterPasses{ new WhenTester }
}
"When, elsewhen, and otherwise with overlapped conditions" should "work" in {
assertTesterPasses{ new OverlappedWhenTester }
}
}
|