Halide 19.0.0
Halide compiler and libraries
Loading...
Searching...
No Matches
ConciseCasts.h
Go to the documentation of this file.
1#ifndef HALIDE_CONCISE_CASTS_H
2#define HALIDE_CONCISE_CASTS_H
3
4#include "IROperator.h"
5
6/** \file
7 *
8 * Defines concise cast and saturating cast operators to make it
9 * easier to read cast-heavy code. Think carefully about the
10 * readability implications before using these. They could make your
11 * code better or worse. Often it's better to add extra Funcs to your
12 * pipeline that do the upcasting and downcasting.
13 */
14
15namespace Halide {
16namespace ConciseCasts {
17
18inline Expr f64(Expr e) {
19 Type t = Float(64, e.type().lanes());
20 return cast(t, std::move(e));
21}
22
23inline Expr f32(Expr e) {
24 Type t = Float(32, e.type().lanes());
25 return cast(t, std::move(e));
26}
27
28inline Expr f16(Expr e) {
29 Type t = Float(16, e.type().lanes());
30 return cast(t, std::move(e));
31}
32
33inline Expr bf16(Expr e) {
34 Type t = BFloat(16, e.type().lanes());
35 return cast(t, std::move(e));
36}
37
38inline Expr i64(Expr e) {
39 Type t = Int(64, e.type().lanes());
40 return cast(t, std::move(e));
41}
42
43inline Expr i32(Expr e) {
44 Type t = Int(32, e.type().lanes());
45 return cast(t, std::move(e));
46}
47
48inline Expr i16(Expr e) {
49 Type t = Int(16, e.type().lanes());
50 return cast(t, std::move(e));
51}
52
53inline Expr i8(Expr e) {
54 Type t = Int(8, e.type().lanes());
55 return cast(t, std::move(e));
56}
57
58inline Expr u64(Expr e) {
59 Type t = UInt(64, e.type().lanes());
60 return cast(t, std::move(e));
61}
62
63inline Expr u32(Expr e) {
64 Type t = UInt(32, e.type().lanes());
65 return cast(t, std::move(e));
66}
67
68inline Expr u16(Expr e) {
69 Type t = UInt(16, e.type().lanes());
70 return cast(t, std::move(e));
71}
72
73inline Expr u8(Expr e) {
74 Type t = UInt(8, e.type().lanes());
75 return cast(t, std::move(e));
76}
77
78inline Expr i8_sat(Expr e) {
79 Type t = Int(8, e.type().lanes());
80 return saturating_cast(t, std::move(e));
81}
82
83inline Expr u8_sat(Expr e) {
84 Type t = UInt(8, e.type().lanes());
85 return saturating_cast(t, std::move(e));
86}
87
88inline Expr i16_sat(Expr e) {
89 Type t = Int(16, e.type().lanes());
90 return saturating_cast(t, std::move(e));
91}
92
93inline Expr u16_sat(Expr e) {
94 Type t = UInt(16, e.type().lanes());
95 return saturating_cast(t, std::move(e));
96}
97
98inline Expr i32_sat(Expr e) {
99 Type t = Int(32, e.type().lanes());
100 return saturating_cast(t, std::move(e));
101}
102
103inline Expr u32_sat(Expr e) {
104 Type t = UInt(32, e.type().lanes());
105 return saturating_cast(t, std::move(e));
106}
107
108inline Expr i64_sat(Expr e) {
109 Type t = Int(64, e.type().lanes());
110 return saturating_cast(t, std::move(e));
111}
112
113inline Expr u64_sat(Expr e) {
114 Type t = UInt(64, e.type().lanes());
115 return saturating_cast(t, std::move(e));
116}
117
118}; // namespace ConciseCasts
119}; // namespace Halide
120
121#endif
Defines various operator overloads and utility functions that make it more pleasant to work with Hali...
Expr u16_sat(Expr e)
Expr i8_sat(Expr e)
Expr u8_sat(Expr e)
Expr i16_sat(Expr e)
Expr i32_sat(Expr e)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Type BFloat(int bits, int lanes=1)
Construct a floating-point type in the bfloat format.
Definition Type.h:556
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
Definition Type.h:546
Type Float(int bits, int lanes=1)
Construct a floating-point type.
Definition Type.h:551
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Definition Type.h:541
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
Internal::ConstantInterval saturating_cast(Type t, const Internal::ConstantInterval &a)
A fragment of Halide syntax.
Definition Expr.h:258
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
Definition Expr.h:327
Types in the halide type system.
Definition Type.h:283
HALIDE_ALWAYS_INLINE int lanes() const
Return the number of vector elements in this type.
Definition Type.h:355