aboutsummaryrefslogtreecommitdiff
path: root/src/test/scala/firrtlTests/fixed/FixedPointMathSpec.scala
diff options
context:
space:
mode:
authorchick2020-08-14 19:47:53 -0700
committerJack Koenig2020-08-14 19:47:53 -0700
commit6fc742bfaf5ee508a34189400a1a7dbffe3f1cac (patch)
tree2ed103ee80b0fba613c88a66af854ae9952610ce /src/test/scala/firrtlTests/fixed/FixedPointMathSpec.scala
parentb516293f703c4de86397862fee1897aded2ae140 (diff)
All of src/ formatted with scalafmt
Diffstat (limited to 'src/test/scala/firrtlTests/fixed/FixedPointMathSpec.scala')
-rw-r--r--src/test/scala/firrtlTests/fixed/FixedPointMathSpec.scala65
1 files changed, 36 insertions, 29 deletions
diff --git a/src/test/scala/firrtlTests/fixed/FixedPointMathSpec.scala b/src/test/scala/firrtlTests/fixed/FixedPointMathSpec.scala
index c4de1f46..a41ac90a 100644
--- a/src/test/scala/firrtlTests/fixed/FixedPointMathSpec.scala
+++ b/src/test/scala/firrtlTests/fixed/FixedPointMathSpec.scala
@@ -2,21 +2,21 @@
package firrtlTests.fixed
-import firrtl.{CircuitState, ChirrtlForm, LowFirrtlCompiler}
+import firrtl.{ChirrtlForm, CircuitState, LowFirrtlCompiler}
import firrtl.testutils.FirrtlFlatSpec
class FixedPointMathSpec extends FirrtlFlatSpec {
- val SumPattern = """.*output sum.*<(\d+)>.*.*""".r
- val ProductPattern = """.*output product.*<(\d+)>.*""".r
+ val SumPattern = """.*output sum.*<(\d+)>.*.*""".r
+ val ProductPattern = """.*output product.*<(\d+)>.*""".r
val DifferencePattern = """.*output difference.*<(\d+)>.*""".r
- val AssignPattern = """\s*(\w+) <= (\w+)\((.*)\)\s*""".r
+ val AssignPattern = """\s*(\w+) <= (\w+)\((.*)\)\s*""".r
for {
- bits1 <- 1 to 4
+ bits1 <- 1 to 4
binaryPoint1 <- 1 to 4
- bits2 <- 1 to 4
+ bits2 <- 1 to 4
binaryPoint2 <- 1 to 4
} {
def config = s"($bits1,$binaryPoint1)($bits2,$binaryPoint2)"
@@ -25,26 +25,26 @@ class FixedPointMathSpec extends FirrtlFlatSpec {
val input =
s"""circuit Unit :
- | module Unit :
- | input a : Fixed<$bits1><<$binaryPoint1>>
- | input b : Fixed<$bits2><<$binaryPoint2>>
- | output sum : Fixed
- | output product : Fixed
- | output difference : Fixed
- | sum <= add(a, b)
- | product <= mul(a, b)
- | difference <= sub(a, b)
- | """.stripMargin
+ | module Unit :
+ | input a : Fixed<$bits1><<$binaryPoint1>>
+ | input b : Fixed<$bits2><<$binaryPoint2>>
+ | output sum : Fixed
+ | output product : Fixed
+ | output difference : Fixed
+ | sum <= add(a, b)
+ | product <= mul(a, b)
+ | difference <= sub(a, b)
+ | """.stripMargin
val lowerer = new LowFirrtlCompiler
val res = lowerer.compileAndEmit(CircuitState(parse(input), ChirrtlForm))
- val output = res.getEmittedCircuit.value split "\n"
+ val output = res.getEmittedCircuit.value.split("\n")
def inferredAddWidth: Int = {
val binaryDifference = binaryPoint1 - binaryPoint2
- val (newW1, newW2) = if(binaryDifference > 0) {
+ val (newW1, newW2) = if (binaryDifference > 0) {
(bits1, bits2 + binaryDifference)
} else {
(bits1 + binaryDifference.abs, bits2)
@@ -54,11 +54,11 @@ class FixedPointMathSpec extends FirrtlFlatSpec {
for (line <- output) {
line match {
- case SumPattern(varWidth) =>
+ case SumPattern(varWidth) =>
assert(varWidth.toInt === inferredAddWidth, s"$config sum sint bits wrong for $line")
case ProductPattern(varWidth) =>
assert(varWidth.toInt === bits1 + bits2, s"$config product bits wrong for $line")
- case DifferencePattern(varWidth) =>
+ case DifferencePattern(varWidth) =>
assert(varWidth.toInt === inferredAddWidth, s"$config difference bits wrong for $line")
case AssignPattern(varName, operation, args) =>
varName match {
@@ -66,11 +66,15 @@ class FixedPointMathSpec extends FirrtlFlatSpec {
assert(operation === "add", s"var sum should be result of an add in $line")
if (binaryPoint1 > binaryPoint2) {
assert(!args.contains("shl(a"), s"$config first arg should be just a in $line")
- assert(args.contains(s"shl(b, ${binaryPoint1 - binaryPoint2})"),
- s"$config second arg incorrect in $line")
+ assert(
+ args.contains(s"shl(b, ${binaryPoint1 - binaryPoint2})"),
+ s"$config second arg incorrect in $line"
+ )
} else if (binaryPoint1 < binaryPoint2) {
- assert(args.contains(s"shl(a, ${(binaryPoint1 - binaryPoint2).abs})"),
- s"$config second arg incorrect in $line")
+ assert(
+ args.contains(s"shl(a, ${(binaryPoint1 - binaryPoint2).abs})"),
+ s"$config second arg incorrect in $line"
+ )
assert(!args.contains("shl(b"), s"$config second arg should be just b in $line")
} else {
assert(!args.contains("shl(a"), s"$config first arg should be just a in $line")
@@ -84,11 +88,15 @@ class FixedPointMathSpec extends FirrtlFlatSpec {
assert(operation === "sub", s"var difference should be result of an sub in $line")
if (binaryPoint1 > binaryPoint2) {
assert(!args.contains("shl(a"), s"$config first arg should be just a in $line")
- assert(args.contains(s"shl(b, ${binaryPoint1 - binaryPoint2})"),
- s"$config second arg incorrect in $line")
+ assert(
+ args.contains(s"shl(b, ${binaryPoint1 - binaryPoint2})"),
+ s"$config second arg incorrect in $line"
+ )
} else if (binaryPoint1 < binaryPoint2) {
- assert(args.contains(s"shl(a, ${(binaryPoint1 - binaryPoint2).abs})"),
- s"$config second arg incorrect in $line")
+ assert(
+ args.contains(s"shl(a, ${(binaryPoint1 - binaryPoint2).abs})"),
+ s"$config second arg incorrect in $line"
+ )
assert(!args.contains("shl(b"), s"$config second arg should be just b in $line")
} else {
assert(!args.contains("shl(a"), s"$config first arg should be just a in $line")
@@ -102,4 +110,3 @@ class FixedPointMathSpec extends FirrtlFlatSpec {
}
}
}
-