From 60325019aa7926c1ceaeb4701d31ea74831c9de1 Mon Sep 17 00:00:00 2001 From: Kai Vehmanen Date: Mon, 3 Jan 2022 20:32:18 +0200 Subject: [PATCH] samples/subsys/audio/sof: use -fstrict-overflow for SOF Align compiler flags of SOF Zephyr build with the build SOF XTOS and use -fstrict-overflow. With -fno-strict-overflow, some versions of XCC compiler (e.g. xt-xcc 12.0.8) always emit a "bltu" instruction to check for overflow in loops like: unsigned int n; for(n = 0; n < 1024; n++) do_arithmetic(); With "-fno-strict-overflow", you'll have: 18: 068076 loop a0, 22 1b: 445a add.n a4, a4, a5 1d: 551b addi.n a5, a5, 1 1f: 023657 bltu a6, a5, 25 22: fffc86 j 18 With "-fstrict-overflow": 16: 038476 loop a4, 1d 19: 223a add.n a2, a2, a3 1b: 331b addi.n a3, a3, 1 As this is a common pattern in audio DSP code, change the default for SOF builds to -fstrict-overflow. Signed-off-by: Kai Vehmanen --- samples/subsys/audio/sof/prj.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/subsys/audio/sof/prj.conf b/samples/subsys/audio/sof/prj.conf index 033a9bef442..ae16a6dd8a8 100644 --- a/samples/subsys/audio/sof/prj.conf +++ b/samples/subsys/audio/sof/prj.conf @@ -8,6 +8,10 @@ CONFIG_DEBUG_MEMORY_USAGE_SCAN=n # Ensure -O2 (or similar) is used for optimization CONFIG_SPEED_OPTIMIZATIONS=y +# Zephyr top-level default of -fno-strict-overflow is +# not a good fit for audio DSP code +CONFIG_COMPILER_OPT="-fstrict-overflow" + CONFIG_SCHED_DEADLINE=y CONFIG_SCHED_CPU_MASK=y CONFIG_SMP_BOOT_DELAY=y