Confusion regarding range within inside operator

Hi All,
Consider the following code

bit [47:0] addr;
 parameter AXI_BASE_ADDR = 32'h1504000;
  
 initial begin
   
   repeat(5)	
      if(! std::randomize(addr) with { addr inside {[AXI_BASE_ADDR:'h115_4FFF],['h150_0000:'h17F_FFFF],['h190_0000:'h19F_FFFF]}; }) $error("Randomization Failed");
    else
      $display("addr is 0x%0h",addr);    
    
  end

I observe that ‘addr’ is never constrained to value in the 1st range [AXI_BASE_ADDR:'h115_4FFF],
why is it so ?

(2) On adding another inline constraint ( addr == 'h115_4FFF )

initial begin
   
   repeat(5)	
      if(! std::randomize(addr) with { addr inside {[AXI_BASE_ADDR:'h115_4FFF],['h150_0000:'h17F_FFFF],['h190_0000:'h19F_FFFF]}; addr == 'h115_4FFF; }) $error("Randomization Failed");
    else
      $display("addr is 0x%0h",addr);    
    
  end  

Why do I observe constraint failure ?
Also the error message across different tools is interesting

//  Error message from Tool1
=======================================================

Solver failed when solving following set of constraints 


rand bit[47:0] addr; // rand_mode = ON 

constraint WITH_CONSTRAINT    // (from this) (constraint_mode = ON) (testbench.sv:10)
{
   (addr inside {[32'h1504000:32'h1154fff], [32'h1500000:32'h17fffff], [32'h1900000:32'h19fffff]});
   (addr == 32'h1154fff);
}

=======================================================

There is no mention of the 1st range ( [AXI_BASE_ADDR:'h115_4FFF] ) within the inside operator

//  Error message from Tool2
 ** Error: Randomization Failed
    Time: 0 ns  Scope: tb File: testbench.sv Line: 12
 testbench.sv(12): randomize() failed due to conflicts between the following constraints:
 	testbench.sv(12): $inline { (addr inside { [48'h000001504000:48'h000001154fff], [48'h000001500000:48'h0000017fffff], [48'h000001900000:48'h0000019fffff] }); }
 Where:
 	addr = 48'h000001154fff

Tool2 does mention the 1st range, however it still gives conflict during randomization

The inside operator requires the range to be expressed in the format min:max. If min is greater than max, it is considered an empty match, meaning it cannot be matched. For instance, your min:’h150_4000’ is larger than your max:’h115_4FFF’.

Hi Dave,
So if I were to write only the high:low range, shouldn’t it be considered as if there is no constraint on addr ?

bit [47:0] addr;
parameter AXI_BASE_ADDR = 32'h1504000;

initial begin
   
   repeat(5)	
      if(! std::randomize(addr) with { addr inside {[AXI_BASE_ADDR:'h115_4FFF] }) $error("Randomization Failed");
    else
      $display("addr is 0x%0h",addr);    
    
 end  

Can addr have any value from 0 to '1 ( all ones ) ?

No, then it would be an expression that could never be true.

1 Like