Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
ConstantInterval.h
Go to the documentation of this file.
1#ifndef HALIDE_CONSTANT_INTERVAL_H
2#define HALIDE_CONSTANT_INTERVAL_H
3
4#include <stdint.h>
5
6/** \file
7 * Defines the ConstantInterval class, and operators on it.
8 */
9
10namespace Halide {
11
12struct Type;
13
14namespace Internal {
15
16/** A class to represent ranges of integers. Can be unbounded above or below,
17 * but they cannot be empty. */
19 /** The lower and upper bound of the interval. They are included
20 * in the interval. */
21 int64_t min = 0, max = 0;
22 bool min_defined = false, max_defined = false;
23
24 /* A default-constructed Interval is everything */
25 ConstantInterval() = default;
26
27 /** Construct an interval from a lower and upper bound. */
29
30 /** The interval representing everything. */
32
33 /** Construct an interval representing a single point. */
35
36 /** Construct intervals bounded above or below. */
39
40 /** Is the interval the entire range */
41 bool is_everything() const;
42
43 /** Is the interval just a single value (min == max) */
44 bool is_single_point() const;
45
46 /** Is the interval a particular single value */
47 bool is_single_point(int64_t x) const;
48
49 /** Does the interval have a finite upper and lower bound */
50 bool is_bounded() const;
51
52 /** Expand the interval to include another Interval */
53 void include(const ConstantInterval &i);
54
55 /** Expand the interval to include a point */
57
58 /** Test if the interval contains a particular value */
59 bool contains(int32_t x) const;
60
61 /** Test if the interval contains a particular value */
62 bool contains(int64_t x) const;
63
64 /** Test if the interval contains a particular unsigned value */
65 bool contains(uint64_t x) const;
66
67 /** Construct the smallest interval containing two intervals. */
69
70 /** Construct the largest interval contained within two intervals. Throws an
71 * error if the interval is empty. */
73
74 /** Equivalent to same_as. Exists so that the autoscheduler can
75 * compare two map<string, Interval> for equality in order to
76 * cache computations. */
77 bool operator==(const ConstantInterval &other) const;
78
79 /** In-place versions of the arithmetic operators below. */
80 // @{
81 void operator+=(const ConstantInterval &other);
83 void operator-=(const ConstantInterval &other);
85 void operator*=(const ConstantInterval &other);
87 void operator/=(const ConstantInterval &other);
89 void operator%=(const ConstantInterval &other);
91 // @}
92
93 /** Negate an interval. */
95
96 /** Track what happens if a constant integer interval is forced to fit into
97 * a concrete integer type. */
98 void cast_to(const Type &t);
99
100 /** Get constant integer bounds on a type. */
102};
103
104/** Arithmetic operators on ConstantIntervals. The resulting interval contains
105 * all possible values of the operator applied to any two elements of the
106 * argument intervals. Note that these operator on unbounded integers. If you
107 * are applying this to concrete small integer types, you will need to manually
108 * cast the constant interval back to the desired type to model the effect of
109 * overflow. */
110// @{
132// @}
133
134/** Comparison operators on ConstantIntervals. Returns whether the comparison is
135 * true for all values of the two intervals. */
136// @{
143
144inline bool operator>=(const ConstantInterval &a, const ConstantInterval &b) {
145 return b <= a;
146}
147inline bool operator>(const ConstantInterval &a, const ConstantInterval &b) {
148 return b < a;
149}
150inline bool operator>=(const ConstantInterval &a, int64_t b) {
151 return b <= a;
152}
153inline bool operator>(const ConstantInterval &a, int64_t b) {
154 return b < a;
155}
156inline bool operator>=(int64_t a, const ConstantInterval &b) {
157 return b <= a;
158}
159inline bool operator>(int64_t a, const ConstantInterval &b) {
160 return b < a;
161}
162
163// @}
164} // namespace Internal
165
166/** Cast operators for ConstantIntervals. These ones have to live out in
167 * Halide::, to avoid C++ name lookup confusion with the Halide::cast variants
168 * that take Exprs. */
169// @{
172// @}
173
174} // namespace Halide
175
176#endif
ConstantInterval operator*(const ConstantInterval &a, const ConstantInterval &b)
bool operator>=(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval operator>>(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval operator%(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval min(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval max(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval operator/(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval operator-(const ConstantInterval &a, const ConstantInterval &b)
bool operator<(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval operator+(const ConstantInterval &a, const ConstantInterval &b)
Arithmetic operators on ConstantIntervals.
ConstantInterval operator<<(const ConstantInterval &a, const ConstantInterval &b)
bool operator<=(const ConstantInterval &a, const ConstantInterval &b)
Comparison operators on ConstantIntervals.
bool operator>(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval abs(const ConstantInterval &a)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
Internal::ConstantInterval saturating_cast(Type t, const Internal::ConstantInterval &a)
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
signed __INT32_TYPE__ int32_t
A class to represent ranges of integers.
void operator-=(const ConstantInterval &other)
void operator/=(const ConstantInterval &other)
static ConstantInterval bounded_above(int64_t max)
void operator+=(const ConstantInterval &other)
In-place versions of the arithmetic operators below.
static ConstantInterval bounds_of_type(Type)
Get constant integer bounds on a type.
bool contains(uint64_t x) const
Test if the interval contains a particular unsigned value.
bool is_bounded() const
Does the interval have a finite upper and lower bound.
ConstantInterval(int64_t min, int64_t max)
Construct an interval from a lower and upper bound.
static ConstantInterval make_intersection(const ConstantInterval &a, const ConstantInterval &b)
Construct the largest interval contained within two intervals.
bool operator==(const ConstantInterval &other) const
Equivalent to same_as.
static ConstantInterval make_union(const ConstantInterval &a, const ConstantInterval &b)
Construct the smallest interval containing two intervals.
static ConstantInterval bounded_below(int64_t min)
Construct intervals bounded above or below.
void operator%=(const ConstantInterval &other)
bool is_single_point() const
Is the interval just a single value (min == max)
bool is_everything() const
Is the interval the entire range.
void include(const ConstantInterval &i)
Expand the interval to include another Interval.
void operator*=(const ConstantInterval &other)
void include(int64_t x)
Expand the interval to include a point.
void cast_to(const Type &t)
Track what happens if a constant integer interval is forced to fit into a concrete integer type.
bool contains(int64_t x) const
Test if the interval contains a particular value.
static ConstantInterval everything()
The interval representing everything.
ConstantInterval operator-() const
Negate an interval.
bool is_single_point(int64_t x) const
Is the interval a particular single value.
static ConstantInterval single_point(int64_t x)
Construct an interval representing a single point.
bool contains(int32_t x) const
Test if the interval contains a particular value.
Types in the halide type system.
Definition Type.h:283