Skip to content

vhdl shift_left bounds problem with 1.6.3 #2215

Description

@pbreuer

Another vhdl problem, but is it ghdl or is it clash? The runtime error reported from ghdl is:

./kpu_test:error: bound check failure at Test_Trace_kpu_test32_execA.vhdl:9809

The lines are:

cds_app_arg_2_shiftL : block
  signal sh_7 : natural;
begin
  sh_7 <=
      -- pragma translate_off
      natural'high when (\c$shI_4\(64-1 downto 31) /= 0) else
      -- pragma translate_on
      to_integer(\c$shI_4\               <------ line 9809 HERE!
      -- pragma translate_off
      (30 downto 0)
      -- pragma translate_on
      );
  \c$ds_app_arg_2\ <= shift_left(\x'_0\,sh_7)
      -- pragma translate_off
      when (((to_signed(23,64) - n_0) and to_signed(2147483647,64)) >= 0) else (others => 'X')
      -- pragma translate_on
      ;
end block;

The problem looks to be the index 30 downto 0 but I don't exactly see why. That's a 31 bit part (of a 64-bit signal) written to a 'natural'. Is a natural 31 bits or 32 bits? I think it is 31 bit, but perhaps it is implemented as 32 in ghdl or vdl and something goes wrong writing 31 bits to it here via to_integer.

The 63 downto 31 part higher up can be questioned too, depending.

This I think is the generating pattern in Clash_Sized_Internal_BitVector.primitives.yaml:

    template: |-
      ~GENSYM[~RESULT_shiftR][0] : block
        signal ~GENSYM[sh][1] : natural;
      begin
        ~SYM[1] <=
            -- pragma translate_off
            natural'high when (~VAR[shI][2](~SIZE[~TYP[2]]-1 downto 31) /= 0) else
            -- pragma translate_on
            to_integer(~VAR[shI][2]
            -- pragma translate_off
            (30 downto 0)
           -- pragma translate_on
            );
        ~RESULT <= std_logic_vector(shift_right(unsigned(~ARG[1]),~SYM[1]))
            -- pragma translate_off
            when ((~ARG[2]) >= 0) else (others => 'X')
            -- pragma translate_on
            ;
      end block;

and in my old 1.5.0pre it used to be:

shift_left(~ARG[1],to_integer(~ARG[2]))

and that doesn't generate runtime errors in ghdl.

So, who is right? Clash or ghdl? Why does ghdl error here?

Regards

PTB

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions