简体   繁体   English

在verilog或系统verilog中生成块内部case语句

[英]Generate block inside case statement in verilog or system verilog

Is there a way in Verilog or SystemVerilog to insert generate statement inside case statement to generate all the possible input combinations. 在Verilog或SystemVerilog中是否有一种方法可以在case语句中插入generate语句来生成所有可能的输入组合。 For example a typical use case would be for a N:1 mux. 例如,典型的用例是N:1 mux。

case(sel)
  generate
    for(i = 0; i < N; i += 1)
      i: out = q[i];
  endgenerate
endcase

I tried this, but the tool gives error. 我尝试了这个,但该工具给出了错误。 An alternate syntax is available which is 可用的替代语法是

out <= q[sel];

But, my tool is not understanding this(the mux is fully decoded) and generating combinational loops. 但是,我的工具不理解这个(多路复用器被完全解码)并产生组合循环。 I can use if statement to get the expected mux. 我可以使用if语句来获得预期的多路复用器。 But, I was wondering if there was a better way to do it. 但是,我想知道是否有更好的方法来做到这一点。

You can't mix a for and a case like that. 你不能混合for和这样的case If you're just trying to write a multiplexer, have a look at this older question: How to define a parameterized multiplexer using SystemVerilog 如果您只是想编写一个多路复用器,请看一下这个较老的问题: 如何使用SystemVerilog定义参数化多路复用器

The only difference there is that the select signal is supposed to be onehot encoded. 唯一的区别是选择信号应该是单一编码的。 For your case you would have: 对于您的情况,您将拥有:

always_comb begin
out = 'z;
for (int i = 0; i < N; i++) begin
  if(sel == i)
    out = q[i];
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM