Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Illegal Verilog output after 'proc_prune'; assigns 'reg' from a constant #2035

Closed
strobo5 opened this issue May 6, 2020 · 6 comments · Fixed by #4314
Closed

Illegal Verilog output after 'proc_prune'; assigns 'reg' from a constant #2035

strobo5 opened this issue May 6, 2020 · 6 comments · Fixed by #4314
Labels

Comments

@strobo5
Copy link

strobo5 commented May 6, 2020

Steps to reproduce the issue

The following procedure generates illegal Verilog (at least XST fails and quick research tells me it cannot be blamed).
assign a_pc[1:0] = 2'h0; (outside an always block)
When the ilang code is changed so that the default case is named explicitly (case -> case 1'1) then the Verilog code is as expected.

$ yosys -p "read_ilang bug.il; proc_prune; write_verilog bug.v"
[..]
2. Executing PROC_PRUNE pass (remove redundant assignments in processes).
Removed 0 redundant assignments.
Promoted 1 assignment to connection.
[..]
module\top
  wire width 1 input 0 \sel
  wire width 8 output 1 \a_pc
  process $group_1
    assign \a_pc 8'00000000
    switch \sel
      case 1'0
        assign \a_pc [7:2] 6'101010
      case
        assign \a_pc [7:2] 6'111111
    end
    sync init
  end
end

Expected behavior

/* Generated by Yosys 0.9+2406 (git sha1 584780d7, gcc 9.2.0-r2 -O2 -march=bdver2 -mmmx -msse -msse2 -msse3 -mssse3 -msse4a -mcx16 -msahf -maes -mpclmul -mpopcnt -mabm -mlwp -mfma -mfma4 -mxop -mbmi -mtbm -mavx -msse4.2 -msse4.1 -mlzcnt -mf16c -mprfchw -mfxsr -mxsave -mtune=bdver2 -fPIC -Os) */

module top(a_pc, sel);
  output [7:0] a_pc;
  reg [7:0] a_pc;
  input sel;
  always @* begin
    a_pc = 8'h00;
    casez (sel)
      1'h0:
          a_pc[7:2] = 6'h2a;
      1'h1:
          a_pc[7:2] = 6'h3f;
    endcase
  end
  initial begin
  end
endmodule

Actual behavior

/* Generated by Yosys 0.9+2406 (git sha1 584780d7, gcc 9.2.0-r2 -O2 -march=bdver2 -mmmx -msse -msse2 -msse3 -mssse3 -msse4a -mcx16 -msahf -maes -mpclmul -mpopcnt -mabm -mlwp -mfma -mfma4 -mxop -mbmi -mtbm -mavx -msse4.2 -msse4.1 -mlzcnt -mf16c -mprfchw -mfxsr -mxsave -mtune=bdver2 -fPIC -Os) */

module top(a_pc, sel);
  output [7:0] a_pc;
  reg [7:0] a_pc;
  input sel;
  always @* begin
    casez (sel)
      1'h0:
          a_pc[7:2] = 6'h2a;
      default:
          a_pc[7:2] = 6'h3f;
    endcase
  end
  initial begin
  end
  assign a_pc[1:0] = 2'h0;
endmodule
@whitequark
Copy link
Member

So, write_verilog tells you that the input contains processes and it doesn't guarantee that the result will be correct, right? Looks like one of those cases.

What are you trying to do exactly?

@strobo5
Copy link
Author

strobo5 commented May 7, 2020

So, write_verilog tells you that the input contains processes and it doesn't guarantee that the result will be correct, right? Looks like one of those cases.

Mh well it says "Unintended changes in simulation behavior are possible!"

What are you trying to do exactly?

I have a small nMigen design around minerva which fails during synthesis in ISE after a recent change minerva-cpu/minerva@890975e . This is the troublesome part of the Verilog code from nMigen (python mydesign.py generate mydesign.v):

  always @* begin
    (* src = "/foo/minerva/minerva/units/fetch.py:49" *)
    casez ({ \$21 , \$19 , \$17  })
      /* src = "/foo/minerva/minerva/units/fetch.py:49" */
      3'b??1:
          a_pc[31:2] = m_a_pc[31:2];
      /* src = "/foo/minerva/minerva/units/fetch.py:51" */
      3'b?1?:
          a_pc[31:2] = d_pc[31:2];
      /* src = "/foo/minerva/minerva/units/fetch.py:53" */
      3'b1??:
          a_pc[31:2] = d_branch_target[31:2];
      /* src = "/foo/minerva/minerva/units/fetch.py:55" */
      default:
          a_pc[31:2] = \$23 [29:0];
    endcase
  end
  assign \$23  = \$24 ;
  assign a_pc[1:0] = 2'h0;

@whitequark
Copy link
Member

whitequark commented May 7, 2020

Hm, you're right, and my initial assessment was incorrect--this has nothing to do with processes.

Rather this is an interesting corner case and a bug in write_verilog. There is no problem in proc_prune though, since it produces perfectly valid RTLIL.

@whitequark whitequark added the bug label May 7, 2020
@whitequark
Copy link
Member

As a workaround I suggest you use the complete proc command before handing off the results to ISE.

@whitequark
Copy link
Member

I've looked closer at this and I'm afraid it'll require some fairly significant re-engineering of the Verilog backend to properly fix.

jfng pushed a commit to jfng/yosys that referenced this issue Nov 28, 2020
Before this commit, in a process like:
  process $group_0
    assign $o 2'00
    attribute \full_case 1
    switch \x
      case 1'1
        assign $o [0] 1'1
      case
        assign $o [0] 1'0
    end
  end
"assign $o 2'00" would be promoted to "connect $o [1] 1'0".

Mixing assign and connect statements to different bits of the same
signal results in incorrect codegen from the write_verilog backend.

After this commit, "assign $o 2'00" is pruned to "assign $o [1] 1'0"
as a workaround.

Fixes YosysHQ#2035.
jfng pushed a commit to minerva-cpu/minerva that referenced this issue Jan 22, 2021
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post72 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post73 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post74 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post76 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post77 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post79 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post80 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post81 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post82 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post84 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post85 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post86 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post87 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post88 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 4, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post89 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 15, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post90 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Feb 15, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post91 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Mar 5, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post92 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Mar 5, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post94 from https://github.com/litex-hub/litex-data-auto
symbiflow-robot pushed a commit to litex-hub/pythondata-cpu-minerva that referenced this issue Mar 5, 2021
Updated data to v0.0-99-g0b5f6b2 based on 0b5f6b2 from https://github.com/lambdaconcept/minerva.
> commit 0b5f6b2
> Author: Jean-François Nguyen <jf@lambdaconcept.com>
> Date:   Fri Jan 22 15:20:35 2021 +0100
>
>     fetch: workaround YosysHQ/yosys#2035.
>

Updated using 0.0.post95 from https://github.com/litex-hub/litex-data-auto
whitequark added a commit to whitequark/yosys that referenced this issue Apr 3, 2024
whitequark added a commit to whitequark/yosys that referenced this issue Apr 3, 2024
@whitequark
Copy link
Member

Will be fixed by #4314.

mwkmwkmwk pushed a commit that referenced this issue Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants