ModArith
ModArith ops
mod_arith.add
(heir::mod_arith::AddOp)
Modular addition operation
Syntax:
operation ::= `mod_arith.add` operands attr-dict `:` type($output)
Computes addition modulo a statically known modulus $q$.
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
modulus | ::mlir::IntegerAttr | arbitrary integer attribute |
Operands:
Operand | Description |
---|---|
lhs | signless-integer-like |
rhs | signless-integer-like |
Results:
Result | Description |
---|---|
output | signless-integer-like |
mod_arith.barrett_reduce
(heir::mod_arith::BarrettReduceOp)
Compute the first step of the Barrett reduction.
Syntax:
operation ::= `mod_arith.barrett_reduce` operands attr-dict `:` qualified(type($input))
Let $q$ denote a statically known modulus and $b = 4^{w}$, where $w$ is the
smallest bit-width that contains the range $[0, q)$. The Barrett reduce
operation computes barret_reduce x = x - floor(x * floor(b / q) / b) * q
.
Given $0 <= x < q^2$, then this will compute $(x \mod q)$ or $(x \mod q) + p$.
Traits: SameOperandsAndResultType
Interfaces: InferTypeOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
modulus | ::mlir::IntegerAttr | arbitrary integer attribute |
Operands:
Operand | Description |
---|---|
input | signless-integer-like |
Results:
Result | Description |
---|---|
output | signless-integer-like |
mod_arith.mac
(heir::mod_arith::MacOp)
Modular multiplication-and-accumulation operation
Syntax:
operation ::= `mod_arith.mac` operands attr-dict `:` type($output)
mod_arith.mac x, y, z {modulus = q}
computes $(x * y) + z \mod q$
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
modulus | ::mlir::IntegerAttr | arbitrary integer attribute |
Operands:
Operand | Description |
---|---|
lhs | signless-integer-like |
rhs | signless-integer-like |
acc | signless-integer-like |
Results:
Result | Description |
---|---|
output | signless-integer-like |
mod_arith.mul
(heir::mod_arith::MulOp)
Modular multiplication operation
Syntax:
operation ::= `mod_arith.mul` operands attr-dict `:` type($output)
Computes multiplication modulo a statically known modulus $q$.
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
modulus | ::mlir::IntegerAttr | arbitrary integer attribute |
Operands:
Operand | Description |
---|---|
lhs | signless-integer-like |
rhs | signless-integer-like |
Results:
Result | Description |
---|---|
output | signless-integer-like |
mod_arith.reduce
(heir::mod_arith::ReduceOp)
Reduce a signed integer to its congruence modulo equivalent
Syntax:
operation ::= `mod_arith.reduce` operands attr-dict `:` type($output)
mod_arith.reduce x {modulus = q}
computes $y \in [0, q)$ such that
$x \equiv y \mod n$.
Note this will interpret x
as a signed integer. For an unsigned integer,
equivalent functionality is: y = arith.remui x
.
Traits: SameOperandsAndResultType
Interfaces: InferTypeOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
modulus | ::mlir::IntegerAttr | arbitrary integer attribute |
Operands:
Operand | Description |
---|---|
input | signless-integer-like |
Results:
Result | Description |
---|---|
output | signless-integer-like |
mod_arith.subifge
(heir::mod_arith::SubIfGEOp)
Compute (x >= y) ? x - y : x.
Syntax:
operation ::= `mod_arith.subifge` operands attr-dict `:` qualified(type($output))
Traits: SameOperandsAndResultType
Interfaces: InferTypeOpInterface
Operands:
Operand | Description |
---|---|
lhs | signless-integer-like |
rhs | signless-integer-like |
Results:
Result | Description |
---|---|
output | signless-integer-like |
mod_arith.sub
(heir::mod_arith::SubOp)
Modular subtraction operation
Syntax:
operation ::= `mod_arith.sub` operands attr-dict `:` type($output)
Computes subtraction modulo a statically known modulus $q$.
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
modulus | ::mlir::IntegerAttr | arbitrary integer attribute |
Operands:
Operand | Description |
---|---|
lhs | signless-integer-like |
rhs | signless-integer-like |
Results:
Result | Description |
---|---|
output | signless-integer-like |