|
|
|

|
|
|
|
|
|

|
|
 |
Iterative constraints
|
|
|
Iterative constraints allow arrayed variables to be constrained in a parameterized manner using loop variables and indexing expressions. |
|
|

|
|
|
The foreach construct specifies iteration over the elements of an array. Its argument is an identifier that designates any type of array (fixed-size, dynamic, associative, or queue) followed by a list of loop variables enclosed in square brackets. Each loop variable corresponds to one of the dimensions of the array. |
|
|

|
|
|
|
|
|

|
|
 |
Example : Iterative
|
|
|

|
|
|
1 program iterative_con;
2 class frame_t;
3 rand bit [15:0] data [];
4
5 constraint frame_sizes {
6 data.size inside {[1:10]};
7 foreach (data[i])
8 data[i] == i;
9 }
10 function void post_randomize();
11 begin
12 $display("length : %0d", data.size());
13 for (integer i = 0; i < data.size(); i++) begin
14 $write ("%2x ",data[i]);
15 end
16 $write("\n");
17 end
18 endfunction
19 endclass
20
21 initial begin
22 frame_t frame = new();
23 integer i,j = 0;
24 for (j=0;j < 4; j++) begin
25 $write("-------------------------------\n");
26 $write("Randomize Value\n");
27 i = frame.randomize();
28 end
29 $write("-------------------------------\n");
30 end
31
32 endprogram
You could download file iterative_con.sv here
|
|
|

|
|
 |
Simulation : Iterative
|
|
|

|
|
|
-------------------------------
Randomize Value
length : 4
00 01 02 03
-------------------------------
Randomize Value
length : 2
00 01
-------------------------------
Randomize Value
length : 8
00 01 02 03 04 05 06 07
-------------------------------
Randomize Value
length : 9
00 01 02 03 04 05 06 07 08
-------------------------------
|
|
|

|
|
|

|
|
|

|
|
|
|
|
|

|
|
|
|
|
|

|
|
Copyright © 1998-2025 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|