docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
Arithmetic Operations

Functions for building arithmetic expressions. More...

Classes

class  sdfg::symbolic::IModFunction
 Function class for integer modulo operation. More...
class  sdfg::symbolic::ZExtI64Function
 Function class for zero-extension to 64-bit integer. More...
class  sdfg::symbolic::TruncI32Function
 Function class for truncation to 32-bit integer. More...

Functions

Expression sdfg::symbolic::add (const Expression lhs, const Expression rhs)
 Addition of two expressions.
Expression sdfg::symbolic::sub (const Expression lhs, const Expression rhs)
 Subtraction of two expressions.
Expression sdfg::symbolic::mul (const Expression lhs, const Expression rhs)
 Multiplication of two expressions.
Expression sdfg::symbolic::div (const Expression lhs, const Expression rhs)
 Integer division idiv(lhs, rhs) with the semantics of signed C/C++ lhs / rhs on int64.
Expression sdfg::symbolic::floor_div (const Expression lhs, const Expression divisor)
 Exact floor division floor(lhs / divisor) in terms of idiv.
Expression sdfg::symbolic::ceil_div (const Expression dividend, const Expression divisor)
 Exact ceiling division ceil(dividend / divisor) in terms of idiv.
Expression sdfg::symbolic::ceil_count (const Expression extent, const Expression chunk)
 Number of chunks of size chunk (positive) covering extent: max(0, ceil(extent / chunk)).
Expression sdfg::symbolic::min (const Expression lhs, const Expression rhs)
 Minimum of two expressions.
Expression sdfg::symbolic::max (const Expression lhs, const Expression rhs)
 Maximum of two expressions.
Expression sdfg::symbolic::abs (const Expression expr)
 Absolute value of an expression.
Expression sdfg::symbolic::mod (const Expression lhs, const Expression rhs)
 Integer remainder imod(lhs, rhs) with the semantics of signed C/C++ lhs % rhs on int64.
Expression sdfg::symbolic::bit_xor (const Expression lhs, const Expression rhs)
 Bitwise XOR operation (integer).
Expression sdfg::symbolic::pow (const Expression base, const Expression exp)
 Power/exponentiation operation.
Expression sdfg::symbolic::zext_i64 (const Expression expr)
 Zero-extend to 64-bit integer.
Expression sdfg::symbolic::trunc_i32 (const Expression expr)
 Truncate to 32-bit integer.

Detailed Description

Functions for building arithmetic expressions.

These functions construct symbolic arithmetic expressions representing integer operations. They are used in address calculations (memlets) and loop bounds.

// Example: Compute 2*i + j
auto i = symbolic::symbol("i");
auto j = symbolic::symbol("j");
Expression add(const Expression lhs, const Expression rhs)
Addition of two expressions.
Expression mul(const Expression lhs, const Expression rhs)
Multiplication of two expressions.
Integer integer(int64_t value)
Creates an integer constant.
Symbol symbol(const std::string &name)
Creates a symbolic variable with the given name.

Function Documentation

◆ abs()

Expression sdfg::symbolic::abs ( const Expression expr)

Absolute value of an expression.

Parameters
exprExpression to take absolute value of
Returns
Expression representing |expr|

◆ add()

Expression sdfg::symbolic::add ( const Expression lhs,
const Expression rhs )

Addition of two expressions.

Parameters
lhsLeft-hand side expression
rhsRight-hand side expression
Returns
Expression representing (lhs + rhs)

◆ bit_xor()

Expression sdfg::symbolic::bit_xor ( const Expression lhs,
const Expression rhs )

Bitwise XOR operation (integer).

Parameters
lhsLeft operand
rhsRight operand
Returns
Expression representing (lhs ^ rhs); lowered to ^ by codegen. Used by swizzled shared-memory layouts (a bijection on a power-of-two range).

◆ ceil_count()

Expression sdfg::symbolic::ceil_count ( const Expression extent,
const Expression chunk )

Number of chunks of size chunk (positive) covering extent: max(0, ceil(extent / chunk)).

For trip counts, grid sizes, page counts, etc. Cheaper than max(0, ceil_div(...)): idiv(extent + chunk - 1, chunk) is exact under the clamp.

◆ ceil_div()

Expression sdfg::symbolic::ceil_div ( const Expression dividend,
const Expression divisor )

Exact ceiling division ceil(dividend / divisor) in terms of idiv.

Integer literals fold for any non-zero divisor. Otherwise the divisor must be positive (a negative integer literal is normalized by negating both operands).

◆ div()

Expression sdfg::symbolic::div ( const Expression lhs,
const Expression rhs )

Integer division idiv(lhs, rhs) with the semantics of signed C/C++ lhs / rhs on int64.

The quotient is truncated toward zero, e.g. idiv(-7, 2) == -3; codegen emits /. Integer literals are folded unless the result is undefined in C (rhs == 0, INT64_MIN / -1).

◆ floor_div()

Expression sdfg::symbolic::floor_div ( const Expression lhs,
const Expression divisor )

Exact floor division floor(lhs / divisor) in terms of idiv.

Integer literals fold for any non-zero divisor. Otherwise the divisor must be positive (a negative integer literal is normalized by negating both operands).

◆ max()

Expression sdfg::symbolic::max ( const Expression lhs,
const Expression rhs )

Maximum of two expressions.

Parameters
lhsFirst expression
rhsSecond expression
Returns
Expression representing max(lhs, rhs)

◆ min()

Expression sdfg::symbolic::min ( const Expression lhs,
const Expression rhs )

Minimum of two expressions.

Parameters
lhsFirst expression
rhsSecond expression
Returns
Expression representing min(lhs, rhs)

◆ mod()

Expression sdfg::symbolic::mod ( const Expression lhs,
const Expression rhs )

Integer remainder imod(lhs, rhs) with the semantics of signed C/C++ lhs % rhs on int64.

The result has the sign of lhs and satisfies lhs == rhs * idiv(lhs, rhs) + imod(lhs, rhs), e.g. imod(-7, 2) == -1; codegen emits %. Folding follows the same rules as div.

◆ mul()

Expression sdfg::symbolic::mul ( const Expression lhs,
const Expression rhs )

Multiplication of two expressions.

Parameters
lhsLeft-hand side expression
rhsRight-hand side expression
Returns
Expression representing (lhs * rhs)

◆ pow()

Expression sdfg::symbolic::pow ( const Expression base,
const Expression exp )

Power/exponentiation operation.

Parameters
baseBase expression
expExponent expression
Returns
Expression representing base^exp

◆ sub()

Expression sdfg::symbolic::sub ( const Expression lhs,
const Expression rhs )

Subtraction of two expressions.

Parameters
lhsLeft-hand side expression
rhsRight-hand side expression
Returns
Expression representing (lhs - rhs)

◆ trunc_i32()

Expression sdfg::symbolic::trunc_i32 ( const Expression expr)

Truncate to 32-bit integer.

Parameters
exprExpression to truncate
Returns
Expression representing the truncated value

◆ zext_i64()

Expression sdfg::symbolic::zext_i64 ( const Expression expr)

Zero-extend to 64-bit integer.

Parameters
exprExpression to zero-extend
Returns
Expression representing the zero-extended value