Math
math
¶
The math dialect is intended to hold mathematical operations on integer and floating types beyond simple arithmetics.
See external documentation.
signlessIntegerLike = container_of(AnySignlessIntegerType | IndexType)
module-attribute
¶
floatingPointLike = container_of(AnyFloat)
module-attribute
¶
Math = Dialect('math', [AbsFOp, AbsIOp, AcosOp, AcoshOp, AsinOp, AsinhOp, Atan2Op, AtanOp, AtanhOp, CbrtOp, CeilOp, CopySignOp, CosOp, CoshOp, CountLeadingZerosOp, CountTrailingZerosOp, CtPopOp, ErfOp, Exp2Op, ExpM1Op, ExpOp, FPowIOp, FloorOp, FmaOp, IPowIOp, Log10Op, Log1pOp, Log2Op, LogOp, PowFOp, RoundEvenOp, RoundOp, RsqrtOp, SinOp, SinhOp, SqrtOp, TanOp, TanhOp, TruncOp])
module-attribute
¶
SignlessIntegerLikeUnaryMathOperation
¶
Bases: IRDLOperation, ABC
A generic signless integer-like unary math operation.
Source code in xdsl/dialects/math.py
T: ClassVar = VarConstraint('T', signlessIntegerLike)
class-attribute
instance-attribute
¶
operand = operand_def(T)
class-attribute
instance-attribute
¶
result = result_def(T)
class-attribute
instance-attribute
¶
assembly_format = '$operand attr-dict `:` type($result)'
class-attribute
instance-attribute
¶
FloatingPointLikeUnaryMathOperation
¶
Bases: IRDLOperation, ABC
A generic floating-point-like unary math operation with fastmath flags.
Source code in xdsl/dialects/math.py
T: ClassVar = VarConstraint('T', floatingPointLike)
class-attribute
instance-attribute
¶
operand = operand_def(T)
class-attribute
instance-attribute
¶
result = result_def(T)
class-attribute
instance-attribute
¶
fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr('none'))
class-attribute
instance-attribute
¶
assembly_format = '$operand (`fastmath` `` $fastmath^)? attr-dict `:` type($result)'
class-attribute
instance-attribute
¶
__init__(operand: Operation | SSAValue, fastmath: FastMathFlagsAttr | None = None)
¶
SignlessIntegerLikeBinaryMathOperation
¶
Bases: IRDLOperation, ABC
A generic signless integer-like binary math operation.
Source code in xdsl/dialects/math.py
T: ClassVar = VarConstraint('T', signlessIntegerLike)
class-attribute
instance-attribute
¶
lhs = operand_def(T)
class-attribute
instance-attribute
¶
rhs = operand_def(T)
class-attribute
instance-attribute
¶
result = result_def(T)
class-attribute
instance-attribute
¶
assembly_format = '$lhs `,` $rhs attr-dict `:` type($result)'
class-attribute
instance-attribute
¶
FloatingPointLikeBinaryMathOperation
¶
Bases: IRDLOperation, ABC
A generic floating-point-like binary math operation.
Source code in xdsl/dialects/math.py
T: ClassVar = VarConstraint('T', floatingPointLike)
class-attribute
instance-attribute
¶
lhs = operand_def(T)
class-attribute
instance-attribute
¶
rhs = operand_def(T)
class-attribute
instance-attribute
¶
result = result_def(T)
class-attribute
instance-attribute
¶
fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr('none'))
class-attribute
instance-attribute
¶
assembly_format = '$lhs `,` $rhs (`fastmath` `` $fastmath^)? attr-dict `:` type($result)'
class-attribute
instance-attribute
¶
__init__(lhs: Operation | SSAValue, rhs: Operation | SSAValue, fastmath: FastMathFlagsAttr | None = None)
¶
Source code in xdsl/dialects/math.py
AbsFOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The absf operation computes the absolute value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type.
Example:
// Scalar absolute value. %a = math.absf %b : f64
Source code in xdsl/dialects/math.py
AbsIOp
dataclass
¶
Bases: SignlessIntegerLikeUnaryMathOperation
The absi operation computes the absolute value. It takes one operand of integer type (i.e., scalar, tensor or vector) and returns one result of the same type.
Example:
// Scalar absolute value. %a = math.absi %b : i64
Source code in xdsl/dialects/math.py
AcosOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
Arcus cosine of the specified value
The acos operation computes the arcus cosine of a given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example: // Scalar arcus cosine value. %a = math.acos %b : f64
Source code in xdsl/dialects/math.py
AcoshOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
Hyperbolic arcus cosine of the given value
The acosh operation computes the arcus cosine of a given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example: // Hyperbolic arcus cosine of scalar value. %a = math.acosh %b : f64
Source code in xdsl/dialects/math.py
AsinOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
Arcus sine of the given value
The asin operation computes the arcus sine of a given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example: // Arcus sine of scalar value. %a = math.asin %b : f64
Source code in xdsl/dialects/math.py
AsinhOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
Hyperbolic arcus sine of the given value
The asinh operation computes the hyperbolic arcus sine of a given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example: // Hyperbolic arcus sine of scalar value. %a = math.asinh %b : f64
Source code in xdsl/dialects/math.py
AtanhOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
Hyperbolic arcus tangent of the given value
The atanh operation computes the hyperbolic arcus tangent of a given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example: // Hyperbolic arcus tangent of scalar value. %a = math.atanh %b : f64
Source code in xdsl/dialects/math.py
Atan2Op
dataclass
¶
Bases: FloatingPointLikeBinaryMathOperation
The atan2 operation takes two operands and returns one result, all of which must be of the same type. The operands must be of floating point type (i.e., scalar, tensor or vector).
The 2-argument arcus tangent atan2(y, x) returns the angle in the
Euclidian plane between the positive x-axis and the ray through the point
(x, y). It is a generalization of the 1-argument arcus tangent which
returns the angle on the basis of the ratio y/x.
See also wikipedia.
Example:
// Scalar variant. %a = math.atan2 %b, %c : f32
Source code in xdsl/dialects/math.py
AtanOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The atan operation computes the arcus tangent of a given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Arcus tangent of scalar value. %a = math.atan %b : f64
Source code in xdsl/dialects/math.py
CbrtOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The cbrt operation computes the cube root. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar cube root value. %a = math.cbrt %b : f64
Note: This op is not equivalent to powf(..., ⅓.0).
Source code in xdsl/dialects/math.py
CeilOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The ceil operation computes the ceiling of a given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar ceiling value. %a = math.ceil %b : f64
Source code in xdsl/dialects/math.py
CopySignOp
dataclass
¶
Bases: FloatingPointLikeBinaryMathOperation
The copysign returns a value with the magnitude of the first operand and the sign of the second operand. It takes two operands and returns one result of the same type. The operands must be of floating point type (i.e., scalar, tensor or vector). It has no standard attributes.
Example:
// Scalar copysign value. %a = math.copysign %b, %c : f64
Source code in xdsl/dialects/math.py
CosOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The cos operation computes the cosine of a given value. It takes one
operand of floating point type (i.e., scalar, tensor or vector) and returns one
result of the same type. It has no standard attributes.
Example:
// Scalar cosine value. %a = math.cos %b : f64
Source code in xdsl/dialects/math.py
CoshOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The cosh operation computes the hyperbolic cosine. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar hyperbolic cosine value. %a = math.cosh %b : f64
Source code in xdsl/dialects/math.py
CountLeadingZerosOp
dataclass
¶
Bases: SignlessIntegerLikeUnaryMathOperation
The ctlz operation computes the number of leading zeros of an integer value. It operates on scalar, tensor or vector.
Example:
// Scalar ctlz function value. %a = math.ctlz %b : i32
Source code in xdsl/dialects/math.py
CountTrailingZerosOp
dataclass
¶
Bases: SignlessIntegerLikeUnaryMathOperation
The cttz operation computes the number of trailing zeros of an integer value. It operates on scalar, tensor or vector.
Example:
// Scalar cttz function value. %a = math.cttz %b : i32
Source code in xdsl/dialects/math.py
CtPopOp
dataclass
¶
Bases: SignlessIntegerLikeUnaryMathOperation
The ctpop operation computes the number of set bits of an integer value. It operates on scalar, tensor or vector.
Example:
// Scalar ctpop function value. %a = math.ctpop %b : i32
Source code in xdsl/dialects/math.py
ErfOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The erf operation computes the error function. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar error function value. %a = math.erf %b : f64
Source code in xdsl/dialects/math.py
Exp2Op
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The exp operation takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar natural exponential. %a = math.exp2 %b : f64
Source code in xdsl/dialects/math.py
ExpM1Op
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
expm1(x) := exp(x) - 1
The expm1 operation takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar natural exponential minus 1. %a = math.expm1 %b : f64
Source code in xdsl/dialects/math.py
ExpOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The exp operation takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar natural exponential. %a = math.exp %b : f64
Source code in xdsl/dialects/math.py
FPowIOp
¶
Bases: IRDLOperation
The fpowi operation takes a base operand of floating point type
(i.e. scalar, tensor or vector) and a power operand of integer type
(also scalar, tensor or vector) and returns one result of the same type
as base. The result is base raised to the power of power.
The operation is elementwise for non-scalars, e.g.:
%v = math.fpowi %base, %power : vector<2xf32>, vector<2xi32>
The result is a vector of:
[
Example:
// Scalar exponentiation. %a = math.fpowi %base, %power : f64, i32
Source code in xdsl/dialects/math.py
name = 'math.fpowi'
class-attribute
instance-attribute
¶
T: ClassVar = VarConstraint('T1', floatingPointLike)
class-attribute
instance-attribute
¶
fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr('none'))
class-attribute
instance-attribute
¶
lhs = operand_def(T)
class-attribute
instance-attribute
¶
rhs = operand_def(signlessIntegerLike)
class-attribute
instance-attribute
¶
result = result_def(T)
class-attribute
instance-attribute
¶
traits = traits_def(Pure())
class-attribute
instance-attribute
¶
assembly_format = '$lhs `,` $rhs (`fastmath` `` $fastmath^)? attr-dict `:` type($lhs) `,` type($rhs)'
class-attribute
instance-attribute
¶
__init__(lhs: Operation | SSAValue, rhs: Operation | SSAValue, fastmath: FastMathFlagsAttr | None = None)
¶
Source code in xdsl/dialects/math.py
FloorOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The floor operation computes the floor of a given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar floor value. %a = math.floor %b : f64
Source code in xdsl/dialects/math.py
FmaOp
¶
Bases: IRDLOperation
The fma operation takes three operands and returns one result, each of these is required to be the same type. Operands must be of floating point type (i.e., scalar, tensor or vector).
Example:
// Scalar fused multiply-add: d = a*b + c %d = math.fma %a, %b, %c : f64
The semantics of the operation correspond to those of the llvm.fma
intrinsic. In the
particular case of lowering to LLVM, this is guaranteed to lower
to the llvm.fma.* intrinsic.
Source code in xdsl/dialects/math.py
T: ClassVar = VarConstraint('T', floatingPointLike)
class-attribute
instance-attribute
¶
name = 'math.fma'
class-attribute
instance-attribute
¶
fastmath = prop_def(FastMathFlagsAttr, default_value=FastMathFlagsAttr('none'))
class-attribute
instance-attribute
¶
a = operand_def(T)
class-attribute
instance-attribute
¶
b = operand_def(T)
class-attribute
instance-attribute
¶
c = operand_def(T)
class-attribute
instance-attribute
¶
result = result_def(T)
class-attribute
instance-attribute
¶
traits = traits_def(Pure(), SameOperandsAndResultType())
class-attribute
instance-attribute
¶
assembly_format = '$a `,` $b `,` $c (`fastmath` `` $fastmath^)? attr-dict `:` type($result)'
class-attribute
instance-attribute
¶
__init__(a: Operation | SSAValue, b: Operation | SSAValue, c: Operation | SSAValue, fastmath: FastMathFlagsAttr | None = None)
¶
Source code in xdsl/dialects/math.py
IPowIOp
dataclass
¶
Bases: SignlessIntegerLikeBinaryMathOperation
The ipowi operation takes two operands of integer type (i.e., scalar, tensor or vector) and returns one result of the same type. Operands must have the same type.
Example: // Scalar signed integer exponentiation. %a = math.ipowi %b, %c : i32
Source code in xdsl/dialects/math.py
Log10Op
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
Computes the base-10 logarithm of the given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type.
Example:
// Scalar log10 operation. %y = math.log10 %x : f64
Source code in xdsl/dialects/math.py
Log1pOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
Computes the base-e logarithm of one plus the given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type.
log1p(x) := log(1 + x)
Example:
// Scalar log1p operation. %y = math.log1p %x : f64
Source code in xdsl/dialects/math.py
Log2Op
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
Computes the base-2 logarithm of the given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type.
Example:
// Scalar log2 operation. %y = math.log2 %x : f64
Source code in xdsl/dialects/math.py
LogOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
Computes the base-e logarithm of the given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type.
Example:
// Scalar log operation. %y = math.log %x : f64
Source code in xdsl/dialects/math.py
PowFOp
dataclass
¶
Bases: FloatingPointLikeBinaryMathOperation
The powf operation takes two operands of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. Operands must have the same type.
Example:
// Scalar exponentiation. %a = math.powf %b, %c : f64
Source code in xdsl/dialects/math.py
RoundEvenOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The roundeven operation returns the operand rounded to the nearest integer value in floating-point format. It takes one operand of floating point type (i.e., scalar, tensor or vector) and produces one result of the same type. The operation rounds the argument to the nearest integer value in floating-point format, rounding halfway cases to even, regardless of the current rounding direction.
Example:
// Scalar round operation. %a = math.roundeven %b : f64
Source code in xdsl/dialects/math.py
RoundOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The round operation returns the operand rounded to the nearest integer value in floating-point format. It takes one operand of floating point type (i.e., scalar, tensor or vector) and produces one result of the same type. The operation rounds the argument to the nearest integer value in floating-point format, rounding halfway cases away from zero, regardless of the current rounding direction.
Example:
// Scalar round operation. %a = math.round %b : f64
Source code in xdsl/dialects/math.py
RsqrtOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The rsqrt operation computes the reciprocal of the square root. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example: // Scalar reciprocal square root value. %a = math.rsqrt %b : f64
Source code in xdsl/dialects/math.py
SinOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The sin operation computes the sine of a given value. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar sine value. %a = math.sin %b : f64
Source code in xdsl/dialects/math.py
SinhOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The sinh operation computes the hyperbolic sine. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar hyperbolic sine value. %a = math.sinh %b : f64
Source code in xdsl/dialects/math.py
SqrtOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The sqrt operation computes the square root. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example: // Scalar square root value. %a = math.sqrt %b : f64
Source code in xdsl/dialects/math.py
TanOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The tan operation computes the tangent. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar tangent value. %a = math.tan %b : f64
Source code in xdsl/dialects/math.py
TanhOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The tanh operation computes the hyperbolic tangent. It takes one operand of floating point type (i.e., scalar, tensor or vector) and returns one result of the same type. It has no standard attributes.
Example:
// Scalar hyperbolic tangent value. %a = math.tanh %b : f64
Source code in xdsl/dialects/math.py
TruncOp
dataclass
¶
Bases: FloatingPointLikeUnaryMathOperation
The trunc operation returns the operand rounded to the nearest integer value in floating-point format. It takes one operand of floating point type (i.e., scalar, tensor or vector) and produces one result of the same type. The operation always rounds to the nearest integer not larger in magnitude than the operand, regardless of the current rounding direction.
Example:
// Scalar trunc operation. %a = math.trunc %b : f64