I did some tests with the 4.5.2 m68k gcc on the code you posted... here's the exact code tested:
Code:
#include <stdint.h>
void vsync(void) {
volatile uint16_t* const vdpctrl = (uint16_t*) 0xC00004;
while (*vdpctrl & 0x0008);
while (!(*vdpctrl & 0x0008));
}
and here is the code generated for -O1, -O2, and -O3 respectively:
Code:
#NO_APP
.file "test.c"
.text
.align 2
.globl vsync
.type vsync, @function
vsync:
link.w %fp,#0
.L2:
move.w 12582916,%d0
btst #3,%d0
jne .L2
.L4:
move.w 12582916,%d0
btst #3,%d0
jeq .L4
unlk %fp
rts
.size vsync, .-vsync
.ident "GCC: (GNU) 4.5.2"
Code:
#NO_APP
.file "test.c"
.text
.align 2
.globl vsync
.type vsync, @function
vsync:
link.w %fp,#0
.L2:
move.w 12582916,%d0
btst #3,%d0
jne .L2
.L4:
move.w 12582916,%d0
btst #3,%d0
jeq .L4
unlk %fp
rts
.size vsync, .-vsync
.ident "GCC: (GNU) 4.5.2"
Code:
#NO_APP
.file "test.c"
.text
.align 2
.globl vsync
.type vsync, @function
vsync:
link.w %fp,#0
.L2:
move.w 12582916,%d0
btst #3,%d0
jne .L2
.L4:
move.w 12582916,%d0
btst #3,%d0
jeq .L4
unlk %fp
rts
.size vsync, .-vsync
.ident "GCC: (GNU) 4.5.2"
In this case, the function is so simple that it can't be optimized any more by gcc. It also looks like good code... nothing funky going on. Well, ONE optimization I could see - not using the frame pointer... adding -fomit-frame-pointer to the compile options gives:
Code:
#NO_APP
.file "test.c"
.text
.align 2
.globl vsync
.type vsync, @function
vsync:
.L2:
move.w 12582916,%d0
btst #3,%d0
jne .L2
.L4:
move.w 12582916,%d0
btst #3,%d0
jeq .L4
rts
.size vsync, .-vsync
.ident "GCC: (GNU) 4.5.2"