Skip to content

Commit 475c65a

Browse files
committed
Saving work
1 parent 22ab085 commit 475c65a

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

examples_tests

include/nbl/builtin/hlsl/cpp_compat/intrinsics.hlsl

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ int findLSB(NBL_CONST_REF_ARG(Integer) val)
149149
}
150150

151151
template<typename Integer>
152-
int findMSB(NBL_CONST_REF_ARG(Integer) val)
152+
inline int findMSB(NBL_CONST_REF_ARG(Integer) val)
153153
{
154154
#ifdef __HLSL_VERSION
155155
if (is_signed_v<Integer>)
@@ -178,6 +178,40 @@ int findMSB(NBL_CONST_REF_ARG(Integer) val)
178178
#endif
179179
}
180180

181+
template<>
182+
inline int findMSB<uint64_t>(NBL_CONST_REF_ARG(uint64_t) val)
183+
{
184+
#ifdef __HLSL_VERSION
185+
uint32_t highBits = uint32_t(val >> 32);
186+
uint32_t lowBits = uint32_t(val);
187+
188+
int highBitsMSB = spirv::findUMsb(highBits);
189+
if (highBitsMSB == -1)
190+
return spirv::findUMsb(lowBits);
191+
192+
return highBitsMSB;
193+
#else
194+
return glm::findMSB(val);
195+
#endif
196+
}
197+
198+
template<>
199+
inline int findMSB<int64_t>(NBL_CONST_REF_ARG(int64_t) val)
200+
{
201+
#ifdef __HLSL_VERSION
202+
int32_t highBits = int32_t(val >> 32);
203+
int32_t lowBits = int32_t(val);
204+
205+
int highBitsMSB = spirv::findSMsb(highBits);
206+
if (highBitsMSB == -1)
207+
return spirv::findSMsb(lowBits);
208+
209+
return highBitsMSB;
210+
#else
211+
return glm::findMSB(val);
212+
#endif
213+
}
214+
181215
// TODO: some of the functions in this header should move to `tgmath`
182216
template<typename T>
183217
inline T floor(NBL_CONST_REF_ARG(T) val)

0 commit comments

Comments
 (0)