From 3a659d460dda44e93225ac5327b7af05f1a69b39 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 28 Jul 2024 14:40:55 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20=3D=3D=3F=20and=20!=3D=3F=20with=20X=20va?= =?UTF-8?q?lues.?= --- src/V3Number.cpp | 20 ++++++++++++-------- test_regress/t/t_math_eq.v | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/V3Number.cpp b/src/V3Number.cpp index 58192c310..996de3898 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -1696,11 +1696,13 @@ V3Number& V3Number::opWildEq(const V3Number& lhs, const V3Number& rhs) { NUM_ASSERT_LOGIC_ARGS2(lhs, rhs); char outc = 1; for (int bit = 0; bit < std::max(lhs.width(), rhs.width()); bit++) { - if (!rhs.bitIsXZ(bit) && lhs.bitIs(bit) != rhs.bitIs(bit)) { - outc = 0; - goto last; + if (!rhs.bitIsXZ(bit)) { + if (lhs.bitIs(bit) != rhs.bitIs(bit)) { + outc = 0; + goto last; + } + if (lhs.bitIsXZ(bit)) outc = 'x'; } - if (lhs.bitIsXZ(bit)) outc = 'x'; } last: return setSingleBits(outc); @@ -1711,11 +1713,13 @@ V3Number& V3Number::opWildNeq(const V3Number& lhs, const V3Number& rhs) { NUM_ASSERT_LOGIC_ARGS2(lhs, rhs); char outc = 0; for (int bit = 0; bit < std::max(lhs.width(), rhs.width()); bit++) { - if (!rhs.bitIsXZ(bit) && lhs.bitIs(bit) != rhs.bitIs(bit)) { - outc = 1; - goto last; + if (!rhs.bitIsXZ(bit)) { + if (lhs.bitIs(bit) != rhs.bitIs(bit)) { + outc = 1; + goto last; + } + if (lhs.bitIsXZ(bit)) outc = 'x'; } - if (lhs.bitIsXZ(bit)) outc = 'x'; } last: return setSingleBits(outc); diff --git a/test_regress/t/t_math_eq.v b/test_regress/t/t_math_eq.v index c1b5a8ae6..018f190c7 100644 --- a/test_regress/t/t_math_eq.v +++ b/test_regress/t/t_math_eq.v @@ -4,6 +4,9 @@ // any use, without warranty, 2007 by Wilson Snyder. // SPDX-License-Identifier: CC0-1.0 +`define stop $stop +`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0) + module t (/*AUTOARG*/ // Inputs clk @@ -35,6 +38,25 @@ module t (/*AUTOARG*/ // What checksum will we end up with `define EXPECTED_SUM 64'h1a0d07009b6a30d2 + initial begin + `checkh(3'b101 ==? 3'b100, 1'b0); + `checkh(3'b101 ==? 3'b101, 1'b1); + `checkh(3'b100 ==? 3'b10x, 1'b1); + `checkh(3'b101 ==? 3'b10x, 1'b1); + `checkh(3'b10x ==? 3'b10?, 1'b1); + `checkh(3'b110 ==? 3'b10?, 1'b0); + `checkh(3'b111 ==? 3'b10?, 1'b0); + `checkh(3'b11x ==? 3'b10?, 1'b0); + `checkh(3'b101 !=? 3'b100, !1'b0); + `checkh(3'b101 !=? 3'b101, !1'b1); + `checkh(3'b100 !=? 3'b10x, !1'b1); + `checkh(3'b101 !=? 3'b10x, !1'b1); + `checkh(3'b10x !=? 3'b10?, !1'b1); + `checkh(3'b110 !=? 3'b10?, !1'b0); + `checkh(3'b111 !=? 3'b10?, !1'b0); + `checkh(3'b11x !=? 3'b10?, !1'b0); + end + // Test loop always @ (posedge clk) begin `ifdef TEST_VERBOSE