Skip to content

Commit dfdb909

Browse files
author
devsh
committed
clean up type_traits.hlsl and spot a bug in limits.hlsl max_exponent and min_exponent
1 parent 03fb95f commit dfdb909

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

include/nbl/builtin/hlsl/limits.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ struct num_base : type_identity<T>
127127
*/
128128
NBL_CONSTEXPR_STATIC_INLINE int32_t float_max_decimal_exponent = 4*S16 + 30*S32 + 232*S64;
129129

130-
NBL_CONSTEXPR_STATIC_INLINE int32_t float_exponent_bits = 8 * size - float_digits - 1;
131-
NBL_CONSTEXPR_STATIC_INLINE int32_t float_max_exponent = 1 << float_exponent_bits;
130+
NBL_CONSTEXPR_STATIC_INLINE int32_t float_exponent_bits = 8 * size - 1 - (float_digits-1);
131+
NBL_CONSTEXPR_STATIC_INLINE int32_t float_max_exponent = 1 << (float_exponent_bits-1);
132132
NBL_CONSTEXPR_STATIC_INLINE int32_t float_min_exponent = 3 - float_max_exponent;
133133
NBL_CONSTEXPR_STATIC_INLINE bool is_bool = is_same<T, bool>::value;
134134

include/nbl/builtin/hlsl/type_traits.hlsl

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -302,29 +302,21 @@ NBL_CONSTEXPR_STATIC_INLINE bool is_spirv_type_v = is_spirv_type<T>::value;
302302

303303
template<class T>
304304
struct is_unsigned : impl::base_type_forwarder<impl::is_unsigned, typename remove_cv<T>::type> {};
305-
template<class T>
306-
NBL_CONSTEXPR_STATIC_INLINE bool is_unsigned_v = is_unsigned<T>::value;
307305

308306
template<class T>
309307
struct is_integral : impl::base_type_forwarder<impl::is_integral, typename remove_cv<T>::type> {};
310-
template<class T>
311-
NBL_CONSTEXPR_STATIC_INLINE bool is_integral_v = is_integral<T>::value;
312308

313309
template<class T>
314310
struct is_floating_point : impl::base_type_forwarder<impl::is_floating_point, typename remove_cv<T>::type> {};
315311

316312
template<class T>
317313
struct is_signed : impl::base_type_forwarder<impl::is_signed, typename remove_cv<T>::type> {};
318-
template<class T>
319-
NBL_CONSTEXPR_STATIC_INLINE bool is_signed_v = is_signed<T>::value;
320314

321315
template<class T>
322316
struct is_scalar : bool_constant<
323317
impl::is_integral<typename remove_cv<T>::type>::value ||
324318
impl::is_floating_point<typename remove_cv<T>::type>::value
325319
> {};
326-
template<class T>
327-
NBL_CONSTEXPR_STATIC_INLINE bool is_scalar_v = is_scalar<T>::value;
328320

329321
template<class T>
330322
struct is_const : bool_constant<false> {};
@@ -396,13 +388,8 @@ struct enable_if {};
396388
template<class T>
397389
struct enable_if<true, T> : type_identity<T> {};
398390

399-
template<bool B, class T = void>
400-
using enable_if_t = typename enable_if<B, T>::type;
401-
402391
template<class T>
403392
struct alignment_of;
404-
template<class T>
405-
NBL_CONSTEXPR_STATIC_INLINE uint32_t alignment_of_v = alignment_of<T>::value;
406393

407394
template<class>
408395
struct make_void { using type = void; };
@@ -527,9 +514,6 @@ using is_unbounded_array = std::is_unbounded_array<T>;
527514
template<class T>
528515
using is_scalar = std::is_scalar<T>;
529516

530-
template<class T>
531-
NBL_CONSTEXPR_STATIC_INLINE bool is_scalar_v = is_scalar<T>::value;
532-
533517
template<class T>
534518
struct is_signed : impl::base_type_forwarder<std::is_signed, T> {};
535519

@@ -539,9 +523,6 @@ struct is_unsigned : impl::base_type_forwarder<std::is_unsigned, T> {};
539523
template<class T>
540524
struct is_integral : impl::base_type_forwarder<std::is_integral, T> {};
541525

542-
template<class T>
543-
NBL_CONSTEXPR_STATIC_INLINE bool is_integral_v = is_integral<T>::value;
544-
545526
template<class T>
546527
struct is_floating_point : impl::base_type_forwarder<std::is_floating_point, T> {};
547528

@@ -590,9 +571,6 @@ using extent = std::extent<T, I>;
590571
template<bool B, class T = void>
591572
using enable_if = std::enable_if<B, T>;
592573

593-
template<bool B, class T = void>
594-
using enable_if_t = typename enable_if<B, T>::type;
595-
596574
template<class T>
597575
using alignment_of = std::alignment_of<T>;
598576

@@ -614,9 +592,26 @@ using make_unsigned = std::make_unsigned<T>;
614592

615593
#endif
616594

595+
// Template Types
596+
template<bool B, class T = void>
597+
using enable_if_t = typename enable_if<B,T>::type;
598+
template<bool C, class T, class F>
599+
using conditional_t = typename conditional<C,T,F>::type;
600+
601+
617602
// Template Variables
618603
template<typename A, typename B>
619-
NBL_CONSTEXPR bool is_same_v = is_same<A,B>::value;
604+
NBL_CONSTEXPR bool is_same_v = is_same<A, B>::value;
605+
template<class T>
606+
NBL_CONSTEXPR bool is_unsigned_v = is_unsigned<T>::value;
607+
template<class T>
608+
NBL_CONSTEXPR bool is_integral_v = is_integral<T>::value;
609+
template<class T>
610+
NBL_CONSTEXPR bool is_signed_v = is_signed<T>::value;
611+
template<class T>
612+
NBL_CONSTEXPR bool is_scalar_v = is_scalar<T>::value;
613+
template<class T>
614+
NBL_CONSTEXPR uint32_t alignment_of_v = alignment_of<T>::value;
620615

621616
// Overlapping definitions
622617
template<bool C, typename T, T A, T B>

0 commit comments

Comments
 (0)