Loading...
Searching...
No Matches
ConciseCasts.h
Go to the documentation of this file.
#ifndef HALIDE_CONCISE_CASTS_H
#define HALIDE_CONCISE_CASTS_H
#include "IROperator.h"
/** \file
*
* Defines concise cast and saturating cast operators to make it
* easier to read cast-heavy code. Think carefully about the
* readability implications before using these. They could make your
* code better or worse. Often it's better to add extra Funcs to your
* pipeline that do the upcasting and downcasting.
*/
namespace Halide {
namespace ConciseCasts {
inline Expr f64(Expr e) {
Type t = Float(64, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr f32(Expr e) {
Type t = Float(32, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr f16(Expr e) {
Type t = Float(16, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr bf16(Expr e) {
Type t = BFloat(16, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr i64(Expr e) {
Type t = Int(64, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr i32(Expr e) {
Type t = Int(32, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr i16(Expr e) {
Type t = Int(16, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr i8(Expr e) {
Type t = Int(8, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr u64(Expr e) {
Type t = UInt(64, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr u32(Expr e) {
Type t = UInt(32, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr u16(Expr e) {
Type t = UInt(16, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr u8(Expr e) {
Type t = UInt(8, e.type().lanes());
return cast(t, std::move(e));
}
inline Expr i8_sat(Expr e) {
Type t = Int(8, e.type().lanes());
return saturating_cast(t, std::move(e));
}
inline Expr u8_sat(Expr e) {
Type t = UInt(8, e.type().lanes());
return saturating_cast(t, std::move(e));
}
inline Expr i16_sat(Expr e) {
Type t = Int(16, e.type().lanes());
return saturating_cast(t, std::move(e));
}
inline Expr u16_sat(Expr e) {
Type t = UInt(16, e.type().lanes());
return saturating_cast(t, std::move(e));
}
inline Expr i32_sat(Expr e) {
Type t = Int(32, e.type().lanes());
return saturating_cast(t, std::move(e));
}
inline Expr u32_sat(Expr e) {
Type t = UInt(32, e.type().lanes());
return saturating_cast(t, std::move(e));
}
inline Expr i64_sat(Expr e) {
Type t = Int(64, e.type().lanes());
return saturating_cast(t, std::move(e));
}
inline Expr u64_sat(Expr e) {
Type t = UInt(64, e.type().lanes());
return saturating_cast(t, std::move(e));
}
}; // namespace ConciseCasts
}; // namespace Halide
#endif
IROperator.h
Defines various operator overloads and utility functions that make it more pleasant to work with Hali...
Halide::ConciseCasts
Definition ConciseCasts.h:16
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:556
Halide::UInt
Type UInt(int bits, int lanes=1)
Constructing an unsigned integer type.
Definition Type.h:546
Halide::Float
Type Float(int bits, int lanes=1)
Construct a floating-point type.
Definition Type.h:551
Halide::Int
Type Int(int bits, int lanes=1)
Constructing a signed integer type.
Definition Type.h:541
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:283
Halide::Type::lanes
HALIDE_ALWAYS_INLINE int lanes() const
Return the number of vector elements in this type.
Definition Type.h:355