tgingold-cern / cheby

GNU General Public License v3.0
7 stars 4 forks source link

VHDL Const Preset Range #35

Closed stefanlippuner closed 7 months ago

stefanlippuner commented 7 months ago

We've run into problems with the PRESET constants generated by Cheby:

cheby/proto/../testfiles/features/semver1.cheby:warning: memory-map:version is deprecated
cheby/proto/../testfiles/bug-const-range/const_range-consts.vhdl:4:53:error: static expression violates bounds
  constant CONST_RANGE_LARGE_VAL_0_PRESET : Natural := 16#f38243bb#;
                                                       ^
error: VHDL elaboration failed for cheby/proto/../testfiles/bug-const-range/const_range-consts.vhdl

The problem is that the maximum legal* value of a natural in VHDL is 2^31-1. Therefore, it cannot correctly represent all preset values for 32-bit registers. To address this, I've changed the type of the PRESETs to std_logic_vector:

  constant CONST_RANGE_LARGE_VAL_0_PRESET : std_logic_vector(32-1 downto 0) := x"f38243bb";

This should allow for larger preset values, including for 64-bit registers.

This MR also adds a test for such a case and runs (VHDL) elaboration on the generated packages.

tgingold-cern commented 7 months ago

Yes, this is not backward compatible but the choice to use natural was obviously wrong.