Support IEEE time units and time precisions, #234. (#2253)

Includes `timescale, $printtimescale, $timeformat.
VL_TIME_MULTIPLIER, VL_TIME_PRECISION, VL_TIME_UNIT have been removed
and the time precision must now match the SystemC time precision.
To get closer behavior to older versions, use e.g. --timescale-override
"1ps/1ps".
This commit is contained in:
Wilson Snyder
2020-04-15 19:39:03 -04:00
committed by GitHub
parent 9b8aebb00c
commit d4f7f5297a
131 changed files with 2611 additions and 1290 deletions
+14 -3
View File
@@ -1241,10 +1241,12 @@ PLI_INT32 vpi_get(PLI_INT32 property, vpiHandle object) {
_VL_VPI_ERROR_RESET();
switch (property) {
case vpiTimePrecision: {
return VL_TIME_PRECISION;
return Verilated::timeprecision();
}
case vpiTimeUnit: {
return VL_TIME_UNIT;
VerilatedVpioScope* vop = VerilatedVpioScope::castp(object);
if (!vop) return Verilated::timeunit(); // Null asks for global, not unlikely
return vop->scopep()->timeunit();
}
case vpiType: {
VerilatedVpio* vop = VerilatedVpio::castp(object);
@@ -1903,7 +1905,7 @@ void vpi_put_value_array(vpiHandle /*object*/, p_vpi_arrayvalue /*arrayvalue_p*/
// time processing
void vpi_get_time(vpiHandle /*object*/, p_vpi_time time_p) {
void vpi_get_time(vpiHandle object, p_vpi_time time_p) {
VerilatedVpiImp::assertOneCheck();
// cppcheck-suppress nullPointer
if (VL_UNLIKELY(!time_p)) {
@@ -1917,6 +1919,15 @@ void vpi_get_time(vpiHandle /*object*/, p_vpi_time time_p) {
time_p->low = itime[0];
time_p->high = itime[1];
return;
} else if (time_p->type == vpiScaledRealTime) {
double dtime = VL_TIME_D();
if (VerilatedVpioScope* vop = VerilatedVpioScope::castp(object)) {
int scalePow10 = Verilated::timeprecision() - vop->scopep()->timeunit();
double scale = vl_time_multiplier(scalePow10); // e.g. 0.0001
dtime *= scale;
}
time_p->real = dtime;
return;
}
_VL_VPI_ERROR(__FILE__, __LINE__, "%s: Unsupported type (%d)", VL_FUNC, time_p->type);
}