From 0954945e1613b419dfe2d0cdd058b4103a75d09a Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Mon, 30 Mar 2026 14:51:51 -0400 Subject: [PATCH] xo-procedure2 stack: + report-gc-object-ages() primitive --- include/xo/arena/AllocHeaderConfig.hpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/include/xo/arena/AllocHeaderConfig.hpp b/include/xo/arena/AllocHeaderConfig.hpp index d2b6db9..d574b29 100644 --- a/include/xo/arena/AllocHeaderConfig.hpp +++ b/include/xo/arena/AllocHeaderConfig.hpp @@ -60,6 +60,12 @@ namespace xo { std::uint64_t mkheader(std::uint64_t t, std::uint64_t a, std::uint64_t z) const noexcept { + + // don't let age wrap around. + // Expect std::min() to compile to cmov (no branch) + // + a = std::min(a, this->max_age()); + uint64_t tseq_bits = (t << (age_bits_ + size_bits_)) & tseq_mask(); uint64_t age_bits = (a << size_bits_) & age_mask(); uint64_t size_bits = z & size_mask();; @@ -75,12 +81,16 @@ namespace xo { return ((1ul << tseq_bits_) - 1) << (age_bits_ + size_bits_); } + std::uint64_t max_age() const noexcept { + return ((1ul << age_bits_) - 1); + } + std::uint64_t age_mask() const noexcept { // e.g. // 00 00 00 FF 00 00 00 00 // with age_bits=8, size_bits=32 // - return ((1ul << age_bits_) - 1) << size_bits_; + return this->max_age() << size_bits_; } std::uint64_t size_mask() const noexcept {