[clang] [llvm] Add normalize builtins and normalize HLSL function to DirectX and SPIR-V backend (PR #102683)

Joshua Batista via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 12 11:55:42 PDT 2024


================
@@ -4725,6 +4725,12 @@ def HLSLMad : LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLNormalize : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_normalize"];
----------------
bob80905 wrote:

I don't believe normalize is an elementwise operation. 
"elementwise" semantically means "for each element". We have operations like elementwise_log, and elementwise_pow, etc. What they do is apply a specific binary operation to each element in a vector. Applying log to each element of a vector is applying log "elementwise", for each element.
The normalize operation can never be applied to a singular element in a vector, it doesn't make sense to normalize a single vector element. Normalization always applies to the whole vector, although what is actually happening is a division across each element in the vector. 
So I don't think elementwise_normalize makes sense, because it doesn't make sense to normalize a singular vector element, say a float.

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


More information about the cfe-commits mailing list