[clang] [llvm] [HLSL] Implement elementwise firstbitlow builtin (PR #116858)

Steven Perron via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 21 08:47:26 PST 2024


================
@@ -3158,6 +3172,166 @@ bool SPIRVInstructionSelector::selectFirstBitHigh(Register ResVReg,
   }
 }
 
+bool SPIRVInstructionSelector::selectFirstBitLow16(Register ResVReg,
+                                                   const SPIRVType *ResType,
+                                                   MachineInstr &I) const {
+  // OpUConvert treats the operand bits as an unsigned i16 and zero extends it
+  // to an unsigned i32. As this leaves all the least significant bits unchanged
+  // the first set bit from the LSB side doesn't change.
+  Register ExtReg = MRI->createVirtualRegister(GR.getRegClass(ResType));
+  bool Result = selectNAryOpWithSrcs(
+      ExtReg, ResType, I, {I.getOperand(2).getReg()}, SPIRV::OpUConvert);
----------------
s-perron wrote:

I was looking at the wrong version of the spec: https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html.

This version limits FindILsb to 32-bits components.

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


More information about the cfe-commits mailing list