i am trying to randomize a variable addr in the same class where it is defined , but it is not getting randomized. can anyone please let me know why its working ?
task main_phase(uvm_phase);
bit [63:0] addr1;
addr = std::randomize(addr1) with {addr1 <= end_addr ; addr1 >= start_addr;};
endtask
start_addr and end_addr are generated at run time.
hi dave,
i was trying to follow the example mentioned in sv lrm :
task stimulus( int length );
int a, b, c, success;
success = std::randomize( a, b, c ) with { a < b ; a + b < length };
…
success = std::randomize( a, b ) with { b - a > length };
…
endtask
based on the above example i was trying to randomize my addr1. start_addr and end_addr are generated before i am randomizing addr1 but its returing 0.
can you please let me know how can i randomize the same. suppose my start_addr is 5 and end_addr is 10 then addr1 can be anything between 5 and 10.
As i mentioned earlier print both the start_addr,end_addr values before calling randomize.
let say by mistake start_addr is 10 and end_addr is 5 in this case no value can be found by randomize function which satisfy the condition: addr1 <= end_addr ; addr1 >= start_addr;
hi dave,
below is the part of code i am trying to use.
class xyz extends abc;
rand bit[63:0] addr;
task main_phase(uvm_phase phase);
rand bit [63:0] addr1 ;
phase.raise_objection(this,“starting sequence”);
if(!mss_env_obj.mss_mem_manager_obj.get_addr(start_addr,'hfffff,60,MSS_ECC_CORR))//this part is to get the address range,
`uvm_error(get_name(),$psprintf(“Could not allocate memory space”))
end_addr = start_addr + 'hfffff -'h1;//use 1 kb range
$display(“samir debug - start_addr=%0h end_addr=%0h”,start_addr,end_addr);
addr = std::randomize(addr1) with { addr1 <= end_addr ; addr1 >= start_addr ;} ;
$display(“samir debug - addr is %0h”,addr);
endtask
Please use code tags in the future to make your code more readable.
Why do you need two separate variables: a rand class member addr AND an automatic task variable addr1? Which by the way is not legal to be declared as rand. Only class members can be declared as rand.
i want to get the value of addr between start_addr and end_addr.
can’t i get it by using std::randomize()??
i declared automatic task variable addr1 following the syntax mentioned in sv lrm.
can you please help me with the appropriate syntax that would work for the same.
intent :
i just want to get a random address between start_addr and end_addr using std::randomize()
the solution provided by you is fine and that is working but i wanted to used std::randomize().
please let me know if i can use std::randomize() over here or it has some specific use??