SystemVerilog 距离约束

SystemVerilog dist constraint

我在如何设置 dist 约束方面遗漏了一些东西。我试图在两个范围 [0:31] 和 [32:65535] 之间获得相等的权重。我设置了一个简单的测试:

class data;
  rand bit [15:0] field1;
  constraint c_f1 { field1 dist {[0:31] := 1, [32:65535] := 1};}
endclass

module testbench;
   
  initial begin
    data test_h;
    test_h = new();
    
    repeat(10) begin
        assert(test_h.randomize());
        $display("field1 = %h", test_h.field1);
    end
  end

endmodule

但是,我看到大多数值 > 32。我在这里误解了什么?

使用 :/ 运算符而不是 := 运算符。变化:

  constraint c_f1 { field1 dist {[0:31] := 1, [32:65535] := 1};}

至:

  constraint c_f1 { field1 dist {[0:31] :/ 1, [32:65535] :/ 1};}

请参阅 IEEE 标准 1800-2017,第 18.5.4 节分布

The :/ operator assigns the specified weight to the item or, if the item is a range, to the range as a whole. If there are n values in the range, the weight of each value is range_weight / n .

这给出了 0-31 之间的更多值:

field1 = 0012
field1 = 001f
field1 = 000f
field1 = a138
field1 = 0018
field1 = 001c
field1 = 9d48
field1 = 0009
field1 = 85bf
field1 = f930