create a list of instructions (size=20) from ADD, MUL, SUB and NOP instructions.
- Such that No add instruction is repeated in 3 clock cycles and
- MUL is not repeated in 4 clock cycles and
- SUB is not repeated in the last 3 valid instructions.
(I don’t understand how to implement this #3)
Valid instruction = any other instruction except “nop” . “nop” is considered empty cycle do nothing instruction.
instruction cycle #
ADD 1
MUL 2
SUB 3
ADD 4
NOP 4
NOP 4
ADD 5
MUL 6
SUB 7
// assuming "1" = add instruction. Later can define as enum
// assuming "2" = mul inst.
// assuming "3" = sub inst.
// assuming "4" = nop inst.
class A;
rand int q[$];
constraint q_c {
q.size == 21;
foreach (q[i]) {
q[i] inside {[1:4]};
//q[i] == 1 -> q[i+1] != 1 -> q[i+2] != 1;
if (q[i] == 1) {
q[i+1] != 1;
q[i+2] != 1;
}
//q[i] == 2 -> q[i+1] != 2 -> q[i+2] != 2 -> q[i+3] != 2;
if (q[i] == 2) {
q[i+1] != 2;
q[i+2] != 2;
q[i+3] != 2;
}
}
}
endclass
module top;
A a_h;
initial begin
repeat (5) begin
a_h = new();
a_h.randomize();
$display("***************************** q = %0p ****************************************", a_h.q);
end
end
endmodule
EDIT: Gives correct output for scenario 1 and scenario 2.
But need help with #3 implementation
***************************** q = '{3, 2, 3, 3, 4, 4, 4, 3, 1, 4, 3, 4, 3, 2, 4, 4, 1, 2, 3, 4, 4} ****************************************
***************************** q = '{1, 4, 4, 2, 4, 1, 3, 2, 1, 4, 4, 2, 4, 3, 1, 4, 4, 2, 3, 1, 3} ****************************************
***************************** q = '{2, 3, 4, 4, 4, 4, 3, 3, 4, 4, 3, 4, 2, 1, 4, 4, 1, 2, 4, 1, 3} ****************************************
***************************** q = '{3, 3, 3, 3, 2, 4, 1, 3, 3, 2, 3, 1, 4, 2, 4, 3, 4, 4, 3, 3, 1} ****************************************
***************************** q = '{4, 1, 4, 4, 3, 3, 1, 3, 3, 3, 4, 1, 2, 4, 3, 4, 3, 1, 2, 4, 3} ****************************************