Repository navigation
Conversation
NVC uses a 64-bit integer with VHDL-2019, but the foreign subprograms of python_bridge_pkg were declared with integer while the native library takes and returns int32_t. Integer results, integer_vector and integer_array_t values and dict entries were transferred as garbage. The foreign subprograms now use c_int32_t, an integer type of their own with the 32-bit range, which every simulator passes as int32_t whatever the width of integer, and python_ffi_pkg converts to and from integer. Results stay limited to the 32-bit range, which runtime.py checks. Arguments are transferred as Python source code and are not limited. tests/integer_width runs with the VHDL standard of the run, and for NVC also with VHDL-2019. Fixes #43. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With a 64-bit integer, as for NVC with VHDL-2019, the results were limited to the 32-bit range of the foreign interface. VHDL now gives runtime.py the width of integer as the width of an integer, integer_vector or dict_t result, which vpy_eval takes but did not use for those kinds. runtime.py checks the results against that range, and a 64-bit value crosses the 32-bit interface as its low and high int32 halves: the integer and the first metadata value for a scalar, a pair per element for an integer_vector. python_ffi_pkg combines them. The native library is unchanged. The integers of a dict_t stay 32 bits since VUnit encodes them in 32 bits, and a larger dict_t integer result is an error saying so. The elements of an integer_array_t are at most 32 bits anyway. docs/types.rst describes the range of integer. The bounds were not literals, so ** started strong emphasis. tests/integer_width covers both halves and the bounds of a 64-bit integer, integer_vector_ptr_t, dict_t and boolean results and 64-bit arguments, and test_python_bridge.py the halves and ranges of runtime.py. The test of integer bounds in tb_python_pkg no longer assumes a 32-bit integer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The release note says which integers have the full 64-bit range and which remain 32 bits. The documentation, comments and release note describe a 64-bit integer by VHDL-2019 rather than by a simulator. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With a 64-bit integer, VUnit lets an integer_array_t with a bit_width of 32 hold a value outside 32 bits, since its limits are integer'low and integer'high. The bridge transfers the elements as 32 bits, and such an element stopped the simulation with a range error of c_int32_t. It is now reported as a failure of the argument naming the element, like any other argument that cannot be converted. tests/integer_width checks that an element outside 32 bits fails as an argument and as a result. The documentation and release note say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #43. Fixes #44.
Problem
With VHDL-2019,
integercan be 64 bits. The foreign subprograms ofpython_bridge_pkgwere declared withinteger, while the native library takes and returnsint32_t, so integer results,integer_vectorandinteger_array_tvalues and dict entries were transferred with the wrong element size, e.g.eval_integer_vector("[3, 1, 4]")gave(4294967299, -9223372036854775804, -9223372036854775808).Change
python_bridge_pkg.vhd.indeclaresc_int32_t(the 32-bit range) andc_int32_vector_t, and every foreign subprogram andinteger_chunk_tuses them. A simulator passes such a type asint32_twhatever the width ofinteger, so the native library and its FLI/VHPI wrappers are unchanged.python_ffi_pkg_bridge.vhdconverts at the foreign calls.runtime.pythe width ofintegeras thewidthof an integer,integer_vectorordict_tresult, whichvpy_evalalready takes but did not use for those kinds.runtime.pychecks results against that range, and with a 64-bitintegera value crosses the 32-bit interface as its low and highint32halves: the integer and the first metadata value for a scalar, a pair per element for aninteger_vector.python_ffi_pkgcombines them. With a 32-bitintegernothing changes on the wire.dict_t, since VUnit's codec encodes them in 32 bits (integer_code_length); a largerdict_tinteger result is an error saying so, whileset_integertruncates a larger argument before the bridge sees it. The elements of aninteger_array_t, which cross asint32: with a 64-bitintegerVUnit lets an array with abit_widthof 32 hold a larger value, and such an argument element is now reported as a failure naming the element (fourth commit) instead of stopping the simulation with a range error; a larger result already failed the word size check.docs/types.rstdescribes the range ofinteger.Tests
tests/integer_width: scalar,integer_vector,integer_vector_ptr_t,integer_array_t,dict_tandbooleanresults, values using both halves,integer_array_telements outside 32 bits,integer'low/integer'high, 64-bit arguments, thedict_tlimit.tests/run.pyruns it with the VHDL standard of the run, and also with VHDL-2019 for the simulators known to have a 64-bitintegerwith it.test_python_bridge.py: the halves and the ranges ofruntime.py.tb_python_pkg's test of the integer bounds no longer assumes a 32-bitinteger.Local, Windows, NVC 1.23.1 and GHDL 6.0 (mcode):
tests/run.py, NVC, VHDL-2008tb_elaboration_arrayfailure); width tests 9/9 with 2008 and 2019tests/run.py, GHDL, VHDL-2008pytest tests/test_python_bridge.pyTestRelativeFileBasetests fail on Windows as onmainThe full suite with VHDL-2019 is not run by CI: 37 of its tests compare mocked log entries, and VUnit gives a log entry the location of its call path with VHDL-2019, which
check_logcompares. That is independent of this change; all other tests pass with VHDL-2019.Not tested here: Questa/ModelSim and Riviera-PRO, whose
integeris 32 bits, soc_int32_tpasses the same way asintegerdid and the results are unchanged.