From f705f9b2751a251f3418c8ff012f796df8f0a084 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 24 May 2014 08:00:01 -0400 Subject: [PATCH] Fix C compiler interpreting signing, bug773. --- Changes | 2 ++ src/V3EmitC.cpp | 5 +++-- test_regress/t/t_math_signed5.v | 14 +++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index 4f3de61d1..8256ec084 100644 --- a/Changes +++ b/Changes @@ -11,6 +11,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix shift corner issues, bug765, bug766, bug768, bug772. [Clifford Wolf] +**** Fix C compiler interpreting signing, bug773. [Clifford Wolf] + **** Fix gate primitives with arrays and non-arrayed pins. **** Fix ENDLABEL warnings on escaped identifiers. diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index 8df3850cd..3c0e2e9a2 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -622,8 +622,9 @@ public: // Only 32 bits - llx + long long here just to appease CPP format warning if (num<10) puts(cvtToStr(num)); else ofp()->printf("0x%" VL_PRI64 "x", (vluint64_t)num); - //Unneeded-Causes %lx format warnings: - // if (!nodep->num().isSigned() && (num & (1UL<<31))) puts("U"); + // If signed, we'll do our own functions + // But must be here, or <= comparisons etc may end up signed + puts("U"); } } void emitSetVarConstant(const string& assignString, AstConst* constp) { diff --git a/test_regress/t/t_math_signed5.v b/test_regress/t/t_math_signed5.v index 26740b20f..c45e92bfd 100644 --- a/test_regress/t/t_math_signed5.v +++ b/test_regress/t/t_math_signed5.v @@ -5,6 +5,11 @@ `define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); fail='1; end while(0) `define checkf(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%f exp=%f\n", `__FILE__,`__LINE__, (gotv), (expv)); fail='1; end while(0) +`ifdef VERILATOR + `define c(v,vs) ($c(vs)) // Don't constify a value +`else + `define c(v,vs) (v) +`endif module t (/*AUTOARG*/); @@ -127,9 +132,7 @@ w4_s = 4'sd4; w4_u = $signed(5'd1 > w4_s-w4_s); `checkh(w4_u, 4'b1111); -`ifdef VERILATOR - w4_s = $c4("4"); // Eval at runtime -`endif + w4_s = `c(4,"4"); // Eval at runtime w4_u = $signed(5'd1 > w4_s-w4_s); `checkh(w4_u, 4'b1111); @@ -139,6 +142,11 @@ `checkh(w4_s, 4'bxxxx); `endif + // bug773 + w5_u = `c(31, "31"); + w5_s = w5_u >> ((w5_u ? 1 : 2) << w5_u); + `checkh(w5_s, 5'b0); + if (fail) $stop; $write("*-* All Finished *-*\n"); $finish;