1#ifndef HALIDE_FLOAT16_H
2#define HALIDE_FLOAT16_H
41#ifdef HALIDE_CPP_COMPILER_HAS_FLOAT16
52 explicit operator float()
const;
56 explicit operator int()
const;
58#ifdef HALIDE_CPP_COMPILER_HAS_FLOAT16
92 return (*
this = *
this +
rhs);
95 return (*
this = *
this -
rhs);
98 return (*
this = *
this *
rhs);
101 return (*
this = *
this /
rhs);
109 return !(*
this ==
rhs);
114 return (*
this >
rhs) || (*
this ==
rhs);
117 return (*
this <
rhs) || (*
this ==
rhs);
141static_assert(
sizeof(
float16_t) == 2,
"float16_t should occupy two bytes");
160 static const int mantissa_bits = 7;
161 static const uint16_t sign_mask = 0x8000;
162 static const uint16_t exponent_mask = 0x7f80;
163 static const uint16_t mantissa_mask = 0x007f;
165 static const bfloat16_t zero, negative_zero, infinity, negative_infinity, nan;
175 explicit bfloat16_t(
float value);
176 explicit bfloat16_t(
double value);
177 explicit bfloat16_t(
int value);
182 bfloat16_t() =
default;
188 explicit operator float()
const;
190 explicit operator double()
const;
192 explicit operator int()
const;
197 static bfloat16_t make_negative_zero();
198 static bfloat16_t make_infinity();
199 static bfloat16_t make_negative_infinity();
200 static bfloat16_t make_nan();
207 static bfloat16_t make_from_bits(
uint16_t bits);
219 return (*
this = *
this +
rhs);
222 return (*
this = *
this -
rhs);
225 return (*
this = *
this *
rhs);
228 return (*
this = *
this /
rhs);
236 return !(*
this ==
rhs);
241 return (*
this >
rhs) || (*
this ==
rhs);
244 return (*
this <
rhs) || (*
this ==
rhs);
251 bool is_infinity()
const;
252 bool is_negative()
const;
253 bool is_zero()
const;
268static_assert(
sizeof(bfloat16_t) == 2,
"bfloat16_t should occupy two bytes");
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of< Halide::bfloat16_t >()
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of< Halide::float16_t >()
This file declares the routines used by Halide internally in its runtime.
@ halide_type_float
IEEE floating point numbers.
@ halide_type_bfloat
floating point numbers in the bfloat format
#define HALIDE_ALWAYS_INLINE
ConstantInterval operator*(const ConstantInterval &a, const ConstantInterval &b)
Expr make_zero(Type t)
Construct the representation of zero in the given type.
bool operator>=(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval operator/(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval operator-(const ConstantInterval &a, const ConstantInterval &b)
bool operator<(const ConstantInterval &a, const ConstantInterval &b)
ConstantInterval operator+(const ConstantInterval &a, const ConstantInterval &b)
Arithmetic operators on ConstantIntervals.
bool operator<=(const ConstantInterval &a, const ConstantInterval &b)
Comparison operators on ConstantIntervals.
bool operator>(const ConstantInterval &a, const ConstantInterval &b)
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
auto operator==(const Other &a, const GeneratorParam< T > &b) -> decltype(a==(T) b)
Equality comparison between GeneratorParam<T> and any type that supports operator== with T.
Expr & operator*=(Expr &a, Expr b)
Modify the first expression to be the product of two expressions, without changing its type.
Expr & operator-=(Expr &a, Expr b)
Modify the first expression to be the difference of two expressions, without changing its type.
Expr & operator/=(Expr &a, Expr b)
Modify the first expression to be the ratio of two expressions, without changing its type.
Expr is_nan(Expr x)
Returns true if the argument is a Not a Number (NaN).
auto operator!=(const Other &a, const GeneratorParam< T > &b) -> decltype(a !=(T) b)
Inequality comparison between between GeneratorParam<T> and any type that supports operator!...
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
Expr & operator+=(Expr &a, Expr b)
Modify the first expression to be the sum of two expressions, without changing its type.
unsigned __INT16_TYPE__ uint16_t
void * memcpy(void *s1, const void *s2, size_t n)
Class that provides a type that implements half precision floating point (IEEE754 2008 binary16) in s...
static float16_t make_infinity()
float16_t operator/(float16_t rhs) const
float16_t(double value)
Construct from a float, double, or int using round-to-nearest-ties-to-even.
static const uint16_t sign_mask
float16_t operator+(float16_t rhs) const
Arithmetic operators.
float16_t(int value)
Construct from a float, double, or int using round-to-nearest-ties-to-even.
bool operator>=(float16_t rhs) const
static float16_t make_zero()
Get a new float16_t that represents a special value.
uint16_t to_bits() const
Returns the bits that represent this float16_t.
bool operator<(float16_t rhs) const
static const uint16_t mantissa_mask
bool operator==(float16_t rhs) const
Comparison operators.
static float16_t make_negative_zero()
static float16_t make_from_bits(uint16_t bits)
Get a new float16_t with the given raw bits.
float16_t operator/=(float16_t rhs)
static float16_t make_nan()
float16_t(float value)
Construct from a float, double, or int using round-to-nearest-ties-to-even.
float16_t()=default
Construct a float16_t with the bits initialised to 0.
static const uint16_t exponent_mask
float16_t operator-(float16_t rhs) const
bool is_nan() const
Properties.
static float16_t make_negative_infinity()
static const int mantissa_bits
float16_t operator-=(float16_t rhs)
float16_t operator*(float16_t rhs) const
float16_t operator-() const
Return a new float16_t with a negated sign bit.
bool operator!=(float16_t rhs) const
bool operator<=(float16_t rhs) const
bool operator>(float16_t rhs) const
float16_t operator*=(float16_t rhs)
float16_t operator+=(float16_t rhs)
A runtime tag for a type in the halide type system.