Ensure the copy ctor will clear unused bits

This commit is contained in:
Yuanjie Huang 2019-02-21 12:12:41 +08:00
parent 607126b4f0
commit f4993df359
3 changed files with 22 additions and 0 deletions

View file

@ -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 <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>
@ -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 <int _AP_W2, int _AP_I2, bool _AP_S2, ap_q_mode _AP_Q2,
ap_o_mode _AP_O2, int _AP_N2>

View file

@ -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 <int _AP_W2>
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 <int _AP_W2>
INLINE ap_uint(const ap_uint<_AP_W2>& op) {
Base::V = op.V;

View file

@ -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 <int _AP_W1, bool _AP_S1>