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

Initial value of register ignored during synthesis #997

Closed
ymherklotz opened this issue May 7, 2019 · 2 comments
Assignees

Comments

@ymherklotz
Copy link

@ymherklotz ymherklotz commented May 7, 2019

Steps to reproduce the issue

Consider the following verilog code.

module top (y, clk, wire4);
   output wire [1:0] y;
   input             clk;
   input signed      wire4;
   reg [1:0]  reg10 = 0;
   always @(posedge clk) begin
      reg10 <= wire4;
   end
   assign y = reg10;
endmodule

When synthesised using

yosys -p 'read -formal rtl.v; synth; write_verilog -noattr syn_yosys.v'

and Yosys version

Generated by Yosys 0.8+450 (git sha1 09467bb9, clang 8.0.0 -fPIC -Os)

the initial value of the register seems to be ignored. Therefore, during simulation, the bit is undefined at first, and only behaves correctly after the first clock cycle.

This does not seem to happen with the official 0.8 release of Yosys. In that release, the expected behavior is generated.

Expected behavior

It is expected that the register is initialised with 0. This was generated using the 0.8 release of Yosys.

/* Generated by Yosys 0.8 (git sha1 b003446, clang 7.0.1 -march=x86-64 -mtune=generic -O2 -fno-plt -fPIC -Os) */

module top_1(y, clk, wire4);
  input clk;
  wire [1:0] reg10;
  input wire4;
  output [1:0] y;
  reg \reg10_reg[0]  = 1'h0; // <-----
  always @(posedge clk)
      \reg10_reg[0]  <= wire4;
  assign reg10[0] = \reg10_reg[0] ;
  assign reg10[1] = reg10[0];
  assign y = { reg10[0], reg10[0] };
endmodule

Actual behavior

However, it actually gets initialised with 1'hx.

/* Generated by Yosys 0.8+450 (git sha1 09467bb9, clang 8.0.0 -fPIC -Os) */

module top_1(y, clk, wire4);
  input clk;
  wire [1:0] reg10;
  input wire4;
  output [1:0] y;
  reg \reg10_reg[0]  = 1'hx; // <-----
  always @(posedge clk)
      \reg10_reg[0]  <= wire4;
  assign reg10[0] = \reg10_reg[0] ;
  assign reg10[1] = reg10[0];
  assign y = { reg10[0], reg10[0] };
endmodule
@cliffordwolf cliffordwolf self-assigned this May 7, 2019
cliffordwolf added a commit that referenced this issue May 7, 2019
Signed-off-by: Clifford Wolf <clifford@clifford.at>
@cliffordwolf

This comment has been minimized.

Copy link
Member

@cliffordwolf cliffordwolf commented May 7, 2019

Thanks for the excellent test case! Fixed in 33738c1.

@ymherklotz

This comment has been minimized.

Copy link
Author

@ymherklotz ymherklotz commented May 7, 2019

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.