[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Sat Sep 28 10:28:26 PDT 2024


================
@@ -438,6 +438,55 @@ template <typename T> constexpr uint asuint(T F) {
   return __detail::bit_cast<uint, T>(F);
 }
 
+//===----------------------------------------------------------------------===//
+// asuint splitdouble builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn void asuint(double D, out uint lowbits, out int highbits)
+/// \brief Split and interprets the lowbits and highbits of double D into uints.
+/// \param D The input double.
+/// \param lowbits The output lowbits of D.
+/// \param highbits The highbits lowbits D.
+#if __is_target_arch(dxil)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double, out uint, out uint);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double2, out uint2, out uint2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double3, out uint3, out uint3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
+void asuint(double4, out uint4, out uint4);
+
+#elif __is_target_arch(spirv)
+
+void asuint(double4 D, out uint4 lowbits, out uint4 highbits) {
+  uint4 bottom = __detail::bit_cast<uint4>(D.xy);
+  uint4 top = __detail::bit_cast<uint4>(D.zw);
+  lowbits = uint4(bottom.x, bottom.z, top.x, top.z);
+  highbits = uint4(bottom.y, bottom.w, top.y, top.w);
+}
+
+void asuint(double3 D, out uint3 lowbits, out uint3 highbits) {
+  uint4 bottom = __detail::bit_cast<uint4>(D.xy);
+  uint2 top = __detail::bit_cast<uint2>(D.z);
+  lowbits = uint3(bottom.x, bottom.z, top.x);
+  highbits = uint3(bottom.y, bottom.w, top.y);
+}
+
+void asuint(double2 D, out uint2 lowbits, out uint2 highbits) {
+  uint4 bottom = __detail::bit_cast<uint4>(D.xy);
+  lowbits = uint2(bottom.x, bottom.z);
+  highbits = uint2(bottom.y, bottom.w);
+}
+
+void asuint(double D, out uint lowbits, out uint highbits) {
----------------
llvm-beanz wrote:

If we're going to do standalone functions these should be `constexpr`.

https://github.com/llvm/llvm-project/pull/109331


More information about the cfe-commits mailing list