t: Dropped mtinfo/btinfo, just use data/bptr for everything

It's probably a bad reason, but this avoids wasting too much time
figuring out how to name things.

Now most traversal functions return an lfsr_tag_t + lfsr_bptr_t pair,
which is enough to describe the current relevant traversal objects:

  tag=LFSR_TAG_MDIR   => (lfsr_mdir_t*)bptr.data.u.buffer
  tag=LFSR_TAG_BRANCH => (lfsr_rbyd_t*)bptr.data.u.buffer
  tag=LFSR_TAG_DATA   => bptr.data
  tag=LFSR_TAG_BPTR   => bptr

This would be a bit better if lfsr_data_t's buffer field was a void*,
but that would mess with byte-level arithmetic, which is more common
with lfsr_data_ts.

This also adopts the fragmented/optional out-params used elsewhere in
the codebase. I thought this would add quite a bit more stack cost,
since we need redundant tags/bptrs to make lfsr_mtree_traverse/
lfsr_mtree_gc work, but surprisingly not:

           code          stack
  before: 35256           2680
  after:  35228 (-0.1%)   2680 (+0.0%)

It seems we make up the extra stack cost of redundant tags/bptrs by
giving the compiler more stack-alloc flexibility, tighter per-function
return types, and opting-out of tags/bptrs in most low-level traversals:
lfs_alloc mainly.

But if the fragmented/optional out-params is net harmful for code/stack
size, we should reconsider the pattern system-wide. This does probably
deserve a second look in the future...
This commit is contained in:
Christopher Haster
2024-07-05 14:54:38 -05:00
parent 96834c2460
commit 2e6a5be4e3
6 changed files with 486 additions and 384 deletions
+26 -22
View File
@@ -4098,34 +4098,36 @@ code = '''
assert(i <= 2*N);
lfsr_bid_t bid;
lfsr_btinfo_t btinfo;
int err = lfsr_btree_traverse(&lfs, &btree, &bt, &bid, &btinfo);
lfsr_tag_t tag;
lfsr_data_t data;
int err = lfsr_btree_traverse(&lfs, &btree, &bt,
&bid, &tag, &data);
assert(!err || err == LFS_ERR_NOENT);
if (err == LFS_ERR_NOENT) {
break;
}
if (btinfo.tag == LFSR_TAG_BRANCH) {
if (tag == LFSR_TAG_BRANCH) {
lfsr_rbyd_t *rbyd = (lfsr_rbyd_t*)data.u.buffer;
printf("traversal: %d 0x%x btree 0x%x.%x\n",
bid,
btinfo.tag,
btinfo.u.rbyd->blocks[0], btinfo.u.rbyd->trunk);
tag,
rbyd->blocks[0], rbyd->trunk);
// keep track of seen blocks
seen[btinfo.u.rbyd->blocks[0] / 8]
|= 1 << (btinfo.u.rbyd->blocks[0] % 8);
seen[rbyd->blocks[0] / 8] |= 1 << (rbyd->blocks[0] % 8);
} else if (btinfo.tag == LFSR_TAG_DATA) {
} else if (tag == LFSR_TAG_DATA) {
printf("traversal: %d 0x%x data %d\n",
bid,
btinfo.tag,
lfsr_data_size(btinfo.u.data));
tag,
lfsr_data_size(data));
} else {
// well this shouldn't happen
printf("traversal: %d 0x%x\n",
bid,
btinfo.tag);
tag);
assert(false);
}
}
@@ -4247,34 +4249,36 @@ code = '''
assert(i <= 2*N);
lfsr_bid_t bid;
lfsr_btinfo_t btinfo;
int err = lfsr_btree_traverse(&lfs, &btree, &bt, &bid, &btinfo);
lfsr_tag_t tag;
lfsr_data_t data;
int err = lfsr_btree_traverse(&lfs, &btree, &bt,
&bid, &tag, &data);
assert(!err || err == LFS_ERR_NOENT);
if (err == LFS_ERR_NOENT) {
break;
}
if (btinfo.tag == LFSR_TAG_BRANCH) {
if (tag == LFSR_TAG_BRANCH) {
lfsr_rbyd_t *rbyd = (lfsr_rbyd_t*)data.u.buffer;
printf("traversal: %d 0x%x btree 0x%x.%x\n",
bid,
btinfo.tag,
btinfo.u.rbyd->blocks[0], btinfo.u.rbyd->trunk);
tag,
rbyd->blocks[0], rbyd->trunk);
// keep track of seen blocks
seen[btinfo.u.rbyd->blocks[0] / 8]
|= 1 << (btinfo.u.rbyd->blocks[0] % 8);
seen[rbyd->blocks[0] / 8] |= 1 << (rbyd->blocks[0] % 8);
} else if (btinfo.tag == LFSR_TAG_DATA) {
} else if (tag == LFSR_TAG_DATA) {
printf("traversal: %d 0x%x data %d\n",
bid,
btinfo.tag,
lfsr_data_size(btinfo.u.data));
tag,
lfsr_data_size(data));
} else {
// well this shouldn't happen
printf("traversal: %d 0x%x\n",
bid,
btinfo.tag);
tag);
assert(false);
}
}