16void fill_2(std::span<uint32_t> out, uint32_t val0, uint32_t val1)
18 if (out.empty()) [[unlikely]]
return;
21 if (std::bit_cast<uintptr_t>(out.data()) &
alignof(uint32_t)) [[unlikely]] {
27 std::span<uint64_t> out64{std::bit_cast<uint64_t*>(out.data()), out.size() / 2};
28 uint64_t val64 =
Endian::BIG ? (uint64_t(val0) << 32) | val1
29 : val0 | (uint64_t(val1) << 32);
33 if (out.size() & 1) [[unlikely]] {
56 void insert(
void* aligned,
void* unaligned) {
58 assert(!
contains(allocMap, aligned, &Entry::aligned));
59 allocMap.emplace_back(Entry{aligned, unaligned});
63 if (!aligned)
return nullptr;
67 void* unaligned = it->unaligned;
75 assert(allocMap.empty());
83 std::vector<Entry> allocMap;
88 assert(
"must be a power of 2" && std::has_single_bit(alignment));
89 assert(alignment >=
sizeof(
void*));
90#if HAVE_POSIX_MEMALIGN
91 void* aligned =
nullptr;
92 if (posix_memalign(&aligned, alignment, size)) {
93 throw std::bad_alloc();
100 void* result = _aligned_malloc(size, alignment);
101 if (!result && size)
throw std::bad_alloc();
104 auto t = alignment - 1;
105 void* unaligned = malloc(size +
t);
107 throw std::bad_alloc();
109 auto aligned = std::bit_cast<void*>(
110 (std::bit_cast<uintptr_t>(unaligned) +
t) & ~
t);
118#if HAVE_POSIX_MEMALIGN
123#elif defined _MSC_VER
124 return _aligned_free(aligned);
Aligned memory (de)allocation.
AllocMap(const AllocMap &)=delete
static AllocMap & instance()
void insert(void *, void *unaligned)
AllocMap & operator=(AllocMap &&)=delete
AllocMap & operator=(const AllocMap &)=delete
AllocMap(AllocMap &&)=delete
void fill_2(std::span< uint32_t > out, uint32_t val0, uint32_t val1)
void * mallocAligned(size_t alignment, size_t size)
constexpr void fill(ForwardRange &&range, const T &value)
void move_pop_back(VECTOR &v, typename VECTOR::iterator it)
Erase the pointed to element from the given vector.
auto rfind_unguarded(RANGE &range, const VAL &val, Proj proj={})
Similar to the find(_if)_unguarded functions above, but searches from the back to front.
constexpr bool contains(ITER first, ITER last, const VAL &val)
Check if a range contains a given value, using linear search.