diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/chisel3/Driver.scala | 4 | ||||
| -rw-r--r-- | src/main/scala/chisel3/package.scala | 7 | ||||
| -rw-r--r-- | src/main/scala/chisel3/util/BitPat.scala | 1 | ||||
| -rw-r--r-- | src/main/scala/chisel3/util/Decoupled.scala | 2 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/BundleWire.scala | 28 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/FixedPointSpec.scala | 41 | ||||
| -rw-r--r-- | src/test/scala/chiselTests/Vec.scala | 6 |
7 files changed, 84 insertions, 5 deletions
diff --git a/src/main/scala/chisel3/Driver.scala b/src/main/scala/chisel3/Driver.scala index dbd9b464..a0713379 100644 --- a/src/main/scala/chisel3/Driver.scala +++ b/src/main/scala/chisel3/Driver.scala @@ -119,13 +119,13 @@ trait BackendCompilationUtilities { "-Wno-WIDTH", "-Wno-STMTDLY", "--trace", - "-O2", + "-O0", "--top-module", topModule, "+define+TOP_TYPE=V" + dutFile, s"+define+PRINTF_COND=!$topModule.reset", s"+define+STOP_COND=!$topModule.reset", "-CFLAGS", - s"""-Wno-undefined-bool-conversion -O2 -DTOP_TYPE=V$dutFile -include V$dutFile.h""", + s"""-Wno-undefined-bool-conversion -O0 -DTOP_TYPE=V$dutFile -include V$dutFile.h""", "-Mdir", dir.toString, "--exe", cppHarness.toString) System.out.println(s"${command.mkString(" ")}") // scalastyle:ignore regex diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 0a57b7de..e0364868 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -37,6 +37,8 @@ package object chisel3 { // scalastyle:ignore package.object.name val UInt = chisel3.core.UInt type SInt = chisel3.core.SInt val SInt = chisel3.core.SInt + type FixedPoint = chisel3.core.FixedPoint + val FixedPoint = chisel3.core.FixedPoint type Bool = chisel3.core.Bool val Bool = chisel3.core.Bool val Mux = chisel3.core.Mux @@ -150,8 +152,13 @@ package object chisel3 { // scalastyle:ignore package.object.name def B: Bool = Bool(x) // scalastyle:ignore method.name } + implicit class fromDoubleToLiteral(val x: Double) extends AnyVal { + def F(binaryPoint: Int): FixedPoint = FixedPoint.fromDouble(x, binaryPoint = binaryPoint) + } + implicit class fromUIntToBitPatComparable(val x: UInt) extends AnyVal { final def === (that: BitPat): Bool = macro SourceInfoTransform.thatArg + @deprecated("Use '=/=', which avoids potential precedence problems", "chisel3") final def != (that: BitPat): Bool = macro SourceInfoTransform.thatArg final def =/= (that: BitPat): Bool = macro SourceInfoTransform.thatArg diff --git a/src/main/scala/chisel3/util/BitPat.scala b/src/main/scala/chisel3/util/BitPat.scala index 972010a6..e58258c7 100644 --- a/src/main/scala/chisel3/util/BitPat.scala +++ b/src/main/scala/chisel3/util/BitPat.scala @@ -82,6 +82,7 @@ sealed class BitPat(val value: BigInt, val mask: BigInt, width: Int) { def getWidth: Int = width def === (that: UInt): Bool = macro SourceInfoTransform.thatArg def =/= (that: UInt): Bool = macro SourceInfoTransform.thatArg + @deprecated("Use '=/=', which avoids potential precedence problems", "chisel3") def != (that: UInt): Bool = macro SourceInfoTransform.thatArg def do_=== (that: UInt)(implicit sourceInfo: SourceInfo): Bool = value.asUInt === (that & mask.asUInt) // scalastyle:ignore method.name diff --git a/src/main/scala/chisel3/util/Decoupled.scala b/src/main/scala/chisel3/util/Decoupled.scala index a0cbf4f7..c9d57759 100644 --- a/src/main/scala/chisel3/util/Decoupled.scala +++ b/src/main/scala/chisel3/util/Decoupled.scala @@ -145,6 +145,8 @@ class QueueIO[T <: Data](gen: T, entries: Int) extends Bundle val deq = EnqIO(gen) /** The current amount of data in the queue */ val count = Output(UInt.width(log2Up(entries + 1))) + + override def cloneType = new QueueIO(gen, entries).asInstanceOf[this.type] } /** A hardware module implementing a Queue diff --git a/src/test/scala/chiselTests/BundleWire.scala b/src/test/scala/chiselTests/BundleWire.scala index 53d46e93..5b38ff6e 100644 --- a/src/test/scala/chiselTests/BundleWire.scala +++ b/src/test/scala/chiselTests/BundleWire.scala @@ -24,6 +24,27 @@ class BundleWire(n: Int) extends Module { } } +class BundleToUnitTester extends BasicTester { + val bundle1 = Wire(new Bundle { + val a = UInt(width = 4) + val b = UInt(width = 4) + }) + val bundle2 = Wire(new Bundle { + val a = UInt(width = 2) + val b = UInt(width = 6) + }) + + // 0b00011011 split as 0001 1011 and as 00 011011 + bundle1.a := 1.U + bundle1.b := 11.U + bundle2.a := 0.U + bundle2.b := 27.U + + assert(bundle1.asUInt() === bundle2.asUInt()) + + stop() +} + class BundleWireTester(n: Int, x: Int, y: Int) extends BasicTester { val dut = Module(new BundleWire(n)) dut.io.in.x := UInt(x) @@ -43,3 +64,10 @@ class BundleWireSpec extends ChiselPropSpec { } } } + +class BundleToUIntSpec extends ChiselPropSpec { + property("Bundles with same data but different, underlying elements should compare as UInt") { + assertTesterPasses( new BundleToUnitTester ) + } +} + diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala new file mode 100644 index 00000000..69015e42 --- /dev/null +++ b/src/test/scala/chiselTests/FixedPointSpec.scala @@ -0,0 +1,41 @@ +// See LICENSE for license details. + +package chiselTests + +import chisel3._ +import chisel3.testers.BasicTester +import org.scalatest._ + +//scalastyle:off magic.number +class FixedPointSpec extends FlatSpec with Matchers { + behavior of "fixed point utilities" + + they should "allow conversion between doubles and the bigints needed to represent them" in { + val initialDouble = 0.125 + val bigInt = FixedPoint.toBigInt(initialDouble, 4) + val finalDouble = FixedPoint.toDouble(bigInt, 4) + + initialDouble should be(finalDouble) + } +} + +class SBP extends Module { + val io = IO(new Bundle { + val in = Input(FixedPoint(6, 2)) + val out = Output(FixedPoint(4, 0)) + }) + io.out := io.in.setBinaryPoint(0) +} +class SBPTester extends BasicTester { + val dut = Module(new SBP) + dut.io.in := FixedPoint.fromDouble(3.75, binaryPoint = 2) + + assert(dut.io.out === FixedPoint.fromDouble(3.0, binaryPoint = 0)) + + stop() +} +class SBPSpec extends ChiselPropSpec { + property("should allow set binary point") { + assertTesterPasses { new SBPTester } + } +} diff --git a/src/test/scala/chiselTests/Vec.scala b/src/test/scala/chiselTests/Vec.scala index c5447610..0d5a2188 100644 --- a/src/test/scala/chiselTests/Vec.scala +++ b/src/test/scala/chiselTests/Vec.scala @@ -23,9 +23,9 @@ class TabulateTester(n: Int) extends BasicTester { val x = Vec(Array.tabulate(n){ i => UInt(i * 2) }) val u = Vec.tabulate(n)(i => UInt(i*2)) - assert(v.toBits === x.toBits) - assert(v.toBits === u.toBits) - assert(x.toBits === u.toBits) + assert(v.asUInt() === x.asUInt()) + assert(v.asUInt() === u.asUInt()) + assert(x.asUInt() === u.asUInt()) stop() } |
