migen icon indicating copy to clipboard operation
migen copied to clipboard

VCD file may contain time stamps as floats

Open oscargus opened this issue 8 months ago • 1 comments

Not sure how this happens, but we got a bug report for Surfer Waveform Viewer, https://gitlab.com/surfer-project/surfer/-/issues/402 that it couldn't read a VCD from Migen. The cause seems to be that the time stamps in the VCD are written as floats (which is not supported in the standard). Although they are indeed integers as such, ending with .0.

After quickly browsing the code, it seems like Migen wants to keep timing as integers, but that nothing really prohibits using floats.

Hence, my suggestion is to either check that relevant numbers are integers or make sure that the time stamps are printed as integers. My initial worry was that half_period would be an issue, but that is computed with // 2, so will still be rounded to an integer (if an integer is provided).

oscargus avatar Apr 16 '25 17:04 oscargus

I have now played around with this a bit and my suggestion is to print the values as integers.

(For other readers: providing a clock period as a float will print the number as a float, but because the simulation appears to be built around half clock periods, which are computed using // 2, these will always be "integers", but possibly represented as floats. So printing them as integers will not change anything, except for VCD compliance. Example: clocks = {"sys": 7} is the same as clocks = {"sys": 6}, is almost the same as clocks = {"sys": 7.}, except that time stamps will be printed as 3.0, 6.0, ... )

oscargus avatar Apr 22 '25 15:04 oscargus