From c9aff1ca5bc701678a325fb662427f21c48ea1af Mon Sep 17 00:00:00 2001 From: Albert Magyar Date: Thu, 6 Feb 2020 06:17:40 -0800 Subject: [Behavior change] Andr of zero-width wire now returns UIntLiteral(1) * Fixes #1344 --- src/main/scala/firrtl/passes/ZeroWidth.scala | 1 + src/test/scala/firrtlTests/ZeroWidthTests.scala | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/main/scala/firrtl/passes/ZeroWidth.scala b/src/main/scala/firrtl/passes/ZeroWidth.scala index 83fc1b6b..e01cfffc 100644 --- a/src/main/scala/firrtl/passes/ZeroWidth.scala +++ b/src/main/scala/firrtl/passes/ZeroWidth.scala @@ -114,6 +114,7 @@ object ZeroWidth extends Transform { case Seq(x) => x case seq => DoPrim(Cat, seq, consts, tpe) map onExp } + case DoPrim(Andr, Seq(x), _, _) if (bitWidth(x.tpe) == 0) => UIntLiteral(1) // nothing false case other => other.tpe match { case UIntType(IntWidth(ZERO)) => UIntLiteral(ZERO, IntWidth(BigInt(1))) case SIntType(IntWidth(ZERO)) => SIntLiteral(ZERO, IntWidth(BigInt(1))) diff --git a/src/test/scala/firrtlTests/ZeroWidthTests.scala b/src/test/scala/firrtlTests/ZeroWidthTests.scala index f1dadcee..96d03d08 100644 --- a/src/test/scala/firrtlTests/ZeroWidthTests.scala +++ b/src/test/scala/firrtlTests/ZeroWidthTests.scala @@ -212,6 +212,21 @@ class ZeroWidthTests extends FirrtlFlatSpec { | printf(clk, UInt(1), "%d %d %d\n", x, UInt(0), z)""".stripMargin (parse(exec(input)).serialize) should be (parse(check).serialize) } + + "Andr of zero-width expression" should "return true" in { + val input = + """circuit Top : + | module Top : + | input y : UInt<0> + | output x : UInt<1> + | x <= andr(y)""".stripMargin + val check = + """circuit Top : + | module Top : + | output x : UInt<1> + | x <= UInt<1>(1)""".stripMargin + (parse(exec(input))) should be (parse(check)) + } } class ZeroWidthVerilog extends FirrtlFlatSpec { -- cgit v1.2.3 From 7e3a4240f0ddc24d8effac515b7449df588277da Mon Sep 17 00:00:00 2001 From: Albert Magyar Date: Thu, 6 Feb 2020 06:23:51 -0800 Subject: Add note to spec about reductions on zero-width wires --- spec/spec.pdf | Bin 274485 -> 275421 bytes spec/spec.tex | 2 ++ 2 files changed, 2 insertions(+) diff --git a/spec/spec.pdf b/spec/spec.pdf index 8b7fd125..e49441ad 100644 Binary files a/spec/spec.pdf and b/spec/spec.pdf differ diff --git a/spec/spec.tex b/spec/spec.tex index 68a404a8..a8a40da4 100644 --- a/spec/spec.tex +++ b/spec/spec.tex @@ -1533,6 +1533,8 @@ andr,orr,xorr & (e) & () & (UInt) & UInt & 1\\ The bitwise reduction operations correspond to a bitwise and, or, and exclusive or operation, reduced over every bit in \vv{e}. +In all cases, the reduction incorporates as an inductive base case the ``identity value'' associated with each operator. This is defined as the value that preserves the value of the other argument: one for \vv{and} (as $x \wedge 1 = x$), zero for \vv{or} (as $x \vee 0 = x$), and zero for \vv{xor} (as $x \oplus 0 = x$). Note that the logical consequence is that the and-reduction of a zero-width expression returns a one, while the or- and xor-reductions of a zero-width expression both return zero. + \subsection{Concatenate Operation} \begin{figure}[H] -- cgit v1.2.3