Halide 22.0.0 Halide compiler and libraries

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 {
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 f16(Expr e) {
29 Type t = Float(16, e.type().lanes());
30 return cast(t, std::move(e));
31}
32
33 inline Expr bf16(Expr e) {
34 Type t = BFloat(16, e.type().lanes());
35 return cast(t, std::move(e));
36}
37
38 inline Expr i64(Expr e) {
39 Type t = Int(64, e.type().lanes());
40 return cast(t, std::move(e));
41}
42
43 inline Expr i32(Expr e) {
44 Type t = Int(32, e.type().lanes());
45 return cast(t, std::move(e));
46}
47
48 inline Expr i16(Expr e) {
49 Type t = Int(16, e.type().lanes());
50 return cast(t, std::move(e));
51}
52
53 inline Expr i8(Expr e) {
54 Type t = Int(8, e.type().lanes());
55 return cast(t, std::move(e));
56}
57
58 inline Expr u64(Expr e) {
59 Type t = UInt(64, e.type().lanes());
60 return cast(t, std::move(e));
61}
62
63 inline Expr u32(Expr e) {
64 Type t = UInt(32, e.type().lanes());
65 return cast(t, std::move(e));
66}
67
68 inline Expr u16(Expr e) {
69 Type t = UInt(16, e.type().lanes());
70 return cast(t, std::move(e));
71}
72
73 inline Expr u8(Expr e) {
74 Type t = UInt(8, e.type().lanes());
75 return cast(t, std::move(e));
76}
77
78 inline Expr i8_sat(Expr e) {
79 Type t = Int(8, e.type().lanes());
80 return saturating_cast(t, std::move(e));
81}
82
83 inline Expr u8_sat(Expr e) {
84 Type t = UInt(8, e.type().lanes());
85 return saturating_cast(t, std::move(e));
86}
87
88 inline Expr i16_sat(Expr e) {
89 Type t = Int(16, e.type().lanes());
90 return saturating_cast(t, std::move(e));
91}
92
93 inline Expr u16_sat(Expr e) {
94 Type t = UInt(16, e.type().lanes());
95 return saturating_cast(t, std::move(e));
96}
97
98 inline Expr i32_sat(Expr e) {
99 Type t = Int(32, e.type().lanes());
100 return saturating_cast(t, std::move(e));
101}
102
103 inline Expr u32_sat(Expr e) {
104 Type t = UInt(32, e.type().lanes());
105 return saturating_cast(t, std::move(e));
106}
107
108 inline Expr i64_sat(Expr e) {
109 Type t = Int(64, e.type().lanes());
110 return saturating_cast(t, std::move(e));
111}
112
113 inline 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
IROperator.h
Defines various operator overloads and utility functions that make it more pleasant to work with Hali...
Halide::ConciseCasts::i64_sat
Expr i64_sat(Expr e)
Definition: ConciseCasts.h:108
Halide::ConciseCasts::u16_sat
Expr u16_sat(Expr e)
Definition: ConciseCasts.h:93
Halide::ConciseCasts::i8
Expr i8(Expr e)
Definition: ConciseCasts.h:53
Halide::ConciseCasts::i8_sat
Expr i8_sat(Expr e)
Definition: ConciseCasts.h:78
Halide::ConciseCasts::u32
Expr u32(Expr e)
Definition: ConciseCasts.h:63
Halide::ConciseCasts::u8_sat
Expr u8_sat(Expr e)
Definition: ConciseCasts.h:83
Halide::ConciseCasts::i32
Expr i32(Expr e)
Definition: ConciseCasts.h:43
Halide::ConciseCasts::bf16
Expr bf16(Expr e)
Definition: ConciseCasts.h:33
Halide::ConciseCasts::u64_sat
Expr u64_sat(Expr e)
Definition: ConciseCasts.h:113
Halide::ConciseCasts::f64
Expr f64(Expr e)
Definition: ConciseCasts.h:18
Halide::ConciseCasts::f16
Expr f16(Expr e)
Definition: ConciseCasts.h:28
Halide::ConciseCasts::u16
Expr u16(Expr e)
Definition: ConciseCasts.h:68
Halide::ConciseCasts::u8
Expr u8(Expr e)
Definition: ConciseCasts.h:73
Halide::ConciseCasts::i16_sat
Expr i16_sat(Expr e)
Definition: ConciseCasts.h:88
Halide::ConciseCasts::f32
Expr f32(Expr e)
Definition: ConciseCasts.h:23
Halide::ConciseCasts::u64
Expr u64(Expr e)
Definition: ConciseCasts.h:58
Halide::ConciseCasts::u32_sat
Expr u32_sat(Expr e)
Definition: ConciseCasts.h:103
Halide::ConciseCasts::i64
Expr i64(Expr e)
Definition: ConciseCasts.h:38
Halide::ConciseCasts::i16
Expr i16(Expr e)
Definition: ConciseCasts.h:48
Halide::ConciseCasts::i32_sat
Expr i32_sat(Expr e)
Definition: ConciseCasts.h:98
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::BFloat
Type BFloat(int bits, int lanes=1)
Construct a floating-point type in the bfloat format.
Definition: Type.h:554
Halide::UInt
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
Definition: Type.h:544
Halide::Float
Type Float(int bits, int lanes=1)
Construct a floating-point type.
Definition: Type.h:549
Halide::Int
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Definition: Type.h:539
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)
Halide::Expr
A fragment of Halide syntax.
Definition: Expr.h:258
Halide::Expr::type
HALIDE_ALWAYS_INLINE Type type() const
Get the type of this expression node.
Definition: Expr.h:327
Halide::Type
Types in the halide type system.
Definition: Type.h:281
Halide::Type::lanes
HALIDE_ALWAYS_INLINE int lanes() const
Return the number of vector elements in this type.
Definition: Type.h:353