From 2ed52bf0d181da1d9fd165cc31ab5384771bee91 Mon Sep 17 00:00:00 2001 From: Rutger van Bergen Date: Thu, 7 Nov 2024 08:22:22 +0100 Subject: [PATCH] Revert "Walk prebuilt mask through memory for small steps" --- PrimeCPP/solution_2/PrimeCPP_PAR.cpp | 59 +--------------------------- 1 file changed, 1 insertion(+), 58 deletions(-) diff --git a/PrimeCPP/solution_2/PrimeCPP_PAR.cpp b/PrimeCPP/solution_2/PrimeCPP_PAR.cpp index fe79df276..3345d6505 100644 --- a/PrimeCPP/solution_2/PrimeCPP_PAR.cpp +++ b/PrimeCPP/solution_2/PrimeCPP_PAR.cpp @@ -61,64 +61,7 @@ class BitArray { array[index(n)] |= (uint8_t(1) << (n % 8)); } - static constexpr uint32_t buildSkipMask(size_t skip, size_t offset) - { - uint32_t mask = 0; - for (size_t i = offset; i < 32; i += skip) { - mask |= (1u << i); - } - return ~mask; - } - - uint32_t rol(uint32_t value, size_t bits) - { - bits %= 32; - if (bits == 0) - return value; - // Ensure that the number of bits to rotate is within 0-31 - return (value << bits) | (value >> (32 - bits)); - } - - void setFlagsFalse(size_t n, size_t skip) - { - if (skip <= 12) { - // For small skips, use pre-built mask approach - size_t word_idx = index(n); - size_t bit_pos = n % 32; - size_t curr_n = n; - - while (curr_n < size()) - { - // Build mask for current word starting at bit_pos - uint32_t mask = buildSkipMask(skip, bit_pos); - - // Apply mask to current word - array[word_idx] &= mask; - - // Move to next word - size_t bits_remaining = 32 - bit_pos; - curr_n += ((bits_remaining + skip - 1) / skip) * skip; - - if (curr_n >= size()) break; - - word_idx = index(curr_n); - bit_pos = curr_n % 32; - } - } - else - { - // Original implementation for larger skips - auto rolling_mask = ~uint32_t(1 << (n % 32)); - auto roll_bits = skip % 32; - while (n < size()) { - array[index(n)] &= rolling_mask; - n += skip; - rolling_mask = rol(rolling_mask, roll_bits); - } - } - } - - inline size_t size() const + constexpr size_t size() const { return logicalSize; }