简体   繁体   English

systemverilog中的重复运算符

[英]repetition operator in systemverilog

I have a system verilog comparison as follows.我有一个系统verilog比较如下。

module m();
  int count = 4;
  logic [3:0] first = 14;
  logic [3:0] second = 15;
  initial begin
    $display("Second %b\n", {count{1'b1}});
    if(first == {count{1'b1}}) $display("FIRST Equals\n");
    else $display("FIRST Not equal %b and %b\n", first, {count{1'b1}});
    if(second == {count{1'b1}}) $display("SECOND Equals\n");
    else $display("SECOND Not equal %b and %b\n", second, {count{1'b1}});
  end
endmodule

This is the output这是输出

Second 1

FIRST Not equal 1110 and 1

SECOND Equals

What I did not understand is the print statements Second 1 and FIRST Not equal 1110 and 1我不明白的是打印语句Second 1FIRST Not equal 1110 and 1

Why is it printing 1 instead of 1111?为什么打印 1 而不是 1111?

One simulator tool I use generates compiler errors.我使用的一种模拟器工具会产生编译器错误。 According to IEEE Std 1800-2012 , section 11.4.12.1 Replication operator:根据IEEE Std 1800-2012 ,第 11.4.12.1 节复制运算符:

A replication operator (also called a multiple concatenation) is expressed by a concatenation preceded by a non-negative, non-x, and non-z constant expression, called a replication constant复制运算符(也称为多重串联)由串联表示,前面有一个非负、非 x 和非 z 常量表达式,称为复制常量

With replication, I think you need to use a numeric constant, like 4, or a constant type, like parameter .对于复制,我认为您需要使用数字常量(如 4)或常量类型(如parameter

  parameter count = 4;

Another simulator I use generates warnings and produces the results you see.我使用的另一个模拟器会生成警告并产生您看到的结果。

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

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