Halide 22.0.0 Halide compiler and libraries

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. */
18 struct ConstantInterval {
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. */
28 ConstantInterval(int64_t min, int64_t max);
29
30 /** The interval representing everything. */
31 static ConstantInterval everything();
32
33 /** Construct an interval representing a single point. */
34 static ConstantInterval single_point(int64_t x);
35
36 /** Construct intervals bounded above or below. */
37 static ConstantInterval bounded_below(int64_t min);
38 static ConstantInterval bounded_above(int64_t max);
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 */
56 void include(int64_t x);
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. */
68 static ConstantInterval make_union(const ConstantInterval &a, const ConstantInterval &b);
69
70 /** Construct the largest interval contained within two intervals. Throws an
71 * error if the interval is empty. */
72 static ConstantInterval make_intersection(const ConstantInterval &a, const ConstantInterval &b);
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);
82 void operator+=(int64_t);
83 void operator-=(const ConstantInterval &other);
84 void operator-=(int64_t);
85 void operator*=(const ConstantInterval &other);
86 void operator*=(int64_t);
87 void operator/=(const ConstantInterval &other);
88 void operator/=(int64_t);
89 void operator%=(const ConstantInterval &other);
90 void operator%=(int64_t);
91 // @}
92
93 /** Negate an interval. */
94 ConstantInterval operator-() const;
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. */
101 static ConstantInterval bounds_of_type(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// @{
111 ConstantInterval operator+(const ConstantInterval &a, const ConstantInterval &b);
112 ConstantInterval operator+(const ConstantInterval &a, int64_t b);
113 ConstantInterval operator-(const ConstantInterval &a, const ConstantInterval &b);
114 ConstantInterval operator-(const ConstantInterval &a, int64_t b);
115 ConstantInterval operator/(const ConstantInterval &a, const ConstantInterval &b);
116 ConstantInterval operator/(const ConstantInterval &a, int64_t b);
117 ConstantInterval operator*(const ConstantInterval &a, const ConstantInterval &b);
118 ConstantInterval operator*(const ConstantInterval &a, int64_t b);
119 ConstantInterval operator%(const ConstantInterval &a, const ConstantInterval &b);
120 ConstantInterval operator%(const ConstantInterval &a, int64_t b);
121 ConstantInterval min(const ConstantInterval &a, const ConstantInterval &b);
122 ConstantInterval min(const ConstantInterval &a, int64_t b);
123 ConstantInterval max(const ConstantInterval &a, const ConstantInterval &b);
124 ConstantInterval max(const ConstantInterval &a, int64_t b);
125 ConstantInterval abs(const ConstantInterval &a);
126 ConstantInterval operator<<(const ConstantInterval &a, const ConstantInterval &b);
127 ConstantInterval operator<<(const ConstantInterval &a, int64_t b);
128 ConstantInterval operator<<(int64_t a, const ConstantInterval &b);
129 ConstantInterval operator>>(const ConstantInterval &a, const ConstantInterval &b);
130 ConstantInterval operator>>(const ConstantInterval &a, int64_t b);
131 ConstantInterval operator>>(int64_t a, const ConstantInterval &b);
132// @}
133
134/** Comparison operators on ConstantIntervals. Returns whether the comparison is
135 * true for all values of the two intervals. */
136// @{
137 bool operator<=(const ConstantInterval &a, const ConstantInterval &b);
138 bool operator<=(const ConstantInterval &a, int64_t b);
139 bool operator<=(int64_t a, const ConstantInterval &b);
140 bool operator<(const ConstantInterval &a, const ConstantInterval &b);
141 bool operator<(const ConstantInterval &a, int64_t b);
142 bool operator<(int64_t a, const ConstantInterval &b);
143
144 inline bool operator>=(const ConstantInterval &a, const ConstantInterval &b) {
145 return b <= a;
146}
147 inline bool operator>(const ConstantInterval &a, const ConstantInterval &b) {
148 return b < a;
149}
150 inline bool operator>=(const ConstantInterval &a, int64_t b) {
151 return b <= a;
152}
153 inline bool operator>(const ConstantInterval &a, int64_t b) {
154 return b < a;
155}
156 inline bool operator>=(int64_t a, const ConstantInterval &b) {
157 return b <= a;
158}
159 inline 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// @{
170 Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a);
171 Internal::ConstantInterval saturating_cast(Type t, const Internal::ConstantInterval &a);
172// @}
173
174} // namespace Halide
175
176#endif
Halide::Internal::operator*
ConstantInterval operator*(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::operator>=
bool operator>=(const ConstantInterval &a, const ConstantInterval &b)
Definition: ConstantInterval.h:144
Halide::Internal::operator>>
ConstantInterval operator>>(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::operator%
ConstantInterval operator%(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::min
ConstantInterval min(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::SyntheticParamType::Type
@ Type
Halide::Internal::max
ConstantInterval max(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::operator/
ConstantInterval operator/(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::operator-
ConstantInterval operator-(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::operator<
bool operator<(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::operator+
ConstantInterval operator+(const ConstantInterval &a, const ConstantInterval &b)
Arithmetic operators on ConstantIntervals.
Halide::Internal::operator<<
ConstantInterval operator<<(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::operator<=
bool operator<=(const ConstantInterval &a, const ConstantInterval &b)
Comparison operators on ConstantIntervals.
Halide::Internal::operator>
bool operator>(const ConstantInterval &a, const ConstantInterval &b)
Definition: ConstantInterval.h:147
Halide::Internal::abs
ConstantInterval abs(const ConstantInterval &a)
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.
Halide::cast
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
Halide::saturating_cast
Internal::ConstantInterval saturating_cast(Type t, const Internal::ConstantInterval &a)
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition: runtime_internal.h:23
int64_t
signed __INT64_TYPE__ int64_t
Definition: runtime_internal.h:22
int32_t
signed __INT32_TYPE__ int32_t
Definition: runtime_internal.h:24
Halide::Internal::ConstantInterval
A class to represent ranges of integers.
Definition: ConstantInterval.h:18
Halide::Internal::ConstantInterval::min
int64_t min
The lower and upper bound of the interval.
Definition: ConstantInterval.h:21
Halide::Internal::ConstantInterval::operator-=
void operator-=(const ConstantInterval &other)
Halide::Internal::ConstantInterval::operator/=
void operator/=(const ConstantInterval &other)
Halide::Internal::ConstantInterval::bounded_above
static ConstantInterval bounded_above(int64_t max)
Halide::Internal::ConstantInterval::operator/=
void operator/=(int64_t)
Halide::Internal::ConstantInterval::operator+=
void operator+=(const ConstantInterval &other)
In-place versions of the arithmetic operators below.
Halide::Internal::ConstantInterval::bounds_of_type
static ConstantInterval bounds_of_type(Type)
Get constant integer bounds on a type.
Halide::Internal::ConstantInterval::contains
bool contains(uint64_t x) const
Test if the interval contains a particular unsigned value.
Halide::Internal::ConstantInterval::is_bounded
bool is_bounded() const
Does the interval have a finite upper and lower bound.
Halide::Internal::ConstantInterval::ConstantInterval
ConstantInterval(int64_t min, int64_t max)
Construct an interval from a lower and upper bound.
Halide::Internal::ConstantInterval::operator+=
void operator+=(int64_t)
Halide::Internal::ConstantInterval::make_intersection
static ConstantInterval make_intersection(const ConstantInterval &a, const ConstantInterval &b)
Construct the largest interval contained within two intervals.
Halide::Internal::ConstantInterval::operator%=
void operator%=(int64_t)
Halide::Internal::ConstantInterval::operator==
bool operator==(const ConstantInterval &other) const
Equivalent to same_as.
Halide::Internal::ConstantInterval::make_union
static ConstantInterval make_union(const ConstantInterval &a, const ConstantInterval &b)
Construct the smallest interval containing two intervals.
Halide::Internal::ConstantInterval::bounded_below
static ConstantInterval bounded_below(int64_t min)
Construct intervals bounded above or below.
Halide::Internal::ConstantInterval::max_defined
bool max_defined
Definition: ConstantInterval.h:22
Halide::Internal::ConstantInterval::operator%=
void operator%=(const ConstantInterval &other)
Halide::Internal::ConstantInterval::ConstantInterval
ConstantInterval()=default
Halide::Internal::ConstantInterval::is_single_point
bool is_single_point() const
Is the interval just a single value (min == max)
Halide::Internal::ConstantInterval::is_everything
bool is_everything() const
Is the interval the entire range.
Halide::Internal::ConstantInterval::include
void include(const ConstantInterval &i)
Expand the interval to include another Interval.
Halide::Internal::ConstantInterval::max
int64_t max
Definition: ConstantInterval.h:21
Halide::Internal::ConstantInterval::operator*=
void operator*=(const ConstantInterval &other)
Halide::Internal::ConstantInterval::operator*=
void operator*=(int64_t)
Halide::Internal::ConstantInterval::include
void include(int64_t x)
Expand the interval to include a point.
Halide::Internal::ConstantInterval::cast_to
void cast_to(const Type &t)
Track what happens if a constant integer interval is forced to fit into a concrete integer type.
Halide::Internal::ConstantInterval::contains
bool contains(int64_t x) const
Test if the interval contains a particular value.
Halide::Internal::ConstantInterval::operator-=
void operator-=(int64_t)
Halide::Internal::ConstantInterval::min_defined
bool min_defined
Definition: ConstantInterval.h:22
Halide::Internal::ConstantInterval::everything
static ConstantInterval everything()
The interval representing everything.
Halide::Internal::ConstantInterval::operator-
ConstantInterval operator-() const
Negate an interval.
Halide::Internal::ConstantInterval::is_single_point
bool is_single_point(int64_t x) const
Is the interval a particular single value.
Halide::Internal::ConstantInterval::single_point
static ConstantInterval single_point(int64_t x)
Construct an interval representing a single point.
Halide::Internal::ConstantInterval::contains
bool contains(int32_t x) const
Test if the interval contains a particular value.
Halide::Type
Types in the halide type system.
Definition: Type.h:281