Describe the bug
According to the IEEE Standard for SystemC® Language Reference Manual
(2023), section 7.2.9 — Bit-select for sc_signed and section 7.6.4.9
for sc_unsigned, writing to individual bits via operator[] shall
modify the value correctly.
The set(int i) and clear(int i) member
functions in both sc_signed and sc_unsigned modify digit[]
directly but do not call adjust_hod() afterwards.
adjust_hod() normalizes the top digit after any mutation:
- sc_signed: Arithmetic sign-extends spare bits
- sc_unsigned: Zero-fills spare bits
Without this call, the spare bits in the top digit contain stale data
from the previous value, causing to_int(), to_uint(), and other
accessors to return incorrect results.
To Reproduce
SystemC version: 3.0.2
Minimal Example
#include <systemc>
using namespace sc_dt;
using std::cout;
using std::endl;
int sc_main(int, char*[]) {
sc_bigint<6> x;
x = 0x2c; // -20 in 6-bit two's complement
x[5] = 0; // clear sign bit via bitref (calls clear(5))
cout << "After x[5]=0: to_int() = " << x.to_int() << " (expect 12)" << endl;
// Unfixed SystemC: returns -52 (stale sign-extension in digit[0])
return 0;
}
Expected behavior
After clearing bit 5, sc_bigint<6>(0x2c) should become 001100 = 12.
to_int() should return 12.
Instead, to_int() returns -52 because digit[0] is 0xFFFFFFCC
(stale sign-extension bits) instead of 0x0000000C.
Logs / Output
Unfixed output:
After x[5]=0: to_int() = -52 (expect 12)
Fixed output:
After x[5]=0: to_int() = 12 (expect 12)
Environment
- OS: RHEL 7 / Linux x86_64
- Compiler: GCC 12.3.0
- SystemC Version: 3.0.2-Accellera (commit
16b57dc38, main branch)
Additional context
Both sc_signed::set(int i) / sc_signed::clear(int i) and
sc_unsigned::set(int i) / sc_unsigned::clear(int i) are affected.
The fix is to add adjust_hod(); after modifying the bit in digit[].
Describe the bug
According to the IEEE Standard for SystemC® Language Reference Manual
(2023), section 7.2.9 — Bit-select for
sc_signedand section 7.6.4.9for
sc_unsigned, writing to individual bits viaoperator[]shallmodify the value correctly.
The
set(int i)andclear(int i)memberfunctions in both
sc_signedandsc_unsignedmodifydigit[]directly but do not call
adjust_hod()afterwards.adjust_hod()normalizes the top digit after any mutation:Without this call, the spare bits in the top digit contain stale data
from the previous value, causing
to_int(),to_uint(), and otheraccessors to return incorrect results.
To Reproduce
SystemC version: 3.0.2
Minimal Example
Expected behavior
After clearing bit 5,
sc_bigint<6>(0x2c)should become001100= 12.to_int()should return 12.Instead,
to_int()returns -52 becausedigit[0]is0xFFFFFFCC(stale sign-extension bits) instead of
0x0000000C.Logs / Output
Unfixed output:
Fixed output:
Environment
16b57dc38, main branch)Additional context
Both
sc_signed::set(int i)/sc_signed::clear(int i)andsc_unsigned::set(int i)/sc_unsigned::clear(int i)are affected.The fix is to add
adjust_hod();after modifying the bit indigit[].