Tweaked mid to use sign-bit to indicate mroots
This is an intermediate commit as a part of a tangent into compressed
mids.
The idea here, is instead of using bid=-1 as a special value for mroots,
use only the top bit to indicate mroots. This allows you to compare
against the grm/other uninlined mids by masking instead of signed
comparison.
This is valuable for compressed mids since extracting bids relies on
knowledge of the block size, and becomes quite a bit more expensive.
mroot bid mroot cmp
before: 0xffffffff lfs_smax32(a, 0) == lfs_smax32(b, 0)
after: 0x80000000 (a & 0x7fffffff) == (b & 0x7fffffff)
The implementation here is a bit clumsy. I think GCC may be not that
great at optimizing out copies of structs being passed around via
inlined functions. But this is only a proof-of-concept.
This commit is contained in:
@@ -109,7 +109,7 @@ code = '''
|
||||
LFSR_ATTR(0, RM, -1, NULL))) => 0;
|
||||
|
||||
lfsr_mdir_t mdir;
|
||||
lfsr_mtree_lookup(&lfs, LFSR_MID(lfsr_mtree_weight(&lfs)-1, -1),
|
||||
lfsr_mtree_lookup(&lfs, LFSR_MID(0, -1),
|
||||
&mdir) => 0;
|
||||
mdir.mid.rid = 0;
|
||||
|
||||
@@ -144,8 +144,8 @@ code = '''
|
||||
|
||||
// test that all of our metadata entries are still there
|
||||
lfs_size_t i = 0;
|
||||
for (lfs_ssize_t mid = (lfsr_mtree_isinlined(&lfs) ? -1 : 0);
|
||||
mid < (lfs_ssize_t)lfsr_mtree_weight(&lfs);
|
||||
for (lfs_ssize_t mid = 0;
|
||||
mid < lfs_smax32(lfsr_mtree_weight(&lfs), 1);
|
||||
mid++) {
|
||||
lfsr_mdir_t mdir;
|
||||
lfsr_mtree_lookup(&lfs, LFSR_MID(mid, -1), &mdir) => 0;
|
||||
|
||||
Reference in New Issue
Block a user