From b36663f9f3c7042a4c5a5c35245882961e4065ff Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 10 May 2024 22:52:45 -0500 Subject: [PATCH] Tweaked lfsr_attr_isnoop to assert on delta != 0 Now it is fit for purpose and can replace the explicit tag comparison + assert in lfsr_rbyd_appendattr. Previously we had to check if delta==0, but now we just assert that delta!=0 is invalid for noops. Unfortunately this added a couple bytes of code. The disassembly for lfsr_rbyd_appendattr is all shuffled up, so I guess this is just compiler noise. At least it's better than an explicit delta check: code stack before: 33820 2632 check delta: 33832 (+0.0%) 2632 (+0.0%) assert delta: 33828 (+0.0%) 2632 (+0.0%) --- lfs.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lfs.c b/lfs.c index d349397e..68d3be2e 100644 --- a/lfs.c +++ b/lfs.c @@ -1574,7 +1574,9 @@ static int lfsr_bd_progcat(lfs_t *lfs, // other attr helpers static inline bool lfsr_attr_isnoop(lfsr_attr_t attr) { - return !attr.tag && attr.delta == 0; + // noop attrs must have zero delta + LFS_ASSERT(attr.tag || attr.delta == 0); + return !attr.tag; } static inline bool lfsr_attr_isinsert(lfsr_attr_t attr) { @@ -2855,8 +2857,7 @@ static int lfsr_rbyd_appendattr(lfs_t *lfs, lfsr_rbyd_t *rbyd, LFS_ASSERT(attr.delta >= -(lfsr_srid_t)rbyd->weight); // ignore noops - if (!attr.tag) { - LFS_ASSERT(attr.delta == 0); + if (lfsr_attr_isnoop(attr)) { return 0; }