ckparity: Tweaked lfsr_data/ck_t to track parity

So instead of always reading the parity byte on demand, we read it once
in lfsr_bd_readtag, and store it in an unused bit in lfsr_data/ck_t.

The main reason for this is to avoid rereading that byte all the time.

Though I suppose there is also an ever-so-tiny increase in chance of
catching a bit-error after lfsr_bd_readtag. Assuming RAM is more
reliable than disk...

It also keeps the read-parity-byte mess limited to lfsr_bd_readtag, and
simplifies lfsr_bd_ckprefix/cksuffix a bit, which is nice. Though at the
cost of making lfsr_bd_readtag's API a bit most awkward with the
addition of the ckparity-specific parity_ parameter.

This adds a bit more code, but ends up saving some stack:

                    code          stack
  default before:  36412           2616
  default after:   36416 (+0.0%)   2616 (+0.0%)

  ckparity before: 37900           3048
  ckparity after:  37948 (+0.1%)   3032 (-0.5%)

The extra 4-bytes in our non-ckparity build comes from us moving the
saving of the ecksum to after checksum calculation, since we need to
know the parity in the ckparity build. So just compiler noise.
This commit is contained in:
Christopher Haster
2024-08-18 18:18:18 -05:00
parent fd50596dbc
commit 464311b2f8
2 changed files with 87 additions and 53 deletions
+1
View File
@@ -566,6 +566,7 @@ typedef struct lfsr_ck {
// sign(cksize)=1 => parity check
lfs_size_t cksize;
union {
// sign(ckoff) => parity
lfs_size_t ckoff;
uint32_t cksum;
} u;