From 094d676a8b4c4c4e694b7f763555a619b7905e38 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 21 Sep 2011 09:08:05 -0400 Subject: [PATCH] Fix MSVC compile warning with trunc/round, bug394. --- Changes | 5 +++++ include/verilated.h | 4 ++-- include/verilatedos.h | 12 ++++++++++++ src/V3Number.cpp | 4 ++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Changes b/Changes index 5e540c5c9..8bd8d4c19 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,11 @@ Revision history for Verilator The contributors that suggested a given feature are shown in []. [by ...] indicates the contributor was also the author of the fix; Thanks! +* Verilator 3.82*** + +**** Fix MSVC compile warning with trunc/round, bug394. [Amir Gonnen] + + * Verilator 3.821 2011/09/14 **** Fix PowerPC runtime error, bug288. [Ahmed El-Mahmoudy] diff --git a/include/verilated.h b/include/verilated.h index 49471c18f..fdbb92162 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -383,9 +383,9 @@ static inline QData VL_CVT_Q_D(double lhs) { union { double d; QData q; } u; u. /// Return double from QData (numeric) static inline double VL_ITOR_D_I(IData lhs) { return ((double)((vlsint32_t)(lhs))); } /// Return QData from double (numeric) -static inline IData VL_RTOI_I_D(double lhs) { return ((vlsint32_t)(trunc(lhs))); } +static inline IData VL_RTOI_I_D(double lhs) { return ((vlsint32_t)(VL_TRUNC(lhs))); } /// Return QData from double (numeric) -static inline IData VL_RTOIROUND_I_D(double lhs) { return ((vlsint32_t)(round(lhs))); } +static inline IData VL_RTOIROUND_I_D(double lhs) { return ((vlsint32_t)(VL_ROUND(lhs))); } // Sign extend such that if MSB set, we get ffff_ffff, else 0s // (Requires clean input) diff --git a/include/verilatedos.h b/include/verilatedos.h index 989996669..ade2e023e 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -221,6 +221,18 @@ typedef unsigned long long vluint64_t; ///< 64-bit unsigned type #define VL_BITBIT_I(bit) ((bit)&VL_SIZEBITS_I) ///< Bit number for a bit in a long #define VL_BITBIT_Q(bit) ((bit)&VL_SIZEBITS_Q) ///< Bit number for a bit in a quad +//========================================================================= +// Floating point +// #defines, to avoid requiring math.h on all compile runs + +#ifdef _MSC_VER +# define VL_TRUNC(n) (((n)<0) ? ceil((n)) : floor((n))) +# define VL_ROUND(n) (((n)<0) ? ceil((n)-0.5) : floor((n)+0.5)) +#else +# define VL_TRUNC(n) trunc(n) +# define VL_ROUND(n) round(n) +#endif + //========================================================================= #endif /*guard*/ diff --git a/src/V3Number.cpp b/src/V3Number.cpp index 60c8a7d1b..653d2631a 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -1475,12 +1475,12 @@ V3Number& V3Number::opIToRD (const V3Number& lhs) { return setDouble(lhs.toSInt()); } V3Number& V3Number::opRToIS (const V3Number& lhs) { - double v = trunc(lhs.toDouble()); + double v = VL_TRUNC(lhs.toDouble()); vlsint32_t i = (vlsint32_t)v; // C converts from double to vlsint32 return setLongS(i); } V3Number& V3Number::opRToIRoundS (const V3Number& lhs) { - double v = round(lhs.toDouble()); + double v = VL_ROUND(lhs.toDouble()); vlsint32_t i = (vlsint32_t)v; // C converts from double to vlsint32 return setLongS(i); }