17 Operators: Equality and Case Equality
A comparison of the the equality operator and the case equality operator.
==
Equality operator - returns 0,1,x
===
Case Equality operator - returns 0,1
Note: We do not look at wildcard equality or comparing chandles, class handles, null.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//SystemVerilogShow.com - Show a key difference between the equality and case equality operators.
// "==" Equality operator - returns 0,1,x
// "===" Case Equality operator - returns 0,1
module top;
logic array1[3:0] = '{'b1, 'b0, 'bx, 'bz};
logic array2[3:0] = '{'b1, 'b0, 'bx, 'bz};
logic equality_result;
logic case_equality_result;
function void show();
$display(" INPUTS RESULTS");
foreach (array1[iii]) begin
foreach (array2[jjj]) begin
equality_result = (array1[iii] == array2[jjj]);
case_equality_result = (array1[iii] === array2[jjj]);
$write("(%1b vs. %1b) return (== %1b) (=== %1b)",
array1[iii], array2[jjj],equality_result, case_equality_result);
if (equality_result !== case_equality_result) begin
$display(" --- DIFFER");
end else begin
$display("");
end
end
end
endfunction
initial begin
show();
$finish();
end
endmodule
Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
INPUTS RESULTS
(1 vs. 1) return (== 1) (=== 1)
(1 vs. 0) return (== 0) (=== 0)
(1 vs. x) return (== x) (=== 0) --- DIFFER
(1 vs. z) return (== x) (=== 0) --- DIFFER
(0 vs. 1) return (== 0) (=== 0)
(0 vs. 0) return (== 1) (=== 1)
(0 vs. x) return (== x) (=== 0) --- DIFFER
(0 vs. z) return (== x) (=== 0) --- DIFFER
(x vs. 1) return (== x) (=== 0) --- DIFFER
(x vs. 0) return (== x) (=== 0) --- DIFFER
(x vs. x) return (== x) (=== 1) --- DIFFER
(x vs. z) return (== x) (=== 0) --- DIFFER
(z vs. 1) return (== x) (=== 0) --- DIFFER
(z vs. 0) return (== x) (=== 0) --- DIFFER
(z vs. x) return (== x) (=== 0) --- DIFFER
(z vs. z) return (== x) (=== 1) --- DIFFER
Simulation complete via $finish(1) at time 0 FS + 0