diff options
| author | Jack Koenig | 2018-05-29 16:13:39 -0700 |
|---|---|---|
| committer | GitHub | 2018-05-29 16:13:39 -0700 |
| commit | f24a733dc279e93a7d5d945042ec7472a6872aa1 (patch) | |
| tree | 150f7234abc74aa5f248bf2c0041e2f2dfc09c1e /src | |
| parent | 87fe48938a3ccc58b1945bae72f0e7305ac14b3b (diff) | |
Fix pad (#817)
* Make VerilogEmitter properly handle pad of width <= width of arg
* Constant prop pads with pad amount <= width of arg
Diffstat (limited to 'src')
4 files changed, 43 insertions, 2 deletions
diff --git a/src/main/scala/firrtl/Emitter.scala b/src/main/scala/firrtl/Emitter.scala index 9bb8a466..6ffa942c 100644 --- a/src/main/scala/firrtl/Emitter.scala +++ b/src/main/scala/firrtl/Emitter.scala @@ -264,7 +264,7 @@ class VerilogEmitter extends SeqTransform with Emitter { case Pad => val w = bitWidth(a0.tpe) val diff = c0 - w - if (w == BigInt(0)) Seq(a0) + if (w == BigInt(0) || diff <= 0) Seq(a0) else doprim.tpe match { // Either sign extend or zero extend. // If width == BigInt(1), don't extract bit diff --git a/src/main/scala/firrtl/transforms/ConstantPropagation.scala b/src/main/scala/firrtl/transforms/ConstantPropagation.scala index 60d9ac2c..5e9a7850 100644 --- a/src/main/scala/firrtl/transforms/ConstantPropagation.scala +++ b/src/main/scala/firrtl/transforms/ConstantPropagation.scala @@ -212,7 +212,7 @@ class ConstantPropagation extends Transform { case Pad => e.args.head match { case UIntLiteral(v, IntWidth(w)) => UIntLiteral(v, IntWidth(e.consts.head max w)) case SIntLiteral(v, IntWidth(w)) => SIntLiteral(v, IntWidth(e.consts.head max w)) - case _ if bitWidth(e.args.head.tpe) == e.consts.head => e.args.head + case _ if bitWidth(e.args.head.tpe) >= e.consts.head => e.args.head case _ => e } case Bits => e.args.head match { diff --git a/src/test/scala/firrtlTests/ConstantPropagationTests.scala b/src/test/scala/firrtlTests/ConstantPropagationTests.scala index 19fe20c9..6fc685a8 100644 --- a/src/test/scala/firrtlTests/ConstantPropagationTests.scala +++ b/src/test/scala/firrtlTests/ConstantPropagationTests.scala @@ -893,6 +893,23 @@ class ConstantPropagationIntegrationSpec extends LowTransformSpec { execute(input, check, Seq.empty) } + it should "remove pads if the width is <= the width of the argument" in { + def input(w: Int) = + s"""circuit Top : + | module Top : + | input x : UInt<8> + | output z : UInt<8> + | z <= pad(x, $w)""".stripMargin + val check = + """circuit Top : + | module Top : + | input x : UInt<8> + | output z : UInt<8> + | z <= x""".stripMargin + execute(input(6), check, Seq.empty) + execute(input(8), check, Seq.empty) + } + "Registers with no reset or connections" should "be replaced with constant zero" in { val input = diff --git a/src/test/scala/firrtlTests/VerilogEmitterTests.scala b/src/test/scala/firrtlTests/VerilogEmitterTests.scala index 40b66917..f4df8519 100644 --- a/src/test/scala/firrtlTests/VerilogEmitterTests.scala +++ b/src/test/scala/firrtlTests/VerilogEmitterTests.scala @@ -10,6 +10,7 @@ import firrtl.annotations._ import firrtl.ir.Circuit import firrtl.passes._ import firrtl.Parser.IgnoreInfo +import FirrtlCheckers._ class DoPrimVerilog extends FirrtlFlatSpec { "Xorr" should "emit correctly" in { @@ -149,4 +150,27 @@ class VerilogEmitterSpec extends FirrtlFlatSpec { |""".stripMargin.split("\n") map normalized executeTest(input, check, compiler) } + "The Verilog Emitter" should "support pads with width <= the width of the argument" in { + // We do just a few passes instead of using the VerilogCompiler to ensure that the pad actually + // reaches the VerilogEmitter and isn't removed by an optimization transform + val passes = Seq( + ToWorkingIR, + ResolveKinds, + InferTypes + ) + def input(n: Int) = + s"""circuit Test : + | module Test : + | input in : UInt<8> + | output out : UInt<8> + | out <= pad(in, $n) + |""".stripMargin + for (w <- Seq(6, 8)) { + val circuit = passes.foldLeft(parse(input(w))) { case (c, p) => p.run(c) } + val state = CircuitState(circuit, LowForm, Seq(EmitCircuitAnnotation(classOf[VerilogEmitter]))) + val emitter = new VerilogEmitter + val result = emitter.execute(state) + result should containLine ("assign out = in;") + } + } } |
