182 #elif defined(_WIN32)
184 #elif defined(__x86_64__)
185 # include <x86intrin.h>
186 #elif defined(__F16C__)
187 # include <immintrin.h>
193 #ifdef IMATH_HALF_ENABLE_FP_EXCEPTIONS
205 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
208 # define HALF_DENORM_MIN 5.96046448e-08f
210 # define HALF_NRM_MIN 6.10351562e-05f
212 # define HALF_MIN 6.10351562e-05f
214 # define HALF_MAX 65504.0f
216 # define HALF_EPSILON 0.00097656f
219 # define HALF_DENORM_MIN 5.96046448e-08
221 # define HALF_NRM_MIN 6.10351562e-05
223 # define HALF_MIN 6.10351562e-05f
225 # define HALF_MAX 65504.0
227 # define HALF_EPSILON 0.00097656
231 #define HALF_MANT_DIG 11
240 #define HALF_DECIMAL_DIG 5
245 #define HALF_DENORM_MIN_EXP -13
248 #define HALF_MAX_EXP 16
251 #define HALF_DENORM_MIN_10_EXP -4
254 #define HALF_MAX_10_EXP 4
266 #if !defined(__cplusplus) && !defined(__CUDACC__)
271 #if !defined(IMATH_HALF_NO_LOOKUP_TABLE)
272 # if defined(__cplusplus)
287 #if defined(__F16C__)
295 return _mm_cvtss_f32 (_mm_cvtph_ps (_mm_set1_epi16 (h)));
297 return _cvtsh_ss (h);
299 #elif defined(IMATH_HALF_USE_LOOKUP_TABLE) && \
300 !defined(IMATH_HALF_NO_LOOKUP_TABLE)
308 uint32_t hexpmant = ((uint32_t) (h) << 17) >> 4;
309 v.
i = ((uint32_t) (h >> 15)) << 31;
322 else if (hexpmant != 0)
331 # if defined(_MSC_VER)
337 _BitScanReverse (&bsr, hexpmant);
339 # elif defined(__GNUC__) || defined(__clang__)
340 lc = (uint32_t) __builtin_clz (hexpmant);
343 while (0 == ((hexpmant << lc) & 0x80000000))
359 v.
i |= (hexpmant << lc);
374 imath_float_to_half (
float f)
376 #if defined(__F16C__)
379 return _mm_extract_epi16 (
381 _mm_set_ss (f), (_MM_FROUND_TO_NEAREST_INT)),
385 return _cvtss_sh (f, (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC));
390 uint32_t e, m, ui,
r, shift;
394 ui = (v.
i & ~0x80000000);
395 ret = ((v.
i >> 16) & 0x8000);
398 if (ui >= 0x38800000)
404 if (ui == 0x7f800000)
return ret;
405 m = (ui & 0x7fffff) >> 13;
407 return ret | (uint16_t) m | (uint16_t) (m == 0);
413 # ifdef IMATH_HALF_ENABLE_FP_EXCEPTIONS
414 feraiseexcept (FE_OVERFLOW);
420 ui = ((ui + 0x00000fff + ((ui >> 13) & 1)) >> 13);
421 return ret | (uint16_t) ui;
427 # ifdef IMATH_HALF_ENABLE_FP_EXCEPTIONS
428 if (ui == 0)
return ret;
429 feraiseexcept (FE_UNDERFLOW);
437 m = 0x800000 | (ui & 0x7fffff);
438 r = m << (32 - shift);
440 if (r > 0x80000000 || (r == 0x80000000 && (ret & 0x1) != 0)) ++ret;
451 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
518 constexpr
half (FromBitsTag, uint16_t bits) IMATH_NOEXCEPT;
521 constexpr
half (const
half&) IMATH_NOEXCEPT = default;
524 constexpr
half (
half&&) IMATH_NOEXCEPT = default;
527 ~
half () IMATH_NOEXCEPT = default;
532 operator
float () const IMATH_NOEXCEPT;
538 constexpr
half operator- () const IMATH_NOEXCEPT;
541 half& operator= (const
half&
h) IMATH_NOEXCEPT = default;
544 half& operator= (
half&&
h) IMATH_NOEXCEPT = default;
547 half& operator= (
float f) IMATH_NOEXCEPT;
550 half& operator+= (
half h) IMATH_NOEXCEPT;
553 half& operator+= (
float f) IMATH_NOEXCEPT;
556 half& operator-= (
half h) IMATH_NOEXCEPT;
559 half& operator-= (
float f) IMATH_NOEXCEPT;
562 half& operator*= (
half h) IMATH_NOEXCEPT;
565 half& operator*= (
float f) IMATH_NOEXCEPT;
568 half& operator/= (
half h) IMATH_NOEXCEPT;
571 half& operator/= (
float f) IMATH_NOEXCEPT;
578 IMATH_CONSTEXPR14
half round (
unsigned int n) const IMATH_NOEXCEPT;
585 constexpr
bool isFinite () const IMATH_NOEXCEPT;
588 constexpr
bool isNormalized () const IMATH_NOEXCEPT;
591 constexpr
bool isDenormalized () const IMATH_NOEXCEPT;
594 constexpr
bool isZero () const IMATH_NOEXCEPT;
597 constexpr
bool isNan () const IMATH_NOEXCEPT;
600 constexpr
bool isInfinity () const IMATH_NOEXCEPT;
603 constexpr
bool isNegative () const IMATH_NOEXCEPT;
611 static constexpr
half posInf () IMATH_NOEXCEPT;
614 static constexpr
half negInf () IMATH_NOEXCEPT;
617 static constexpr
half qNan () IMATH_NOEXCEPT;
620 static constexpr
half sNan () IMATH_NOEXCEPT;
628 constexpr uint16_t bits () const IMATH_NOEXCEPT;
631 IMATH_CONSTEXPR14
void setBits (uint16_t bits) IMATH_NOEXCEPT;
637 sizeof (
float) == sizeof (uint32_t),
638 "Assumption about the
size of floats correct");
642 constexpr uint16_t mantissa () const IMATH_NOEXCEPT;
643 constexpr uint16_t exponent () const IMATH_NOEXCEPT;
652 inline
half::
half (
float f) IMATH_NOEXCEPT : _h (imath_float_to_half (f))
669 return imath_half_to_float (_h);
676 inline IMATH_CONSTEXPR14
half
683 if (
n >= 10)
return *
this;
690 uint16_t
s = _h & 0x8000;
691 uint16_t e = _h & 0x7fff;
723 half h (FromBits, s | e);
732 inline constexpr
half
735 return half (FromBits, bits () ^ 0x8000);
748 *
this =
half (
float (*
this) +
float (
h));
755 *
this =
half (
float (*
this) + f);
762 *
this =
half (
float (*
this) -
float (
h));
769 *
this =
half (
float (*
this) - f);
776 *
this =
half (
float (*
this) *
float (
h));
783 *
this =
half (
float (*
this) * f);
790 *
this =
half (
float (*
this) /
float (
h));
797 *
this =
half (
float (*
this) / f);
801 inline constexpr uint16_t
807 inline constexpr uint16_t
810 return (_h >> 10) & 0x001f;
813 inline constexpr
bool
816 return exponent () < 31;
819 inline constexpr
bool
822 return exponent () > 0 && exponent () < 31;
825 inline constexpr
bool
828 return exponent () == 0 && mantissa () != 0;
831 inline constexpr
bool
834 return (_h & 0x7fff) == 0;
837 inline constexpr
bool
840 return exponent () == 31 && mantissa () != 0;
843 inline constexpr
bool
846 return exponent () == 31 && mantissa () == 0;
849 inline constexpr
bool
852 return (_h & 0x8000) != 0;
855 inline constexpr
half
858 return half (FromBits, 0x7c00);
861 inline constexpr
half
864 return half (FromBits, 0xfc00);
867 inline constexpr
half
870 return half (FromBits, 0x7fff);
873 inline constexpr
half
876 return half (FromBits, 0x7dff);
879 inline constexpr uint16_t
885 inline IMATH_CONSTEXPR14
void
891 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
909 static const bool is_specialized =
true;
929 static constexpr
bool is_exact =
false;
945 static constexpr
bool has_infinity =
true;
946 static constexpr
bool has_quiet_NaN =
true;
947 static constexpr
bool has_signaling_NaN =
true;
948 static constexpr float_denorm_style has_denorm = denorm_present;
949 static constexpr
bool has_denorm_loss =
false;
967 static constexpr
bool is_iec559 =
false;
968 static constexpr
bool is_bounded =
false;
969 static constexpr
bool is_modulo =
false;
971 static constexpr
bool traps =
true;
972 static constexpr
bool tinyness_before =
false;
973 static constexpr float_round_style round_style = round_to_nearest;
988 #if !defined(__CUDACC__) && !defined(__CUDA_FP16_HPP__) && !defined(__HIP__)
990 #elif defined(__CUDACC__) || defined(__CUDA_FP16_HPP__)
991 #include <cuda_fp16.h>
992 #elif defined(__HIP__)
993 #include <hip/amd_detail/amd_hip_fp16.h>
996 #endif // __cplusplus
998 #endif // IMATH_HALF_H_
bool_constant< is_integral< T >::value &&!std::is_same< T, bool >::value &&!std::is_same< T, char >::value &&!std::is_same< T, wchar_t >::value > is_integer
#define IMATH_INTERNAL_NAMESPACE
imath_half_bits_t half
if we're in a C-only context, alias the half bits type to half
#define IMATH_EXPORT_TYPE
OPENVDB_API void printBits(std::ostream &os, half h)
IMATH_EXPORT const imath_half_uif_t * imath_half_to_float_table
IMATH_HOSTDEVICE constexpr Plane3< T > operator-(const Plane3< T > &plane) IMATH_NOEXCEPT
Reflect the pla.
a type for both C-only programs and C++ to use the same utilities
uint16_t imath_half_bits_t
a type for both C-only programs and C++ to use the same utilities
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool isNegative(const Type &x)
Return true if x is less than zero.
std::ostream & operator<<(std::ostream &ostr, const DataType &a)
#define HALF_DENORM_MIN_EXP
#define HALF_RADIX
Base of the exponent.
#define IMATH_EXPORT_ENUM
bool isNan(const float x)
Return true if x is a NaN (Not-A-Number) value.
vfloat4 round(const vfloat4 &a)
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
GLfloat GLfloat GLfloat GLfloat h
std::integral_constant< bool, std::numeric_limits< T >::is_signed||std::is_same< T, int128_opt >::value > is_signed
IMATH_NAMESPACE::V2f IMATH_NAMESPACE::Box2i std::string this attribute is obsolete as of OpenEXR v3 float
#define IMATH_UNLIKELY(x)
#define HALF_DENORM_MIN_10_EXP
LeafData & operator=(const LeafData &)=delete
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
union imath_half_uif imath_half_uif_t
a type for both C-only programs and C++ to use the same utilities
#define HALF_MANT_DIG
Number of digits in mantissa (significand + hidden leading 1)
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
bool isFinite(const float x)
Return true if x is finite.