summaryrefslogtreecommitdiff
path: root/src/test/scala/cookbook/UInt2VecOfBool.scala
blob: 9aaf63e983a57310167fa434342adda0f4309bbc (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
// SPDX-License-Identifier: Apache-2.0

package cookbook

import chisel3._

/* ### How do I create a Vec of Bools from a UInt?
 *
 * Use the builtin function [[chisel3.Bits.asBools]] to create a Scala Seq of Bool,
 * then wrap the resulting Seq in Vec(...)
 */
class UInt2VecOfBool extends CookbookTester(1) {
  // Example
  val uint = 0xc.U
  val vec = VecInit(uint.asBools)
  printf(p"$vec") // Vec(0, 0, 1, 1)

  // Test
  assert(vec(0) === false.B)
  assert(vec(1) === false.B)
  assert(vec(2) === true.B)
  assert(vec(3) === true.B)
}

class UInt2VecOfBoolSpec extends CookbookSpec {
  "UInt2VecOfBool" should "work" in {
    assertTesterPasses { new UInt2VecOfBool }
  }
}