Dropped the q-bit (previous-perturb) from cksum tags

Now that we perturb commit cksums with the odd-parity zero, the q-bit no
longer serves a purpose other than extra debug info. But this is a
double-edged sword, because redundant info just means another thing that
can go wrong.

For example, should we assert? If the q-bit doesn't reflect the
previous-perturb state it's a bug, but the only thing that would break
would be the q-bit itself. And if we don't assert what's the point of
keeping the q-bit around?

Dropping the q-bit avoids answering this question and saves a bit of
code:

           code          stack          ctx
  before: 37772           2608          620
  after:  37768 (-0.0%)   2608 (+0.0%)  620 (+0.0%)
This commit is contained in:
Christopher Haster
2025-01-10 15:55:48 -06:00
parent d08d254cd2
commit b6ab323eb1
7 changed files with 22 additions and 45 deletions
+1 -11
View File
@@ -1157,7 +1157,6 @@ enum lfsr_tag {
// checksum tags
LFSR_TAG_CKSUM = 0x3000,
LFSR_TAG_P = 0x0001,
LFSR_TAG_Q = 0x0002,
LFSR_TAG_NOTE = 0x3100,
LFSR_TAG_ECKSUM = 0x3200,
@@ -1229,10 +1228,6 @@ static inline bool lfsr_tag_p(lfsr_tag_t tag) {
return tag & LFSR_TAG_P;
}
static inline bool lfsr_tag_q(lfsr_tag_t tag) {
return tag & LFSR_TAG_Q;
}
static inline bool lfsr_tag_isinternal(lfsr_tag_t tag) {
return tag & LFSR_TAG_INTERNAL;
}
@@ -2821,9 +2816,6 @@ static int lfsr_rbyd_fetch(lfs_t *lfs, lfsr_rbyd_t *rbyd,
break;
}
// if checksums match, perturb bits should also match
LFS_ASSERT(lfsr_tag_q(tag) == lfsr_rbyd_isperturb(rbyd));
// save what we've found so far
rbyd->eoff
= ((lfs_size_t)lfsr_tag_p(tag)
@@ -4046,8 +4038,6 @@ static int lfsr_rbyd_appendcksum(lfs_t *lfs, lfsr_rbyd_t *rbyd) {
// set the valid bit to the cksum parity
| ((uint8_t)v << 7);
cksum_buf[1] = (uint8_t)(LFSR_TAG_CKSUM >> 0)
// include the current perturb bit
| ((uint8_t)lfsr_rbyd_isperturb(rbyd) << 1)
// set the perturb bit so next commit is invalid
| ((uint8_t)perturb << 0);
cksum_buf[2] = 0;
@@ -4063,7 +4053,7 @@ static int lfsr_rbyd_appendcksum(lfs_t *lfs, lfsr_rbyd_t *rbyd) {
// calculate the commit checksum
cksum_ = lfs_crc32c(cksum_, cksum_buf, 2+1+4);
// and perturb, perturbing the commit checksum avoids a perturb hole
// after the last valid bit without needing to manually validate q
// after the last valid bit
//
// note the odd-parity zero preserves our position in the crc32c
// ring while only changing the parity