0

Why is my System Verilog Dynamic Array sum constraint is not working? (Run on EDA Playground (Aldec Tool Riviera Pro 2017) /////////////////////////////////////

/////========================

class c ;

string name;

rand logic [4:0] len;

rand logic [4:0] duty_cycles[];

constraint c1 { duty_cycles.size()==len; len inside {[2:5]}; solve len before duty_cycles;};

constraint c2 { duty_cycles.sum() with (int'(item)) == 20;};

function new(string name="randcreater”)

this.name=name;

endfunction

function void post_randomize ();

$display ("New rand of len %d, sum=%d",duty_cycles.size, duty_cycles.sum());

foreach(duty_cycles[i])begin $display("%d",duty_cycles[i]); end

endfunction

endclass

/////=====================

module testbench ();

c obj;

initial begin

obj = new;

repeat (10) begin

obj.randomize();

 #10;

end

end
endmodule


/////////////////////////////////////

Result :

KERNEL: New rand of len 2, sum= 6

KERNEL: 6

KERNEL: 0

KERNEL: New rand of len 2, sum= 4

KERNEL: 2

KERNEL: 2

dave_59
  • 30,490
  • 3
  • 22
  • 48
romi
  • 3
  • 1
  • Works fine on different simulators. As mentioned by Dave, this might be the issue due to older tool version. – sharvil111 Mar 03 '19 at 05:39

1 Answers1

0

The reason for this is your tool has a bug. The software versions on EDAPlayground are old. Try a different simulator.

Also, there is no need for the solve len before duty_cycles; because the size of an array always picks a value before any constraints on its elements.

dave_59
  • 30,490
  • 3
  • 22
  • 48