From 2f0842cfb1b5addfa3fdb450bc76e3a23ead38f4 Mon Sep 17 00:00:00 2001 From: Jan Wassenberg Date: Thu, 10 Oct 2024 05:35:00 -0700 Subject: [PATCH] Minor formatting + DASSERT fixes Profiler: handle wraparound for very long zones (debug-only) aligned_allocator.h: fix constexpr naming aligned_allocator.cc: format PiperOrigin-RevId: 684409187 --- hwy/aligned_allocator.cc | 3 ++- hwy/aligned_allocator.h | 12 ++++++------ hwy/profiler.h | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/hwy/aligned_allocator.cc b/hwy/aligned_allocator.cc index b88a64e24e..e857b2288f 100644 --- a/hwy/aligned_allocator.cc +++ b/hwy/aligned_allocator.cc @@ -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); diff --git a/hwy/aligned_allocator.h b/hwy/aligned_allocator.h index 6274c5d192..e738c8be65 100644 --- a/hwy/aligned_allocator.h +++ b/hwy/aligned_allocator.h @@ -181,14 +181,14 @@ static inline constexpr size_t ShiftCount(size_t n) { template 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 } diff --git a/hwy/profiler.h b/hwy/profiler.h index a206c01413..467ac0c4bb 100644 --- a/hwy/profiler.h +++ b/hwy/profiler.h @@ -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; }