# Can we have a unidirectional constraint implementation

**URL:** <https://verificationacademy.com/forums/t/can-we-have-a-unidirectional-constraint-implementation/34963>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, constraints-systemverilog\
**Created:** [August 31, 2018, 12:24pm UTC](https://verificationacademy.com/forums/t/can-we-have-a-unidirectional-constraint-implementation/34963 "2018-08-31T12:24:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chinky](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/2bfe46/32.png) [@Chinky](https://verificationacademy.com/forums/u/Chinky)\
**Post date:** [August 31, 2018, 12:24pm UTC](https://verificationacademy.com/forums/t/can-we-have-a-unidirectional-constraint-implementation/34963/1 "2018-08-31T12:24:40Z")

</div>

There are two fields

```verilog
cmd = {A, B, C, D} 
size = {size_8, size_16, size_32, size_64}

```

The constraints are as follows

```auto
cmd rsize
--------------------
A size_8/size_16/size_32/size_64 (Any size) 
B size_64
C size_8/size_16/size_32/size_64 (Any size)      
D size_8/size_16/size_32/size_64 (Any size)

```

The expectation is to control both cmd and rsize through distribution of weights.

```verilog
constraint cmd_const {
  cmd dist {
            A := weight_A
            ...
            }
  size dist {
            size_8 := weight_size_8
            ...      
            }

```

Now, if below constraint is added,

```verilog
   constraint {
      (cmd == B) -> (size == size_64)
   }

```

As I understand, this leads to having the size as “size\_64” only for “cmd\_B” and not for others, because of the bi-directional nature of the implication

How can we add a constraint such that we can get other legal combinations of {cmd\_A, size\_64}, [cmd\_C, size\_64} etc…

}

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [August 31, 2018, 3:28pm UTC](https://verificationacademy.com/forums/t/can-we-have-a-unidirectional-constraint-implementation/34963/2 "2018-08-31T15:28:25Z")

</div>

_In reply to [Chinky](https://verificationacademy.com/forums/t/can-we-have-a-unidirectional-constraint-implementation/34963):_

The implication _operator_ is not “bidirectional” in the sense that the implication is still satified when size == size\_64 and cmd != B. The _constraint_ is bidirectional in the choice of the random value for size affects the choice for cmd and vice versa. A better choice of words might be “simultaneously”.

What this means is if you pick a distribution for size, or constrain it such that choosing size==size\_64 occurs only 1% of the time, there’s no way you could choose cmd==B more than 1% of the time as well.

---

<div class="post-metadata">

**Author:** ![Chinky](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/c/2bfe46/32.png) [@Chinky](https://verificationacademy.com/forums/u/Chinky)\
**Post date:** [August 31, 2018, 7:21pm UTC](https://verificationacademy.com/forums/t/can-we-have-a-unidirectional-constraint-implementation/34963/3 "2018-08-31T19:21:17Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/can-we-have-a-unidirectional-constraint-implementation/34963/2):_

Thanks Dave! I got what you are saying.

To be more clear, if the weights are such that

Weightage :

```auto
cmd size 
------------------------------
cmd_B =90% size_64 == 10%
cmd_A =10% size_others = 90%

```

The combinations can be

> > {cmd\_B, size\_64} \<= 10% of total weight,

But also, since the cmd\_A is only chosen 10% of the time,

> > {cmd\_A, size\_64/size\_others} ~= 10% of total weight.

Therefore, does this mean the above combination of legal values will happen almost in equal numbers . i.e 50% of the total number of legal combinations.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [August 31, 2018, 10:07pm UTC](https://verificationacademy.com/forums/t/can-we-have-a-unidirectional-constraint-implementation/34963/4 "2018-08-31T22:07:41Z")

</div>

_In reply to [Chinky](https://verificationacademy.com/forums/t/can-we-have-a-unidirectional-constraint-implementation/34963/3):_

The LRM does not spell out how competing distribution play out, but the resulting probability will come out around 50/50. cmd\_B comes out slightly less because there are few valid solutions available.
