From f4993df359b740966fd357a6e91897ac71ead05b Mon Sep 17 00:00:00 2001 From: Yuanjie Huang Date: Thu, 21 Feb 2019 12:12:41 +0800 Subject: [PATCH] Ensure the copy ctor will clear unused bits --- include/ap_fixed.h | 6 ++++++ include/ap_int.h | 8 ++++++++ include/etc/ap_private.h | 8 ++++++++ 3 files changed, 22 insertions(+) diff --git a/include/ap_fixed.h b/include/ap_fixed.h index ed7eab4..cd0192b 100644 --- a/include/ap_fixed.h +++ b/include/ap_fixed.h @@ -32,6 +32,9 @@ struct ap_fixed : ap_fixed_base<_AP_W, _AP_I, true, _AP_Q, _AP_O, _AP_N> { /// default ctor INLINE ap_fixed() : Base() {} + /// default copy ctor + INLINE ap_fixed(const ap_fixed& op) { Base::V = op.V; } + /// copy ctor from ap_fixed_base. template @@ -191,6 +194,9 @@ struct ap_ufixed : ap_fixed_base<_AP_W, _AP_I, false, _AP_Q, _AP_O, _AP_N> { /// default ctor INLINE ap_ufixed() : Base() {} + /// default copy ctor + INLINE ap_ufixed(const ap_ufixed& op) { Base::V = op.V; } + /// copy ctor from ap_fixed_base template diff --git a/include/ap_int.h b/include/ap_int.h index 87f69ae..db3044d 100644 --- a/include/ap_int.h +++ b/include/ap_int.h @@ -29,6 +29,10 @@ struct ap_int : ap_int_base<_AP_W, true> { typedef ap_int_base<_AP_W, true> Base; // Constructor INLINE ap_int() : Base() {} + + // Copy ctor + INLINE ap_int(const ap_int& op) { Base::V = op.V; } + template INLINE ap_int(const ap_int<_AP_W2>& op) { Base::V = op.V; @@ -163,6 +167,10 @@ struct ap_uint : ap_int_base<_AP_W, false> { typedef ap_int_base<_AP_W, false> Base; // Constructor INLINE ap_uint() : Base() {} + + // Copy ctor + INLINE ap_uint(const ap_uint& op) { Base::V = op.V; } + template INLINE ap_uint(const ap_uint<_AP_W2>& op) { Base::V = op.V; diff --git a/include/etc/ap_private.h b/include/etc/ap_private.h index ed22c4b..8e046f1 100644 --- a/include/etc/ap_private.h +++ b/include/etc/ap_private.h @@ -1401,22 +1401,26 @@ class ap_private<_AP_W, _AP_S, true> { void operator=(const ap_private& RHS) volatile { // Don't do anything for X = X VAL = RHS.get_VAL(); // No need to check because no harm done by copying. + clearUnusedBits(); } ap_private& operator=(const ap_private& RHS) { // Don't do anything for X = X VAL = RHS.get_VAL(); // No need to check because no harm done by copying. + clearUnusedBits(); return *this; } void operator=(const volatile ap_private& RHS) volatile { // Don't do anything for X = X VAL = RHS.get_VAL(); // No need to check because no harm done by copying. + clearUnusedBits(); } ap_private& operator=(const volatile ap_private& RHS) { // Don't do anything for X = X VAL = RHS.get_VAL(); // No need to check because no harm done by copying. + clearUnusedBits(); return *this; } @@ -4543,20 +4547,24 @@ class ap_private<_AP_W, _AP_S, false> { /// @brief Copy assignment operator. INLINE ap_private& operator=(const ap_private& RHS) { if (this != &RHS) memcpy(pVal, RHS.get_pVal(), _AP_N * APINT_WORD_SIZE); + clearUnusedBits(); return *this; } INLINE ap_private& operator=(const volatile ap_private& RHS) { if (this != &RHS) for (int i = 0; i < _AP_N; ++i) pVal[i] = RHS.get_pVal(i); + clearUnusedBits(); return *this; } INLINE void operator=(const ap_private& RHS) volatile { if (this != &RHS) for (int i = 0; i < _AP_N; ++i) pVal[i] = RHS.get_pVal(i); + clearUnusedBits(); } INLINE void operator=(const volatile ap_private& RHS) volatile { if (this != &RHS) for (int i = 0; i < _AP_N; ++i) pVal[i] = RHS.get_pVal(i); + clearUnusedBits(); } template