Halide
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 
15 namespace Halide {
16 namespace ConciseCasts {
17 
18 inline Expr f64(Expr e) {
19  Type t = Float(64, e.type().lanes());
20  return cast(t, std::move(e));
21 }
22 
23 inline Expr f32(Expr e) {
24  Type t = Float(32, e.type().lanes());
25  return cast(t, std::move(e));
26 }
27 
28 inline Expr i64(Expr e) {
29  Type t = Int(64, e.type().lanes());
30  return cast(t, std::move(e));
31 }
32 
33 inline Expr i32(Expr e) {
34  Type t = Int(32, e.type().lanes());
35  return cast(t, std::move(e));
36 }
37 
38 inline Expr i16(Expr e) {
39  Type t = Int(16, e.type().lanes());
40  return cast(t, std::move(e));
41 }
42 
43 inline Expr i8(Expr e) {
44  Type t = Int(8, e.type().lanes());
45  return cast(t, std::move(e));
46 }
47 
48 inline Expr u64(Expr e) {
49  Type t = UInt(64, e.type().lanes());
50  return cast(t, std::move(e));
51 }
52 
53 inline Expr u32(Expr e) {
54  Type t = UInt(32, e.type().lanes());
55  return cast(t, std::move(e));
56 }
57 
58 inline Expr u16(Expr e) {
59  Type t = UInt(16, e.type().lanes());
60  return cast(t, std::move(e));
61 }
62 
63 inline Expr u8(Expr e) {
64  Type t = UInt(8, e.type().lanes());
65  return cast(t, std::move(e));
66 }
67 
68 inline Expr i8_sat(Expr e) {
69  Type t = Int(8, e.type().lanes());
70  return saturating_cast(t, std::move(e));
71 }
72 
73 inline Expr u8_sat(Expr e) {
74  Type t = UInt(8, e.type().lanes());
75  return saturating_cast(t, std::move(e));
76 }
77 
78 inline Expr i16_sat(Expr e) {
79  Type t = Int(16, e.type().lanes());
80  return saturating_cast(t, std::move(e));
81 }
82 
83 inline Expr u16_sat(Expr e) {
84  Type t = UInt(16, e.type().lanes());
85  return saturating_cast(t, std::move(e));
86 }
87 
88 inline Expr i32_sat(Expr e) {
89  Type t = Int(32, e.type().lanes());
90  return saturating_cast(t, std::move(e));
91 }
92 
93 inline Expr u32_sat(Expr e) {
94  Type t = UInt(32, e.type().lanes());
95  return saturating_cast(t, std::move(e));
96 }
97 
98 inline Expr i64_sat(Expr e) {
99  Type t = Int(64, e.type().lanes());
100  return saturating_cast(t, std::move(e));
101 }
102 
103 inline Expr u64_sat(Expr e) {
104  Type t = UInt(64, e.type().lanes());
105  return saturating_cast(t, std::move(e));
106 }
107 
108 }; // namespace ConciseCasts
109 }; // namespace Halide
110 
111 #endif
Halide::ConciseCasts::u64_sat
Expr u64_sat(Expr e)
Definition: ConciseCasts.h:103
Halide::ConciseCasts::i64_sat
Expr i64_sat(Expr e)
Definition: ConciseCasts.h:98
Halide::ConciseCasts::i16
Expr i16(Expr e)
Definition: ConciseCasts.h:38
Halide::Float
Type Float(int bits, int lanes=1)
Construct a floating-point type.
Definition: Type.h:482
IROperator.h
Halide::ConciseCasts::i32_sat
Expr i32_sat(Expr e)
Definition: ConciseCasts.h:88
Halide::ConciseCasts::i8
Expr i8(Expr e)
Definition: ConciseCasts.h:43
Halide::Type::lanes
HALIDE_ALWAYS_INLINE int lanes() const
Return the number of vector elements in this type.
Definition: Type.h:337
Halide::ConciseCasts::u32_sat
Expr u32_sat(Expr e)
Definition: ConciseCasts.h:93
Halide::ConciseCasts::f64
Expr f64(Expr e)
Definition: ConciseCasts.h:18
Halide::ConciseCasts::u8_sat
Expr u8_sat(Expr e)
Definition: ConciseCasts.h:73
Halide::cast
Expr cast(Expr a)
Cast an expression to the halide type corresponding to the C++ type T.
Definition: IROperator.h:342
Halide::ConciseCasts::u8
Expr u8(Expr e)
Definition: ConciseCasts.h:63
Halide::ConciseCasts::f32
Expr f32(Expr e)
Definition: ConciseCasts.h:23
Halide::ConciseCasts::u32
Expr u32(Expr e)
Definition: ConciseCasts.h:53
Halide::Type
Types in the halide type system.
Definition: Type.h:269
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AddAtomicMutex.h:21
Halide::ConciseCasts::u16
Expr u16(Expr e)
Definition: ConciseCasts.h:58
Halide::Expr::type
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
Definition: Expr.h:320
Halide::ConciseCasts::i8_sat
Expr i8_sat(Expr e)
Definition: ConciseCasts.h:68
Halide::UInt
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
Definition: Type.h:477
Halide::ConciseCasts::u16_sat
Expr u16_sat(Expr e)
Definition: ConciseCasts.h:83
Halide::ConciseCasts::i64
Expr i64(Expr e)
Definition: ConciseCasts.h:28
Halide::ConciseCasts::i32
Expr i32(Expr e)
Definition: ConciseCasts.h:33
Halide::ConciseCasts::u64
Expr u64(Expr e)
Definition: ConciseCasts.h:48
Halide::ConciseCasts::i16_sat
Expr i16_sat(Expr e)
Definition: ConciseCasts.h:78
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:256
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::Int
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Definition: Type.h:472