182 #elif defined(__x86_64__)
183 # include <x86intrin.h>
184 #elif defined(__F16C__)
185 # include <immintrin.h>
191 #ifdef IMATH_HALF_ENABLE_FP_EXCEPTIONS
203 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
206 # define HALF_DENORM_MIN 5.96046448e-08f
208 # define HALF_NRM_MIN 6.10351562e-05f
210 # define HALF_MIN 6.10351562e-05f
212 # define HALF_MAX 65504.0f
214 # define HALF_EPSILON 0.00097656f
217 # define HALF_DENORM_MIN 5.96046448e-08
219 # define HALF_NRM_MIN 6.10351562e-05
221 # define HALF_MIN 6.10351562e-05f
223 # define HALF_MAX 65504.0
225 # define HALF_EPSILON 0.00097656
229 #define HALF_MANT_DIG 11
238 #define HALF_DECIMAL_DIG 5
243 #define HALF_DENORM_MIN_EXP -13
246 #define HALF_MAX_EXP 16
249 #define HALF_DENORM_MIN_10_EXP -4
252 #define HALF_MAX_10_EXP 4
264 #if !defined(__cplusplus) && !defined(__CUDACC__)
269 #if !defined(IMATH_HALF_NO_LOOKUP_TABLE)
270 # if defined(__cplusplus)
285 #if defined(__F16C__)
293 return _mm_cvtss_f32 (_mm_cvtph_ps (_mm_set1_epi16 (h)));
295 return _cvtsh_ss (h);
297 #elif defined(IMATH_HALF_USE_LOOKUP_TABLE) && !defined(IMATH_HALF_NO_LOOKUP_TABLE)
305 uint32_t hexpmant = ( (uint32_t)(h) << 17 ) >> 4;
306 v.
i = ((uint32_t)(h >> 15)) << 31;
319 else if (hexpmant != 0)
328 # if defined(_MSC_VER) && (_M_IX86 || _M_X64)
329 lc = __lzcnt (hexpmant);
330 # elif defined(__GNUC__) || defined(__clang__)
331 lc = (uint32_t) __builtin_clz (hexpmant);
334 while (0 == ((hexpmant << lc) & 0x80000000))
350 v.
i |= (hexpmant << lc);
365 imath_float_to_half (
float f)
367 #if defined(__F16C__)
370 return _mm_extract_epi16 (
371 _mm_cvtps_ph (_mm_set_ss (f), (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)),
375 return _cvtss_sh (f, (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC));
380 uint32_t e, m, ui,
r, shift;
384 ui = (v.
i & ~0x80000000);
385 ret = ((v.
i >> 16) & 0x8000);
388 if (ui >= 0x38800000)
394 if (ui == 0x7f800000)
396 m = (ui & 0x7fffff) >> 13;
398 return ret | (uint16_t)m | (uint16_t)(m == 0);
404 # ifdef IMATH_HALF_ENABLE_FP_EXCEPTIONS
405 feraiseexcept (FE_OVERFLOW);
411 ui = ((ui + 0x00000fff + ((ui >> 13) & 1)) >> 13);
412 return ret | (uint16_t)ui;
418 # ifdef IMATH_HALF_ENABLE_FP_EXCEPTIONS
421 feraiseexcept (FE_UNDERFLOW);
429 m = 0x800000 | (ui & 0x7fffff);
430 r = m << (32 - shift);
432 if (r > 0x80000000 || (r == 0x80000000 && (ret & 0x1) != 0))
444 IMATH_INTERNAL_NAMESPACE_HEADER_ENTER
511 constexpr
half (FromBitsTag, uint16_t bits) IMATH_NOEXCEPT;
514 constexpr
half (const
half&) IMATH_NOEXCEPT = default;
517 constexpr
half (
half&&) IMATH_NOEXCEPT = default;
520 ~
half() IMATH_NOEXCEPT = default;
525 operator
float() const IMATH_NOEXCEPT;
531 constexpr
half operator-() const IMATH_NOEXCEPT;
534 half& operator= (const
half&
h) IMATH_NOEXCEPT = default;
537 half& operator= (
half&&
h) IMATH_NOEXCEPT = default;
540 half& operator= (
float f) IMATH_NOEXCEPT;
543 half& operator+= (
half h) IMATH_NOEXCEPT;
546 half& operator+= (
float f) IMATH_NOEXCEPT;
549 half& operator-= (
half h) IMATH_NOEXCEPT;
552 half& operator-= (
float f) IMATH_NOEXCEPT;
555 half& operator*= (
half h) IMATH_NOEXCEPT;
558 half& operator*= (
float f) IMATH_NOEXCEPT;
561 half& operator/= (
half h) IMATH_NOEXCEPT;
564 half& operator/= (
float f) IMATH_NOEXCEPT;
571 IMATH_CONSTEXPR14
half round (
unsigned int n) const IMATH_NOEXCEPT;
578 constexpr
bool isFinite() const IMATH_NOEXCEPT;
581 constexpr
bool isNormalized() const IMATH_NOEXCEPT;
584 constexpr
bool isDenormalized() const IMATH_NOEXCEPT;
587 constexpr
bool isZero() const IMATH_NOEXCEPT;
590 constexpr
bool isNan() const IMATH_NOEXCEPT;
593 constexpr
bool isInfinity() const IMATH_NOEXCEPT;
596 constexpr
bool isNegative() const IMATH_NOEXCEPT;
604 static constexpr
half posInf() IMATH_NOEXCEPT;
607 static constexpr
half negInf() IMATH_NOEXCEPT;
610 static constexpr
half qNan() IMATH_NOEXCEPT;
613 static constexpr
half sNan() IMATH_NOEXCEPT;
621 IMATH_EXPORT constexpr uint16_t bits() const IMATH_NOEXCEPT;
624 IMATH_EXPORT IMATH_CONSTEXPR14
void setBits (uint16_t bits) IMATH_NOEXCEPT;
629 static_assert (sizeof (
float) == sizeof (uint32_t),
630 "Assumption about the
size of floats correct");
635 constexpr uint16_t mantissa() const IMATH_NOEXCEPT;
636 constexpr uint16_t exponent() const IMATH_NOEXCEPT;
645 inline
half::
half (
float f) IMATH_NOEXCEPT
646 : _h (imath_float_to_half (f))
663 return imath_half_to_float (_h);
670 inline IMATH_CONSTEXPR14
half
685 uint16_t
s = _h & 0x8000;
686 uint16_t e = _h & 0x7fff;
718 half h (FromBits, s | e);
727 inline constexpr
half
730 return half (FromBits, bits() ^ 0x8000);
743 *
this =
half (
float (*
this) +
float (
h));
750 *
this =
half (
float (*
this) + f);
757 *
this =
half (
float (*
this) -
float (
h));
764 *
this =
half (
float (*
this) - f);
771 *
this =
half (
float (*
this) *
float (
h));
778 *
this =
half (
float (*
this) * f);
785 *
this =
half (
float (*
this) /
float (
h));
792 *
this =
half (
float (*
this) / f);
796 inline constexpr uint16_t
802 inline constexpr uint16_t
805 return (_h >> 10) & 0x001f;
808 inline constexpr
bool
811 return exponent() < 31;
814 inline constexpr
bool
817 return exponent() > 0 && exponent() < 31;
820 inline constexpr
bool
823 return exponent() == 0 && mantissa() != 0;
826 inline constexpr
bool
829 return (_h & 0x7fff) == 0;
832 inline constexpr
bool
835 return exponent() == 31 && mantissa() != 0;
838 inline constexpr
bool
841 return exponent() == 31 && mantissa() == 0;
844 inline constexpr
bool
847 return (_h & 0x8000) != 0;
850 inline constexpr
half
853 return half (FromBits, 0x7c00);
856 inline constexpr
half
859 return half (FromBits, 0xfc00);
862 inline constexpr
half
865 return half (FromBits, 0x7fff);
868 inline constexpr
half
871 return half (FromBits, 0x7dff);
874 inline constexpr uint16_t
880 inline IMATH_CONSTEXPR14
void
886 IMATH_INTERNAL_NAMESPACE_HEADER_EXIT
902 static const bool is_specialized =
true;
922 static constexpr
bool is_exact =
false;
938 static constexpr
bool has_infinity =
true;
939 static constexpr
bool has_quiet_NaN =
true;
940 static constexpr
bool has_signaling_NaN =
true;
941 static constexpr float_denorm_style has_denorm = denorm_present;
942 static constexpr
bool has_denorm_loss =
false;
960 static constexpr
bool is_iec559 =
false;
961 static constexpr
bool is_bounded =
false;
962 static constexpr
bool is_modulo =
false;
964 static constexpr
bool traps =
true;
965 static constexpr
bool tinyness_before =
false;
966 static constexpr float_round_style round_style = round_to_nearest;
983 # include <cuda_fp16.h>
986 #endif // __cplusplus
988 #endif // IMATH_HALF_H_
OIIO_FORCEINLINE const vint4 & operator/=(vint4 &a, const vint4 &b)
#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
IMATH_NAMESPACE::V2f float
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
#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.
OIIO_FORCEINLINE vint4 operator>>(const vint4 &a, const unsigned int bits)
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
#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)
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
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.