Skip to content

Commit a2d8625

Browse files
committed
Added conditional_value
1 parent 409e498 commit a2d8625

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

include/nbl/builtin/hlsl/mpl.hlsl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ struct countl_zero
4141
{
4242
NBL_CONSTEXPR_STATIC_INLINE bool CHOOSE_HIGH = N&(countl_zero_masks<bits_log2>::LO_MASK<<countl_zero_masks<bits_log2>::SHIFT);
4343
NBL_CONSTEXPR_STATIC_INLINE uint64_t NEXT_N = (CHOOSE_HIGH ? (N>>countl_zero_masks<bits_log2>::SHIFT):N)&countl_zero_masks<bits_log2>::LO_MASK;
44-
NBL_CONSTEXPR_STATIC_INLINE uint16_t value = type_traits::conditional<bits_log2,countl_zero<NEXT_N,bits_log2-1>,type_traits::integral_constant<uint16_t,0> >::type::value + (CHOOSE_HIGH ? 0ull:countl_zero_masks<bits_log2>::SHIFT);
44+
//NBL_CONSTEXPR_STATIC_INLINE uint16_t value = type_traits::conditional_value<bits_log2,uint16_t,countl_zero<NEXT_N,bits_log2-1>::value,type_traits::integral_constant<uint16_t,0>::value>::value + (CHOOSE_HIGH ? 0ull:countl_zero_masks<bits_log2>::SHIFT);
45+
NBL_CONSTEXPR_STATIC_INLINE uint16_t value = type_traits::conditional<bits_log2,countl_zero<NEXT_N,bits_log2-1>,type_traits::integral_constant<uint16_t,0> >::type::value + (CHOOSE_HIGH ? 0ull:countl_zero_masks<bits_log2>::SHIFT);
4546
};
4647

4748
}
@@ -78,11 +79,8 @@ struct rotr
7879
static const uint32_t N = 32u;
7980
static const int32_t r = S % N;
8081
static const T value = (S >= 0) ? ((X >> r) | (X << (N - r))) : (X << (-r)) | (X >> (N - (-r)));
81-
8282
};
8383

84-
#endif
85-
8684
}
8785
}
8886
}

include/nbl/builtin/hlsl/type_traits.hlsl

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,24 +159,30 @@ struct integral_constant {
159159
using value_type = T;
160160
};
161161

162-
template <bool val>
162+
template<bool val>
163163
struct bool_constant : integral_constant<bool, val> {};
164164

165165
struct true_type : bool_constant<true> {};
166166
struct false_type : bool_constant<true> {};
167167

168-
template <bool C, class T, class F>
168+
template<bool C, class T, class F>
169169
struct conditional
170170
{
171171
using type = T;
172172
};
173173

174-
template <class T, class F>
174+
template<class T, class F>
175175
struct conditional<false, T, F>
176176
{
177177
using type = F;
178178
};
179179

180+
template<bool C, typename T, T A, T B>
181+
struct conditional_value
182+
{
183+
NBL_CONSTEXPR_STATIC_INLINE T value = C ? A : B;
184+
};
185+
180186
template<class A, class B>
181187
struct is_same : bool_constant<false> {};
182188

0 commit comments

Comments
 (0)