summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/scala/chiselTests/FixedPointSpec.scala42
-rw-r--r--src/test/scala/chiselTests/IntegerMathSpec.scala33
2 files changed, 58 insertions, 17 deletions
diff --git a/src/test/scala/chiselTests/FixedPointSpec.scala b/src/test/scala/chiselTests/FixedPointSpec.scala
index bfbb4e46..d0557e66 100644
--- a/src/test/scala/chiselTests/FixedPointSpec.scala
+++ b/src/test/scala/chiselTests/FixedPointSpec.scala
@@ -21,23 +21,31 @@ class FixedPointLiteralSpec extends FlatSpec with Matchers {
}
class FixedPointFromBitsTester extends BasicTester {
- val uint = 3.U(4.W)
- val sint = -3.S
- val fp = FixedPoint.fromDouble(3.0, width = 4, binaryPoint = 0)
- 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 fp_result = FixedPoint.fromDouble(1.5, width = 4, binaryPoint = 1)
-
- val uint2fp = fp_tpe.fromBits(uint)
- val sint2fp = fp_tpe.fromBits(sint)
- val fp2fp = fp_tpe.fromBits(fp)
-
- assert(uint2fp === uint_result)
- assert(sint2fp === sint_result)
- assert(fp2fp === fp_result)
-
- stop()
+ val uint = 3.U(4.W)
+ val sint = -3.S
+
+ val fp = FixedPoint.fromDouble(3.0, width = 4, binaryPoint = 0)
+ 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 fp_result = FixedPoint.fromDouble(1.5, width = 4, binaryPoint = 1)
+
+ val uint2fp = fp_tpe.fromBits(uint)
+ val sint2fp = fp_tpe.fromBits(sint)
+ val fp2fp = fp_tpe.fromBits(fp)
+
+ val negativefp = -3.5.F(binaryPoint = 4)
+ val positivefp = 3.5.F(binaryPoint = 4)
+
+ assert(uint2fp === uint_result)
+ assert(sint2fp === sint_result)
+ assert(fp2fp === fp_result)
+
+ assert(positivefp.abs() === positivefp)
+ assert(negativefp.abs() === positivefp)
+ assert(negativefp.abs() =/= negativefp)
+
+ stop()
}
class SBP extends Module {
diff --git a/src/test/scala/chiselTests/IntegerMathSpec.scala b/src/test/scala/chiselTests/IntegerMathSpec.scala
new file mode 100644
index 00000000..3ccade8e
--- /dev/null
+++ b/src/test/scala/chiselTests/IntegerMathSpec.scala
@@ -0,0 +1,33 @@
+// See LICENSE for license details.
+
+package chiselTests
+
+import chisel3._
+import chisel3.testers.BasicTester
+
+//scalastyle:off magic.number
+class IntegerMathTester extends BasicTester {
+
+ //TODO: Add more operators
+
+ /* absolute values tests */
+
+ val uint = 3.U(4.W)
+ val sint = (-3).S()
+ val sintpos = 3.S()
+ val wrongSIntPos = 4.S()
+
+ assert(uint.abs() === uint)
+ assert(sint.abs() === sintpos)
+ assert(sintpos.abs() === sintpos)
+
+ assert(sint.abs() =/= wrongSIntPos)
+
+ stop()
+}
+
+class IntegerMathSpec extends ChiselPropSpec {
+ property("All integer ops should return the correct result") {
+ assertTesterPasses{ new IntegerMathTester }
+ }
+}