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  return cast(Float(64, e.type().lanes()), e);
20 }
21 
22 inline Expr f32(Expr e) {
23  return cast(Float(32, e.type().lanes()), e);
24 }
25 
26 inline Expr i64(Expr e) {
27  return cast(Int(64, e.type().lanes()), e);
28 }
29 
30 inline Expr i32(Expr e) {
31  return cast(Int(32, e.type().lanes()), e);
32 }
33 
34 inline Expr i16(Expr e) {
35  return cast(Int(16, e.type().lanes()), e);
36 }
37 
38 inline Expr i8(Expr e) {
39  return cast(Int(8, e.type().lanes()), e);
40 }
41 
42 inline Expr u64(Expr e) {
43  return cast(UInt(64, e.type().lanes()), e);
44 }
45 
46 inline Expr u32(Expr e) {
47  return cast(UInt(32, e.type().lanes()), e);
48 }
49 
50 inline Expr u16(Expr e) {
51  return cast(UInt(16, e.type().lanes()), e);
52 }
53 
54 inline Expr u8(Expr e) {
55  return cast(UInt(8, e.type().lanes()), e);
56 }
57 
58 inline Expr i8_sat(Expr e) {
59  return saturating_cast(Int(8, e.type().lanes()), e);
60 }
61 
62 inline Expr u8_sat(Expr e) {
63  return saturating_cast(UInt(8, e.type().lanes()), e);
64 }
65 
66 inline Expr i16_sat(Expr e) {
67  return saturating_cast(Int(16, e.type().lanes()), e);
68 }
69 
70 inline Expr u16_sat(Expr e) {
71  return saturating_cast(UInt(16, e.type().lanes()), e);
72 }
73 
74 inline Expr i32_sat(Expr e) {
75  return saturating_cast(Int(32, e.type().lanes()), e);
76 }
77 
78 inline Expr u32_sat(Expr e) {
79  return saturating_cast(UInt(32, e.type().lanes()), e);
80 }
81 
82 inline Expr i64_sat(Expr e) {
83  return saturating_cast(Int(64, e.type().lanes()), e);
84 }
85 
86 inline Expr u64_sat(Expr e) {
87  return saturating_cast(UInt(64, e.type().lanes()), e);
88 }
89 
90 };
91 };
92 
93 #endif
Expr u64_sat(Expr e)
Definition: ConciseCasts.h:86
A fragment of Halide syntax.
Definition: Expr.h:276
Expr i16(Expr e)
Definition: ConciseCasts.h:34
Expr f64(Expr e)
Definition: ConciseCasts.h:18
Expr i64_sat(Expr e)
Definition: ConciseCasts.h:82
Expr u32_sat(Expr e)
Definition: ConciseCasts.h:78
Expr u8_sat(Expr e)
Definition: ConciseCasts.h:62
Expr i32_sat(Expr e)
Definition: ConciseCasts.h:74
Expr cast(Expr a)
Cast an expression to the halide type corresponding to the C++ type T.
Definition: IROperator.h:205
Defines methods for manipulating and analyzing boolean expressions.
Expr u32(Expr e)
Definition: ConciseCasts.h:46
Expr f32(Expr e)
Definition: ConciseCasts.h:22
Expr u16(Expr e)
Definition: ConciseCasts.h:50
Defines various operator overloads and utility functions that make it more pleasant to work with Hali...
Expr i8_sat(Expr e)
Definition: ConciseCasts.h:58
Type type() const
Get the type of this expression node.
Definition: Expr.h:302
Expr i32(Expr e)
Definition: ConciseCasts.h:30
Expr u64(Expr e)
Definition: ConciseCasts.h:42
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
Definition: Type.h:442
Expr u16_sat(Expr e)
Definition: ConciseCasts.h:70
Expr i64(Expr e)
Definition: ConciseCasts.h:26
Expr i16_sat(Expr e)
Definition: ConciseCasts.h:66
int lanes() const
Return the number of vector elements in this type.
Definition: Type.h:334
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Definition: Type.h:437
Expr saturating_cast(Expr e)
Cast an expression to the halide type corresponding to the C++ type T clamping to the minimum and max...
Definition: IROperator.h:1904
Type Float(int bits, int lanes=1)
Construct a floating-point type.
Definition: Type.h:447