12 #ifndef OPENVDB_MATH_HALF_HAS_BEEN_INCLUDED 13 #define OPENVDB_MATH_HALF_HAS_BEEN_INCLUDED 177 #include <openvdb/version.h> 184 #elif defined(__x86_64__) 185 #include <x86intrin.h> 186 #elif defined(__F16C__) 187 #include <immintrin.h> 193 #ifdef IMATH_HALF_ENABLE_FP_EXCEPTIONS 209 #undef IMATH_HALF_USE_LOOKUP_TABLE 210 #define IMATH_HALF_NO_LOOKUP_TABLE 220 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER 223 #define VDBB_HALF_DENORM_MIN 5.96046448e-08f 225 #define VDB_HALF_NRM_MIN 6.10351562e-05f 227 #define VDB_HALF_MIN 6.10351562e-05f 229 #define VDB_HALF_MAX 65504.0f 231 #define VDB_HALF_EPSILON 0.00097656f 234 #define VDBB_HALF_DENORM_MIN 5.96046448e-08 236 #define VDB_HALF_NRM_MIN 6.10351562e-05 238 #define VDB_HALF_MIN 6.10351562e-05f 240 #define VDB_HALF_MAX 65504.0 242 #define VDB_HALF_EPSILON 0.00097656 246 #define VDB_HALF_MANT_DIG 11 250 #define VDB_HALF_DIG 3 255 #define VDB_HALF_DECIMAL_DIG 5 257 #define VDB_HALF_RADIX 2 260 #define VDBB_HALF_DENORM_MIN_EXP -13 263 #define VDB_HALF_MAX_EXP 16 266 #define VDBB_HALF_DENORM_MIN_10_EXP -4 269 #define VDB_HALF_MAX_10_EXP 4 281 #if !defined(__cplusplus) && !defined(__CUDACC__) 283 typedef imath_half_bits_t
half;
286 #if !defined(IMATH_HALF_NO_LOOKUP_TABLE) 287 #if defined(__cplusplus) 302 #if defined(__F16C__) 310 return _mm_cvtss_f32 (_mm_cvtph_ps (_mm_set1_epi16 (h)));
312 return _cvtsh_ss (h);
314 #elif defined(IMATH_HALF_USE_LOOKUP_TABLE) && !defined(IMATH_HALF_NO_LOOKUP_TABLE) 315 return imath_half_to_float_table[h].f;
322 uint32_t hexpmant = ( (uint32_t)(h) << 17 ) >> 4;
323 v.
i = ((uint32_t)(h >> 15)) << 31;
336 else if (hexpmant != 0)
345 # if defined(_MSC_VER) && (_M_IX86 || _M_X64) 346 lc = __lzcnt (hexpmant);
347 # elif defined(__GNUC__) || defined(__clang__) 348 lc = (uint32_t) __builtin_clz (hexpmant);
351 while (0 == ((hexpmant << lc) & 0x80000000))
367 v.
i |= (hexpmant << lc);
381 static inline imath_half_bits_t
384 #if defined(__F16C__) 387 return _mm_extract_epi16 (
388 _mm_cvtps_ph (_mm_set_ss (f), (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC)),
392 return _cvtss_sh (f, (_MM_FROUND_TO_NEAREST_INT | _MM_FROUND_NO_EXC));
396 imath_half_bits_t ret;
397 uint32_t e, m, ui, r, shift;
401 ui = (v.
i & ~0x80000000);
402 ret = ((v.
i >> 16) & 0x8000);
405 if (ui >= 0x38800000)
411 if (ui == 0x7f800000)
413 m = (ui & 0x7fffff) >> 13;
415 return ret | (uint16_t)m | (uint16_t)(m == 0);
421 # ifdef IMATH_HALF_ENABLE_FP_EXCEPTIONS 422 feraiseexcept (FE_OVERFLOW);
428 ui = ((ui + 0x00000fff + ((ui >> 13) & 1)) >> 13);
429 return ret | (uint16_t)ui;
435 # ifdef IMATH_HALF_ENABLE_FP_EXCEPTIONS 438 feraiseexcept (FE_UNDERFLOW);
446 m = 0x800000 | (ui & 0x7fffff);
447 r = m << (32 - shift);
449 if (r > 0x80000000 || (r == 0x80000000 && (ret & 0x1) != 0))
516 half() noexcept =
default;
519 half (
float f) noexcept;
522 constexpr
half (FromBitsTag, uint16_t bits) noexcept;
525 constexpr
half (
const half&) noexcept =
default;
528 constexpr
half (half&&) noexcept =
default;
531 ~half() noexcept =
default;
536 operator float()
const noexcept;
542 constexpr half
operator-()
const noexcept;
545 half& operator= (
const half& h) noexcept =
default;
548 half& operator= (half&& h) noexcept =
default;
551 half& operator= (
float f) noexcept;
554 half& operator+= (half h) noexcept;
557 half& operator+= (
float f) noexcept;
560 half& operator-= (half h) noexcept;
563 half& operator-= (
float f) noexcept;
566 half& operator*= (half h) noexcept;
569 half& operator*= (
float f) noexcept;
572 half& operator/= (half h) noexcept;
575 half& operator/= (
float f) noexcept;
582 constexpr half round (
unsigned int n)
const noexcept;
589 constexpr
bool isFinite()
const noexcept;
592 constexpr
bool isNormalized()
const noexcept;
595 constexpr
bool isDenormalized()
const noexcept;
598 constexpr
bool isZero()
const noexcept;
601 constexpr
bool isNan()
const noexcept;
604 constexpr
bool isInfinity()
const noexcept;
615 static constexpr half posInf() noexcept;
618 static constexpr half negInf() noexcept;
621 static constexpr half qNan() noexcept;
624 static constexpr half sNan() noexcept;
632 constexpr uint16_t bits()
const noexcept;
635 constexpr
void setBits (uint16_t bits) noexcept;
640 static_assert (
sizeof (
float) ==
sizeof (uint32_t),
641 "Assumption about the size of floats correct");
646 constexpr uint16_t mantissa() const noexcept;
647 constexpr uint16_t exponent() const noexcept;
656 inline half::half (
float f) noexcept
665 inline constexpr
half::half (FromBitsTag, uint16_t bits) noexcept : _h (bits)
672 inline half::operator float() const noexcept
681 inline constexpr half
682 half::round (
unsigned int n)
const noexcept
696 uint16_t s = _h & 0x8000;
697 uint16_t e = _h & 0x7fff;
729 half h (FromBits, s | e);
738 inline constexpr half
741 return half (FromBits, bits() ^ 0x8000);
745 half::operator= (
float f) noexcept
752 half::operator+= (half h) noexcept
754 *
this =
half (
float (*
this) +
float (h));
759 half::operator+= (
float f) noexcept
761 *
this =
half (
float (*
this) + f);
766 half::operator-= (half h) noexcept
768 *
this =
half (
float (*
this) -
float (h));
773 half::operator-= (
float f) noexcept
775 *
this =
half (
float (*
this) - f);
780 half::operator*= (half h) noexcept
782 *
this =
half (
float (*
this) *
float (h));
787 half::operator*= (
float f) noexcept
789 *
this =
half (
float (*
this) * f);
794 half::operator/= (half h) noexcept
796 *
this =
half (
float (*
this) /
float (h));
801 half::operator/= (
float f) noexcept
803 *
this =
half (
float (*
this) / f);
807 inline constexpr uint16_t
808 half::mantissa()
const noexcept
813 inline constexpr uint16_t
814 half::exponent()
const noexcept
816 return (_h >> 10) & 0x001f;
819 inline constexpr
bool 822 return exponent() < 31;
825 inline constexpr
bool 826 half::isNormalized() const noexcept
828 return exponent() > 0 && exponent() < 31;
831 inline constexpr
bool 832 half::isDenormalized() const noexcept
834 return exponent() == 0 && mantissa() != 0;
837 inline constexpr
bool 840 return (_h & 0x7fff) == 0;
843 inline constexpr
bool 846 return exponent() == 31 && mantissa() != 0;
849 inline constexpr
bool 850 half::isInfinity() const noexcept
852 return exponent() == 31 && mantissa() == 0;
855 inline constexpr
bool 858 return (_h & 0x8000) != 0;
861 inline constexpr half
862 half::posInf() noexcept
864 return half (FromBits, 0x7c00);
867 inline constexpr half
868 half::negInf() noexcept
870 return half (FromBits, 0xfc00);
873 inline constexpr half
874 half::qNan() noexcept
876 return half (FromBits, 0x7fff);
879 inline constexpr half
880 half::sNan() noexcept
882 return half (FromBits, 0x7dff);
885 inline constexpr uint16_t
886 half::bits() const noexcept
891 inline constexpr
void 892 half::setBits (uint16_t bits) noexcept
925 static const bool is_specialized =
true;
943 static constexpr
bool is_signed =
true;
944 static constexpr
bool is_integer =
false;
945 static constexpr
bool is_exact =
false;
961 static constexpr
bool has_infinity =
true;
962 static constexpr
bool has_quiet_NaN =
true;
963 static constexpr
bool has_signaling_NaN =
true;
964 static constexpr float_denorm_style has_denorm = denorm_present;
965 static constexpr
bool has_denorm_loss =
false;
983 static constexpr
bool is_iec559 =
false;
984 static constexpr
bool is_bounded =
false;
985 static constexpr
bool is_modulo =
false;
987 static constexpr
bool traps =
true;
988 static constexpr
bool tinyness_before =
false;
989 static constexpr float_round_style round_style = round_to_nearest;
996 #endif // OPENVDB_MATH_HALF_HAS_BEEN_INCLUDED
static constexpr openvdb::math::internal::half epsilon() noexcept
Definition: Half.h:947
bool isNan(const float x)
Return true if x is a NaN (Not-A-Number) value.
Definition: Math.h:395
uint32_t i
Definition: Half.h:274
bool isFinite(const float x)
Return true if x is finite.
Definition: Math.h:375
static float imath_half_to_float(imath_half_bits_t h)
Definition: Half.h:300
static constexpr openvdb::math::internal::half denorm_min() noexcept
Definition: Half.h:978
OPENVDB_API void printBits(char c[35], float f)
a type for both C-only programs and C++ to use the same utilities
Definition: Half.h:272
static constexpr openvdb::math::internal::half max() noexcept
Definition: Half.h:931
#define VDB_HALF_DIG
Definition: Half.h:250
static imath_half_bits_t imath_float_to_half(float f)
Definition: Half.h:382
Vec3< typename promote< T, Coord::ValueType >::type > operator-(const Vec3< T > &v0, const Coord &v1)
Allow a Coord to be subtracted from a Vec3.
Definition: Coord.h:553
bool isZero(const Type &x)
Return true if x is exactly equal to zero.
Definition: Math.h:337
#define VDB_HALF_MAX_10_EXP
Definition: Half.h:269
static constexpr openvdb::math::internal::half signaling_NaN() noexcept
Definition: Half.h:974
OPENVDB_API std::istream & operator>>(std::istream &is, half &h)
Input h from is.
uint16_t imath_half_bits_t
a type for both C-only programs and C++ to use the same utilities
Definition: Half.h:279
static constexpr openvdb::math::internal::half lowest()
Definition: Half.h:935
OPENVDB_API std::ostream & operator<<(std::ostream &os, half h)
Output h to os, formatted as a float.
#define VDB_HALF_RADIX
Base of the exponent.
Definition: Half.h:257
#define VDB_HALF_MANT_DIG
Number of digits in mantissa (significand + hidden leading 1)
Definition: Half.h:246
Definition: Exceptions.h:13
#define VDBB_HALF_DENORM_MIN_EXP
Definition: Half.h:260
static constexpr openvdb::math::internal::half quiet_NaN() noexcept
Definition: Half.h:970
float f
Definition: Half.h:275
bool isNegative(const Type &x)
Return true if x is less than zero.
Definition: Math.h:367
#define VDB_HALF_DECIMAL_DIG
Definition: Half.h:255
#define VDB_HALF_MAX_EXP
Definition: Half.h:263
static constexpr openvdb::math::internal::half min() noexcept
Definition: Half.h:927
imath_half_bits_t half
if we're in a C-only context, alias the half bits type to half
Definition: Half.h:283
union openvdb::v11_0::math::internal::imath_half_uif imath_half_uif_t
a type for both C-only programs and C++ to use the same utilities
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
static constexpr openvdb::math::internal::half round_error() noexcept
Definition: Half.h:951
static constexpr openvdb::math::internal::half infinity() noexcept
Definition: Half.h:966
#define VDBB_HALF_DENORM_MIN_10_EXP
Definition: Half.h:266
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:212