From 13ed247834f194c291b377dcf5f94b528ba1e356 Mon Sep 17 00:00:00 2001 From: KRM7 <70973547+KRM7@users.noreply.github.com> Date: Sun, 15 Sep 2024 16:30:36 +0200 Subject: [PATCH] Update rng.hpp --- .github/workflows/macos.yml | 2 +- .github/workflows/windows.yml | 5 ++++- src/utility/rng.hpp | 8 ++++---- src/utility/small_vector.hpp | 20 ++++++++------------ test/unit/small_vector.cpp | 1 - 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 9b059178..62bfcb90 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -17,7 +17,7 @@ jobs: { cxx: $(brew --prefix llvm@15)/bin/clang++, pkgs: llvm@15 gcc@11, - extra-flags: "-femulated-tls -stdlib=libstdc++ -stdlib++-isystem $(brew --prefix gcc@11)/include/c++/11 -cxx-isystem $(brew --prefix gcc@11)/include/c++/11/aarch64-apple-darwin23", + extra-flags: "-femulated-tls -stdlib=libstdc++ -stdlib++-isystem $(brew --prefix gcc@11)/include/c++/11 -cxx-isystem $(brew --prefix gcc@11)/include/c++/11/aarch64-apple-darwin23 -fsanitize=address -g -fno-omit-frame-pointer", linker-flags: "-L$(brew --prefix gcc@11)/lib/gcc/11" } ] diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 6f41a7e6..88035bdb 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -9,13 +9,16 @@ jobs: fail-fast: false matrix: build-type: [ Release, RelWithDebInfo ] - platform: [ x64 ] + platform: [ x64, Win32 ] generator: [ "Visual Studio 17 2022" ] compiler: [ { name: msvc, toolset: v143 }, { name: clang, toolset: ClangCL } ] build-shared: [ "ON", "OFF" ] + exclude: + - platform: Win32 + build-type: Release defaults: run: diff --git a/src/utility/rng.hpp b/src/utility/rng.hpp index 7fa8a378..3c223131 100644 --- a/src/utility/rng.hpp +++ b/src/utility/rng.hpp @@ -480,14 +480,14 @@ namespace gapp::rng GAPP_ASSERT(ubound >= lbound); GAPP_ASSERT(range_len >= count); - const bool select_many = (count > 0.6 * range_len); - const bool huge_range = (range_len >= 65536); + const bool select_many = std::cmp_greater_equal(count, size_t(0.6 * range_len)); + //const bool huge_range = std::cmp_greater_equal(range_len, 65536); - if (huge_range) [[unlikely]] return rng::sampleUniqueSet(lbound, ubound, count); + if (std::cmp_greater_equal(range_len, 65536)) return rng::sampleUniqueSet(lbound, ubound, count); small_vector numbers(count); - thread_local detail::dynamic_bitset is_selected; + /*thread_local */detail::dynamic_bitset is_selected; is_selected.resize(range_len); is_selected.fill(select_many); diff --git a/src/utility/small_vector.hpp b/src/utility/small_vector.hpp index 60decf5a..7e93e084 100644 --- a/src/utility/small_vector.hpp +++ b/src/utility/small_vector.hpp @@ -302,18 +302,17 @@ namespace gapp::detail struct small_vector_buffer { public: - constexpr small_vector_buffer() noexcept {}; // NOLINT(*default) - constexpr ~small_vector_buffer() noexcept {}; // NOLINT(*default) + small_vector_buffer() = default; - constexpr auto begin() noexcept { return std::begin(data_); } - constexpr auto begin() const noexcept { return std::begin(data_); } + auto begin() noexcept { return std::launder(reinterpret_cast(&data_)); } + auto begin() const noexcept { return std::launder(reinterpret_cast(&data_)); } - constexpr auto end() noexcept { return std::end(data_); } - constexpr auto end() const noexcept { return std::end(data_); } + auto end() noexcept { return begin() + Size; } + auto end() const noexcept { return begin() + Size; } - constexpr std::size_t size() const noexcept { return std::size(data_); } + constexpr std::size_t size() const noexcept { return Size; } private: - union { char dummy_ = {}; T data_[Size]; }; // NOLINT(*arrays) + alignas(T) unsigned char data_[Size * sizeof(T)] = {}; // NOLINT(*arrays) }; @@ -890,10 +889,7 @@ namespace gapp } private: - static constexpr std::size_t alignment = std::max(alignof(T), detail::cache_line_size); - - alignas(alignment) - GAPP_NO_UNIQUE_ADDRESS detail::small_vector_buffer buffer_; + detail::small_vector_buffer buffer_; pointer first_ = nullptr; pointer last_ = nullptr; pointer last_alloc_ = nullptr; diff --git a/test/unit/small_vector.cpp b/test/unit/small_vector.cpp index eac5e696..55210221 100644 --- a/test/unit/small_vector.cpp +++ b/test/unit/small_vector.cpp @@ -97,7 +97,6 @@ TEST_CASE("small_vector_size", "[object_layout][!mayfail]") // fails under clang STATIC_REQUIRE(std::is_standard_layout_v>); CHECK(sizeof(small_vector) == detail::cache_line_size); - CHECK(alignof(small_vector) == detail::cache_line_size); }