[clang] [llvm] [HLSL] Move `normalize` implementation to header files (PR #216228)
Farzon Lotfi via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 14 11:05:51 PDT 2026
================
@@ -28,6 +28,14 @@ length_impl(vector<T, N> X) {
#endif
}
+template <typename T> constexpr T normalize_impl(T X) {
+#if (__has_builtin(__builtin_spirv_normalize))
+ return __builtin_spirv_normalize(X);
+#else
+ return X * rsqrt(dot(X, X));
----------------
farzonl wrote:
you should do `X / length(X)`. Look at length implemented above it is just `sqrt(dot(X, X));` so that means X/sqrt(dot(X, X)); you are doing X * rsqrt(dot(X, X)) --> X * 1/sqrt(dot(X,X) which means you are doing an extra multiply which probably gets optomied away by O1 but still would be good not to do.
https://github.com/llvm/llvm-project/pull/216228
More information about the llvm-commits
mailing list