From 48003e9d32cc9efb83ae194c0519270dc711852f Mon Sep 17 00:00:00 2001 From: Sven van Haastregt Date: Thu, 4 Apr 2024 15:12:10 +0200 Subject: [PATCH] [NFC] subgroups: clarify bs128 to uint4 conversion (#1893) There appears to have been some confusion over `uint_mask` during the initial reviews of the subgroup tests. Add a comment to clarify the purpose of the mask. Use a 32-bit all-ones mask (`0xffffffff`) instead of a 64-bit all-ones mask to further clarify the intent, that is, don't delay discarding the upper 32 bits until the assignment but mask them out immediately. Fixes https://github.com/KhronosGroup/OpenCL-CTS/issues/1203 Signed-off-by: Sven van Haastregt --- test_conformance/subgroups/subhelpers.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test_conformance/subgroups/subhelpers.cpp b/test_conformance/subgroups/subhelpers.cpp index 0899ef9c..2e9753ff 100644 --- a/test_conformance/subgroups/subhelpers.cpp +++ b/test_conformance/subgroups/subhelpers.cpp @@ -102,8 +102,9 @@ cl_uint4 generate_bit_mask(cl_uint subgroup_local_id, if (mask_type == "gt") mask128.reset(pos); } - // convert std::bitset<128> to uint4 - auto const uint_mask = bs128{ static_cast(-1) }; + // convert std::bitset<128> to uint4. + // Use a mask to avoid std::overflow_error from to_ulong(). + auto const uint_mask = bs128{ 0xffffffff }; mask.s0 = (mask128 & uint_mask).to_ulong(); mask128 >>= 32; mask.s1 = (mask128 & uint_mask).to_ulong();