Halide
IROperator.h
Go to the documentation of this file.
1 #ifndef HALIDE_IR_OPERATOR_H
2 #define HALIDE_IR_OPERATOR_H
3 
4 /** \file
5  *
6  * Defines various operator overloads and utility functions that make
7  * it more pleasant to work with Halide expressions.
8  */
9 
10 #include <cmath>
11 
12 #include "Expr.h"
13 #include "Tuple.h"
14 
15 namespace Halide {
16 
17 namespace Internal {
18 /** Is the expression either an IntImm, a FloatImm, a StringImm, or a
19  * Cast of the same, or a Ramp or Broadcast of the same. Doesn't do
20  * any constant folding. */
21 bool is_const(const Expr &e);
22 
23 /** Is the expression an IntImm, FloatImm of a particular value, or a
24  * Cast, or Broadcast of the same. */
25 bool is_const(const Expr &e, int64_t v);
26 
27 /** If an expression is an IntImm or a Broadcast of an IntImm, return
28  * a pointer to its value. Otherwise returns nullptr. */
29 const int64_t *as_const_int(const Expr &e);
30 
31 /** If an expression is a UIntImm or a Broadcast of a UIntImm, return
32  * a pointer to its value. Otherwise returns nullptr. */
33 const uint64_t *as_const_uint(const Expr &e);
34 
35 /** If an expression is a FloatImm or a Broadcast of a FloatImm,
36  * return a pointer to its value. Otherwise returns nullptr. */
37 const double *as_const_float(const Expr &e);
38 
39 /** Is the expression a constant integer power of two. Also returns
40  * log base two of the expression if it is. Only returns true for
41  * integer types. */
42 bool is_const_power_of_two_integer(const Expr &e, int *bits);
43 
44 /** Is the expression a const (as defined by is_const), and also
45  * strictly greater than zero (in all lanes, if a vector expression) */
46 bool is_positive_const(const Expr &e);
47 
48 /** Is the expression a const (as defined by is_const), and also
49  * strictly less than zero (in all lanes, if a vector expression) */
50 bool is_negative_const(const Expr &e);
51 
52 /** Is the expression a const (as defined by is_const), and also
53  * strictly less than zero (in all lanes, if a vector expression) and
54  * is its negative value representable. (This excludes the most
55  * negative value of the Expr's type from inclusion. Intended to be
56  * used when the value will be negated as part of simplification.)
57  */
58 bool is_negative_negatable_const(const Expr &e);
59 
60 /** Is the expression an undef */
61 bool is_undef(const Expr &e);
62 
63 /** Is the expression a const (as defined by is_const), and also equal
64  * to zero (in all lanes, if a vector expression) */
65 bool is_zero(const Expr &e);
66 
67 /** Is the expression a const (as defined by is_const), and also equal
68  * to one (in all lanes, if a vector expression) */
69 bool is_one(const Expr &e);
70 
71 /** Is the expression a const (as defined by is_const), and also equal
72  * to two (in all lanes, if a vector expression) */
73 bool is_two(const Expr &e);
74 
75 /** Is the statement a no-op (which we represent as either an
76  * undefined Stmt, or as an Evaluate node of a constant) */
77 bool is_no_op(const Stmt &s);
78 
79 /** Does the expression
80  * 1) Take on the same value no matter where it appears in a Stmt, and
81  * 2) Evaluating it has no side-effects
82  */
83 bool is_pure(const Expr &e);
84 
85 /** Construct an immediate of the given type from any numeric C++ type. */
86 // @{
87 Expr make_const(Type t, int64_t val);
88 Expr make_const(Type t, uint64_t val);
89 Expr make_const(Type t, double val);
90 inline Expr make_const(Type t, int32_t val) {
91  return make_const(t, (int64_t)val);
92 }
93 inline Expr make_const(Type t, uint32_t val) {
94  return make_const(t, (uint64_t)val);
95 }
96 inline Expr make_const(Type t, int16_t val) {
97  return make_const(t, (int64_t)val);
98 }
99 inline Expr make_const(Type t, uint16_t val) {
100  return make_const(t, (uint64_t)val);
101 }
102 inline Expr make_const(Type t, int8_t val) {
103  return make_const(t, (int64_t)val);
104 }
105 inline Expr make_const(Type t, uint8_t val) {
106  return make_const(t, (uint64_t)val);
107 }
108 inline Expr make_const(Type t, bool val) {
109  return make_const(t, (uint64_t)val);
110 }
111 inline Expr make_const(Type t, float val) {
112  return make_const(t, (double)val);
113 }
114 inline Expr make_const(Type t, float16_t val) {
115  return make_const(t, (double)val);
116 }
117 // @}
118 
119 /** Construct a unique signed_integer_overflow Expr */
121 
122 /** Check if a constant value can be correctly represented as the given type. */
123 void check_representable(Type t, int64_t val);
124 
125 /** Construct a boolean constant from a C++ boolean value.
126  * May also be a vector if width is given.
127  * It is not possible to coerce a C++ boolean to Expr because
128  * if we provide such a path then char objects can ambiguously
129  * be converted to Halide Expr or to std::string. The problem
130  * is that C++ does not have a real bool type - it is in fact
131  * close enough to char that C++ does not know how to distinguish them.
132  * make_bool is the explicit coercion. */
133 Expr make_bool(bool val, int lanes = 1);
134 
135 /** Construct the representation of zero in the given type */
136 Expr make_zero(Type t);
137 
138 /** Construct the representation of one in the given type */
139 Expr make_one(Type t);
140 
141 /** Construct the representation of two in the given type */
142 Expr make_two(Type t);
143 
144 /** Construct the constant boolean true. May also be a vector of
145  * trues, if a lanes argument is given. */
146 Expr const_true(int lanes = 1);
147 
148 /** Construct the constant boolean false. May also be a vector of
149  * falses, if a lanes argument is given. */
150 Expr const_false(int lanes = 1);
151 
152 /** Attempt to cast an expression to a smaller type while provably not
153  * losing information. If it can't be done, return an undefined
154  * Expr. */
156 
157 /** Coerce the two expressions to have the same type, using C-style
158  * casting rules. For the purposes of casting, a boolean type is
159  * UInt(1). We use the following procedure:
160  *
161  * If the types already match, do nothing.
162  *
163  * Then, if one type is a vector and the other is a scalar, the scalar
164  * is broadcast to match the vector width, and we continue.
165  *
166  * Then, if one type is floating-point and the other is not, the
167  * non-float is cast to the floating-point type, and we're done.
168  *
169  * Then, if both types are unsigned ints, the one with fewer bits is
170  * cast to match the one with more bits and we're done.
171  *
172  * Then, if both types are signed ints, the one with fewer bits is
173  * cast to match the one with more bits and we're done.
174  *
175  * Finally, if one type is an unsigned int and the other type is a signed
176  * int, both are cast to a signed int with the greater of the two
177  * bit-widths. For example, matching an Int(8) with a UInt(16) results
178  * in an Int(16).
179  *
180  */
181 void match_types(Expr &a, Expr &b);
182 
183 /** Asserts that both expressions are integer types and are either
184  * both signed or both unsigned. If one argument is scalar and the
185  * other a vector, the scalar is broadcasted to have the same number
186  * of lanes as the vector. If one expression is of narrower type than
187  * the other, it is widened to the bit width of the wider. */
188 void match_types_bitwise(Expr &a, Expr &b, const char *op_name);
189 
190 /** Halide's vectorizable transcendentals. */
191 // @{
192 Expr halide_log(const Expr &a);
193 Expr halide_exp(const Expr &a);
194 Expr halide_erf(const Expr &a);
195 // @}
196 
197 /** Raise an expression to an integer power by repeatedly multiplying
198  * it by itself. */
200 
201 /** Split a boolean condition into vector of ANDs. If 'cond' is undefined,
202  * return an empty vector. */
203 void split_into_ands(const Expr &cond, std::vector<Expr> &result);
204 
205 /** A builder to help create Exprs representing halide_buffer_t
206  * structs (e.g. foo.buffer) via calls to halide_buffer_init. Fill out
207  * the fields and then call build. The resulting Expr will be a call
208  * to halide_buffer_init with the struct members as arguments. If the
209  * buffer_memory field is undefined, it uses a call to alloca to make
210  * some stack memory for the buffer. If the shape_memory field is
211  * undefined, it similarly uses stack memory for the shape. If the
212  * shape_memory field is null, it uses the dim field already in the
213  * buffer. Other unitialized fields will take on a value of zero in
214  * the constructed buffer. */
219  int dimensions = 0;
220  std::vector<Expr> mins, extents, strides;
222  Expr build() const;
223 };
224 
225 /** If e is a ramp expression with stride, default 1, return the base,
226  * otherwise undefined. */
227 Expr strided_ramp_base(const Expr &e, int stride = 1);
228 
229 /** Implementations of division and mod that are specific to Halide.
230  * Use these implementations; do not use native C division or mod to
231  * simplify Halide expressions. Halide division and modulo satisify
232  * the Euclidean definition of division for integers a and b:
233  *
234  /code
235  when b != 0, (a/b)*b + a%b = a
236  0 <= a%b < |b|
237  /endcode
238  *
239  * Additionally, mod by zero returns zero, and div by zero returns
240  * zero. This makes mod and div total functions.
241  */
242 // @{
243 template<typename T>
244 inline T mod_imp(T a, T b) {
245  Type t = type_of<T>();
246  if (!t.is_float() && b == 0) {
247  return 0;
248  } else if (t.is_int()) {
249  int64_t ia = a;
250  int64_t ib = b;
251  int64_t a_neg = ia >> 63;
252  int64_t b_neg = ib >> 63;
253  int64_t b_zero = (ib == 0) ? -1 : 0;
254  ia -= a_neg;
255  int64_t r = ia % (ib | b_zero);
256  r += (a_neg & ((ib ^ b_neg) + ~b_neg));
257  r &= ~b_zero;
258  return r;
259  } else {
260  return a % b;
261  }
262 }
263 
264 template<typename T>
265 inline T div_imp(T a, T b) {
266  Type t = type_of<T>();
267  if (!t.is_float() && b == 0) {
268  return (T)0;
269  } else if (t.is_int()) {
270  // Do it as 64-bit
271  int64_t ia = a;
272  int64_t ib = b;
273  int64_t a_neg = ia >> 63;
274  int64_t b_neg = ib >> 63;
275  int64_t b_zero = (ib == 0) ? -1 : 0;
276  ib -= b_zero;
277  ia -= a_neg;
278  int64_t q = ia / ib;
279  q += a_neg & (~b_neg - b_neg);
280  q &= ~b_zero;
281  return (T)q;
282  } else {
283  return a / b;
284  }
285 }
286 // @}
287 
288 // Special cases for float, double.
289 template<>
290 inline float mod_imp<float>(float a, float b) {
291  float f = a - b * (floorf(a / b));
292  // The remainder has the same sign as b.
293  return f;
294 }
295 template<>
296 inline double mod_imp<double>(double a, double b) {
297  double f = a - b * (std::floor(a / b));
298  return f;
299 }
300 
301 template<>
302 inline float div_imp<float>(float a, float b) {
303  return a / b;
304 }
305 template<>
306 inline double div_imp<double>(double a, double b) {
307  return a / b;
308 }
309 
310 /** Return an Expr that is identical to the input Expr, but with
311  * all calls to likely() and likely_if_innermost() removed. */
312 Expr remove_likelies(const Expr &e);
313 
314 /** Return a Stmt that is identical to the input Stmt, but with
315  * all calls to likely() and likely_if_innermost() removed. */
316 Stmt remove_likelies(const Stmt &s);
317 
318 // Secondary args to print can be Exprs or const char *
319 inline HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector<Expr> &args) {
320 }
321 
322 template<typename... Args>
323 inline HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector<Expr> &args, const char *arg, Args &&... more_args) {
324  args.emplace_back(std::string(arg));
325  collect_print_args(args, std::forward<Args>(more_args)...);
326 }
327 
328 template<typename... Args>
329 inline HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector<Expr> &args, Expr arg, Args &&... more_args) {
330  args.push_back(std::move(arg));
331  collect_print_args(args, std::forward<Args>(more_args)...);
332 }
333 
334 Expr requirement_failed_error(Expr condition, const std::vector<Expr> &args);
335 
336 Expr memoize_tag_helper(Expr result, const std::vector<Expr> &cache_key_values);
337 
338 } // namespace Internal
339 
340 /** Cast an expression to the halide type corresponding to the C++ type T. */
341 template<typename T>
342 inline Expr cast(Expr a) {
343  return cast(type_of<T>(), std::move(a));
344 }
345 
346 /** Cast an expression to a new type. */
347 Expr cast(Type t, Expr a);
348 
349 /** Return the sum of two expressions, doing any necessary type
350  * coercion using \ref Internal::match_types */
351 Expr operator+(Expr a, Expr b);
352 
353 /** Add an expression and a constant integer. Coerces the type of the
354  * integer to match the type of the expression. Errors if the integer
355  * cannot be represented in the type of the expression. */
356 // @{
357 Expr operator+(Expr a, int b);
358 
359 /** Add a constant integer and an expression. Coerces the type of the
360  * integer to match the type of the expression. Errors if the integer
361  * cannot be represented in the type of the expression. */
362 Expr operator+(int a, Expr b);
363 
364 /** Modify the first expression to be the sum of two expressions,
365  * without changing its type. This casts the second argument to match
366  * the type of the first. */
367 Expr &operator+=(Expr &a, Expr b);
368 
369 /** Return the difference of two expressions, doing any necessary type
370  * coercion using \ref Internal::match_types */
371 Expr operator-(Expr a, Expr b);
372 
373 /** Subtracts a constant integer from an expression. Coerces the type of the
374  * integer to match the type of the expression. Errors if the integer
375  * cannot be represented in the type of the expression. */
376 Expr operator-(Expr a, int b);
377 
378 /** Subtracts an expression from a constant integer. Coerces the type
379  * of the integer to match the type of the expression. Errors if the
380  * integer cannot be represented in the type of the expression. */
381 Expr operator-(int a, Expr b);
382 
383 /** Return the negative of the argument. Does no type casting, so more
384  * formally: return that number which when added to the original,
385  * yields zero of the same type. For unsigned integers the negative is
386  * still an unsigned integer. E.g. in UInt(8), the negative of 56 is
387  * 200, because 56 + 200 == 0 */
388 Expr operator-(Expr a);
389 
390 /** Modify the first expression to be the difference of two expressions,
391  * without changing its type. This casts the second argument to match
392  * the type of the first. */
393 Expr &operator-=(Expr &a, Expr b);
394 
395 /** Return the product of two expressions, doing any necessary type
396  * coercion using \ref Internal::match_types */
397 Expr operator*(Expr a, Expr b);
398 
399 /** Multiply an expression and a constant integer. Coerces the type of the
400  * integer to match the type of the expression. Errors if the integer
401  * cannot be represented in the type of the expression. */
402 Expr operator*(Expr a, int b);
403 
404 /** Multiply a constant integer and an expression. Coerces the type of
405  * the integer to match the type of the expression. Errors if the
406  * integer cannot be represented in the type of the expression. */
407 Expr operator*(int a, Expr b);
408 
409 /** Modify the first expression to be the product of two expressions,
410  * without changing its type. This casts the second argument to match
411  * the type of the first. */
412 Expr &operator*=(Expr &a, Expr b);
413 
414 /** Return the ratio of two expressions, doing any necessary type
415  * coercion using \ref Internal::match_types. Note that integer
416  * division in Halide is not the same as integer division in C-like
417  * languages in two ways.
418  *
419  * First, signed integer division in Halide rounds according to the
420  * sign of the denominator. This means towards minus infinity for
421  * positive denominators, and towards positive infinity for negative
422  * denominators. This is unlike C, which rounds towards zero. This
423  * decision ensures that upsampling expressions like f(x/2, y/2) don't
424  * have funny discontinuities when x and y cross zero.
425  *
426  * Second, division by zero returns zero instead of faulting. For
427  * types where overflow is defined behavior, division of the largest
428  * negative signed integer by -1 returns the larged negative signed
429  * integer for the type (i.e. it wraps). This ensures that a division
430  * operation can never have a side-effect, which is helpful in Halide
431  * because scheduling directives can expand the domain of computation
432  * of a Func, potentially introducing new zero-division.
433  */
434 Expr operator/(Expr a, Expr b);
435 
436 /** Modify the first expression to be the ratio of two expressions,
437  * without changing its type. This casts the second argument to match
438  * the type of the first. Note that signed integer division in Halide
439  * rounds towards minus infinity, unlike C, which rounds towards
440  * zero. */
441 Expr &operator/=(Expr &a, Expr b);
442 
443 /** Divides an expression by a constant integer. Coerces the type
444  * of the integer to match the type of the expression. Errors if the
445  * integer cannot be represented in the type of the expression. */
446 Expr operator/(Expr a, int b);
447 
448 /** Divides a constant integer by an expression. Coerces the type
449  * of the integer to match the type of the expression. Errors if the
450  * integer cannot be represented in the type of the expression. */
451 Expr operator/(int a, Expr b);
452 
453 /** Return the first argument reduced modulo the second, doing any
454  * necessary type coercion using \ref Internal::match_types. There are
455  * two key differences between C-like languages and Halide for the
456  * modulo operation, which complement the way division works.
457  *
458  * First, the result is never negative, so x % 2 is always zero or
459  * one, unlike in C-like languages. x % -2 is equivalent, and is also
460  * always zero or one. Second, mod by zero evaluates to zero (unlike
461  * in C, where it faults). This makes modulo, like division, a
462  * side-effect-free operation. */
463 Expr operator%(Expr a, Expr b);
464 
465 /** Mods an expression by a constant integer. Coerces the type
466  * of the integer to match the type of the expression. Errors if the
467  * integer cannot be represented in the type of the expression. */
468 Expr operator%(Expr a, int b);
469 
470 /** Mods a constant integer by an expression. Coerces the type
471  * of the integer to match the type of the expression. Errors if the
472  * integer cannot be represented in the type of the expression. */
473 Expr operator%(int a, Expr b);
474 
475 /** Return a boolean expression that tests whether the first argument
476  * is greater than the second, after doing any necessary type coercion
477  * using \ref Internal::match_types */
478 Expr operator>(Expr a, Expr b);
479 
480 /** Return a boolean expression that tests whether an expression is
481  * greater than a constant integer. Coerces the integer to the type of
482  * the expression. Errors if the integer is not representable in that
483  * type. */
484 Expr operator>(Expr a, int b);
485 
486 /** Return a boolean expression that tests whether a constant integer is
487  * greater than an expression. Coerces the integer to the type of
488  * the expression. Errors if the integer is not representable in that
489  * type. */
490 Expr operator>(int a, Expr b);
491 
492 /** Return a boolean expression that tests whether the first argument
493  * is less than the second, after doing any necessary type coercion
494  * using \ref Internal::match_types */
495 Expr operator<(Expr a, Expr b);
496 
497 /** Return a boolean expression that tests whether an expression is
498  * less than a constant integer. Coerces the integer to the type of
499  * the expression. Errors if the integer is not representable in that
500  * type. */
501 Expr operator<(Expr a, int b);
502 
503 /** Return a boolean expression that tests whether a constant integer is
504  * less than an expression. Coerces the integer to the type of
505  * the expression. Errors if the integer is not representable in that
506  * type. */
507 Expr operator<(int a, Expr b);
508 
509 /** Return a boolean expression that tests whether the first argument
510  * is less than or equal to the second, after doing any necessary type
511  * coercion using \ref Internal::match_types */
512 Expr operator<=(Expr a, Expr b);
513 
514 /** Return a boolean expression that tests whether an expression is
515  * less than or equal to a constant integer. Coerces the integer to
516  * the type of the expression. Errors if the integer is not
517  * representable in that type. */
518 Expr operator<=(Expr a, int b);
519 
520 /** Return a boolean expression that tests whether a constant integer
521  * is less than or equal to an expression. Coerces the integer to the
522  * type of the expression. Errors if the integer is not representable
523  * in that type. */
524 Expr operator<=(int a, Expr b);
525 
526 /** Return a boolean expression that tests whether the first argument
527  * is greater than or equal to the second, after doing any necessary
528  * type coercion using \ref Internal::match_types */
529 Expr operator>=(Expr a, Expr b);
530 
531 /** Return a boolean expression that tests whether an expression is
532  * greater than or equal to a constant integer. Coerces the integer to
533  * the type of the expression. Errors if the integer is not
534  * representable in that type. */
535 Expr operator>=(const Expr &a, int b);
536 
537 /** Return a boolean expression that tests whether a constant integer
538  * is greater than or equal to an expression. Coerces the integer to the
539  * type of the expression. Errors if the integer is not representable
540  * in that type. */
541 Expr operator>=(int a, const Expr &b);
542 
543 /** Return a boolean expression that tests whether the first argument
544  * is equal to the second, after doing any necessary type coercion
545  * using \ref Internal::match_types */
546 Expr operator==(Expr a, Expr b);
547 
548 /** Return a boolean expression that tests whether an expression is
549  * equal to a constant integer. Coerces the integer to the type of the
550  * expression. Errors if the integer is not representable in that
551  * type. */
552 Expr operator==(Expr a, int b);
553 
554 /** Return a boolean expression that tests whether a constant integer
555  * is equal to an expression. Coerces the integer to the type of the
556  * expression. Errors if the integer is not representable in that
557  * type. */
558 Expr operator==(int a, Expr b);
559 
560 /** Return a boolean expression that tests whether the first argument
561  * is not equal to the second, after doing any necessary type coercion
562  * using \ref Internal::match_types */
563 Expr operator!=(Expr a, Expr b);
564 
565 /** Return a boolean expression that tests whether an expression is
566  * not equal to a constant integer. Coerces the integer to the type of
567  * the expression. Errors if the integer is not representable in that
568  * type. */
569 Expr operator!=(Expr a, int b);
570 
571 /** Return a boolean expression that tests whether a constant integer
572  * is not equal to an expression. Coerces the integer to the type of
573  * the expression. Errors if the integer is not representable in that
574  * type. */
575 Expr operator!=(int a, Expr b);
576 
577 /** Returns the logical and of the two arguments */
578 Expr operator&&(Expr a, Expr b);
579 
580 /** Logical and of an Expr and a bool. Either returns the Expr or an
581  * Expr representing false, depending on the bool. */
582 // @{
583 Expr operator&&(Expr a, bool b);
584 Expr operator&&(bool a, Expr b);
585 // @}
586 
587 /** Returns the logical or of the two arguments */
588 Expr operator||(Expr a, Expr b);
589 
590 /** Logical or of an Expr and a bool. Either returns the Expr or an
591  * Expr representing true, depending on the bool. */
592 // @{
593 Expr operator||(Expr a, bool b);
594 Expr operator||(bool a, Expr b);
595 // @}
596 
597 /** Returns the logical not the argument */
598 Expr operator!(Expr a);
599 
600 /** Returns an expression representing the greater of the two
601  * arguments, after doing any necessary type coercion using
602  * \ref Internal::match_types. Vectorizes cleanly on most platforms
603  * (with the exception of integer types on x86 without SSE4). */
604 Expr max(Expr a, Expr b);
605 
606 /** Returns an expression representing the greater of an expression
607  * and a constant integer. The integer is coerced to the type of the
608  * expression. Errors if the integer is not representable as that
609  * type. Vectorizes cleanly on most platforms (with the exception of
610  * integer types on x86 without SSE4). */
611 Expr max(Expr a, int b);
612 
613 /** Returns an expression representing the greater of a constant
614  * integer and an expression. The integer is coerced to the type of
615  * the expression. Errors if the integer is not representable as that
616  * type. Vectorizes cleanly on most platforms (with the exception of
617  * integer types on x86 without SSE4). */
618 Expr max(int a, Expr b);
619 
620 inline Expr max(float a, Expr b) {
621  return max(Expr(a), std::move(b));
622 }
623 inline Expr max(Expr a, float b) {
624  return max(std::move(a), Expr(b));
625 }
626 
627 /** Returns an expression representing the greater of an expressions
628  * vector, after doing any necessary type coersion using
629  * \ref Internal::match_types. Vectorizes cleanly on most platforms
630  * (with the exception of integer types on x86 without SSE4).
631  * The expressions are folded from right ie. max(.., max(.., ..)).
632  * The arguments can be any mix of types but must all be convertible to Expr. */
633 template<typename A, typename B, typename C, typename... Rest,
634  typename std::enable_if<Halide::Internal::all_are_convertible<Expr, Rest...>::value>::type * = nullptr>
635 inline Expr max(A &&a, B &&b, C &&c, Rest &&... rest) {
636  return max(std::forward<A>(a), max(std::forward<B>(b), std::forward<C>(c), std::forward<Rest>(rest)...));
637 }
638 
639 Expr min(Expr a, Expr b);
640 
641 /** Returns an expression representing the lesser of an expression
642  * and a constant integer. The integer is coerced to the type of the
643  * expression. Errors if the integer is not representable as that
644  * type. Vectorizes cleanly on most platforms (with the exception of
645  * integer types on x86 without SSE4). */
646 Expr min(Expr a, int b);
647 
648 /** Returns an expression representing the lesser of a constant
649  * integer and an expression. The integer is coerced to the type of
650  * the expression. Errors if the integer is not representable as that
651  * type. Vectorizes cleanly on most platforms (with the exception of
652  * integer types on x86 without SSE4). */
653 Expr min(int a, Expr b);
654 
655 inline Expr min(float a, Expr b) {
656  return min(Expr(a), std::move(b));
657 }
658 inline Expr min(Expr a, float b) {
659  return min(std::move(a), Expr(b));
660 }
661 
662 /** Returns an expression representing the lesser of an expressions
663  * vector, after doing any necessary type coersion using
664  * \ref Internal::match_types. Vectorizes cleanly on most platforms
665  * (with the exception of integer types on x86 without SSE4).
666  * The expressions are folded from right ie. min(.., min(.., ..)).
667  * The arguments can be any mix of types but must all be convertible to Expr. */
668 template<typename A, typename B, typename C, typename... Rest,
669  typename std::enable_if<Halide::Internal::all_are_convertible<Expr, Rest...>::value>::type * = nullptr>
670 inline Expr min(A &&a, B &&b, C &&c, Rest &&... rest) {
671  return min(std::forward<A>(a), min(std::forward<B>(b), std::forward<C>(c), std::forward<Rest>(rest)...));
672 }
673 
674 /** Operators on floats treats those floats as Exprs. Making these
675  * explicit prevents implicit float->int casts that might otherwise
676  * occur. */
677 // @{
678 inline Expr operator+(Expr a, float b) {
679  return std::move(a) + Expr(b);
680 }
681 inline Expr operator+(float a, Expr b) {
682  return Expr(a) + std::move(b);
683 }
684 inline Expr operator-(Expr a, float b) {
685  return std::move(a) - Expr(b);
686 }
687 inline Expr operator-(float a, Expr b) {
688  return Expr(a) - std::move(b);
689 }
690 inline Expr operator*(Expr a, float b) {
691  return std::move(a) * Expr(b);
692 }
693 inline Expr operator*(float a, Expr b) {
694  return Expr(a) * std::move(b);
695 }
696 inline Expr operator/(Expr a, float b) {
697  return std::move(a) / Expr(b);
698 }
699 inline Expr operator/(float a, Expr b) {
700  return Expr(a) / std::move(b);
701 }
702 inline Expr operator%(Expr a, float b) {
703  return std::move(a) % Expr(b);
704 }
705 inline Expr operator%(float a, Expr b) {
706  return Expr(a) % std::move(b);
707 }
708 inline Expr operator>(Expr a, float b) {
709  return std::move(a) > Expr(b);
710 }
711 inline Expr operator>(float a, Expr b) {
712  return Expr(a) > std::move(b);
713 }
714 inline Expr operator<(Expr a, float b) {
715  return std::move(a) < Expr(b);
716 }
717 inline Expr operator<(float a, Expr b) {
718  return Expr(a) < std::move(b);
719 }
720 inline Expr operator>=(Expr a, float b) {
721  return std::move(a) >= Expr(b);
722 }
723 inline Expr operator>=(float a, Expr b) {
724  return Expr(a) >= std::move(b);
725 }
726 inline Expr operator<=(Expr a, float b) {
727  return std::move(a) <= Expr(b);
728 }
729 inline Expr operator<=(float a, Expr b) {
730  return Expr(a) <= std::move(b);
731 }
732 inline Expr operator==(Expr a, float b) {
733  return std::move(a) == Expr(b);
734 }
735 inline Expr operator==(float a, Expr b) {
736  return Expr(a) == std::move(b);
737 }
738 inline Expr operator!=(Expr a, float b) {
739  return std::move(a) != Expr(b);
740 }
741 inline Expr operator!=(float a, Expr b) {
742  return Expr(a) != std::move(b);
743 }
744 // @}
745 
746 /** Clamps an expression to lie within the given bounds. The bounds
747  * are type-cast to match the expression. Vectorizes as well as min/max. */
748 Expr clamp(Expr a, const Expr &min_val, const Expr &max_val);
749 
750 /** Returns the absolute value of a signed integer or floating-point
751  * expression. Vectorizes cleanly. Unlike in C, abs of a signed
752  * integer returns an unsigned integer of the same bit width. This
753  * means that abs of the most negative integer doesn't overflow. */
754 Expr abs(Expr a);
755 
756 /** Return the absolute difference between two values. Vectorizes
757  * cleanly. Returns an unsigned value of the same bit width. There are
758  * various ways to write this yourself, but they contain numerous
759  * gotchas and don't always compile to good code, so use this
760  * instead. */
761 Expr absd(Expr a, Expr b);
762 
763 /** Returns an expression similar to the ternary operator in C, except
764  * that it always evaluates all arguments. If the first argument is
765  * true, then return the second, else return the third. Typically
766  * vectorizes cleanly, but benefits from SSE41 or newer on x86. */
767 Expr select(Expr condition, Expr true_value, Expr false_value);
768 
769 /** A multi-way variant of select similar to a switch statement in C,
770  * which can accept multiple conditions and values in pairs. Evaluates
771  * to the first value for which the condition is true. Returns the
772  * final value if all conditions are false. */
773 template<typename... Args,
774  typename std::enable_if<Halide::Internal::all_are_convertible<Expr, Args...>::value>::type * = nullptr>
775 inline Expr select(Expr c0, Expr v0, Expr c1, Expr v1, Args &&... args) {
776  return select(std::move(c0), std::move(v0), select(std::move(c1), std::move(v1), std::forward<Args>(args)...));
777 }
778 
779 /** Equivalent of ternary select(), but taking/returning tuples. If the condition is
780  * a Tuple, it must match the size of the true and false Tuples. */
781 // @{
782 Tuple tuple_select(const Tuple &condition, const Tuple &true_value, const Tuple &false_value);
783 Tuple tuple_select(const Expr &condition, const Tuple &true_value, const Tuple &false_value);
784 // @}
785 
786 /** Equivalent of multiway select(), but taking/returning tuples. If the condition is
787  * a Tuple, it must match the size of the true and false Tuples. */
788 // @{
789 template<typename... Args>
790 inline Tuple tuple_select(const Tuple &c0, const Tuple &v0, const Tuple &c1, const Tuple &v1, Args &&... args) {
791  return tuple_select(c0, v0, tuple_select(c1, v1, std::forward<Args>(args)...));
792 }
793 
794 template<typename... Args>
795 inline Tuple tuple_select(const Expr &c0, const Tuple &v0, const Expr &c1, const Tuple &v1, Args &&... args) {
796  return tuple_select(c0, v0, tuple_select(c1, v1, std::forward<Args>(args)...));
797 }
798 // @}
799 
800 /** Oftentimes we want to pack a list of expressions with the same type
801  * into a channel dimension, e.g.,
802  * img(x, y, c) = select(c == 0, 100, // Red
803  * c == 1, 50, // Green
804  * 25); // Blue
805  * This is tedious when the list is long. The following function
806  * provide convinent syntax that allow one to write:
807  * img(x, y, c) = mux(c, {100, 50, 25});
808  */
809 // @{
810 Expr mux(const Expr &id, const std::initializer_list<Expr> &values);
811 Expr mux(const Expr &id, const std::vector<Expr> &values);
812 Expr mux(const Expr &id, const Tuple &values);
813 // @}
814 
815 /** Return the sine of a floating-point expression. If the argument is
816  * not floating-point, it is cast to Float(32). Does not vectorize
817  * well. */
818 Expr sin(Expr x);
819 
820 /** Return the arcsine of a floating-point expression. If the argument
821  * is not floating-point, it is cast to Float(32). Does not vectorize
822  * well. */
823 Expr asin(Expr x);
824 
825 /** Return the cosine of a floating-point expression. If the argument
826  * is not floating-point, it is cast to Float(32). Does not vectorize
827  * well. */
828 Expr cos(Expr x);
829 
830 /** Return the arccosine of a floating-point expression. If the
831  * argument is not floating-point, it is cast to Float(32). Does not
832  * vectorize well. */
833 Expr acos(Expr x);
834 
835 /** Return the tangent of a floating-point expression. If the argument
836  * is not floating-point, it is cast to Float(32). Does not vectorize
837  * well. */
838 Expr tan(Expr x);
839 
840 /** Return the arctangent of a floating-point expression. If the
841  * argument is not floating-point, it is cast to Float(32). Does not
842  * vectorize well. */
843 Expr atan(Expr x);
844 
845 /** Return the angle of a floating-point gradient. If the argument is
846  * not floating-point, it is cast to Float(32). Does not vectorize
847  * well. */
848 Expr atan2(Expr y, Expr x);
849 
850 /** Return the hyperbolic sine of a floating-point expression. If the
851  * argument is not floating-point, it is cast to Float(32). Does not
852  * vectorize well. */
853 Expr sinh(Expr x);
854 
855 /** Return the hyperbolic arcsinhe of a floating-point expression. If
856  * the argument is not floating-point, it is cast to Float(32). Does
857  * not vectorize well. */
858 Expr asinh(Expr x);
859 
860 /** Return the hyperbolic cosine of a floating-point expression. If
861  * the argument is not floating-point, it is cast to Float(32). Does
862  * not vectorize well. */
863 Expr cosh(Expr x);
864 
865 /** Return the hyperbolic arccosine of a floating-point expression.
866  * If the argument is not floating-point, it is cast to
867  * Float(32). Does not vectorize well. */
868 Expr acosh(Expr x);
869 
870 /** Return the hyperbolic tangent of a floating-point expression. If
871  * the argument is not floating-point, it is cast to Float(32). Does
872  * not vectorize well. */
873 Expr tanh(Expr x);
874 
875 /** Return the hyperbolic arctangent of a floating-point expression.
876  * If the argument is not floating-point, it is cast to
877  * Float(32). Does not vectorize well. */
878 Expr atanh(Expr x);
879 
880 /** Return the square root of a floating-point expression. If the
881  * argument is not floating-point, it is cast to Float(32). Typically
882  * vectorizes cleanly. */
883 Expr sqrt(Expr x);
884 
885 /** Return the square root of the sum of the squares of two
886  * floating-point expressions. If the argument is not floating-point,
887  * it is cast to Float(32). Vectorizes cleanly. */
888 Expr hypot(const Expr &x, const Expr &y);
889 
890 /** Return the exponential of a floating-point expression. If the
891  * argument is not floating-point, it is cast to Float(32). For
892  * Float(64) arguments, this calls the system exp function, and does
893  * not vectorize well. For Float(32) arguments, this function is
894  * vectorizable, does the right thing for extremely small or extremely
895  * large inputs, and is accurate up to the last bit of the
896  * mantissa. Vectorizes cleanly. */
897 Expr exp(Expr x);
898 
899 /** Return the logarithm of a floating-point expression. If the
900  * argument is not floating-point, it is cast to Float(32). For
901  * Float(64) arguments, this calls the system log function, and does
902  * not vectorize well. For Float(32) arguments, this function is
903  * vectorizable, does the right thing for inputs <= 0 (returns -inf or
904  * nan), and is accurate up to the last bit of the
905  * mantissa. Vectorizes cleanly. */
906 Expr log(Expr x);
907 
908 /** Return one floating point expression raised to the power of
909  * another. The type of the result is given by the type of the first
910  * argument. If the first argument is not a floating-point type, it is
911  * cast to Float(32). For Float(32), cleanly vectorizable, and
912  * accurate up to the last few bits of the mantissa. Gets worse when
913  * approaching overflow. Vectorizes cleanly. */
914 Expr pow(Expr x, Expr y);
915 
916 /** Evaluate the error function erf. Only available for
917  * Float(32). Accurate up to the last three bits of the
918  * mantissa. Vectorizes cleanly. */
919 Expr erf(const Expr &x);
920 
921 /** Fast vectorizable approximation to some trigonometric functions for Float(32).
922  * Absolute approximation error is less than 1e-5. */
923 // @{
924 Expr fast_sin(const Expr &x);
925 Expr fast_cos(const Expr &x);
926 // @}
927 
928 /** Fast approximate cleanly vectorizable log for Float(32). Returns
929  * nonsense for x <= 0.0f. Accurate up to the last 5 bits of the
930  * mantissa. Vectorizes cleanly. */
931 Expr fast_log(const Expr &x);
932 
933 /** Fast approximate cleanly vectorizable exp for Float(32). Returns
934  * nonsense for inputs that would overflow or underflow. Typically
935  * accurate up to the last 5 bits of the mantissa. Gets worse when
936  * approaching overflow. Vectorizes cleanly. */
937 Expr fast_exp(const Expr &x);
938 
939 /** Fast approximate cleanly vectorizable pow for Float(32). Returns
940  * nonsense for x < 0.0f. Accurate up to the last 5 bits of the
941  * mantissa for typical exponents. Gets worse when approaching
942  * overflow. Vectorizes cleanly. */
943 Expr fast_pow(Expr x, Expr y);
944 
945 /** Fast approximate inverse for Float(32). Corresponds to the rcpps
946  * instruction on x86, and the vrecpe instruction on ARM. Vectorizes
947  * cleanly. Note that this can produce slightly different results
948  * across different implementations of the same architecture (e.g. AMD vs Intel),
949  * even when strict_float is enabled. */
950 Expr fast_inverse(Expr x);
951 
952 /** Fast approximate inverse square root for Float(32). Corresponds to
953  * the rsqrtps instruction on x86, and the vrsqrte instruction on
954  * ARM. Vectorizes cleanly. Note that this can produce slightly different results
955  * across different implementations of the same architecture (e.g. AMD vs Intel),
956  * even when strict_float is enabled. */
957 Expr fast_inverse_sqrt(Expr x);
958 
959 /** Return the greatest whole number less than or equal to a
960  * floating-point expression. If the argument is not floating-point,
961  * it is cast to Float(32). The return value is still in floating
962  * point, despite being a whole number. Vectorizes cleanly. */
963 Expr floor(Expr x);
964 
965 /** Return the least whole number greater than or equal to a
966  * floating-point expression. If the argument is not floating-point,
967  * it is cast to Float(32). The return value is still in floating
968  * point, despite being a whole number. Vectorizes cleanly. */
969 Expr ceil(Expr x);
970 
971 /** Return the whole number closest to a floating-point expression. If the
972  * argument is not floating-point, it is cast to Float(32). The return value
973  * is still in floating point, despite being a whole number. On ties, we
974  * follow IEEE754 conventions and round to the nearest even number. Vectorizes
975  * cleanly. */
976 Expr round(Expr x);
977 
978 /** Return the integer part of a floating-point expression. If the argument is
979  * not floating-point, it is cast to Float(32). The return value is still in
980  * floating point, despite being a whole number. Vectorizes cleanly. */
981 Expr trunc(Expr x);
982 
983 /** Returns true if the argument is a Not a Number (NaN). Requires a
984  * floating point argument. Vectorizes cleanly.
985  * Note that the Expr passed in will be evaluated in strict_float mode,
986  * regardless of whether strict_float mode is enabled in the current Target. */
987 Expr is_nan(Expr x);
988 
989 /** Returns true if the argument is Inf or -Inf. Requires a
990  * floating point argument. Vectorizes cleanly.
991  * Note that the Expr passed in will be evaluated in strict_float mode,
992  * regardless of whether strict_float mode is enabled in the current Target. */
993 Expr is_inf(Expr x);
994 
995 /** Returns true if the argument is a finite value (ie, neither NaN nor Inf).
996  * Requires a floating point argument. Vectorizes cleanly.
997  * Note that the Expr passed in will be evaluated in strict_float mode,
998  * regardless of whether strict_float mode is enabled in the current Target. */
999 Expr is_finite(Expr x);
1000 
1001 /** Return the fractional part of a floating-point expression. If the argument
1002  * is not floating-point, it is cast to Float(32). The return value has the
1003  * same sign as the original expression. Vectorizes cleanly. */
1004 Expr fract(const Expr &x);
1005 
1006 /** Reinterpret the bits of one value as another type. */
1007 Expr reinterpret(Type t, Expr e);
1008 
1009 template<typename T>
1011  return reinterpret(type_of<T>(), e);
1012 }
1013 
1014 /** Return the bitwise and of two expressions (which need not have the
1015  * same type). The result type is the wider of the two expressions.
1016  * Only integral types are allowed and both expressions must be signed
1017  * or both must be unsigned. */
1018 Expr operator&(Expr x, Expr y);
1019 
1020 /** Return the bitwise and of an expression and an integer. The type
1021  * of the result is the type of the expression argument. */
1022 // @{
1023 Expr operator&(Expr x, int y);
1024 Expr operator&(int x, Expr y);
1025 // @}
1026 
1027 /** Return the bitwise or of two expressions (which need not have the
1028  * same type). The result type is the wider of the two expressions.
1029  * Only integral types are allowed and both expressions must be signed
1030  * or both must be unsigned. */
1031 Expr operator|(Expr x, Expr y);
1032 
1033 /** Return the bitwise or of an expression and an integer. The type of
1034  * the result is the type of the expression argument. */
1035 // @{
1036 Expr operator|(Expr x, int y);
1037 Expr operator|(int x, Expr y);
1038 // @}
1039 
1040 /** Return the bitwise xor of two expressions (which need not have the
1041  * same type). The result type is the wider of the two expressions.
1042  * Only integral types are allowed and both expressions must be signed
1043  * or both must be unsigned. */
1044 Expr operator^(Expr x, Expr y);
1045 
1046 /** Return the bitwise xor of an expression and an integer. The type
1047  * of the result is the type of the expression argument. */
1048 // @{
1049 Expr operator^(Expr x, int y);
1050 Expr operator^(int x, Expr y);
1051 // @}
1052 
1053 /** Return the bitwise not of an expression. */
1054 Expr operator~(Expr x);
1055 
1056 /** Shift the bits of an integer value left. This is actually less
1057  * efficient than multiplying by 2^n, because Halide's optimization
1058  * passes understand multiplication, and will compile it to
1059  * shifting. This operator is only for if you really really need bit
1060  * shifting (e.g. because the exponent is a run-time parameter). The
1061  * type of the result is equal to the type of the first argument. Both
1062  * arguments must have integer type. */
1063 // @{
1064 Expr operator<<(Expr x, Expr y);
1065 Expr operator<<(Expr x, int y);
1066 // @}
1067 
1068 /** Shift the bits of an integer value right. Does sign extension for
1069  * signed integers. This is less efficient than dividing by a power of
1070  * two. Halide's definition of division (always round to negative
1071  * infinity) means that all divisions by powers of two get compiled to
1072  * bit-shifting, and Halide's optimization routines understand
1073  * division and can work with it. The type of the result is equal to
1074  * the type of the first argument. Both arguments must have integer
1075  * type. */
1076 // @{
1077 Expr operator>>(Expr x, Expr y);
1078 Expr operator>>(Expr x, int y);
1079 // @}
1080 
1081 /** Linear interpolate between the two values according to a weight.
1082  * \param zero_val The result when weight is 0
1083  * \param one_val The result when weight is 1
1084  * \param weight The interpolation amount
1085  *
1086  * Both zero_val and one_val must have the same type. All types are
1087  * supported, including bool.
1088  *
1089  * The weight is treated as its own type and must be float or an
1090  * unsigned integer type. It is scaled to the bit-size of the type of
1091  * x and y if they are integer, or converted to float if they are
1092  * float. Integer weights are converted to float via division by the
1093  * full-range value of the weight's type. Floating-point weights used
1094  * to interpolate between integer values must be between 0.0f and
1095  * 1.0f, and an error may be signaled if it is not provably so. (clamp
1096  * operators can be added to provide proof. Currently an error is only
1097  * signalled for constant weights.)
1098  *
1099  * For integer linear interpolation, out of range values cannot be
1100  * represented. In particular, weights that are conceptually less than
1101  * 0 or greater than 1.0 are not representable. As such the result is
1102  * always between x and y (inclusive of course). For lerp with
1103  * floating-point values and floating-point weight, the full range of
1104  * a float is valid, however underflow and overflow can still occur.
1105  *
1106  * Ordering is not required between zero_val and one_val:
1107  * lerp(42, 69, .5f) == lerp(69, 42, .5f) == 56
1108  *
1109  * Results for integer types are for exactly rounded arithmetic. As
1110  * such, there are cases where 16-bit and float differ because 32-bit
1111  * floating-point (float) does not have enough precision to produce
1112  * the exact result. (Likely true for 32-bit integer
1113  * vs. double-precision floating-point as well.)
1114  *
1115  * At present, double precision and 64-bit integers are not supported.
1116  *
1117  * Generally, lerp will vectorize as if it were an operation on a type
1118  * twice the bit size of the inferred type for x and y.
1119  *
1120  * Some examples:
1121  * \code
1122  *
1123  * // Since Halide does not have direct type delcarations, casts
1124  * // below are used to indicate the types of the parameters.
1125  * // Such casts not required or expected in actual code where types
1126  * // are inferred.
1127  *
1128  * lerp(cast<float>(x), cast<float>(y), cast<float>(w)) ->
1129  * x * (1.0f - w) + y * w
1130  *
1131  * lerp(cast<uint8_t>(x), cast<uint8_t>(y), cast<uint8_t>(w)) ->
1132  * cast<uint8_t>(cast<uint8_t>(x) * (1.0f - cast<uint8_t>(w) / 255.0f) +
1133  * cast<uint8_t>(y) * cast<uint8_t>(w) / 255.0f + .5f)
1134  *
1135  * // Note addition in Halide promoted uint8_t + int8_t to int16_t already,
1136  * // the outer cast is added for clarity.
1137  * lerp(cast<uint8_t>(x), cast<int8_t>(y), cast<uint8_t>(w)) ->
1138  * cast<int16_t>(cast<uint8_t>(x) * (1.0f - cast<uint8_t>(w) / 255.0f) +
1139  * cast<int8_t>(y) * cast<uint8_t>(w) / 255.0f + .5f)
1140  *
1141  * lerp(cast<int8_t>(x), cast<int8_t>(y), cast<float>(w)) ->
1142  * cast<int8_t>(cast<int8_t>(x) * (1.0f - cast<float>(w)) +
1143  * cast<int8_t>(y) * cast<uint8_t>(w))
1144  *
1145  * \endcode
1146  * */
1147 Expr lerp(Expr zero_val, Expr one_val, Expr weight);
1148 
1149 /** Count the number of set bits in an expression. */
1150 Expr popcount(Expr x);
1151 
1152 /** Count the number of leading zero bits in an expression. If the expression is
1153  * zero, the result is the number of bits in the type. */
1154 Expr count_leading_zeros(Expr x);
1155 
1156 /** Count the number of trailing zero bits in an expression. If the expression is
1157  * zero, the result is the number of bits in the type. */
1158 Expr count_trailing_zeros(Expr x);
1159 
1160 /** Divide two integers, rounding towards zero. This is the typical
1161  * behavior of most hardware architectures, which differs from
1162  * Halide's division operator, which is Euclidean (rounds towards
1163  * -infinity). Will throw a runtime error if y is zero, or if y is -1
1164  * and x is the minimum signed integer. */
1165 Expr div_round_to_zero(Expr x, Expr y);
1166 
1167 /** Compute the remainder of dividing two integers, when division is
1168  * rounding toward zero. This is the typical behavior of most hardware
1169  * architectures, which differs from Halide's mod operator, which is
1170  * Euclidean (produces the remainder when division rounds towards
1171  * -infinity). Will throw a runtime error if y is zero. */
1172 Expr mod_round_to_zero(Expr x, Expr y);
1173 
1174 /** Return a random variable representing a uniformly distributed
1175  * float in the half-open interval [0.0f, 1.0f). For random numbers of
1176  * other types, use lerp with a random float as the last parameter.
1177  *
1178  * Optionally takes a seed.
1179  *
1180  * Note that:
1181  \code
1182  Expr x = random_float();
1183  Expr y = x + x;
1184  \endcode
1185  *
1186  * is very different to
1187  *
1188  \code
1189  Expr y = random_float() + random_float();
1190  \endcode
1191  *
1192  * The first doubles a random variable, and the second adds two
1193  * independent random variables.
1194  *
1195  * A given random variable takes on a unique value that depends
1196  * deterministically on the pure variables of the function they belong
1197  * to, the identity of the function itself, and which definition of
1198  * the function it is used in. They are, however, shared across tuple
1199  * elements.
1200  *
1201  * This function vectorizes cleanly.
1202  */
1203 Expr random_float(Expr seed = Expr());
1204 
1205 /** Return a random variable representing a uniformly distributed
1206  * unsigned 32-bit integer. See \ref random_float. Vectorizes cleanly. */
1207 Expr random_uint(Expr seed = Expr());
1208 
1209 /** Return a random variable representing a uniformly distributed
1210  * 32-bit integer. See \ref random_float. Vectorizes cleanly. */
1211 Expr random_int(Expr seed = Expr());
1212 
1213 /** Create an Expr that prints out its value whenever it is
1214  * evaluated. It also prints out everything else in the arguments
1215  * list, separated by spaces. This can include string literals. */
1216 //@{
1217 Expr print(const std::vector<Expr> &values);
1218 
1219 template<typename... Args>
1220 inline HALIDE_NO_USER_CODE_INLINE Expr print(Expr a, Args &&... args) {
1221  std::vector<Expr> collected_args = {std::move(a)};
1222  Internal::collect_print_args(collected_args, std::forward<Args>(args)...);
1223  return print(collected_args);
1224 }
1225 //@}
1226 
1227 /** Create an Expr that prints whenever it is evaluated, provided that
1228  * the condition is true. */
1229 // @{
1230 Expr print_when(Expr condition, const std::vector<Expr> &values);
1231 
1232 template<typename... Args>
1233 inline HALIDE_NO_USER_CODE_INLINE Expr print_when(Expr condition, Expr a, Args &&... args) {
1234  std::vector<Expr> collected_args = {std::move(a)};
1235  Internal::collect_print_args(collected_args, std::forward<Args>(args)...);
1236  return print_when(std::move(condition), collected_args);
1237 }
1238 
1239 // @}
1240 
1241 /** Create an Expr that that guarantees a precondition.
1242  * If 'condition' is true, the return value is equal to the first Expr.
1243  * If 'condition' is false, halide_error() is called, and the return value
1244  * is arbitrary. Any additional arguments after the first Expr are stringified
1245  * and passed as a user-facing message to halide_error(), similar to print().
1246  *
1247  * Note that this essentially *always* inserts a runtime check into the
1248  * generated code (except when the condition can be proven at compile time);
1249  * as such, it should be avoided inside inner loops, except for debugging
1250  * or testing purposes. Note also that it does not vectorize cleanly (vector
1251  * values will be scalarized for the check).
1252  *
1253  * However, using this to make assertions about (say) input values
1254  * can be useful, both in terms of correctness and (potentially) in terms
1255  * of code generation, e.g.
1256  \code
1257  Param<int> p;
1258  Expr y = require(p > 0, p);
1259  \endcode
1260  * will allow the optimizer to assume positive, nonzero values for y.
1261  */
1262 // @{
1263 Expr require(Expr condition, const std::vector<Expr> &values);
1264 
1265 template<typename... Args>
1266 inline HALIDE_NO_USER_CODE_INLINE Expr require(Expr condition, Expr value, Args &&... args) {
1267  std::vector<Expr> collected_args = {std::move(value)};
1268  Internal::collect_print_args(collected_args, std::forward<Args>(args)...);
1269  return require(std::move(condition), collected_args);
1270 }
1271 // @}
1272 
1273 /** Return an undef value of the given type. Halide skips stores that
1274  * depend on undef values, so you can use this to mean "do not modify
1275  * this memory location". This is an escape hatch that can be used for
1276  * several things:
1277  *
1278  * You can define a reduction with no pure step, by setting the pure
1279  * step to undef. Do this only if you're confident that the update
1280  * steps are sufficient to correctly fill in the domain.
1281  *
1282  * For a tuple-valued reduction, you can write an update step that
1283  * only updates some tuple elements.
1284  *
1285  * You can define single-stage pipeline that only has update steps,
1286  * and depends on the values already in the output buffer.
1287  *
1288  * Use this feature with great caution, as you can use it to load from
1289  * uninitialized memory.
1290  */
1291 Expr undef(Type t);
1292 
1293 template<typename T>
1294 inline Expr undef() {
1295  return undef(type_of<T>());
1296 }
1297 
1298 /** Control the values used in the memoization cache key for memoize.
1299  * Normally parameters and other external dependencies are
1300  * automatically inferred and added to the cache key. The memoize_tag
1301  * operator allows computing one expression and using either the
1302  * computed value, or one or more other expressions in the cache key
1303  * instead of the parameter dependencies of the computation. The
1304  * single argument version is completely safe in that the cache key
1305  * will use the actual computed value -- it is difficult or imposible
1306  * to produce erroneous caching this way. The more-than-one argument
1307  * version allows generating cache keys that do not uniquely identify
1308  * the computation and thus can result in caching errors.
1309  *
1310  * A potential use for the single argument version is to handle a
1311  * floating-point parameter that is quantized to a small
1312  * integer. Mutliple values of the float will produce the same integer
1313  * and moving the caching to using the integer for the key is more
1314  * efficient.
1315  *
1316  * The main use for the more-than-one argument version is to provide
1317  * cache key information for Handles and ImageParams, which otherwise
1318  * are not allowed inside compute_cached operations. E.g. when passing
1319  * a group of parameters to an external array function via a Handle,
1320  * memoize_tag can be used to isolate the actual values used by that
1321  * computation. If an ImageParam is a constant image with a persistent
1322  * digest, memoize_tag can be used to key computations using that image
1323  * on the digest. */
1324 // @{
1325 template<typename... Args>
1326 inline HALIDE_NO_USER_CODE_INLINE Expr memoize_tag(Expr result, Args &&... args) {
1327  std::vector<Expr> collected_args{std::forward<Args>(args)...};
1328  return Internal::memoize_tag_helper(std::move(result), collected_args);
1329 }
1330 // @}
1331 
1332 /** Expressions tagged with this intrinsic are considered to be part
1333  * of the steady state of some loop with a nasty beginning and end
1334  * (e.g. a boundary condition). When Halide encounters likely
1335  * intrinsics, it splits the containing loop body into three, and
1336  * tries to simplify down all conditions that lead to the likely. For
1337  * example, given the expression: select(x < 1, bar, x > 10, bar,
1338  * likely(foo)), Halide will split the loop over x into portions where
1339  * x < 1, 1 <= x <= 10, and x > 10.
1340  *
1341  * You're unlikely to want to call this directly. You probably want to
1342  * use the boundary condition helpers in the BoundaryConditions
1343  * namespace instead.
1344  */
1345 Expr likely(Expr e);
1346 
1347 /** Equivalent to likely, but only triggers a loop partitioning if
1348  * found in an innermost loop. */
1349 Expr likely_if_innermost(Expr e);
1350 
1351 /** Cast an expression to the halide type corresponding to the C++
1352  * type T. As part of the cast, clamp to the minimum and maximum
1353  * values of the result type. */
1354 template<typename T>
1356  return saturating_cast(type_of<T>(), std::move(e));
1357 }
1358 
1359 /** Cast an expression to a new type, clamping to the minimum and
1360  * maximum values of the result type. */
1361 Expr saturating_cast(Type t, Expr e);
1362 
1363 /** Makes a best effort attempt to preserve IEEE floating-point
1364  * semantics in evaluating an expression. May not be implemented for
1365  * all backends. (E.g. it is difficult to do this for C++ code
1366  * generation as it depends on the compiler flags used to compile the
1367  * generated code. */
1368 Expr strict_float(Expr e);
1369 
1370 /** Create an Expr that that promises another Expr is clamped but do
1371  * not generate code to check the assertion or modify the value. No
1372  * attempt is made to prove the bound at compile time. (If it is
1373  * proved false as a result of something else, an error might be
1374  * generated, but it is also possible the compiler will crash.) The
1375  * promised bound is used in bounds inference so it will allow
1376  * satisfying bounds checks as well as possibly aiding optimization.
1377  *
1378  * unsafe_promise_clamped returns its first argument, the Expr 'value'
1379  *
1380  * This is a very easy way to make Halide generate erroneous code if
1381  * the bound promises is not kept. Use sparingly when there is no
1382  * other way to convey the information to the compiler and it is
1383  * required for a valuable optimization.
1384  *
1385  * Unsafe promises can be checked by turning on
1386  * Target::CheckUnsafePromises. This is intended for debugging only.
1387  */
1388 Expr unsafe_promise_clamped(const Expr &value, const Expr &min, const Expr &max);
1389 
1390 namespace Internal {
1391 /**
1392  * FOR INTERNAL USE ONLY.
1393  *
1394  * An entirely unchecked version of unsafe_promise_clamped, used
1395  * inside the compiler as an annotation of the known bounds of an Expr
1396  * when it has proved something is bounded and wants to record that
1397  * fact for later passes (notably bounds inference) to exploit. This
1398  * gets introduced by GuardWithIf tail strategies, because the bounds
1399  * machinery has a hard time exploiting if statement conditions.
1400  *
1401  * Unlike unsafe_promise_clamped, this expression is
1402  * context-dependent, because 'value' might be statically bounded at
1403  * some point in the IR (e.g. due to a containing if statement), but
1404  * not elsewhere.
1405  **/
1406 Expr promise_clamped(const Expr &value, const Expr &min, const Expr &max);
1407 } // namespace Internal
1408 
1409 } // namespace Halide
1410 
1411 #endif
Halide::count_trailing_zeros
Expr count_trailing_zeros(Expr x)
Count the number of trailing zero bits in an expression.
int32_t
signed __INT32_TYPE__ int32_t
Definition: runtime_internal.h:20
Halide::Internal::all_are_convertible
Definition: Util.h:210
Halide::Internal::BufferBuilder
A builder to help create Exprs representing halide_buffer_t structs (e.g.
Definition: IROperator.h:215
Halide::Internal::halide_erf
Expr halide_erf(const Expr &a)
Halide::Internal::BufferBuilder::strides
std::vector< Expr > strides
Definition: IROperator.h:220
Halide::Internal::BufferBuilder::shape_memory
Expr shape_memory
Definition: IROperator.h:216
Tuple.h
Halide::random_uint
Expr random_uint(Expr seed=Expr())
Return a random variable representing a uniformly distributed unsigned 32-bit integer.
Halide::Internal::is_two
bool is_two(const Expr &e)
Is the expression a const (as defined by is_const), and also equal to two (in all lanes,...
Halide::popcount
Expr popcount(Expr x)
Count the number of set bits in an expression.
Halide::acosh
Expr acosh(Expr x)
Return the hyperbolic arccosine of a floating-point expression.
Halide::Internal::mod_imp
T mod_imp(T a, T b)
Implementations of division and mod that are specific to Halide.
Definition: IROperator.h:244
Halide::operator||
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.
Definition: Generator.h:1176
uint8_t
unsigned __INT8_TYPE__ uint8_t
Definition: runtime_internal.h:25
Halide::Internal::match_types_bitwise
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.
Halide::mod_round_to_zero
Expr mod_round_to_zero(Expr x, Expr y)
Compute the remainder of dividing two integers, when division is rounding toward zero.
Halide::operator>
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.
Definition: Generator.h:1081
Halide::require
Expr require(Expr condition, const std::vector< Expr > &values)
Create an Expr that that guarantees a precondition.
uint16_t
unsigned __INT16_TYPE__ uint16_t
Definition: runtime_internal.h:23
Halide::count_leading_zeros
Expr count_leading_zeros(Expr x)
Count the number of leading zero bits in an expression.
Halide::operator!=
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!...
Definition: Generator.h:1146
Halide::is_finite
Expr is_finite(Expr x)
Returns true if the argument is a finite value (ie, neither NaN nor Inf).
Halide::Internal::strided_ramp_base
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.
Halide::min
Expr min(const FuncRef &a, const FuncRef &b)
Explicit overloads of min and max for FuncRef.
Definition: Func.h:577
Halide::operator+=
Expr & operator+=(Expr &a, Expr b)
Modify the first expression to be the sum of two expressions, without changing its type.
int8_t
signed __INT8_TYPE__ int8_t
Definition: runtime_internal.h:24
Halide::Type::is_float
HALIDE_ALWAYS_INLINE bool is_float() const
Is this type a floating point type (float or double).
Definition: Type.h:384
Halide::fast_log
Expr fast_log(const Expr &x)
Fast approximate cleanly vectorizable log for Float(32).
Halide::operator>=
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...
Definition: Generator.h:1107
Halide::absd
Expr absd(Expr a, Expr b)
Return the absolute difference between two values.
Halide::Internal::BufferBuilder::type
Type type
Definition: IROperator.h:218
Halide::Internal::check_representable
void check_representable(Type t, int64_t val)
Check if a constant value can be correctly represented as the given type.
Halide::Internal::mod_imp< double >
double mod_imp< double >(double a, double b)
Definition: IROperator.h:296
Halide::Internal::BufferBuilder::device_dirty
Expr device_dirty
Definition: IROperator.h:221
Halide::Internal::is_one
bool is_one(const Expr &e)
Is the expression a const (as defined by is_const), and also equal to one (in all lanes,...
Halide::Internal::is_no_op
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...
Halide::cast
Expr cast(Expr a)
Cast an expression to the halide type corresponding to the C++ type T.
Definition: IROperator.h:342
Halide::Internal::is_negative_negatable_const
bool is_negative_negatable_const(const Expr &e)
Is the expression a const (as defined by is_const), and also strictly less than zero (in all lanes,...
Halide::fract
Expr fract(const Expr &x)
Return the fractional part of a floating-point expression.
Halide::sin
Expr sin(Expr x)
Return the sine of a floating-point expression.
Halide::Internal::make_signed_integer_overflow
Expr make_signed_integer_overflow(Type type)
Construct a unique signed_integer_overflow Expr.
Halide::clamp
Expr clamp(Expr a, const Expr &min_val, const Expr &max_val)
Clamps an expression to lie within the given bounds.
Halide::sqrt
Expr sqrt(Expr x)
Return the square root of a floating-point expression.
Halide::operator%
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.
Definition: Generator.h:1068
Halide::tan
Expr tan(Expr x)
Return the tangent of a floating-point expression.
Halide::undef
Expr undef(Type t)
Return an undef value of the given type.
Halide::mux
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,...
Halide::random_float
Expr random_float(Expr seed=Expr())
Return a random variable representing a uniformly distributed float in the half-open interval [0....
Halide::Internal::BufferBuilder::device
Expr device
Definition: IROperator.h:217
Halide::Internal::is_negative_const
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,...
Halide::fast_inverse
Expr fast_inverse(Expr x)
Fast approximate inverse for Float(32).
Halide::Internal::raise_to_integer_power
Expr raise_to_integer_power(Expr a, int64_t b)
Raise an expression to an integer power by repeatedly multiplying it by itself.
Halide::fast_sin
Expr fast_sin(const Expr &x)
Fast vectorizable approximation to some trigonometric functions for Float(32).
Halide::operator*
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.
Definition: Generator.h:1042
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition: runtime_internal.h:19
Halide::Type
Types in the halide type system.
Definition: Type.h:269
Halide::Internal::BufferBuilder::host_dirty
Expr host_dirty
Definition: IROperator.h:221
Halide::Internal::is_positive_const
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...
Halide::fast_pow
Expr fast_pow(Expr x, Expr y)
Fast approximate cleanly vectorizable pow for Float(32).
Halide::Internal::make_one
Expr make_one(Type t)
Construct the representation of one in the given type.
Halide::Internal::BufferBuilder::host
Expr host
Definition: IROperator.h:217
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::Internal::make_bool
Expr make_bool(bool val, int lanes=1)
Construct a boolean constant from a C++ boolean value.
Halide::operator*=
Expr & operator*=(Expr &a, Expr b)
Modify the first expression to be the product of two expressions, without changing its type.
Halide::select
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...
Halide::acos
Expr acos(Expr x)
Return the arccosine of a floating-point expression.
Halide::Internal::remove_likelies
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...
Halide::Internal::split_into_ands
void split_into_ands(const Expr &cond, std::vector< Expr > &result)
Split a boolean condition into vector of ANDs.
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::Internal::make_zero
Expr make_zero(Type t)
Construct the representation of zero in the given type.
Halide::cos
Expr cos(Expr x)
Return the cosine of a floating-point expression.
Halide::print
Expr print(const std::vector< Expr > &values)
Create an Expr that prints out its value whenever it is evaluated.
Halide::div_round_to_zero
Expr div_round_to_zero(Expr x, Expr y)
Divide two integers, rounding towards zero.
Halide::reinterpret
Expr reinterpret(Type t, Expr e)
Reinterpret the bits of one value as another type.
Halide::Internal::const_false
Expr const_false(int lanes=1)
Construct the constant boolean false.
Halide::cosh
Expr cosh(Expr x)
Return the hyperbolic cosine of a floating-point expression.
Halide::tuple_select
Tuple tuple_select(const Tuple &condition, const Tuple &true_value, const Tuple &false_value)
Equivalent of ternary select(), but taking/returning tuples.
Halide::Internal::collect_print_args
HALIDE_NO_USER_CODE_INLINE void collect_print_args(std::vector< Expr > &args)
Definition: IROperator.h:319
Halide::ceil
Expr ceil(Expr x)
Return the least whole number greater than or equal to a floating-point expression.
Halide::log
Expr log(Expr x)
Return the logarithm of a floating-point expression.
Halide::operator!
auto operator!(const GeneratorParam< T > &a) -> decltype(!(T) a)
Not operator for GeneratorParam.
Definition: Generator.h:1248
Halide::Internal::as_const_int
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.
Halide::Internal::BufferBuilder::dimensions
int dimensions
Definition: IROperator.h:219
Halide::Internal::make_two
Expr make_two(Type t)
Construct the representation of two in the given type.
Halide::Internal::halide_exp
Expr halide_exp(const Expr &a)
Halide::unsafe_promise_clamped
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...
Halide::sinh
Expr sinh(Expr x)
Return the hyperbolic sine of a floating-point expression.
Halide::is_inf
Expr is_inf(Expr x)
Returns true if the argument is Inf or -Inf.
Halide::atan2
Expr atan2(Expr y, Expr x)
Return the angle of a floating-point gradient.
Halide::Internal::BufferBuilder::build
Expr build() const
Halide::operator==
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.
Definition: Generator.h:1133
Halide::Internal::div_imp< float >
float div_imp< float >(float a, float b)
Definition: IROperator.h:302
Halide::atanh
Expr atanh(Expr x)
Return the hyperbolic arctangent of a floating-point expression.
Halide::Internal::div_imp
T div_imp(T a, T b)
Definition: IROperator.h:265
Halide::random_int
Expr random_int(Expr seed=Expr())
Return a random variable representing a uniformly distributed 32-bit integer.
int64_t
signed __INT64_TYPE__ int64_t
Definition: runtime_internal.h:18
Halide::operator/
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.
Definition: Generator.h:1055
Halide::floor
Expr floor(Expr x)
Return the greatest whole number less than or equal to a floating-point expression.
Halide::fast_exp
Expr fast_exp(const Expr &x)
Fast approximate cleanly vectorizable exp for Float(32).
Halide::abs
Expr abs(Expr a)
Returns the absolute value of a signed integer or floating-point expression.
Halide::operator|
Expr operator|(Expr x, Expr y)
Return the bitwise or of two expressions (which need not have the same type).
Halide::operator-
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.
Definition: Generator.h:1029
Halide::Internal::make_const
Expr make_const(Type t, int64_t val)
Construct an immediate of the given type from any numeric C++ type.
Expr.h
Halide::Internal::is_undef
bool is_undef(const Expr &e)
Is the expression an undef.
Halide::operator+
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.
Definition: Generator.h:1016
Halide::pow
Expr pow(Expr x, Expr y)
Return one floating point expression raised to the power of another.
Halide::operator-=
Expr & operator-=(Expr &a, Expr b)
Modify the first expression to be the difference of two expressions, without changing its type.
Halide::trunc
Expr trunc(Expr x)
Return the integer part of a floating-point expression.
HALIDE_NO_USER_CODE_INLINE
#define HALIDE_NO_USER_CODE_INLINE
Definition: Util.h:44
Halide::likely_if_innermost
Expr likely_if_innermost(Expr e)
Equivalent to likely, but only triggers a loop partitioning if found in an innermost loop.
Halide::Internal::is_const_power_of_two_integer
bool is_const_power_of_two_integer(const Expr &e, int *bits)
Is the expression a constant integer power of two.
Halide::fast_inverse_sqrt
Expr fast_inverse_sqrt(Expr x)
Fast approximate inverse square root for Float(32).
Halide::operator/=
Expr & operator/=(Expr &a, Expr b)
Modify the first expression to be the ratio of two expressions, without changing its type.
Halide::memoize_tag
HALIDE_NO_USER_CODE_INLINE Expr memoize_tag(Expr result, Args &&... args)
Control the values used in the memoization cache key for memoize.
Definition: IROperator.h:1326
Halide::Internal::match_types
void match_types(Expr &a, Expr &b)
Coerce the two expressions to have the same type, using C-style casting rules.
Halide::operator<=
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.
Definition: Generator.h:1120
Halide::Internal::halide_log
Expr halide_log(const Expr &a)
Halide's vectorizable transcendentals.
Halide::asin
Expr asin(Expr x)
Return the arcsine of a floating-point expression.
Halide::operator<<
std::ostream & operator<<(std::ostream &stream, const Expr &)
Emit an expression on an output stream (such as std::cout) in human-readable form.
Halide::Internal::BufferBuilder::mins
std::vector< Expr > mins
Definition: IROperator.h:220
Halide::Internal::as_const_float
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.
Halide::operator^
Expr operator^(Expr x, Expr y)
Return the bitwise xor of two expressions (which need not have the same type).
Halide::operator>>
Expr operator>>(Expr x, Expr y)
Shift the bits of an integer value right.
Halide::print_when
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.
Halide::fast_cos
Expr fast_cos(const Expr &x)
Halide::Internal::is_pure
bool is_pure(const Expr &e)
Does the expression 1) Take on the same value no matter where it appears in a Stmt,...
Halide::Type::is_int
HALIDE_ALWAYS_INLINE bool is_int() const
Is this type a signed integer type?
Definition: Type.h:396
Halide::hypot
Expr hypot(const Expr &x, const Expr &y)
Return the square root of the sum of the squares of two floating-point expressions.
Halide::likely
Expr likely(Expr e)
Expressions tagged with this intrinsic are considered to be part of the steady state of some loop wit...
Halide::Internal::const_true
Expr const_true(int lanes=1)
Construct the constant boolean true.
Halide::Internal::mod_imp< float >
float mod_imp< float >(float a, float b)
Definition: IROperator.h:290
Halide::is_nan
Expr is_nan(Expr x)
Returns true if the argument is a Not a Number (NaN).
Halide::lerp
Expr lerp(Expr zero_val, Expr one_val, Expr weight)
Linear interpolate between the two values according to a weight.
Halide::Internal::memoize_tag_helper
Expr memoize_tag_helper(Expr result, const std::vector< Expr > &cache_key_values)
int16_t
signed __INT16_TYPE__ int16_t
Definition: runtime_internal.h:22
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:256
Halide::Internal::BufferBuilder::extents
std::vector< Expr > extents
Definition: IROperator.h:220
Halide::Internal::lossless_cast
Expr lossless_cast(Type t, Expr e)
Attempt to cast an expression to a smaller type while provably not losing information.
Halide::float16_t
Class that provides a type that implements half precision floating point (IEEE754 2008 binary16) in s...
Definition: Float16.h:17
Halide::operator&
Expr operator&(Expr x, Expr y)
Return the bitwise and of two expressions (which need not have the same type).
Halide::Internal::requirement_failed_error
Expr requirement_failed_error(Expr condition, const std::vector< Expr > &args)
Halide::Internal::BufferBuilder::device_interface
Expr device_interface
Definition: IROperator.h:217
Halide::Internal::promise_clamped
Expr promise_clamped(const Expr &value, const Expr &min, const Expr &max)
FOR INTERNAL USE ONLY.
Halide::Internal::is_const
bool is_const(const Expr &e)
Is the expression either an IntImm, a FloatImm, a StringImm, or a Cast of the same,...
uint32_t
unsigned __INT32_TYPE__ uint32_t
Definition: runtime_internal.h:21
Halide::strict_float
Expr strict_float(Expr e)
Makes a best effort attempt to preserve IEEE floating-point semantics in evaluating an expression.
Halide::Internal::as_const_uint
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.
Halide::tanh
Expr tanh(Expr x)
Return the hyperbolic tangent of a floating-point expression.
Halide::max
Expr max(const FuncRef &a, const FuncRef &b)
Definition: Func.h:580
Halide::round
Expr round(Expr x)
Return the whole number closest to a floating-point expression.
Halide::Tuple
Create a small array of Exprs for defining and calling functions with multiple outputs.
Definition: Tuple.h:18
Halide::operator&&
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.
Definition: Generator.h:1159
Halide::saturating_cast
Expr saturating_cast(Expr e)
Cast an expression to the halide type corresponding to the C++ type T.
Definition: IROperator.h:1355
Halide::Internal::is_zero
bool is_zero(const Expr &e)
Is the expression a const (as defined by is_const), and also equal to zero (in all lanes,...
Halide::operator~
Expr operator~(Expr x)
Return the bitwise not of an expression.
Halide::operator<
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.
Definition: Generator.h:1094
Halide::Internal::BufferBuilder::buffer_memory
Expr buffer_memory
Definition: IROperator.h:216
Halide::atan
Expr atan(Expr x)
Return the arctangent of a floating-point expression.
Halide::asinh
Expr asinh(Expr x)
Return the hyperbolic arcsinhe of a floating-point expression.
Halide::erf
Expr erf(const Expr &x)
Evaluate the error function erf.
Halide::exp
Expr exp(Expr x)
Return the exponential of a floating-point expression.
Halide::Internal::div_imp< double >
double div_imp< double >(double a, double b)
Definition: IROperator.h:306