circt
circt copied to clipboard
[HW] Enum comparison operation
Related to #3480
%0 = hw.enum.constant A : !hw.enum<A, B, C>
%1 = hw.enum.constant B : !hw.enum<A, B, C>
%2 = <compare %0 with %1> : i1
We'd expect the ability to compare two SSA enum values in the IR. However, since enum values are not HWIntegerLike (intended), we currently cannot use comb.icmp operations to perform this.
I see two paths forward:
- Enum comparisons should be performed through an integer-cast version of the enum (through #3480). Integer casting an enum will not have an effect on the generated SV and is strictly for type safety in the IR.
%0 = hw.enum.constant A : !hw.enum<A, B, C>
%1 = hw.enum.constant B : !hw.enum<A, B, C>
%2 = hw.enum.cast %0 : !hw.enum<A, B, C> to i32
%3 = hw.enum.cast %1 : !hw.enum<A, B, C> to i32
%4 = comb.icmp eq %2, %2 : i32
- A separate enum comparison operator should be implemented. This operation will only have eq, neq modes
hw.enum.cmp [eq/ne] %0, %1 : ...
%0 = hw.enum.constant A : !hw.enum<A, B, C>
%1 = hw.enum.constant B : !hw.enum<A, B, C>
%4 = hw.enum.cmp eq %0, %1 : !hw.enum<A, B, C>
As i see it, these two options are strictly IR choices, and the generated SV will be the same (%0 == %1).