MLIR

Multi-Level IR Compiler Framework

'math' Dialect

The math dialect is intended to hold mathematical operations on integer and floating types beyond simple arithmetics. Each operation works on scalar, vector or tensor type. On vector and tensor type operations apply elementwise unless explicitly specified otherwise. As an example, the floating point absolute value can be expressed as:

// Scalar absolute value.
%a = math.absf %b : f64

// Vector elementwise absolute value.
%f = math.absf %g : vector<4xf32>

// Tensor elementwise absolute value.
%x = math.absf %y : tensor<4x?xf8>

Operation definition 

math.absf (::mlir::math::AbsFOp) 

floating point absolute-value operation

Syntax:

operation ::= `math.absf` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.absi (::mlir::math::AbsIOp) 

integer absolute-value operation

Syntax:

operation ::= `math.absi` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandsignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

math.atan2 (::mlir::math::Atan2Op) 

2-argument arcus tangent of the given values

Syntax:

operation ::= `math.atan2` $lhs `,` $rhs attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.atan2` ssa-use `,` ssa-use `:` type

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 https://en.wikipedia.org/wiki/Atan2

Example:

// Scalar variant.
%a = math.atan2 %b, %c : f32

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.atan (::mlir::math::AtanOp) 

arcus tangent of the given value

Syntax:

operation ::= `math.atan` $operand attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.atan` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.ceil (::mlir::math::CeilOp) 

ceiling of the specified value

Syntax:

operation ::= `math.ceil` $operand attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.ceil` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.copysign (::mlir::math::CopySignOp) 

A copysign operation

Syntax:

operation ::= `math.copysign` $lhs `,` $rhs attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.copysign` ssa-use `,` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.cos (::mlir::math::CosOp) 

cosine of the specified value

Syntax:

operation ::= `math.cos` $operand attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.cos` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.ctlz (::mlir::math::CountLeadingZerosOp) 

counts the leading zeros an integer value

Syntax:

operation ::= `math.ctlz` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandsignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

math.cttz (::mlir::math::CountTrailingZerosOp) 

counts the trailing zeros an integer value

Syntax:

operation ::= `math.cttz` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandsignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

math.ctpop (::mlir::math::CtPopOp) 

counts the number of set bits of an integer value

Syntax:

operation ::= `math.ctpop` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandsignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

math.erf (::mlir::math::ErfOp) 

error function of the specified value

Syntax:

operation ::= `math.erf` $operand attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.erf` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.exp2 (::mlir::math::Exp2Op) 

base-2 exponential of the specified value

Syntax:

operation ::= `math.exp2` $operand attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.exp2` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.expm1 (::mlir::math::ExpM1Op) 

base-e exponential of the specified value minus 1

Syntax:

operation ::= `math.expm1` $operand attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.expm1` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.exp (::mlir::math::ExpOp) 

base-e exponential of the specified value

Syntax:

operation ::= `math.exp` $operand attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.exp` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.floor (::mlir::math::FloorOp) 

floor of the specified value

Syntax:

operation ::= `math.floor` $operand attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.floor` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.fma (::mlir::math::FmaOp) 

floating point fused multipy-add operation

Syntax:

operation ::= `math.fma` $a `,` $b `,` $c attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.fma` ssa-use `,` ssa-use `,` ssa-use `:` type

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.

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
afloating-point-like
bfloating-point-like
cfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.ipowi (::mlir::math::IPowIOp) 

signed integer raised to the power of operation

Syntax:

operation ::= `math.ipowi` $lhs `,` $rhs attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.ipowi` ssa-use `,` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhssignless-integer-like
rhssignless-integer-like

Results: 

ResultDescription
resultsignless-integer-like

math.log10 (::mlir::math::Log10Op) 

base-10 logarithm of the specified value

Syntax:

operation ::= `math.log10` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.log1p (::mlir::math::Log1pOp) 

Computes the natural logarithm of one plus the given value

Syntax:

operation ::= `math.log1p` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.log2 (::mlir::math::Log2Op) 

base-2 logarithm of the specified value

Syntax:

operation ::= `math.log2` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.log (::mlir::math::LogOp) 

base-e logarithm of the specified value

Syntax:

operation ::= `math.log` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.powf (::mlir::math::PowFOp) 

floating point raised to the power of operation

Syntax:

operation ::= `math.powf` $lhs `,` $rhs attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.powf` ssa-use `,` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
lhsfloating-point-like
rhsfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.round (::mlir::math::RoundOp) 

round of the specified value

Syntax:

operation ::= `math.round` $operand attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.round` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.rsqrt (::mlir::math::RsqrtOp) 

reciprocal of sqrt (1 / sqrt of the specified value)

Syntax:

operation ::= `math.rsqrt` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.sin (::mlir::math::SinOp) 

sine of the specified value

Syntax:

operation ::= `math.sin` $operand attr-dict `:` type($result)

Syntax:

operation ::= ssa-id `=` `math.sin` ssa-use `:` type

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.sqrt (::mlir::math::SqrtOp) 

sqrt of the specified value

Syntax:

operation ::= `math.sqrt` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.tan (::mlir::math::TanOp) 

tangent of the specified value

Syntax:

operation ::= `math.tan` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like

math.tanh (::mlir::math::TanhOp) 

hyperbolic tangent of the specified value

Syntax:

operation ::= `math.tanh` $operand attr-dict `:` type($result)

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

Traits: Elementwise, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable

Interfaces: InferTypeOpInterface, NoSideEffect (MemoryEffectOpInterface), VectorUnrollOpInterface

Effects: MemoryEffects::Effect{}

Operands: 

OperandDescription
operandfloating-point-like

Results: 

ResultDescription
resultfloating-point-like