奇怪的RTL输出

时间:2019-04-26 04:56:02

标签: yosys

[Yosys 0.8]

我的一位同事向Yosys投了一些随机 Verilog代码,以查看其反应。

这里是:

module top(input clk, input led, output led2, output to_port1,output [24:0] to_port2);


reg ctr = 0;
reg[24:0] counter = 2;
always@(posedge clk) begin
    if (ctr == 1) begin
        ctr <= 0;
        counter <= counter + 1;
    end
    else
        ctr <= 1;
end

assign led2 = ctr;
assign to_port1 = led;
assign to_port2 = counter;
endmodule

和Yosys,使用命令yosys -o synth.v x.v抛出:

module top(clk, led, led2, to_port1, to_port2);

  reg [24:0] _0_;
  reg _1_;
  reg [24:0] _2_;
  reg _3_;
  wire [31:0] _4_;
  wire _5_;
  input clk;
  reg [24:0] counter;
  reg ctr;
  input led;
  output led2;
  output to_port1;
  output [24:0] to_port2;

  assign _4_ = counter + 32'd1;
  assign _5_ = ctr == 32'd1;
  always @* begin
    _3_ = 1'h0;
  end
  always @* begin
  end
  always @({  }) begin
      ctr <= _3_;
  end
  always @* begin
    _2_ = 25'h0000002;
  end
  always @* begin
  end
  always @({  }) begin
      counter <= _2_;
  end
  always @* begin
    _1_ = ctr;
    _0_ = counter;
    casez (_5_)
      1'h1:
        begin
          _1_ = 1'h0;
          _0_ = _4_[24:0];
        end
      default:
          _1_ = 1'h1;
    endcase
  end
  always @(posedge clk) begin
      ctr <= _1_;
      counter <= _0_;
  end
  assign led2 = ctr;
  assign to_port1 = led;
  assign to_port2 = counter;
endmodule

某些构造最终变得很复杂。上面的结果代码在原始结果可以的情况下,不能由最新的verilog编译器进行编译。

为什么使用always @({ }) begin构造并清空always @* begin? 有没有我们错过的选择?

谢谢

1 个答案:

答案 0 :(得分:0)

由于Yosys内部读取的Verilog的性质,通常应该在读写Verilog之间始终运行proc(-p proc)