From 49b823244732e8d3a4b0fe91d0f10625fea34eec Mon Sep 17 00:00:00 2001 From: Jack Koenig Date: Fri, 19 Mar 2021 13:59:52 -0700 Subject: Legalize neg: -x becomes 0 - x (#2128) This fixes an error with negating a negative SInt literal and a [debatable] lint warning in Verilator when negating any value. This behavior matches that of Chisel (which directly emits the 0 - x already).--- src/test/resources/passes/Legalize/Legalize.fir | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/test/resources') diff --git a/src/test/resources/passes/Legalize/Legalize.fir b/src/test/resources/passes/Legalize/Legalize.fir index 7e538695..a0a39845 100644 --- a/src/test/resources/passes/Legalize/Legalize.fir +++ b/src/test/resources/passes/Legalize/Legalize.fir @@ -39,3 +39,25 @@ circuit Legalize : when neq(bar_15, UInt(1)) : printf(clock, UInt(1), "Assertion failed!\n bar_15 != 0\n") stop(clock, UInt(1), 1) + + ; Check neg of literals + node negUInt0 = neg(UInt(123)) + when neq(negUInt0, SInt(-123)) : + printf(clock, UInt(1), "Assertion failed!\n negUInt0 != -123\n") + stop(clock, UInt(1), 1) + node negUInt1 = neg(UInt<8>(0)) + when neq(negUInt1, SInt<8>(0)) : + printf(clock, UInt(1), "Assertion failed!\n negUInt1 != 0\n") + stop(clock, UInt(1), 1) + node negSInt0 = neg(SInt(123)) + when neq(negSInt0, SInt(-123)) : + printf(clock, UInt(1), "Assertion failed!\n negSInt0 != -123\n") + stop(clock, UInt(1), 1) + node negSInt1 = neg(SInt(-123)) + when neq(negSInt1, SInt(123)) : + printf(clock, UInt(1), "Assertion failed!\n negSInt1 != 123\n") + stop(clock, UInt(1), 1) + node negSInt2 = neg(SInt(0)) + when neq(negSInt2, SInt(0)) : + printf(clock, UInt(1), "Assertion failed!\n negSInt2 != 0\n") + stop(clock, UInt(1), 1) -- cgit v1.2.3