ghdl / ghdl-yosys-plugin

VHDL synthesis (based on ghdl)
GNU General Public License v3.0
296 stars 32 forks source link

Cannot handle dynamic slicing and other operations in a single statement #108

Closed kammoh closed 4 years ago

kammoh commented 4 years ago

MWE:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity MWE is

  port (
    a   : in std_logic_vector(0 to 3);
    b   : in std_logic_vector(0 to 3);
    sel : in std_logic_vector(0 to 1);
    o   : out std_logic_vector(0 to 1)
  );
end MWE;

architecture behavioral of MWE is
  signal cnt : integer range 0 to 1;
begin
  cnt <= to_integer(unsigned(sel));
  o <= a(cnt*o'length to (cnt + 1)*o'length - 1) xor b(cnt*o'length to (cnt + 1)*o'length - 1);
end architecture behavioral;

works fine in simulation. In synthesis:

$ yosys -m ghdl -p 'ghdl mwe.vhdl -e MWE' 

******************** GHDL Bug occurred ***************************
Please report this bug on https://github.com/ghdl/ghdl/issues
GHDL release: 1.0-dev (v0.37.0-371-gb800347e) [Dunoon edition]
Compiled with unknown compiler version
Target: x86_64-apple-darwin15
/Volumes/src/ghdl-yosys-mwe-3/
Command line:

Exception CONSTRAINT_ERROR raised
Exception information:
raised CONSTRAINT_ERROR : synth-oper.adb:131 discriminant check failed
******************************************************************
ERROR: vhdl import failed.

While the following works:

...
  signal tmp1, tmp2 : std_logic_vector(0 to 1);
...
  tmp1 <= b(cnt*o'length to (cnt + 1)*o'length - 1);
  tmp2 <= a(cnt*o'length to (cnt + 1)*o'length - 1);
  o    <= tmp1 xor tmp2;
tgingold commented 4 years ago

Now fixed.

kammoh commented 4 years ago

While the trimmed down MWE works now, it still fails other instances like this one:

 tag_match <= '1' when ((c_dout_r(word_cnt_r*CCW to (word_cnt_r+1)*CCW -1) xor bdo_offset_mux) = bdi) else '0';
******************** GHDL Bug occurred ***************************
Please report this bug on https://github.com/ghdl/ghdl/issues
GHDL release: 1.0-dev (v0.37.0-386-g5b9fb819) [Dunoon edition]
Compiled with unknown compiler version
Target: x86_64-apple-darwin15
/Volumes/src/lwc/lwc_candidates_rtl/Pyjamask/src_rtl/
Command line:

Exception CONSTRAINT_ERROR raised
Exception information:
raised CONSTRAINT_ERROR : synth-oper.adb:131 discriminant check failed
******************************************************************
ERROR: vhdl import failed.

As before, no information on which file / line / compilation unit / entity this is happening, so have to do a binary search with commenting out code to find where it actually chokes :))

edit: It's actually resolved! Thank you! Although I thought I had the latest git and rebuilt and reinstall both ghdl (d8cd7bc8) and ghdl-yosys-plugin (386ad815), apparently there was a problem with make install (at least on macOS) which causes ghdl.so not to be update. Pretty weird as running yosys-config --exec cp ghdl.so --datdir/plugins manually seems to work!

tgingold commented 4 years ago

GHDL release: 1.0-dev (v0.37.0-386-g5b9fb819) [Dunoon edition]

It looks like you are using a version of ghdl before the fix was pushed. Otherwise, an mwe would be nice.

The crash is really unexpected. You can use '-v' to view which instance was synthesized if you want to trim down. But that's not required. I will be happy with a large file as I will easily know which construct was the cause of the crash.

An MWE must be standalone: the reproducer must not require external modules or libraries. Having a small MWE is nice as that's easier to handle, but not really necessary.