From 53e9794ea4471d0da29d688cefdc462a9be98b63 Mon Sep 17 00:00:00 2001 From: Paul Rigge Date: Mon, 5 Dec 2016 16:54:37 -0800 Subject: Add a test for fromBits on fixed point numbers. --- src/test/scala/chiselTests/FixedPointSpec.scala | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala index 69015e42..b3ea30b5 100644 --- a/src/test/scala/chiselTests/FixedPointSpec.scala +++ b/src/test/scala/chiselTests/FixedPointSpec.scala @@ -17,6 +17,22 @@ class FixedPointSpec extends FlatSpec with Matchers { initialDouble should be(finalDouble) } + + behavior of "fixed point" + + they should "allow fromBits from now fixed point types" in { + val uint = 3.U + val sint = -3.S + val fp_tpe = FixedPoint(width = 4, binaryPoint = 1) + val uint_result = FixedPoint.fromDouble(1.5, width = 4, binaryPoint = 1) + val sint_result = FixedPoint.fromDouble(-1.5, width = 4, binaryPoint = 1) + + val uint2fp = fp_tpe.fromBits(uint) + val sint2fp = fp_tpe.fromBits(sint) + + uint2fp should be (uint_result) + sint2fp should be (sint_result) + } } class SBP extends Module { -- cgit v1.2.3 From 316d749df58421b52a72344c27137284d1413131 Mon Sep 17 00:00:00 2001 From: Paul Rigge Date: Tue, 13 Dec 2016 15:10:05 -0800 Subject: Checkpoint --- src/main/scala/chisel3/package.scala | 1 + src/test/scala/chiselTests/FixedPointSpec.scala | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main/scala/chisel3/package.scala b/src/main/scala/chisel3/package.scala index 25d3ec3a..f20bb453 100644 --- a/src/main/scala/chisel3/package.scala +++ b/src/main/scala/chisel3/package.scala @@ -216,6 +216,7 @@ package object chisel3 { // scalastyle:ignore package.object.name implicit class fromBooleanToLiteral(val x: Boolean) extends chisel3.core.fromBooleanToLiteral(x) implicit class fromDoubleToLiteral(val x: Double) extends chisel3.core.fromDoubleToLiteral(x) implicit class fromIntToWidth(val x: Int) extends chisel3.core.fromIntToWidth(x) + implicit class fromIntToBinaryPoint(val x: Int) extends chisel3.core.fromIntToBinaryPoint(x) implicit class fromUIntToBitPatComparable(val x: UInt) { import scala.language.experimental.macros diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala index b3ea30b5..478e1716 100644 --- a/src/test/scala/chiselTests/FixedPointSpec.scala +++ b/src/test/scala/chiselTests/FixedPointSpec.scala @@ -7,7 +7,7 @@ import chisel3.testers.BasicTester import org.scalatest._ //scalastyle:off magic.number -class FixedPointSpec extends FlatSpec with Matchers { +class FixedPointLiteralSpec extends FlatSpec with Matchers { behavior of "fixed point utilities" they should "allow conversion between doubles and the bigints needed to represent them" in { @@ -17,22 +17,22 @@ class FixedPointSpec extends FlatSpec with Matchers { initialDouble should be(finalDouble) } +} - behavior of "fixed point" - - they should "allow fromBits from now fixed point types" in { +class FixedPointFromBitsTester extends BasicTester { val uint = 3.U val sint = -3.S - val fp_tpe = FixedPoint(width = 4, binaryPoint = 1) + val fp_tpe = FixedPoint(4.W, 1.BP) val uint_result = FixedPoint.fromDouble(1.5, width = 4, binaryPoint = 1) val sint_result = FixedPoint.fromDouble(-1.5, width = 4, binaryPoint = 1) val uint2fp = fp_tpe.fromBits(uint) val sint2fp = fp_tpe.fromBits(sint) - uint2fp should be (uint_result) - sint2fp should be (sint_result) - } + assert(uint2fp === uint_result) + assert(sint2fp === sint_result) + + stop() } class SBP extends Module { @@ -50,8 +50,12 @@ class SBPTester extends BasicTester { stop() } -class SBPSpec extends ChiselPropSpec { + +class FixedPointSpec extends ChiselPropSpec { property("should allow set binary point") { assertTesterPasses { new SBPTester } } + property("should allow fromBits") { + assertTesterPasses { new FixedPointFromBitsTester } + } } -- cgit v1.2.3 From f9d528b3763429275430b84839ccf0b4570531a2 Mon Sep 17 00:00:00 2001 From: Paul Rigge Date: Tue, 13 Dec 2016 15:54:36 -0800 Subject: Fix test. --- src/test/scala/chiselTests/FixedPointSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala index 478e1716..a08de073 100644 --- a/src/test/scala/chiselTests/FixedPointSpec.scala +++ b/src/test/scala/chiselTests/FixedPointSpec.scala @@ -20,7 +20,7 @@ class FixedPointLiteralSpec extends FlatSpec with Matchers { } class FixedPointFromBitsTester extends BasicTester { - val uint = 3.U + val uint = 3.U(4.W) val sint = -3.S val fp_tpe = FixedPoint(4.W, 1.BP) val uint_result = FixedPoint.fromDouble(1.5, width = 4, binaryPoint = 1) -- cgit v1.2.3