I am not sure why can I not check multiple conditions with “OR” operator as shown below?
class bus_seq;
rand bit queue[$];
constraint qsize {
queue.size() == 3;
}
endclass : bus_seq
module randm();
bus_seq bs = new();
initial begin
repeat (10) begin
if (!bs.randomize())
$error("Randomization failed");
$display(" --> randomized queue = %p \n", bs.queue);
//if ((bs.queue != {1,1,0}) or (bs.queue != {1,0,0})) begin //dont work
//if ((bs.queue != {1,1,0}) | (bs.queue != {1,0,0})) begin //dont work
//if ((bs.queue != {1,1,0}) || (bs.queue != {1,0,0})) begin //dont work
if (bs.queue != {1,1,0}) begin //only option work, which is single value if condition
$display(" --> NOT equal randomized queue = %p \n", bs.queue);
end
end
end
endmodule : randm
What did you meant “don’t work”? What did you see?
According to your code, I don’t see any problem with logical operator (||) or bitwise operator (|). It should work. The “or” instruction is not valid in SV.
However, I’m confuse that you are using condition “||” or “|” in this case, the if condition always reaches for any value of bs.queue.
And please note:
You should specify the size of each queue element: {1’b1, 1’b1, 1’b0}
You should use static cast to avoid compilation error (in some simulators):
class bus_seq;
rand bit queue[$];
constraint qsize {
queue.size() == 3;
}
endclass : bus_seq
module randm();
bus_seq bs = new();
initial begin
typedef bit bit_queue_t[$];
repeat (10) begin
if (!bs.randomize())
$error("Randomization failed");
$display(" --> randomized queue = %p \n", bs.queue);
//if ((bs.queue != {1,1,0}) or (bs.queue != {1,0,0})) begin //dont work
//if ((bs.queue != {1,1,0}) | (bs.queue != {1,0,0})) begin //dont work
if ((bs.queue != bit_queue_t'({1'b1,1'b1,1'b0})) || (bs.queue != bit_queue_t({1'b1,1'b0,1'b0}))) begin //dont work
//if (bs.queue != {1,1,0}) begin //only option work, which is single value if condition
$display(" --> NOT equal randomized queue = %p \n", bs.queue);
end
end
end
endmodule : randm