Verilog 填充0';s与1';两个1';s(可合成)

Verilog 填充0';s与1';两个1';s(可合成),verilog,system-verilog,Verilog,System Verilog,假设我们有MSB\u限制和LSB\u限制。这两个作为两个标志,它们之间的所有位(甚至是1-我认为这简化了问题)必须转到1 有没有一个可综合的解决方案 问题的例子: MSB_limit = 7; LSB_limit = 2; //Let's suppose our register is 16bits, desired output: 0000000011111100 ^ ^ ^ ^ | | | | 15 7 2 0 //

假设我们有
MSB\u限制
LSB\u限制
。这两个作为两个标志,它们之间的所有位(甚至是1-我认为这简化了问题)必须转到1

有没有一个可综合的解决方案

问题的例子:

MSB_limit = 7;
LSB_limit = 2;

//Let's suppose our register is 16bits, desired output:

 0000000011111100
 ^       ^    ^ ^
 |       |    | |
15       7    2 0       //positions

unsigned int my_reg=1可通过for循环轻松实现:

SystemVerilog(IEEE 1800):

Verilog(IEEE 1364-2001或更高版本):

reg[N-1:0]my\u reg;
整数idx;
总是开始
对于(idx=0;idxmy_reg[idx]=(idx>=LSB_limit)&&(idx复制运营商如何

assign out = { '0, { MSB_limit-LSB_limit+1{1'b1} }, { LSB_limit{1'b0} } };

对于
循环,RTL/synthesis代码是否鼓励使用循环?为什么有人应该选择这种类型而不是其他两个答案?(优点、缺点等),因为循环在RTL中使用,并且可以在静态展开时进行合成。它们倾向于使用较少的门和比移位运算符更好的计时。复制只对常量有效(例如:LSB/MSB_限制是参数)。对于动态限制,for循环允许合成器决定使用组合解码或移位寄存器。这取决于合成器的智能。在我的工作中,静态限制允许移位和复制。for循环优先使用动态限制。尝试所有方法并使用符合您要求的方法这只有在MSB_限制和LSB_限制得到同意的情况下才有效。
logic [N-1:0] my_reg;
always_comb begin
  foreach(my_reg[idx])
     my_reg[idx] = idx inside {[LSB_limit:MSB_limit]};
end
reg [N-1:0] my_reg;
integer idx;
always @* begin
  for (idx = 0; idx < N; idx=idx+1) begin
    my_reg[idx] = (idx >= LSB_limit) && ( idx <= MSB_limit);
  end
end
assign out = { '0, { MSB_limit-LSB_limit+1{1'b1} }, { LSB_limit{1'b0} } };