首页 > 其他 > 详细

systemverilog soft constraint

时间:2019-04-11 11:03:16      阅读:1014      评论:0      收藏:0      [点我收藏+]
1.
class my_item; rand bit constrainted_random; rand bit usually_one; endclass class my_generator; my_item item; function void go(); item = new(); item.usually_one.rand_mode(0); item.usually_one = 1; for(int i = 0; i < 10; i++) begin assert(item.randomize() with {constrainted_random == bit‘(i);}); $display("item=%0p", item); end item.usually_one.rand_mode(1); for(int i = 0; i < 10; i++) begin assert(item.randomize() with {constrainted_random == bit‘(i);}); $display("item=%0p", item); end endfunction endclass module top(); my_generator generator; initial begin generator = new(); generator.go(); end endmodule

2.
class my_item;
  rand bit constrainted_random;
  rand bit usually_one;
  function void pre_randomize();
    usually_one = 1;
  endfunction
endclass

class my_generator;
  my_item item;

  function void go();
    item = new();

    for(int j = 0; j < 2; j++) begin

      item.usually_one.rand_mode(0);
      for(int i = 0; i < 3; i++) begin
        assert(item.randomize()
          with {constrainted_random == bit‘(i);});
        $display("item=%0p (usually_one.rand_mode off)", item);
      end

      item.usually_one.rand_mode(1);
      for(int i = 0; i < 3; i++) begin
        assert(item.randomize()
          with {constrainted_random == bit‘(i);});
        $display("item=%0p (usually_one.rand_mode on)", item);
      end
    end
  endfunction
endclass

module top();
  my_generator generator;

  initial begin
    generator = new();
    generator.go();
  end
endmodule

3.
soft my_arr inside {[1:6]};

systemverilog soft constraint

原文:https://www.cnblogs.com/littleMa/p/10688300.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!