summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/BitwiseOps.scala
blob: 0c1d4d742974f38b62411b5ca4d40117c69b4957 (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
// See LICENSE for license details.

package chiselTests

import chisel._
import org.scalatest._
import org.scalatest.prop._
import chisel.testers.BasicTester

class BitwiseOpsTester(w: Int, _a: Int, _b: Int) extends BasicTester {
  val mask = (1 << w) - 1
  val a = UInt(_a, w)
  val b = UInt(_b, w)
  assert(~a === UInt(mask & ~_a))
  assert((a & b) === UInt(_a & _b))
  assert((a | b) === UInt(_a | _b))
  assert((a ^ b) === UInt(_a ^ _b))
  stop()
}

class BitwiseOpsSpec extends ChiselPropSpec {
  property("All bit-wise ops should return the correct result") {
    forAll(safeUIntPair) { case(w: Int, a: Int, b: Int) =>
      assertTesterPasses{ new BitwiseOpsTester(w, a, b) }
    }
  }
}