Skip to content

Commit

Permalink
Work around Chisel module naming bug
Browse files Browse the repository at this point in the history
On Chisel 5/5.1, the arithmetic-operation-character argument to the
`ParameterizedNumberOperation` module caused a Chisel elaboration error.
The error goes away in Chisel 6-RC1.
  • Loading branch information
tymcauley committed Jan 16, 2024
1 parent 9481aa7 commit a310a15
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/test/scala/dsptools/numbers/ParameterizedOpSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ import dsptools.misc.PeekPokeDspExtensions

//scalastyle:off magic.number

object Operation extends Enumeration {
type Operation = Value
val Add, Sub, Mul = Value
}
import Operation.{Add, Mul, Sub}

class ParameterizedNumberOperation[T <: Data: Ring](
inputGenerator: () => T,
outputGenerator: () => T,
val op: String = "+")
val op: Operation.Value = Add)
extends Module {
val io = IO(new Bundle {
val a1: T = Input(inputGenerator().cloneType)
Expand All @@ -28,9 +34,9 @@ class ParameterizedNumberOperation[T <: Data: Ring](

register1 := {
op match {
case "+" => io.a1 + io.a2
case "-" => io.a1 - io.a2
case "*" => DspContext.withTrimType(NoTrim) { io.a1 * io.a2 }
case Add => io.a1 + io.a2
case Sub => io.a1 - io.a2
case Mul => DspContext.withTrimType(NoTrim) { io.a1 * io.a2 }
// case "/" => io.a1 / io.a2
case _ => throw new Exception(s"Bad operator $op passed to ParameterizedNumberOperation")
}
Expand All @@ -47,9 +53,9 @@ class ParameterizedOpTester[T <: Data: Ring](c: ParameterizedNumberOperation[T])
j <- BigDecimal(0.0) to 4.0 by 0.5
} {
val expected = c.op match {
case "+" => i + j
case "-" => i - j
case "*" => i * j
case Add => i + j
case Sub => i - j
case Mul => i * j
case _ => i + j
}

Expand All @@ -72,7 +78,7 @@ class ParameterizedOpSpec extends AnyFreeSpec with ChiselScalatestTester {
def fixedOutGenerator(): FixedPoint = FixedPoint(48.W, 8.BP)

"process Real numbers with the basic mathematical operations" - {
Seq("+", "-", "*").foreach { operation =>
Seq(Add, Sub, Mul).foreach { operation =>
s"operation $operation should work for all inputs" in {
test(new ParameterizedNumberOperation(realGenerator, realGenerator, operation))
.withAnnotations(Seq(VerilatorBackendAnnotation))
Expand All @@ -81,7 +87,7 @@ class ParameterizedOpSpec extends AnyFreeSpec with ChiselScalatestTester {
}
}
"process Fixed point numbers with the basic mathematical operations" - {
Seq("+", "-", "*").foreach { operation =>
Seq(Add, Sub, Mul).foreach { operation =>
s"operation $operation should work for all inputs" in {
test(new ParameterizedNumberOperation(fixedInGenerator, fixedOutGenerator, operation))
.runPeekPoke(new ParameterizedOpTester(_))
Expand All @@ -102,9 +108,9 @@ class ComplexOpTester[T <: DspComplex[_]](c: ParameterizedNumberOperation[T])
val c2 = Complex(j, i)

val expected = c.op match {
case "+" => c1 + c2
case "-" => c1 - c2
case "*" => c1 * c2
case Add => c1 + c2
case Sub => c1 - c2
case Mul => c1 * c2
case _ => c1 + c2
}

Expand Down Expand Up @@ -135,7 +141,7 @@ class ComplexOpSpec extends AnyFreeSpec with ChiselScalatestTester {
}

"process DspComplex[Real] numbers with the basic mathematical operations" - {
Seq("+", "-", "*").foreach { operation =>
Seq(Add, Sub, Mul).foreach { operation =>
s"operation $operation should work for all inputs" in {
test(new ParameterizedNumberOperation(complexRealGenerator, complexRealGenerator, operation))
.withAnnotations(Seq(VerilatorBackendAnnotation))
Expand All @@ -145,7 +151,7 @@ class ComplexOpSpec extends AnyFreeSpec with ChiselScalatestTester {
}

"process DspComplex[FixedPoint] numbers with the basic mathematical operations" - {
Seq("+", "-", "*").foreach { operation =>
Seq(Add, Sub, Mul).foreach { operation =>
s"operation $operation should work for all inputs" in {
test(new ParameterizedNumberOperation(complexFixedGenerator, complexFixedOutputGenerator, operation))
.runPeekPoke(new ComplexOpTester(_))
Expand Down

0 comments on commit a310a15

Please sign in to comment.