Skip to content

Commit

Permalink
Double the width of static allocations for empty tables
Browse files Browse the repository at this point in the history
  • Loading branch information
clarfonthey committed Dec 7, 2024
1 parent 6a4ed03 commit 8452ac7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
9 changes: 6 additions & 3 deletions src/control/group/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,23 @@ impl Group {
/// Number of bytes in the group.
pub(crate) const WIDTH: usize = mem::size_of::<Self>();

/// Double the group width; size of [`Group::static_empty`].
pub(crate) const DOUBLE_WIDTH: usize = Group::WIDTH * 2;

/// Returns a full group of empty tags, suitable for use as the initial
/// value for an empty hash table.
///
/// This is guaranteed to be aligned to the group size.
#[inline]
pub(crate) const fn static_empty() -> &'static [Tag; Group::WIDTH] {
pub(crate) const fn static_empty() -> &'static [Tag; Group::DOUBLE_WIDTH] {
#[repr(C)]
struct AlignedTags {
_align: [Group; 0],
tags: [Tag; Group::WIDTH],
tags: [Tag; Group::DOUBLE_WIDTH],
}
const ALIGNED_TAGS: AlignedTags = AlignedTags {
_align: [],
tags: [Tag::EMPTY; Group::WIDTH],
tags: [Tag::EMPTY; Group::DOUBLE_WIDTH],
};
&ALIGNED_TAGS.tags
}
Expand Down
9 changes: 6 additions & 3 deletions src/control/group/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ impl Group {
/// Number of bytes in the group.
pub(crate) const WIDTH: usize = mem::size_of::<Self>();

/// Double the group width; size of [`Group::static_empty`].
pub(crate) const DOUBLE_WIDTH: usize = Group::WIDTH * 2;

/// Returns a full group of empty tags, suitable for use as the initial
/// value for an empty hash table.
///
/// This is guaranteed to be aligned to the group size.
#[inline]
pub(crate) const fn static_empty() -> &'static [Tag; Group::WIDTH] {
pub(crate) const fn static_empty() -> &'static [Tag; Group::DOUBLE_WIDTH] {
#[repr(C)]
struct AlignedTags {
_align: [Group; 0],
tags: [Tag; Group::WIDTH],
tags: [Tag; Group::DOUBLE_WIDTH],
}
const ALIGNED_TAGS: AlignedTags = AlignedTags {
_align: [],
tags: [Tag::EMPTY; Group::WIDTH],
tags: [Tag::EMPTY; Group::DOUBLE_WIDTH],
};
&ALIGNED_TAGS.tags
}
Expand Down
9 changes: 6 additions & 3 deletions src/control/group/sse2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ impl Group {
/// Number of bytes in the group.
pub(crate) const WIDTH: usize = mem::size_of::<Self>();

/// Double the group width; size of [`Group::static_empty`].
pub(crate) const DOUBLE_WIDTH: usize = Group::WIDTH * 2;

/// Returns a full group of empty tags, suitable for use as the initial
/// value for an empty hash table.
///
/// This is guaranteed to be aligned to the group size.
#[inline]
#[allow(clippy::items_after_statements)]
pub(crate) const fn static_empty() -> &'static [Tag; Group::WIDTH] {
pub(crate) const fn static_empty() -> &'static [Tag; Group::DOUBLE_WIDTH] {
#[repr(C)]
struct AlignedTags {
_align: [Group; 0],
tags: [Tag; Group::WIDTH],
tags: [Tag; Group::DOUBLE_WIDTH],
}
const ALIGNED_TAGS: AlignedTags = AlignedTags {
_align: [],
tags: [Tag::EMPTY; Group::WIDTH],
tags: [Tag::EMPTY; Group::DOUBLE_WIDTH],
};
&ALIGNED_TAGS.tags
}
Expand Down

0 comments on commit 8452ac7

Please sign in to comment.