From 187c96d6e5558208266fa0ca81e41e38854ab568 Mon Sep 17 00:00:00 2001 From: Michael Panzlaff Date: Fri, 2 Oct 2020 12:12:31 +0200 Subject: [PATCH] rewrite MultiBootWaitCycles as naked function Before, when compiling MultiBootWaitCycles with O3 and MODERN=1, you might have run into problems during optimizations when the compiler tried to optimize the function, even if declared NOINLINE. When rewriting this function as NAKED function, this no longer happens as the optimizer will treat it as black box and compilation will resume. --- src/multiboot.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/multiboot.c b/src/multiboot.c index c7e14392e8..19245b5b33 100644 --- a/src/multiboot.c +++ b/src/multiboot.c @@ -1,3 +1,4 @@ +#include "global.h" #include "gba/gba.h" #include "multiboot.h" @@ -435,23 +436,23 @@ static int MultiBootHandShake(struct MultiBootParam *mp) #undef must_data } -static NOINLINE void MultiBootWaitCycles(u32 cycles) +NAKED +static void MultiBootWaitCycles(u32 cycles) { - asm("mov r2, pc"); - asm("lsr r2, #24"); - asm("mov r1, #12"); - asm("cmp r2, #0x02"); - asm("beq MultiBootWaitCyclesLoop"); - - asm("mov r1, #13"); - asm("cmp r2, #0x08"); - asm("beq MultiBootWaitCyclesLoop"); - - asm("mov r1, #4"); - - asm("MultiBootWaitCyclesLoop:"); - asm("sub r0, r1"); - asm("bgt MultiBootWaitCyclesLoop"); + asm_unified("\ + mov r2, pc\n\ + lsrs r2, 24\n\ + movs r1, 12\n\ + cmp r2, 2\n\ + beq MultiBootWaitCyclesLoop\n\ + movs r1, 13\n\ + cmp r2, 8\n\ + beq MultiBootWaitCyclesLoop\n\ + movs r1, 4\n\ +MultiBootWaitCyclesLoop:\n\ + subs r0, r1\n\ + bgt MultiBootWaitCyclesLoop\n\ + bx lr\n"); } static void MultiBootWaitSendDone(void)