Skip to content

Commit

Permalink
Update rng.hpp
Browse files Browse the repository at this point in the history
  • Loading branch information
KRM7 committed Sep 16, 2024
1 parent a12b17a commit 3ace736
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions src/utility/rng.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<IntType> 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);

Expand Down
22 changes: 9 additions & 13 deletions src/utility/small_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
auto begin() noexcept { return std::launder(reinterpret_cast<T*>(&data_)); }
auto begin() const noexcept { return std::launder(reinterpret_cast<const T*>(&data_)); }

constexpr auto begin() noexcept { return std::begin(data_); }
constexpr auto begin() const noexcept { return std::begin(data_); }
auto end() noexcept { return begin() + Size; }
auto end() const noexcept { return begin() + Size; }

constexpr auto end() noexcept { return std::end(data_); }
constexpr auto end() const noexcept { return std::end(data_); }

constexpr std::size_t size() const noexcept { return std::size(data_); }
std::size_t size() const noexcept { return Size; }
private:
union { char dummy_ = {}; T data_[Size]; }; // NOLINT(*arrays)
using buffer_t = unsigned char[Size * sizeof(T)];

alignas(T) buffer_t GAPP_MAY_ALIAS data_ = {};
};


Expand Down Expand Up @@ -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<T, Size> buffer_;
detail::small_vector_buffer<T, Size> buffer_;
pointer first_ = nullptr;
pointer last_ = nullptr;
pointer last_alloc_ = nullptr;
Expand Down
7 changes: 7 additions & 0 deletions src/utility/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@
#endif


#if defined(__GNUC__) || defined(__clang__)
# define GAPP_MAY_ALIAS __attribute__((may_alias))
#else
# define GAPP_MAY_ALIAS
#endif


#if defined(__GNUC__) || defined(__clang__)
# define GAPP_NOINLINE __attribute((noinline))
#elif defined(_MSC_VER)
Expand Down
1 change: 0 additions & 1 deletion test/unit/small_vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ TEST_CASE("small_vector_size", "[object_layout][!mayfail]") // fails under clang
STATIC_REQUIRE(std::is_standard_layout_v<small_vector<int>>);

CHECK(sizeof(small_vector<int>) == detail::cache_line_size);
CHECK(alignof(small_vector<int>) == detail::cache_line_size);
}


Expand Down

0 comments on commit 3ace736

Please sign in to comment.