summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests/FixedPointSpec.scala
diff options
context:
space:
mode:
authorAdam Izraelevitz2017-01-11 13:02:47 -0800
committerGitHub2017-01-11 13:02:47 -0800
commit3215df07a97b58babb1deb3fab0928198b1daad2 (patch)
tree0099c332f9a629a0b41eb3680f6c493e18bf57ca /src/test/scala/chiselTests/FixedPointSpec.scala
parent06df5adfd78061aa5ae7567882fb8c42d7260a46 (diff)
parent514eadb99e6715e161c73f487347872eed004230 (diff)
Merge pull request #391 from grebe/fixedPointFromBits
Have FixedPoint use asFixedPoint in fromBits.
Diffstat (limited to 'src/test/scala/chiselTests/FixedPointSpec.scala')
-rw-r--r--src/test/scala/chiselTests/FixedPointSpec.scala24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala
index 69015e42..a08de073 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 {
@@ -19,6 +19,22 @@ class FixedPointSpec extends FlatSpec with Matchers {
}
}
+class FixedPointFromBitsTester extends BasicTester {
+ 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)
+ val sint_result = FixedPoint.fromDouble(-1.5, width = 4, binaryPoint = 1)
+
+ val uint2fp = fp_tpe.fromBits(uint)
+ val sint2fp = fp_tpe.fromBits(sint)
+
+ assert(uint2fp === uint_result)
+ assert(sint2fp === sint_result)
+
+ stop()
+}
+
class SBP extends Module {
val io = IO(new Bundle {
val in = Input(FixedPoint(6, 2))
@@ -34,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 }
+ }
}