From 7c6faf62158eed309f01bbef8a7b88e0c36459c7 Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Fri, 7 Jun 2024 09:48:24 -0400 Subject: Precompute UIntSet from individual capabilities inside generator (#4269) * fixes: #4163 Precompute UIntSet from individual capabilities inside generator (removes intermediate form of capabilities). note: 1. I still expand capabilities which are missing `target` and `stage` atoms. * fix compile warning<->error with clang * address review preallocate the pregenerated UIntSet's * disable incorrect warning of 'unreachable code' The warning is wrong since, when `out` has 0 elements (does not start `for` loop), the `return` is reached. * fix clang warnings 1. use unsigned long for the buffer serializer 2. braces around scalar init * address review added work around to avoid warning with `for(...) return; return;` pattern `else if constexpr` addition instead of cascading blocks * push fix for use of `_BitScanForward` * cleanup * move around assert for proper checking * syntax error * use SLANG_ASSERT instead of assert * test for why SLANG_ASSERT caused CI to fail with linux-arm builds * test if `SLANG_ASSERT` really is causing a build issue for linux-arm --- source/core/slang-uint-set.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source/core') diff --git a/source/core/slang-uint-set.h b/source/core/slang-uint-set.h index 7e08500fd..077bc7981 100644 --- a/source/core/slang-uint-set.h +++ b/source/core/slang-uint-set.h @@ -19,8 +19,10 @@ constexpr Index intLog2(unsigned x) return x == 1 ? 0 : 1 + intLog2(x >> 1); } +// if `in` is 0, result is undefined behavior static inline Index bitscanForward(uint64_t in) { + SLANG_ASSERT(in != 0); #if defined(_MSC_VER) #ifdef _WIN64 @@ -28,14 +30,12 @@ static inline Index bitscanForward(uint64_t in) _BitScanForward64((unsigned long*)&out, in); return Index(out); #else - constexpr uint32_t bitsInType = sizeof(uint32_t) * 8; uint32_t out; // check for 0s in 0bit->31bit. If all 0's, check for 0s in 32bit->63bit - _BitScanForward((unsigned long*)&out, *(((uint32_t*)&in) + 1)); - if (out != bitsInType) + if (_BitScanForward((unsigned long*)&out, *(((uint32_t*)&in) + 1))) return Index(out); _BitScanForward((unsigned long*)&out, *(((uint32_t*)&in))); - return Index(out + bitsInType); + return Index(out); #endif// #ifdef _WIN64 #else -- cgit v1.2.3