From ee50dc5307835b096cd9387ed81a41498e92070f Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 4 Dec 2025 00:33:05 -0600 Subject: [PATCH] Added shift-table hack comment to lfs3_tag_mask Was reading through some old commits (7cd4c1f), and realized this should really be committed into the code. --- lfs3.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lfs3.c b/lfs3.c index 3026aee9..70d52a63 100644 --- a/lfs3.c +++ b/lfs3.c @@ -1107,7 +1107,20 @@ static inline bool lfs3_tag_ismask12(lfs3_tag_t tag) { } static inline lfs3_tag_t lfs3_tag_mask(lfs3_tag_t tag) { + // this is based off the parity impl in Sean Eron Anderson's Bit + // Twiddling Hacks, who attributes the idea to Mathew Hendry + // + // basically the idea is to encode a small lookup table in an + // integer, and extract using a shift + mask + // + // .-- LFS3_tag_MASK0 + // .|-- LFS3_tag_MASK2 + // .||-- LFS3_tag_MASK8 + // .|||-- LFS3_tag_MASK12 + // vvvv return 0x0fff & (-1U << ((0xc820 >> (4*((tag >> 12) & 0x3))) & 0xf)); + // '--.-' ^ '--------.--------' + // key mask gcc complains w/o this mask bits } // alt operations