gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > gcc -O3 problem

#797 - col - Fri Jan 10, 2003 6:36 pm

hello

I've recently been having problems with my gba register access code.

Symptoms are:

the game works perfect on emulators, but crashed intermittently on hardware.
This was tracked down (thanks to VBA) to illegal word READS from the bios area!

It turned out that these reads were being caused by some code that uses register defines to WRITE!? to gba registers.

the registers are all defined in the usual manner
#define REG_XXXX *(volatile u32*)0x04000nnn

After some fiddling i discovered that everything is Aok when only optimising -O2.

The thing is - I get a noticable performance boost using -O3, and want to keep this switched on, so does anyone know what the problem might be?
why does -O3 think that it can optimise a write to a volatile by including a read??

and how can i switch this behaviour off? any ideas?

I'm using the latest windoze devkitadv


thanks

col

#825 - col - Fri Jan 10, 2003 10:41 pm

after a little detective work, i have discovered that the culprit is

-finline-functions

so i can compile using -O2 adding -frename-registers to get -O3 without -finline-functions

though why -finline-functions would cause the behaviour i described is beyond me - why would the compiler want to read a register to write to it??

I'm not using |= &= etc just plain =

anyone have a clue?

cheers

col

#3094 - mbcook - Tue Feb 18, 2003 4:51 am

I don't know, but I do have an idea. You could basically make wrappers around the functions that are causing problems and put them in one file and compile that at O2. Then put the rest of your source in one (or more) file(s) and compile that at O3. That will keep MOST of your speed bonus, but could make things more confusing.
_________________
--Michael

#3129 - siaspete - Tue Feb 18, 2003 8:33 pm

Most registers are 16-bit, so try using u16 instead of u32 in that #define.

#3175 - jenswa - Wed Feb 19, 2003 12:52 pm

While we are talking about O3, how to use it in my make.bat file ?

when i replace the o with o3, i get a lot of 'messages' during compiling.
_________________
It seems this wasn't lost after all.

#3181 - floatstarpx - Wed Feb 19, 2003 2:26 pm

it has to be a capital -O
(altho don't get rid of the lower case one either!)
add in -O3

has anyone got any tips for make.bat files? any extra commands to put in the line?

#3184 - jenswa - Wed Feb 19, 2003 2:33 pm

I'll try it home, but i thought i used capital O
(i know i wrote little o).

Most people use crts scripts etc, linkscripts and makefiles,
search those files, they contain nice information,
but i don't how to put it in make.but, so it's better to set up
visual studio with devkitadv and use those scripts.
_________________
It seems this wasn't lost after all.