统一地址模式的系统Verilog约束

问题描述

我想对“ rand bit [7:0] addr [10]”添加一个约束,以使我们生成的地址以统一的递增顺序从第0个索引到第5个索引,并以统一的递减顺序从第6个索引到最后一个索引。我是SV约束的新手,有人可以提供帮助吗?

解决方法

class A;
  rand bit [7:0] addr[10];
  rand int step; // this needs to be an int to catch underflow/overflow
  constraint uniform {
     foreach (addr[index]) {
        index inside {[0:4]} -> addr[index] + step == addr[index+1];
        index inside {[6:8]} -> addr[index] - step == addr[index+1];
     }
     step inside {[1:25]};
  }
endclass