Mutuality constraint

i did a constraint:


foreach(portA_Type[i])  portA_Type[i]  dist{A:= 2, B:= 1, C:= 3, D:= 2};
foreach(portB_Type[i])  portB_Type[i]  dist{A:= 2, B:= 1, C:= 3, D:= 2};

i want to constraint too that:


foreach(portA_Type[i])  if(portA_Type[i] == C)  portB_Type[i] dist{C:= 1, D:= 1};
foreach(portB_Type[i])  if(portB_Type[i] == C)  portA_Type[i] dist{C:= 1, D:= 1};

suddenly the result is always C for all or D for all not A or B at all

y is that?
thanks - Chaim

In reply to gotlibhaim:
Can we assume port_A/bBi_Type[i] is an enum {A,B,C,D} ?

What do you mean “C for all” all what? Maybe you should show an example of what you expected for results versus what you are actually getting. Just show one element. This is what I get for portA_Type[0] and portB_type[0]

# A A
# A B
# A B
# A A
# D D
# B C
# B A
# A D
# A D
# C C
# B C
# A B
# D C
# B B
# C D
# B A
# C D
# B A
# B D
# B C
# B B

In reply to dave_59:

yes, it’s an enum.

how this line generated?: # B C
the constraint don’t allow it


foreach(portA_Type[i])  if(portA_Type[i] == C)  portB_Type[i] dist{C:= 1, D:= 1};
foreach(portB_Type[i])  if(portB_Type[i] == C)  portA_Type[i] dist{C:= 1, D:= 1};

and back to my question
in my runing always it C or D for both portA_Type and portB_Type for each I

In reply to gotlibhaim:
You would get better help from people if you showed your code as a complete self-contained example.

module top;
typedef enum {A,B,C,D} p_e;
class c;
   rand p_e pA[2], pB[2];
   constraint c1 { foreach(pA[i]) if(pA[i] == C)  pB[i] dist{C:= 1, D:= 1}; }
   constraint c2 { foreach(pB[i]) if(pB[i] == C)  pA[i] dist{C:= 1, D:= 1}; }
endclass: c
c h=new;
  initial repeat(50) begin
     assert(h.randomize());
     $display("%p %p", h.pA[0], h.pB[0]);
  end
endmodule

Your constraint certainly does allow the result B,C. there is no dist constraint when portA_Type[i] = B

In reply to dave_59:

sorry!
the constraint C2 is on pB not the same as C1:


module top;
typedef enum {A,B,C,D} p_e;
class c;
   rand p_e pA[2], pB[2];
   constraint c1 { foreach(pA[i]) if(pA[i] == C)  pB[i] dist{C:= 1, D:= 1}; }
   constraint c2 { foreach(pB[i]) if(pB[i] == C)  pA[i] dist{C:= 1, D:= 1}; }
endclass: c
c h=new;
  initial repeat(50) begin
     assert(h.randomize());
     $display("%p %p", h.pA[0], h.pB[0]);
  end
endmodule

this code generate the above too?

thanks!!

In reply to gotlibhaim:
I forgot that the dist constraint is not a hard constraint. Try re-writing as

 constraint c1 { foreach(pA[i]) if(pA[i] == C)  pB[i] inside {C,D}; }
 constraint c2 { foreach(pB[i]) if(pB[i] == C)  pA[i] inside {C,D}; }

Which gives me

# C D
# C D
# C C
# D B
# A A
# D D
# A B
# C C
# B B
# D A
# A D
# C D
# D C
# B D
# C C
# A A
# C D
# A A
# C D
# B D
# B A
# D C
# B D
# B D
# D B
# C D
# A B
# B B
# A A
# A B
# D A
# A A
# D C
# C C
# D C
# D D
# A A
# C C
# A D
# A A
# B A
# D C
# D A
# D D
# A B
# B B
# B B
# C D
# B D
# A B

In reply to dave_59:

now it works!
big thanks!!!