sparse fusemap: optimise access when block bits are all 1

This commit is contained in:
ole00 2024-02-02 08:40:56 +00:00
parent 7ff02e0a8d
commit dc16f92a2e
1 changed files with 13 additions and 4 deletions

View File

@ -90,16 +90,17 @@ static uint16_t getFusePositionAndType(uint16_t bitPos) {
//calculate fusemap offset //calculate fusemap offset
while (1) { while (1) {
uint8_t rec = fuseType[i]; uint8_t rec = fuseType[i];
// speed optimised special case: all 8 bits are 0 (4 * 32 bits) // speed optimised special case: all 8 bits are 0 or all are 1 (4 * 32 bits)
if (rec == 0) { if (rec == 0 || rec == 0xFF) {
counter += 128; counter += 128;
if (counter > bitPos) { if (counter > bitPos) {
return (fuseOffset << 2); // type is 0 return (fuseOffset << 2) | (rec & 0b11); // type is 0 or 3
} }
sparseCacheBitPos = counter; sparseCacheBitPos = counter;
sparseCacheOffset = fuseOffset; sparseCacheOffset = fuseOffset;
sparseCacheIndex = i + 1; sparseCacheIndex = i + 1;
} else { }
else {
uint8_t j = 0; uint8_t j = 0;
//4 fuse types per byte //4 fuse types per byte
while (j < 4) { while (j < 4) {
@ -152,6 +153,7 @@ static void sparseCompactFuseMap(void) {
sparseCompactRun++; //statistics sparseCompactRun++; //statistics
#endif #endif
i = total - 1; i = total - 1;
while(i) { while(i) {
// remove 4 fusemap bytes at a position when the bits are all 1's // remove 4 fusemap bytes at a position when the bits are all 1's
@ -176,6 +178,13 @@ static void sparseCompactFuseMap(void) {
sparseCacheBitPos = 0; sparseCacheBitPos = 0;
sparseCacheOffset = 0; sparseCacheOffset = 0;
sparseCacheIndex = 0; sparseCacheIndex = 0;
#if COMPACT_STAT
Serial.print(F("sp comp:"));
Serial.print(sparseCompactRun, DEC);
Serial.print(F(" total:"));
Serial.println(sparseFusemapStat & 0x7FF, DEC);
#endif
} }
static inline uint16_t sparseSetFuseBit(uint16_t bitPos) { static inline uint16_t sparseSetFuseBit(uint16_t bitPos) {