Added lfs_crc32c_cube, replacing lfsr_gcksum_cube
This is a bit on the edge of what is a reasonable to shove in lfs_util.h. But it's useful enough that we were giving it its own function anyways, and moving it to lfs_util.h allows it to be potentially overriden with cube-specific optimizations (expanded terms?). No code changes.
This commit is contained in:
@@ -3967,9 +3967,6 @@ leaf:;
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// needed in lfsr_rbyd_appendcksum
|
|
||||||
static uint32_t lfsr_gcksum_cube(uint32_t gcksum);
|
|
||||||
|
|
||||||
static int lfsr_rbyd_appendcksum_(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
static int lfsr_rbyd_appendcksum_(lfs_t *lfs, lfsr_rbyd_t *rbyd,
|
||||||
uint32_t cksum) {
|
uint32_t cksum) {
|
||||||
// align to the next prog unit
|
// align to the next prog unit
|
||||||
@@ -6818,14 +6815,6 @@ static void lfsr_fs_mkdirty(lfs_t *lfs) {
|
|||||||
|
|
||||||
/// Global-state things ///
|
/// Global-state things ///
|
||||||
|
|
||||||
// gcksum (global checksum) things
|
|
||||||
|
|
||||||
// cubing the gcksum prevents trivial gcksumdeltas
|
|
||||||
static uint32_t lfsr_gcksum_cube(uint32_t gcksum) {
|
|
||||||
return lfs_crc32c_mul(lfs_crc32c_mul(gcksum, gcksum), gcksum);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// grm (global remove) things
|
// grm (global remove) things
|
||||||
static inline uint8_t lfsr_grm_count_(const lfsr_grm_t *grm) {
|
static inline uint8_t lfsr_grm_count_(const lfsr_grm_t *grm) {
|
||||||
return (grm->mids[0] >= 0) + (grm->mids[1] >= 0);
|
return (grm->mids[0] >= 0) + (grm->mids[1] >= 0);
|
||||||
@@ -7741,8 +7730,8 @@ static int lfsr_mdir_commit__(lfs_t *lfs, lfsr_mdir_t *mdir,
|
|||||||
// append gkcsumdelta?
|
// append gkcsumdelta?
|
||||||
if (start_rid <= -2) {
|
if (start_rid <= -2) {
|
||||||
// figure out changes to our gcksumdelta
|
// figure out changes to our gcksumdelta
|
||||||
mdir->gcksumdelta ^= lfsr_gcksum_cube(lfs->gcksum_p)
|
mdir->gcksumdelta ^= lfs_crc32c_cube(lfs->gcksum_p)
|
||||||
^ lfsr_gcksum_cube(lfs->gcksum ^ cksum)
|
^ lfs_crc32c_cube(lfs->gcksum ^ cksum)
|
||||||
^ lfs->gcksum_d;
|
^ lfs->gcksum_d;
|
||||||
|
|
||||||
uint8_t gcksumdelta_buf[LFSR_LE32_DSIZE];
|
uint8_t gcksumdelta_buf[LFSR_LE32_DSIZE];
|
||||||
@@ -13982,10 +13971,10 @@ static int lfsr_mountinited(lfs_t *lfs) {
|
|||||||
// 1->1 mapping of t(g) in 2^31 fields, and losing at most 3-bits of
|
// 1->1 mapping of t(g) in 2^31 fields, and losing at most 3-bits of
|
||||||
// info when calculating d_i.
|
// info when calculating d_i.
|
||||||
//
|
//
|
||||||
if (lfsr_gcksum_cube(lfs->gcksum) != lfs->gcksum_d) {
|
if (lfs_crc32c_cube(lfs->gcksum) != lfs->gcksum_d) {
|
||||||
LFS_ERROR("Found gcksum mismatch, cksum^3 %08"PRIx32" "
|
LFS_ERROR("Found gcksum mismatch, cksum^3 %08"PRIx32" "
|
||||||
"(!= %08"PRIx32")",
|
"(!= %08"PRIx32")",
|
||||||
lfsr_gcksum_cube(lfs->gcksum),
|
lfs_crc32c_cube(lfs->gcksum),
|
||||||
lfs->gcksum_d);
|
lfs->gcksum_d);
|
||||||
return LFS_ERR_CORRUPT;
|
return LFS_ERR_CORRUPT;
|
||||||
}
|
}
|
||||||
@@ -14211,7 +14200,7 @@ static int lfsr_formatinited(lfs_t *lfs) {
|
|||||||
uint8_t gcksumdelta_buf[LFSR_LE32_DSIZE];
|
uint8_t gcksumdelta_buf[LFSR_LE32_DSIZE];
|
||||||
err = lfsr_rbyd_appendrat_(lfs, &rbyd, LFSR_RAT(
|
err = lfsr_rbyd_appendrat_(lfs, &rbyd, LFSR_RAT(
|
||||||
LFSR_TAG_GCKSUMDELTA, 0, LFSR_DATA_LE32(
|
LFSR_TAG_GCKSUMDELTA, 0, LFSR_DATA_LE32(
|
||||||
lfsr_gcksum_cube(cksum), gcksumdelta_buf)));
|
lfs_crc32c_cube(cksum), gcksumdelta_buf)));
|
||||||
|
|
||||||
// and commit
|
// and commit
|
||||||
err = lfsr_rbyd_appendcksum_(lfs, &rbyd, cksum);
|
err = lfsr_rbyd_appendcksum_(lfs, &rbyd, cksum);
|
||||||
|
|||||||
@@ -635,6 +635,11 @@ uint32_t lfs_crc32c(uint32_t crc, const void *buffer, size_t size);
|
|||||||
// Multiply two crc32cs in the crc32c ring
|
// Multiply two crc32cs in the crc32c ring
|
||||||
uint32_t lfs_crc32c_mul(uint32_t a, uint32_t b);
|
uint32_t lfs_crc32c_mul(uint32_t a, uint32_t b);
|
||||||
|
|
||||||
|
// Find the cube of a crc32c in the crc32c ring
|
||||||
|
static inline uint32_t lfs_crc32c_cube(uint32_t a) {
|
||||||
|
return lfs_crc32c_mul(lfs_crc32c_mul(a, a), a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Allocate memory, only used if buffers are not provided to littlefs
|
// Allocate memory, only used if buffers are not provided to littlefs
|
||||||
// Note, memory must be 64-bit aligned
|
// Note, memory must be 64-bit aligned
|
||||||
|
|||||||
Reference in New Issue
Block a user