Commit 837e8c7
committed
[dv,cip] Rewrite `_DV_MUBI_DIST to avoid warnings
It turns out that randomising with a distribution like this
if (0) {
XYZ dist { [1:0] := 1; };
}
generates a runtime warning from Xcelium (even though the distribution
expression isn't actually used).
Fortunately, range endpoints can be general expressions, so we can do
everything with ternary operators instead. We can also avoid repeating
stuff if we define `MIN / `MAX macros.
This commit also fixes the weighting for true/false. Suppose we want
to distribute with weights ZeroW, OneW, OtherW for 0, 1, other in a
way that e.g. the fraction of ones is OneW / (ZeroW + OneW + OtherW).
The following would definitely be wrong:
value dist { 0 := ZeroW,
1 := OneW,
[2:9] := OtherW };
Because there are eight "other" values, the fractions end up looking
like OneW / (ZeroW + OneW + 8 * OtherW). Oops!
To make everything line up properly, we multiply by 8:
value dist { 0 := 8 * ZeroW,
1 := 8 * OneW,
[2:9] := OtherW };
and will now have fractions like
8 * OneW / (8 * ZeroW + 8 * OneW + 8 * OtherW
=
OneW / (ZeroW + OneW + OtherW)
Generalising to the macro, there are (MAX_ - 1) possible
values (instead of 10), so we need to scale up by (MAX_ - 3).
Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>1 parent 97b690f commit 837e8c7
1 file changed
+40
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
59 | 83 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
74 | 93 | | |
75 | 94 | | |
76 | 95 | | |
| |||
0 commit comments