catalog: Fix a subtle bug on DM32 with the catalog content

With the original code, the loop searching for commands to add to the
catalog skips many commands. I suspect this is another case of QSPI
hammering similar to what was observed for fonts. In any case, the
workaround appears to be to slightly deoptimize the code by selecting
a lower optimization level and adding an `else` clause in the inner
`if` statement.

Signed-off-by: Christophe de Dinechin <christophe@dinechin.org>
This commit is contained in:
Christophe de Dinechin 2024-03-11 23:56:09 +01:00
parent a35e3d7dc8
commit 63eb8efabd
2 changed files with 26 additions and 2 deletions

View file

@ -292,8 +292,10 @@ DEFINES_small=RELEASE
DEFINES_fast=RELEASE
DEFINES_faster=RELEASE
DEFINES_fastes=RELEASE
DEFINES_dm32 = DM32 \
CONFIG_FIXED_BASED_OBJECTS
DEFINES_dm32 = DM32 \
CONFIG_FIXED_BASED_OBJECTS \
DEOPTIMIZE_CATALOG
DEFINES_dm42 = DM42
C_DEFS += $(DEFINES:%=-D%)

View file

@ -68,6 +68,13 @@ static uint16_t *sorted_ids = nullptr;
static size_t sorted_ids_count = 0;
#ifdef DEOPTIMIZE_CATALOG
// This is necessary on the DM32, where otherwise we access memory too
// fast and end up with bad data in the sorted array
# pragma GCC push_options
# pragma GCC optimize("-O2")
#endif // DEOPTIMIZE_CATALOG
static int sort_ids(const void *left, const void *right)
// ----------------------------------------------------------------------------
// Sort the IDs alphabetically based on their fancy name
@ -137,11 +144,26 @@ static void initialize_sorted_ids()
}
}
}
else
{
// Do not remove this code
// It seems useless, but without it, the catalog is
// badly broken on DM42. Apparently, the loop is a bit
// too fast, and we end up adding a varying, but too small,
// number of commands to the array
debug_printf(5, "Not a command for %u, type %u[%s]",
i, s.type, object::name(s.type));
debug_wait(-1);
}
}
sorted_ids_count = cmd;
}
}
#ifdef DEOPTIMIZE_CATALOG
#pragma GCC pop_options
#endif // DEOPTIMIZE_CATALOG
static bool matches(utf8 start, size_t size, utf8 name)
// ----------------------------------------------------------------------------