Skip to content

Commit

Permalink
Minor formatting + DASSERT fixes
Browse files Browse the repository at this point in the history
Profiler: handle wraparound for very long zones (debug-only)
aligned_allocator.h: fix constexpr naming
aligned_allocator.cc: format
PiperOrigin-RevId: 684409187
  • Loading branch information
jan-wassenberg authored and copybara-github committed Oct 10, 2024
1 parent bb6c3f3 commit 2f0842c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion hwy/aligned_allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
namespace hwy {
namespace {

#if HWY_ARCH_RISCV && defined(__riscv_v_intrinsic) && __riscv_v_intrinsic >= 11000
#if HWY_ARCH_RISCV && defined(__riscv_v_intrinsic) && \
__riscv_v_intrinsic >= 11000
// Not actually an upper bound on the size, but this value prevents crossing a
// 4K boundary (relevant on Andes).
constexpr size_t kAlignment = HWY_MAX(HWY_ALIGNMENT, 4096);
Expand Down
12 changes: 6 additions & 6 deletions hwy/aligned_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,14 @@ static inline constexpr size_t ShiftCount(size_t n) {

template <typename T>
T* AllocateAlignedItems(size_t items, AllocPtr alloc_ptr, void* opaque_ptr) {
constexpr size_t size = sizeof(T);
constexpr size_t kSize = sizeof(T);

constexpr bool is_pow2 = (size & (size - 1)) == 0;
constexpr size_t bits = ShiftCount(size);
static_assert(!is_pow2 || (1ull << bits) == size, "ShiftCount is incorrect");
constexpr bool kIsPow2 = (kSize & (kSize - 1)) == 0;
constexpr size_t kBits = ShiftCount(kSize);
static_assert(!kIsPow2 || (1ull << kBits) == kSize, "ShiftCount has a bug");

const size_t bytes = is_pow2 ? items << bits : items * size;
const size_t check = is_pow2 ? bytes >> bits : bytes / size;
const size_t bytes = kIsPow2 ? items << kBits : items * kSize;
const size_t check = kIsPow2 ? bytes >> kBits : bytes / kSize;
if (check != items) {
return nullptr; // overflowed
}
Expand Down
2 changes: 1 addition & 1 deletion hwy/profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Packet {
(biased_offset << kTimestampBits) + (timestamp & kTimestampMask);

HWY_DASSERT(packet.BiasedOffset() == biased_offset);
HWY_DASSERT(packet.Timestamp() == timestamp);
HWY_DASSERT(packet.Timestamp() == (timestamp & kTimestampMask));
return packet;
}

Expand Down

0 comments on commit 2f0842c

Please sign in to comment.