================
@@ -148,6 +148,29 @@ template <typename T> constexpr T ldexp_impl(T X, T Exp) {
   return exp2(Exp) * X;
 }
 
+template <typename T, int BitWidth> constexpr uint firstbithigh_impl(T X) {
+  uint FBH = __builtin_hlsl_elementwise_firstbithigh(X);
+#if defined(__DIRECTX__)
+  // The firstbithigh DXIL ops count bits from the wrong side, so we need to
+  // invert it for DirectX.
+  uint Inversion = (BitWidth - 1) - FBH;
+  FBH = select(FBH == -1, FBH, Inversion);
+#endif
+  return FBH;
+}
+
+template <typename T, int N, int BitWidth>
+constexpr vector<uint, N> firstbithigh_impl(vector<T, N> X) {
----------------
farzonl wrote:

Why do you need a vector implementation of this function?  Assuming the 
`Inversion` case is why you can't do something similar to`faceforward_impl` 
above?   If you make T have an arethmetic requirment can you do `T Inversion = 
(BitWidth - 1) - FBH;`?

https://github.com/llvm/llvm-project/pull/166419
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to