Skip to content

Commit

Permalink
Fix shift zero warning
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhao-ye committed Dec 13, 2024
1 parent ef2a538 commit c797563
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 5 additions & 2 deletions include/gcache/ghost_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class SampledGhostCache : public GhostCache<Hash, Meta> {
SampledGhostCache(uint32_t tick, uint32_t min_size, uint32_t max_size)
: GhostCache<Hash, Meta>(tick >> SampleShift, min_size >> SampleShift,
max_size >> SampleShift) {
static_assert(SampleShift <= 32, "SampleShift must be no larger than 32");
assert(tick % (1 << SampleShift) == 0);
assert(min_size % (1 << SampleShift) == 0);
assert(max_size % (1 << SampleShift) == 0);
Expand All @@ -186,8 +187,10 @@ class SampledGhostCache : public GhostCache<Hash, Meta> {
// Only update ghost cache if the first few bits of hash is all zero
void access(uint32_t block_id, AccessMode mode = AccessMode::DEFAULT) {
uint32_t hash = Hash{}(block_id);
if ((hash >> (32 - SampleShift)) == 0)
this->access_impl(block_id, hash, mode);
if constexpr (SampleShift > 0) {
if (hash >> (32 - SampleShift)) return;
}
this->access_impl(block_id, hash, mode);
}

[[nodiscard]] uint32_t get_tick() const { return this->tick << SampleShift; }
Expand Down
8 changes: 6 additions & 2 deletions include/gcache/ghost_kv_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class SampledGhostKvCache {

public:
SampledGhostKvCache(uint32_t tick, uint32_t min_count, uint32_t max_count)
: ghost_cache(tick, min_count, max_count) {}
: ghost_cache(tick, min_count, max_count) {
static_assert(SampleShift <= 32, "SampleShift must be no larger than 32");
}

void access(const std::string_view key, uint32_t kv_size,
AccessMode mode = AccessMode::DEFAULT) {
Expand All @@ -39,7 +41,9 @@ class SampledGhostKvCache {
void access(uint32_t key_hash, uint32_t kv_size,
AccessMode mode = AccessMode::DEFAULT) {
// only with certain number of leading zeros is sampled
if (key_hash >> (32 - SampleShift)) return;
if constexpr (SampleShift > 0) {
if (key_hash >> (32 - SampleShift)) return;
}
auto h = ghost_cache.access_impl(key_hash, key_hash, mode);
h->kv_size = kv_size;
}
Expand Down

0 comments on commit c797563

Please sign in to comment.