4#include <pixie/storage/read_only_view.h>
14inline constexpr std::size_t kAlignedStorageLineBytes = 64;
15inline constexpr std::size_t kAlignedStorageLineBits =
16 kAlignedStorageLineBytes * 8;
17inline constexpr std::size_t kAlignedStorageLineWords64 =
18 kAlignedStorageLineBytes /
sizeof(std::uint64_t);
19inline constexpr std::size_t kAlignedStorageLineWords16 =
20 kAlignedStorageLineBytes /
sizeof(std::uint16_t);
24 std::array<std::byte, kAlignedStorageLineBytes> data{};
27static_assert(
alignof(
CacheLine) == kAlignedStorageLineBytes);
28static_assert(
sizeof(
CacheLine) == kAlignedStorageLineBytes);
39 AlignedStorage() =
default;
47 return data_.size() * kAlignedStorageLineBytes;
52 return std::as_bytes(std::span<const CacheLine>(data_));
57 std::size_t count_bytes)
const {
60 throw std::out_of_range(
"Storage view is outside the allocation");
73 return std::as_writable_bytes(std::span<CacheLine>(data_));
78 return {
reinterpret_cast<std::uint16_t*
>(data_.data()),
79 data_.size() * kAlignedStorageLineWords16};
84 return {
reinterpret_cast<std::uint64_t*
>(data_.data()),
85 data_.size() * kAlignedStorageLineWords64};
90 return data_.capacity() * kAlignedStorageLineBytes;
97 std::span<CacheLine>
as_lines() {
return data_; }
100 std::span<const CacheLine>
as_lines()
const {
return data_; }
103 static constexpr std::size_t lines_for_bits(std::size_t size_bits) {
104 return size_bits / kAlignedStorageLineBits +
105 (size_bits % kAlignedStorageLineBits != 0);
108 std::vector<CacheLine> data_;
std::span< CacheLine > as_lines()
Return mutable cache-line blocks.
Definition aligned.h:97
void shrink_to_fit_impl()
Request release of unused vector capacity.
Definition aligned.h:94
AlignedStorage(std::size_t size_bits)
Construct storage for at least size_bits bits.
Definition aligned.h:42
std::span< const CacheLine > as_lines() const
Return read-only cache-line blocks.
Definition aligned.h:100
std::size_t size_bytes_impl() const
Return the padded allocation size in bytes.
Definition aligned.h:46
void resize_impl(std::size_t size_bits)
Resize to hold at least size_bits bits.
Definition aligned.h:67
std::size_t allocated_bytes_impl() const
Return bytes reserved by the underlying vector.
Definition aligned.h:89
std::span< const std::byte > as_bytes_impl() const
Return the padded allocation as read-only bytes.
Definition aligned.h:51
std::span< std::byte > writable_bytes_impl()
Return writable allocation bytes.
Definition aligned.h:72
ReadOnlyStorageView view_impl(std::size_t offset_bytes, std::size_t count_bytes) const
Return a checked read-only byte subrange.
Definition aligned.h:56
std::span< std::uint64_t > writable_words64_impl()
Return writable allocation as 64-bit words.
Definition aligned.h:83
std::span< std::uint16_t > writable_words16_impl()
Return writable allocation as 16-bit words.
Definition aligned.h:77
A non-owning, read-only view of a byte sequence.
Definition read_only_view.h:17
CRTP facade for byte-addressable storage.
Definition storage.h:27
std::size_t size_bits() const
Definition storage.h:33
Common interface for byte-addressable storage.
A 64-byte aligned storage block.
Definition aligned.h:23