Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lfs.c
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2017-10-18 08:33:59 +0300
committerChristopher Haster <chaster@utexas.edu>2017-10-30 20:03:33 +0300
commit0825d34f3dac9718ebf03a56f51ba3613b3cfb4e (patch)
tree3bc41bad6ed3bb93164bc3271c596fe6d1536590 /lfs.c
parent46e22b2a383528b0733971f8f84550bc6754b939 (diff)
Adopted alternative implementation for lfs_ctz_index
Same runtime cost, however reduces the logic and avoids one of the two big branches. See the DESIGN.md for more info. Now uses these equations instead of the messy guess and correct method: n = (N - w/8(popcount(N/(B-2w/8)) + 2)) / (B-2w/8) off = N - (B-w2/8)n - w/8popcount(n)
Diffstat (limited to 'lfs.c')
-rw-r--r--lfs.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/lfs.c b/lfs.c
index 927e7c8..2859783 100644
--- a/lfs.c
+++ b/lfs.c
@@ -1005,21 +1005,15 @@ int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir) {
/// File index list operations ///
static int lfs_ctz_index(lfs_t *lfs, lfs_off_t *off) {
lfs_off_t size = *off;
- lfs_off_t i = size / (lfs->cfg->block_size-2*4);
+ lfs_off_t b = lfs->cfg->block_size - 2*4;
+ lfs_off_t i = size / b;
if (i == 0) {
return 0;
}
- lfs_off_t nsize = (lfs->cfg->block_size-2*4)*i + 4*lfs_popc(i-1) + 2*4;
- lfs_soff_t noff = size - nsize;
-
- if (noff < 0) {
- *off = noff + lfs->cfg->block_size;
- return i-1;
- } else {
- *off = noff + 4*(lfs_ctz(i) + 1);
- return i;
- }
+ i = (size - 4*(lfs_popc(i-1)+2)) / b;
+ *off = size - b*i - 4*lfs_popc(i);
+ return i;
}
static int lfs_ctz_find(lfs_t *lfs,