|
|
|
|
|
|
|
|
|
|
|
|
Implication Constraints
|
|
|
Constraints provide two constructs for declaring conditional (predicated) relations: implication and |
|
|
if...else. |
|
|
|
|
|
|
|
|
|
|
|
Implication is similar to when in e language. It works like, if condition is true then apply constraint. If-else is similar to Implication => constraint, both can be used. |
|
|
|
|
|
|
|
|
|
|
|
Example : conditional
|
|
|
|
|
|
1 program conditional_con;
2 class frame_t;
3 typedef enum {RUNT,NORMAL,OVERSIZE} size_t;
4 rand bit [15:0] length;
5 rand size_t size;
6
7 constraint frame_sizes {
8 size == NORMAL -> {
9 length dist {
10 [64 : 127 ] := 10,
11 [128 : 511 ] := 10,
12 [512 : 1500] := 10
13 };
14 }
15 if (size == RUNT) {
16 length >= 0;
17 length <= 63;
18 } else if (size == OVERSIZE) {
19 length >= 1501;
20 length <= 5000;
21 }
22 }
23 function void post_randomize();
24 begin
25 $display("length : %0d",length);
26 case(size)
27 RUNT : $display ("Frame size_t is RUNT");
28 NORMAL : $display ("Frame size_t is NORMAL");
29 OVERSIZE : $display ("Frame size_t is OVERSIZE");
30 endcase
31 end
32 endfunction
33 endclass
34
35 initial begin
36 frame_t frame = new();
37 integer i,j = 0;
38 for (j=0;j < 4; j++) begin
39 $write("-------------------------------\n");
40 $write("Randomize Value\n");
41 i = frame.randomize();
42 end
43 $write("-------------------------------\n");
44 end
45
46 endprogram
You could download file conditional_con.sv here
|
|
|
|
|
|
Simulation Output : conditional
|
|
|
|
|
|
-------------------------------
Randomize Value
length : 4948
Frame size_t is OVERSIZE
-------------------------------
Randomize Value
length : 4317
Frame size_t is OVERSIZE
-------------------------------
Randomize Value
length : 1774
Frame size_t is OVERSIZE
-------------------------------
Randomize Value
length : 610
Frame size_t is NORMAL
-------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|