1 #ifndef HALIDE_IR_OPERATOR_H
2 #define HALIDE_IR_OPERATOR_H
240 Type t = type_of<T>();
248 int64_t b_zero = (ib == 0) ? -1 : 0;
250 int64_t r = ia % (ib | b_zero);
251 r += (a_neg & ((ib ^ b_neg) + ~b_neg));
261 Type t = type_of<T>();
270 int64_t b_zero = (ib == 0) ? -1 : 0;
274 q += a_neg & (~b_neg - b_neg);
286 float f = a - b * (floorf(a / b));
329 template<
typename... Args>
331 args.emplace_back(std::string(arg));
335 template<
typename... Args>
337 args.push_back(std::move(arg));
393 return cast(type_of<T>(), std::move(a));
671 return max(
Expr(a), std::move(b));
674 return max(std::move(a),
Expr(b));
683 template<
typename A,
typename B,
typename C,
typename... Rest,
685 inline Expr max(A &&a, B &&b, C &&c, Rest &&...rest) {
686 return max(std::forward<A>(a),
max(std::forward<B>(b), std::forward<C>(c), std::forward<Rest>(rest)...));
706 return min(
Expr(a), std::move(b));
709 return min(std::move(a),
Expr(b));
718 template<
typename A,
typename B,
typename C,
typename... Rest,
720 inline Expr min(A &&a, B &&b, C &&c, Rest &&...rest) {
721 return min(std::forward<A>(a),
min(std::forward<B>(b), std::forward<C>(c), std::forward<Rest>(rest)...));
729 return std::move(a) +
Expr(b);
732 return Expr(a) + std::move(b);
735 return std::move(a) -
Expr(b);
738 return Expr(a) - std::move(b);
741 return std::move(a) *
Expr(b);
744 return Expr(a) * std::move(b);
747 return std::move(a) /
Expr(b);
750 return Expr(a) / std::move(b);
753 return std::move(a) %
Expr(b);
756 return Expr(a) % std::move(b);
759 return std::move(a) >
Expr(b);
762 return Expr(a) > std::move(b);
765 return std::move(a) <
Expr(b);
768 return Expr(a) < std::move(b);
771 return std::move(a) >=
Expr(b);
774 return Expr(a) >= std::move(b);
777 return std::move(a) <=
Expr(b);
780 return Expr(a) <= std::move(b);
783 return std::move(a) ==
Expr(b);
786 return Expr(a) == std::move(b);
789 return std::move(a) !=
Expr(b);
792 return Expr(a) != std::move(b);
823 template<
typename... Args,
826 return select(std::move(c0), std::move(v0),
select(std::move(c1), std::move(v1), std::forward<Args>(args)...));
839 template<
typename... Args>
844 template<
typename... Args>
863 Expr mux(
const Expr &
id,
const std::initializer_list<Expr> &values);
1062 template<
typename T>
1272 template<
typename... Args>
1274 std::vector<Expr> collected_args = {std::move(a)};
1276 return print(collected_args);
1285 template<
typename... Args>
1287 std::vector<Expr> collected_args = {std::move(a)};
1289 return print_when(std::move(condition), collected_args);
1318 template<
typename... Args>
1320 std::vector<Expr> collected_args = {std::move(value)};
1322 return require(std::move(condition), collected_args);
1346 template<
typename T>
1348 return undef(type_of<T>());
1351 namespace Internal {
1359 template<
typename T>
1393 template<
typename... Args>
1395 std::vector<Expr> collected_args{std::forward<Args>(args)...};
1422 template<
typename T>
1555 template<
typename... Args>
1557 return scatter({e, std::forward<Args>(args)...});
1560 template<
typename... Args>
1562 return gather({e, std::forward<Args>(args)...});
Base classes for Halide expressions (Halide::Expr) and statements (Halide::Internal::Stmt)
Defines Tuple - the front-end handle on small arrays of expressions.
#define HALIDE_NO_USER_CODE_INLINE
Create a small array of Exprs for defining and calling functions with multiple outputs.
Expr make_one(Type t)
Construct the representation of one in the given type.
bool is_const_zero(const Expr &e)
Is the expression a const (as defined by is_const), and also equal to zero (in all lanes,...
Expr memoize_tag_helper(Expr result, const std::vector< Expr > &cache_key_values)
Expr make_zero(Type t)
Construct the representation of zero in the given type.
bool is_negative_const(const Expr &e)
Is the expression a const (as defined by is_const), and also strictly less than zero (in all lanes,...
bool is_undef(const Expr &e)
Is the expression an undef.
Expr requirement_failed_error(Expr condition, const std::vector< Expr > &args)
Expr make_two(Type t)
Construct the representation of two in the given type.
Expr rounding_halving_add(Expr a, Expr b)
Compute narrow((widen(a) + widen(b) + 1) / 2)
Expr unreachable(Type t=Int(32))
Return an expression that should never be evaluated.
void check_representable(Type t, int64_t val)
Check if a constant value can be correctly represented as the given type.
Expr mul_shift_right(Expr a, Expr b, Expr q)
Compute saturating_narrow(shift_right(widening_mul(a, b), q))
Expr halide_erf(const Expr &a)
bool is_const_one(const Expr &e)
Is the expression a const (as defined by is_const), and also equal to one (in all lanes,...
void match_types(Expr &a, Expr &b)
Coerce the two expressions to have the same type, using C-style casting rules.
double div_imp< double >(double a, double b)
Expr widening_shift_right(Expr a, Expr b)
Compute widen(a) >> b.
Expr rounding_shift_right(Expr a, Expr b)
Compute saturating_add(a, (1 << max(b, 0)) / 2) >> b.
Expr halving_sub(Expr a, Expr b)
Compute narrow((widen(a) - widen(b)) / 2)
Expr widening_shift_left(Expr a, Expr b)
Compute widen(a) << b.
Expr halide_exp(const Expr &a)
Expr saturating_sub(Expr a, Expr b)
Compute saturating_narrow(widen(a) - widen(b))
Expr make_const(Type t, int64_t val)
Construct an immediate of the given type from any numeric C++ type.
bool is_positive_const(const Expr &e)
Is the expression a const (as defined by is_const), and also strictly greater than zero (in all lanes...
Expr const_true(int lanes=1)
Construct the constant boolean true.
const double * as_const_float(const Expr &e)
If an expression is a FloatImm or a Broadcast of a FloatImm, return a pointer to its value.
bool is_signed_integer_overflow(const Expr &expr)
Check if an expression is a signed_integer_overflow.
T mod_imp(T a, T b)
Implementations of division and mod that are specific to Halide.
Expr widening_sub(Expr a, Expr b)
Compute widen(a) - widen(b).
Expr widening_add(Expr a, Expr b)
Compute widen(a) + widen(b).
Expr rounding_mul_shift_right(Expr a, Expr b, Expr q)
Compute saturating_narrow(rounding_shift_right(widening_mul(a, b), q))
Expr halide_log(const Expr &a)
Halide's vectorizable transcendentals.
bool is_pure(const Expr &e)
Does the expression 1) Take on the same value no matter where it appears in a Stmt,...
void split_into_ands(const Expr &cond, std::vector< Expr > &result)
Split a boolean condition into vector of ANDs.
Expr promise_clamped(const Expr &value, const Expr &min, const Expr &max)
FOR INTERNAL USE ONLY.
bool is_no_op(const Stmt &s)
Is the statement a no-op (which we represent as either an undefined Stmt, or as an Evaluate node of a...
const int64_t * as_const_int(const Expr &e)
If an expression is an IntImm or a Broadcast of an IntImm, return a pointer to its value.
Expr rounding_halving_sub(Expr a, Expr b)
Compute narrow((widen(a) - widen(b) + 1) / 2)
Expr unwrap_tags(const Expr &e)
If the expression is a tag helper call, remove it and return the tagged expression.
float div_imp< float >(float a, float b)
bool is_const_power_of_two_integer(const Expr &e, int *bits)
Is the expression a constant integer power of two.
Expr lossless_negate(const Expr &x)
Attempt to negate x without introducing new IR and without overflow.
Expr widening_mul(Expr a, Expr b)
Compute widen(a) * widen(b).
Expr strided_ramp_base(const Expr &e, int stride=1)
If e is a ramp expression with stride, default 1, return the base, otherwise undefined.
Expr remove_promises(const Expr &e)
Return an Expr that is identical to the input Expr, but with all calls to promise_clamped() and unsaf...
Expr const_false(int lanes=1)
Construct the constant boolean false.
Expr rounding_shift_left(Expr a, Expr b)
Compute saturating_add(a, (1 >> min(b, 0)) / 2) << b.
double mod_imp< double >(double a, double b)
Expr make_bool(bool val, int lanes=1)
Construct a boolean constant from a C++ boolean value.
HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector< Expr > &args)
Expr saturating_add(Expr a, Expr b)
Compute saturating_narrow(widen(a) + widen(b))
void match_types_bitwise(Expr &a, Expr &b, const char *op_name)
Asserts that both expressions are integer types and are either both signed or both unsigned.
float mod_imp< float >(float a, float b)
Expr lossless_cast(Type t, Expr e)
Attempt to cast an expression to a smaller type while provably not losing information.
const uint64_t * as_const_uint(const Expr &e)
If an expression is a UIntImm or a Broadcast of a UIntImm, return a pointer to its value.
Expr halving_add(Expr a, Expr b)
Compute narrow((widen(a) + widen(b)) / 2)
Expr raise_to_integer_power(Expr a, int64_t b)
Raise an expression to an integer power by repeatedly multiplying it by itself.
Expr make_signed_integer_overflow(Type type)
Construct a unique signed_integer_overflow Expr.
bool is_const(const Expr &e)
Is the expression either an IntImm, a FloatImm, a StringImm, or a Cast of the same,...
Expr remove_likelies(const Expr &e)
Return an Expr that is identical to the input Expr, but with all calls to likely() and likely_if_inne...
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
auto operator>=(const Other &a, const GeneratorParam< T > &b) -> decltype(a >=(T) b)
Greater than or equal comparison between GeneratorParam<T> and any type that supports operator>= with...
Expr log(Expr x)
Return the logarithm of a floating-point expression.
Expr operator>>(Expr x, Expr y)
Shift the bits of an integer value right.
Expr ceil(Expr x)
Return the least whole number greater than or equal to a floating-point expression.
HALIDE_NO_USER_CODE_INLINE Expr memoize_tag(Expr result, Args &&...args)
Control the values used in the memoization cache key for memoize.
Expr fast_log(const Expr &x)
Fast approximate cleanly vectorizable log for Float(32).
Expr count_leading_zeros(Expr x)
Count the number of leading zero bits in an expression.
Expr reinterpret(Type t, Expr e)
Reinterpret the bits of one value as another type.
auto operator==(const Other &a, const GeneratorParam< T > &b) -> decltype(a==(T) b)
Equality comparison between GeneratorParam<T> and any type that supports operator== with T.
Expr fast_cos(const Expr &x)
Expr random_uint(Expr seed=Expr())
Return a random variable representing a uniformly distributed unsigned 32-bit integer.
@ Internal
Not visible externally, similar to 'static' linkage in C.
Expr fract(const Expr &x)
Return the fractional part of a floating-point expression.
auto operator<(const Other &a, const GeneratorParam< T > &b) -> decltype(a<(T) b)
Less than comparison between GeneratorParam<T> and any type that supports operator< with T.
auto operator*(const Other &a, const GeneratorParam< T > &b) -> decltype(a *(T) b)
Multiplication between GeneratorParam<T> and any type that supports operator* with T.
Expr trunc(Expr x)
Return the integer part of a floating-point expression.
auto operator||(const Other &a, const GeneratorParam< T > &b) -> decltype(a||(T) b)
Logical or between between GeneratorParam<T> and any type that supports operator|| with T.
Expr acosh(Expr x)
Return the hyperbolic arccosine of a floating-point expression.
Expr fast_inverse(Expr x)
Fast approximate inverse for Float(32).
Expr asin(Expr x)
Return the arcsine of a floating-point expression.
Expr & operator/=(Expr &a, Expr b)
Modify the first expression to be the ratio of two expressions, without changing its type.
auto operator-(const Other &a, const GeneratorParam< T > &b) -> decltype(a -(T) b)
Subtraction between GeneratorParam<T> and any type that supports operator- with T.
Expr clamp(Expr a, const Expr &min_val, const Expr &max_val)
Clamps an expression to lie within the given bounds.
Expr hypot(const Expr &x, const Expr &y)
Return the square root of the sum of the squares of two floating-point expressions.
Expr popcount(Expr x)
Count the number of set bits in an expression.
Expr gather(const std::vector< Expr > &args)
Expr print_when(Expr condition, const std::vector< Expr > &values)
Create an Expr that prints whenever it is evaluated, provided that the condition is true.
Expr pow(Expr x, Expr y)
Return one floating point expression raised to the power of another.
Expr operator&(Expr x, Expr y)
Return the bitwise and of two expressions (which need not have the same type).
Expr cast(Expr a)
Cast an expression to the halide type corresponding to the C++ type T.
auto operator!(const GeneratorParam< T > &a) -> decltype(!(T) a)
Not operator for GeneratorParam.
Expr lerp(Expr zero_val, Expr one_val, Expr weight)
Linear interpolate between the two values according to a weight.
Expr atan2(Expr y, Expr x)
Return the angle of a floating-point gradient.
Expr saturating_cast(Expr e)
Cast an expression to the halide type corresponding to the C++ type T.
Expr random_float(Expr seed=Expr())
Return a random variable representing a uniformly distributed float in the half-open interval [0....
Expr sin(Expr x)
Return the sine of a floating-point expression.
Expr unsafe_promise_clamped(const Expr &value, const Expr &min, const Expr &max)
Create an Expr that that promises another Expr is clamped but do not generate code to check the asser...
Expr mux(const Expr &id, const std::initializer_list< Expr > &values)
Oftentimes we want to pack a list of expressions with the same type into a channel dimension,...
Expr cosh(Expr x)
Return the hyperbolic cosine of a floating-point expression.
std::ostream & operator<<(std::ostream &stream, const Expr &)
Emit an expression on an output stream (such as std::cout) in human-readable form.
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Expr acos(Expr x)
Return the arccosine of a floating-point expression.
Expr fast_exp(const Expr &x)
Fast approximate cleanly vectorizable exp for Float(32).
Expr cos(Expr x)
Return the cosine of a floating-point expression.
auto operator+(const Other &a, const GeneratorParam< T > &b) -> decltype(a+(T) b)
Addition between GeneratorParam<T> and any type that supports operator+ with T.
Expr min(const FuncRef &a, const FuncRef &b)
Explicit overloads of min and max for FuncRef.
Expr exp(Expr x)
Return the exponential of a floating-point expression.
Expr absd(Expr a, Expr b)
Return the absolute difference between two values.
auto operator&&(const Other &a, const GeneratorParam< T > &b) -> decltype(a &&(T) b)
Logical and between between GeneratorParam<T> and any type that supports operator&& with T.
Tuple tuple_select(const Tuple &condition, const Tuple &true_value, const Tuple &false_value)
Equivalent of ternary select(), but taking/returning tuples.
Expr fast_sin(const Expr &x)
Fast vectorizable approximation to some trigonometric functions for Float(32).
Expr undef(Type t)
Return an undef value of the given type.
Expr & operator-=(Expr &a, Expr b)
Modify the first expression to be the difference of two expressions, without changing its type.
Expr fast_pow(Expr x, Expr y)
Fast approximate cleanly vectorizable pow for Float(32).
auto operator%(const Other &a, const GeneratorParam< T > &b) -> decltype(a %(T) b)
Modulo between GeneratorParam<T> and any type that supports operator% with T.
Expr round(Expr x)
Return the whole number closest to a floating-point expression.
Expr select(Expr condition, Expr true_value, Expr false_value)
Returns an expression similar to the ternary operator in C, except that it always evaluates all argum...
Expr count_trailing_zeros(Expr x)
Count the number of trailing zero bits in an expression.
Expr scatter(const std::vector< Expr > &args)
Scatter and gather are used for update definition which must store multiple values to distinct locati...
auto operator<=(const Other &a, const GeneratorParam< T > &b) -> decltype(a<=(T) b)
Less than or equal comparison between GeneratorParam<T> and any type that supports operator<= with T.
Expr random_int(Expr seed=Expr())
Return a random variable representing a uniformly distributed 32-bit integer.
Expr mod_round_to_zero(Expr x, Expr y)
Compute the remainder of dividing two integers, when division is rounding toward zero.
Expr strict_float(Expr e)
Makes a best effort attempt to preserve IEEE floating-point semantics in evaluating an expression.
auto operator>(const Other &a, const GeneratorParam< T > &b) -> decltype(a >(T) b)
Greater than comparison between GeneratorParam<T> and any type that supports operator> with T.
Expr is_nan(Expr x)
Returns true if the argument is a Not a Number (NaN).
Expr asinh(Expr x)
Return the hyperbolic arcsinhe of a floating-point expression.
Expr sqrt(Expr x)
Return the square root of a floating-point expression.
Expr sinh(Expr x)
Return the hyperbolic sine of a floating-point expression.
Expr atan(Expr x)
Return the arctangent of a floating-point expression.
Expr operator|(Expr x, Expr y)
Return the bitwise or of two expressions (which need not have the same type).
auto operator!=(const Other &a, const GeneratorParam< T > &b) -> decltype(a !=(T) b)
Inequality comparison between between GeneratorParam<T> and any type that supports operator!...
Expr & operator*=(Expr &a, Expr b)
Modify the first expression to be the product of two expressions, without changing its type.
Expr require(Expr condition, const std::vector< Expr > &values)
Create an Expr that that guarantees a precondition.
Expr is_inf(Expr x)
Returns true if the argument is Inf or -Inf.
Expr is_finite(Expr x)
Returns true if the argument is a finite value (ie, neither NaN nor Inf).
Expr tanh(Expr x)
Return the hyperbolic tangent of a floating-point expression.
Expr likely_if_innermost(Expr e)
Equivalent to likely, but only triggers a loop partitioning if found in an innermost loop.
Expr & operator+=(Expr &a, Expr b)
Modify the first expression to be the sum of two expressions, without changing its type.
Expr atanh(Expr x)
Return the hyperbolic arctangent of a floating-point expression.
Expr tan(Expr x)
Return the tangent of a floating-point expression.
Expr fast_inverse_sqrt(Expr x)
Fast approximate inverse square root for Float(32).
Expr print(const std::vector< Expr > &values)
Create an Expr that prints out its value whenever it is evaluated.
auto operator/(const Other &a, const GeneratorParam< T > &b) -> decltype(a/(T) b)
Division between GeneratorParam<T> and any type that supports operator/ with T.
Expr abs(Expr a)
Returns the absolute value of a signed integer or floating-point expression.
Expr max(const FuncRef &a, const FuncRef &b)
Expr floor(Expr x)
Return the greatest whole number less than or equal to a floating-point expression.
Expr div_round_to_zero(Expr x, Expr y)
Divide two integers, rounding towards zero.
Expr likely(Expr e)
Expressions tagged with this intrinsic are considered to be part of the steady state of some loop wit...
Expr operator~(Expr x)
Return the bitwise not of an expression.
Expr erf(const Expr &x)
Evaluate the error function erf.
Expr operator^(Expr x, Expr y)
Return the bitwise xor of two expressions (which need not have the same type).
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
signed __INT32_TYPE__ int32_t
unsigned __INT8_TYPE__ uint8_t
unsigned __INT16_TYPE__ uint16_t
unsigned __INT32_TYPE__ uint32_t
signed __INT16_TYPE__ int16_t
signed __INT8_TYPE__ int8_t
A fragment of Halide syntax.
A builder to help create Exprs representing halide_buffer_t structs (e.g.
std::vector< Expr > strides
std::vector< Expr > extents
A reference-counted handle to a statement node.
Types in the halide type system.
HALIDE_ALWAYS_INLINE bool is_int() const
Is this type a signed integer type?
HALIDE_ALWAYS_INLINE bool is_float() const
Is this type a floating point type (float or double).
Class that provides a type that implements half precision floating point (IEEE754 2008 binary16) in s...