cocotb / cocotb

cocotb, a coroutine based cosimulation library for writing VHDL and Verilog testbenches in Python
https://www.cocotb.org
BSD 3-Clause "New" or "Revised" License
1.8k stars 511 forks source link

Xcelium/VHDL: Unable to get correct time precision #3419

Open imphil opened 1 year ago

imphil commented 1 year ago

Getting the simulator's precision in Xcelium with VHDL toplevels is impossible currently for two reasons:

  1. Xcelium does not implement the VHPI call to get the precision in VDHL: vhpi_get_phys(vhpiResolutionLimitP, NULL);, returning invalid data (high == -1, low == 0).
  2. With Xcelium, we always load VPI first and then VHPI as second GPI implementation. However, the cocotb.simulator.get_precision() call only queries the first GPI implementation, which is always VPI.
  3. The VPI time precision seems to be wrong: For unknown reasons (yet), whatever you set as -timescale to xrun, a precision of 1 ns (-9) is returned.

So there are multiple things to sort out for us and Cadence. I opened a Cadence case to ask for support for vhpi_get_phys(), but that alone won't do the trick. Ideally, we want to load VPI only if Verilog is used. We'll need to look into what's preventing that.

tymonx commented 2 months ago

I have workaround that limitation by overriding the Cocotb internal function _get_simulator_precision. Tested with Cocotb 1.9.0 and Cadence Xcelium 24.03.005. It works perfectly fine with VHDL as top level design. I can confirm that the vhpi_get_phys is not implemented and VPI version is not working correctly (it returns -9). But there is no problem to generate signals like clocks with precision below 1ns using VHPI. Maximum value is -15 (fs resolution) according to VHDL specification and Cadence Xcelium prints time with fs resolution as well.

Example workaround:

import cocotb

cocotb.utils._get_simulator_precision = lambda: -12  # Enforce picosecond (ps) resolution

# Cocotb tests
# ...