summaryrefslogtreecommitdiff
path: root/src/test/scala/chiselTests
diff options
context:
space:
mode:
authorChick Markley2016-10-25 08:59:15 -0700
committerGitHub2016-10-25 08:59:15 -0700
commite00ae6ff3518d517733f5cfe3959e8b31c5876b5 (patch)
tree93063422d03f13c6585b7a582dcf24c1f27b0b6a /src/test/scala/chiselTests
parenta44c7aede6902533ea79fcf6a3fbed234b4456c0 (diff)
FixedPoint number support for chisel3 (#328)
* FixedPoint number support for chisel3 FixedPoint numbers have a width and a binary position Either, neither or both maybe inferred. Firrtl will convert these to SInts during lowering passes * Fixes based on Jack's comments on PR #328 * Add experimental warning to FixedPoint class and object * Fixed comment per Adam's comment on PR #328
Diffstat (limited to 'src/test/scala/chiselTests')
-rw-r--r--src/test/scala/chiselTests/FixedPointSpec.scala41
1 files changed, 41 insertions, 0 deletions
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 }
+ }
+}