From 572d38feef2fb5ae765bba63cfb2d5f08f05633a Mon Sep 17 00:00:00 2001 From: BlackMark Date: Wed, 12 Aug 2026 14:40:20 +0200 Subject: [PATCH] build: the libavr pin advances past the audit sweep, and the extents get counted The pin crosses libavr's phase-6 close and the guideline sweep behind it; the example is byte-identical on both chips in both modes. The port's own sweep found rule 36 in seven places, and the fix had to be measured rather than applied. Sakamoto's month offsets as a `std::to_array` local cost **+348 bytes** on a 1480-byte image - an automatic class-type constant inside a `constexpr` function is given an address and built per call, which outlined `weekday()` whole and pulled in `__do_copy_data` and `__udivmodhi4`; `static constexpr` is what folds it, and emits no symbol at all. The six register buffers cost +4 as `to_array`, which materialises its argument array before copying where an aggregate initialiser stores each element as it is computed - so those take CTAD, which counts the extent and keeps the direct initialisation. Both spellings are rule 36; only one is free. Co-Authored-By: Claude Opus 5 --- include/ds3231/ds3231.hpp | 48 ++++++++++++++++++--------------------- libavr | 2 +- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/include/ds3231/ds3231.hpp b/include/ds3231/ds3231.hpp index bd9d8b3..4f8a269 100644 --- a/include/ds3231/ds3231.hpp +++ b/include/ds3231/ds3231.hpp @@ -81,7 +81,7 @@ constexpr std::uint8_t hours_from_reg(std::uint8_t reg) // this maps Sunday to 1. constexpr std::uint8_t weekday(std::uint16_t year, std::uint8_t month, std::uint8_t day) { - constexpr std::uint8_t offsets[]{0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; + static constexpr auto offsets = std::to_array({0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}); if (month < 3) { --year; } @@ -151,34 +151,32 @@ class device { [[nodiscard]] static status write_clock(const date_time &now) { - std::array raw{detail::to_bcd(now.second), - detail::to_bcd(now.minute), - detail::to_bcd(now.hour), - SetWeekday ? detail::weekday(now.year, now.month, now.day) : std::uint8_t{1}, - detail::to_bcd(now.day), - detail::to_bcd(now.month), - detail::to_bcd(static_cast(now.year % 100))}; + std::array raw{detail::to_bcd(now.second), + detail::to_bcd(now.minute), + detail::to_bcd(now.hour), + SetWeekday ? detail::weekday(now.year, now.month, now.day) : std::uint8_t{1}, + detail::to_bcd(now.day), + detail::to_bcd(now.month), + detail::to_bcd(static_cast(now.year % 100))}; return dev::write_regs(reg_clock, raw); } [[nodiscard]] static status write_date(const date &value) { if constexpr (SetWeekday) { - std::array raw{detail::weekday(value.year, value.month, value.day), - detail::to_bcd(value.day), detail::to_bcd(value.month), - detail::to_bcd(static_cast(value.year % 100))}; + std::array raw{detail::weekday(value.year, value.month, value.day), detail::to_bcd(value.day), + detail::to_bcd(value.month), detail::to_bcd(static_cast(value.year % 100))}; return dev::write_regs(reg_clock + 3, raw); } else { - std::array raw{detail::to_bcd(value.day), detail::to_bcd(value.month), - detail::to_bcd(static_cast(value.year % 100))}; + std::array raw{detail::to_bcd(value.day), detail::to_bcd(value.month), + detail::to_bcd(static_cast(value.year % 100))}; return dev::write_regs(reg_clock + 4, raw); } } [[nodiscard]] static status write_time(const time_of_day &value) { - std::array raw{detail::to_bcd(value.second), detail::to_bcd(value.minute), - detail::to_bcd(value.hour)}; + std::array raw{detail::to_bcd(value.second), detail::to_bcd(value.minute), detail::to_bcd(value.hour)}; return dev::write_regs(reg_clock, raw); } @@ -187,12 +185,11 @@ class device { [[nodiscard]] static status set_alarm1(const date_time &at, alarm1_rate rate, bool enable_interrupt = true) { auto m = static_cast(rate); - std::array raw{ - static_cast(detail::to_bcd(at.second) | ((m & 1) << 7)), - static_cast(detail::to_bcd(at.minute) | (((m >> 1) & 1) << 7)), - static_cast(detail::to_bcd(at.hour) | (((m >> 2) & 1) << 7)), - static_cast(day_date(at.day, rate == alarm1_rate::weekday_time_match) | - (((m >> 3) & 1) << 7))}; + std::array raw{static_cast(detail::to_bcd(at.second) | ((m & 1) << 7)), + static_cast(detail::to_bcd(at.minute) | (((m >> 1) & 1) << 7)), + static_cast(detail::to_bcd(at.hour) | (((m >> 2) & 1) << 7)), + static_cast(day_date(at.day, rate == alarm1_rate::weekday_time_match) | + (((m >> 3) & 1) << 7))}; if (auto s = dev::write_regs(reg_alarm1, raw); !s) { return s; } @@ -202,11 +199,10 @@ class device { [[nodiscard]] static status set_alarm2(const date_time &at, alarm2_rate rate, bool enable_interrupt = true) { auto m = static_cast(rate); - std::array raw{ - static_cast(detail::to_bcd(at.minute) | ((m & 1) << 7)), - static_cast(detail::to_bcd(at.hour) | (((m >> 1) & 1) << 7)), - static_cast(day_date(at.day, rate == alarm2_rate::weekday_time_match) | - (((m >> 2) & 1) << 7))}; + std::array raw{static_cast(detail::to_bcd(at.minute) | ((m & 1) << 7)), + static_cast(detail::to_bcd(at.hour) | (((m >> 1) & 1) << 7)), + static_cast(day_date(at.day, rate == alarm2_rate::weekday_time_match) | + (((m >> 2) & 1) << 7))}; if (auto s = dev::write_regs(reg_alarm2, raw); !s) { return s; } diff --git a/libavr b/libavr index 07a0c40..4c7d4d6 160000 --- a/libavr +++ b/libavr @@ -1 +1 @@ -Subproject commit 07a0c4023564eb4bd72e33ff84399105390716e9 +Subproject commit 4c7d4d6ff3af35dc1593a7311a91a1410578e978