pub struct CmpIOperation<'c> { /* private fields */ }
Expand description
A cmpi
operation. Integer comparison operation.
The cmpi
operation is a generic comparison for integer-like types. Its two
arguments can be integers, vectors or tensors thereof as long as their types
match. The operation produces an i1 for the former case, a vector or a
tensor of i1 with the same shape as inputs in the other cases.
Its first argument is an attribute that defines which type of comparison is performed. The following comparisons are supported:
- equal (mnemonic:
"eq"
; integer value:0
) - not equal (mnemonic:
"ne"
; integer value:1
) - signed less than (mnemonic:
"slt"
; integer value:2
) - signed less than or equal (mnemonic:
"sle"
; integer value:3
) - signed greater than (mnemonic:
"sgt"
; integer value:4
) - signed greater than or equal (mnemonic:
"sge"
; integer value:5
) - unsigned less than (mnemonic:
"ult"
; integer value:6
) - unsigned less than or equal (mnemonic:
"ule"
; integer value:7
) - unsigned greater than (mnemonic:
"ugt"
; integer value:8
) - unsigned greater than or equal (mnemonic:
"uge"
; integer value:9
)
The result is 1
if the comparison is true and 0
otherwise. For vector or
tensor operands, the comparison is performed elementwise and the element of
the result indicates whether the comparison is true for the operand elements
with the same indices as those of the result.
Note: while the custom assembly form uses strings, the actual underlying attribute has integer type (or rather enum class in C++ code) as seen from the generic assembly form. String literals are used to improve readability of the IR by humans.
This operation only applies to integer-like operands, but not floats. The
main reason being that comparison operations have diverging sets of
attributes: integers require sign specification while floats require various
floating point-related particularities, e.g., -ffast-math
behavior,
IEEE754 compliance, etc
(rationale).
The type of comparison is specified as attribute to avoid introducing ten
similar operations, taking into account that they are often implemented
using the same operation downstream
(rationale). The
separation between signed and unsigned order comparisons is necessary
because of integers being signless. The comparison operation must know how
to interpret values with the foremost bit being set: negatives in two’s
complement or large positives
(rationale).
Example:
// Custom form of scalar "signed less than" comparison.
%x = arith.cmpi slt, %lhs, %rhs : i32
// Generic form of the same operation.
%x = "arith.cmpi"(%lhs, %rhs) {predicate = 2 : i64} : (i32, i32) -> i1
// Custom form of vector equality comparison.
%x = arith.cmpi eq, %lhs, %rhs : vector<4xi64>
// Generic form of the same operation.
%x = "arith.cmpi"(%lhs, %rhs) {predicate = 0 : i64}
: (vector<4xi64>, vector<4xi64>) -> vector<4xi1>
Implementations§
source§impl<'c> CmpIOperation<'c>
impl<'c> CmpIOperation<'c>
sourcepub fn as_operation(&self) -> &Operation<'c>
pub fn as_operation(&self) -> &Operation<'c>
Returns a generic operation.
sourcepub fn builder(
context: &'c Context,
location: Location<'c>
) -> CmpIOperationBuilder<'c, Unset, Unset, Unset, Unset>
pub fn builder( context: &'c Context, location: Location<'c> ) -> CmpIOperationBuilder<'c, Unset, Unset, Unset, Unset>
Creates a builder.