From 8da08fe51ddaefb52cbe3b6404d4b1250490d7b1 Mon Sep 17 00:00:00 2001 From: Adam Cheney Date: Tue, 22 Oct 2024 13:31:13 -0400 Subject: [PATCH 1/2] Document bit operations Fixes #5307 --- source/slang/hlsl.meta.slang | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index ed011320c4..498f93c739 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -6960,6 +6960,10 @@ vector cospi(vector x) /// Population count. +/// Counts the number of set bits in the binary representation of a value. +/// @param value The value to count bits in. +/// @return The number of bits in the binary representation of `value` that are set to one. +/// @remarks For SPIR-V, this function maps to `OpBitCount`. /// @category bitops [__readNone] [ForceInline] @@ -8022,6 +8026,12 @@ vector faceforward(vector n, vector i, vector ng) } /// Find first set bit starting at high bit and working down. +/// @param value The signed value to find set bits in. +/// @return The bit index number of the most significant bit, +/// or returns -1 if `value` is either 0 or -1. +/// @remarks If `value` is positive, the bit index returned is the highest 1-bit. +/// If `value` is negative, the bit index returned is the highest 0-bit. +/// For SPIR-V, this function maps to GLSL extended instruction `FindSMsb`. /// @category bitops Bit operation functions [__readNone] [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] @@ -8060,6 +8070,11 @@ vector firstbithigh(vector value) } } +/// Find first set bit starting at high bit and working down. +/// @param value The unsigned value to find set bits in. +/// @return The bit index number of the most significant bit, +/// or all ones (-1 when interpretted as signed) if `value` is 0. +/// @remarks For SPIR-V, this function maps to GLSL extended instruction `FindUMsb`. [__readNone] [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] uint firstbithigh(uint value) @@ -8098,6 +8113,10 @@ vector firstbithigh(vector value) } /// Find first set bit starting at low bit and working up. +/// @param value The value to find set bits in. +/// @return The bit index number of the least significant set bit, +/// or all ones (-1 when interpretted as signed) if `value` is 0. +/// @remarks For SPIR-V, this function maps to GLSL extended instruction `FindILsb`. /// @category bitops [__readNone] [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] @@ -11080,6 +11099,9 @@ T refract(T i, T n, T eta) } /// Reverse order of bits. +/// @param value The value to reverse bits of. +/// @return The bits of `value`, reversed such that bit n of the result is equal to bit (width - 1 - n) of `value`. +/// @remarks For SPIR-V, this function maps to `OpBitReverse`. /// @category bitops [__readNone] [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] From 55347a086a992856f6e273a9188f5aaf6021754a Mon Sep 17 00:00:00 2001 From: Adam Cheney Date: Tue, 22 Oct 2024 13:59:42 -0400 Subject: [PATCH 2/2] Update hlsl.meta.slang --- source/slang/hlsl.meta.slang | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index 498f93c739..d399ad6906 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -8026,12 +8026,14 @@ vector faceforward(vector n, vector i, vector ng) } /// Find first set bit starting at high bit and working down. -/// @param value The signed value to find set bits in. +/// @param value The value to find set bits in. /// @return The bit index number of the most significant bit, -/// or returns -1 if `value` is either 0 or -1. -/// @remarks If `value` is positive, the bit index returned is the highest 1-bit. -/// If `value` is negative, the bit index returned is the highest 0-bit. -/// For SPIR-V, this function maps to GLSL extended instruction `FindSMsb`. +/// or returns -1 if `value` is either 0 if `value is +/// a signed type and equal to -1. +/// @remarks If `value` is unsigned, or signed with positive value, the bit index returned is the highest 1-bit. +/// If `value` is signed with negative value, the bit index returned is the highest 0-bit. +/// For SPIR-V, this function maps to GLSL extended instruction `FindSMsb` if `value` is signed, +/// or `FindUMsb` if `value` is unsigned. /// @category bitops Bit operation functions [__readNone] [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] @@ -8070,11 +8072,6 @@ vector firstbithigh(vector value) } } -/// Find first set bit starting at high bit and working down. -/// @param value The unsigned value to find set bits in. -/// @return The bit index number of the most significant bit, -/// or all ones (-1 when interpretted as signed) if `value` is 0. -/// @remarks For SPIR-V, this function maps to GLSL extended instruction `FindUMsb`. [__readNone] [require(cpp_cuda_glsl_hlsl_metal_spirv_wgsl, shader5_sm_5_0)] uint firstbithigh(uint value)