You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support results outside the 32-bit range with a 64-bit INTEGER (NVC with VHDL-2019) #44
#45 now also gives integer, integer_vector and integer_vector_ptr_t results the full range of a 64-bit integer (and the lists of a dict_t), so it resolves this issue.
Two kinds of integers remain 32 bits, and that is an upstream VUnit limitation, tracked in VUnit/vunit#1256:
integer_array_t elements. VUnit's integer_array_pkg does not accept a bit_width above 32, and its save_raw/load_raw use 32-bit words. With a 64-bit integer, VUnit nevertheless lets an array with a bit_width of 32 hold larger values in memory. The bridge transfers the elements as 32 bits and reports a larger element as a failure, in both directions.
dict_t integers. VUnit's codec encodes an integer in 4 bytes (integer_code_length), so set_integer truncates a larger value before the bridge sees it. The bridge reports a larger dict_t integer result as a failure rather than letting VUnit truncate it.
Once VUnit supports 64-bit values there, the bridge can follow.
Summary
Follow-up to #43 and #45. #45 makes the bridge work with a 64-bit INTEGER, such as NVC 1.20+ with VHDL-2019 (integer'high = 2⁶³−1), by declaring the foreign subprograms with a 32-bit integer type of their own (c_int32_t). Arguments reach Python in full since they are transferred as Python source code, but results are limited to the 32-bit range: eval_integer("2**40") fails with an OverflowError although the value fits in the integer of the simulator. This issue is about results with the full range of a 64-bit integer.
Where the 32-bit limit is
integer_chunk_t (c_int32_vector_t) transfers in python_ffi_pkg_bridge.vhd: vpy_result_read_integers (integer_vector and integer_array_t results, dict entries), and vpy_result_integer.
The native side (src/vunit_python_bridge/native/), whose result buffers and exported functions are int32_t.
INTEGER_LOW/INTEGER_HIGH in runtime.py, whose OverflowError messages also say "outside the range of VHDL integer" with the 32-bit bounds, which is misleading with a 64-bit integer.
Suggested approach
Let VHDL tell the native library the width, since VHPIDIRECT gives the C side no type information:
python_ffi_pkg_bridge passes the width once, derived from integer'high, e.g. as an argument of vpy_setup/vpy_begin or through a new vpy_set_integer_width(bits).
runtime.py checks results against that range.
The integer results cross the interface as 64 bits when integer is 64 bits: e.g. a second set of result entry points with a c_int64_t (64-bit range) type, declared only where the simulator supports 64-bit integer types, or a split into two c_int32_t halves that works everywhere.
integer_array_t: VUnit limits its bit_width to 32, so it can stay 32 bits.
Extend tests/integer_width (which runs with a 32-bit and, for NVC, a 64-bit integer) with round trips of values outside the 32-bit range.
Alternatives considered: querying the range of STD.STANDARD.INTEGER through VHPI only works for the VHPI application; inferring the width in Python from the simulator, its version and vhdl_standard is fragile.
changed the title [-]Support a 64-bit INTEGER (NVC with VHDL-2019) in the integer transfers[/-][+]Support results outside the 32-bit range with a 64-bit INTEGER (NVC with VHDL-2019)[/+]on Nov 18, 2026
Activity
[-]Support a 64-bit INTEGER (NVC with VHDL-2019) in the integer transfers[/-][+]Support results outside the 32-bit range with a 64-bit INTEGER (NVC with VHDL-2019)[/+]