Page 1 of 1
GCC Optimisations
Posted: Wed Jun 09, 2004 1:46 am
by srg
Hi
I was just wondering what optimisation level in GCC you compile your OSs with.
With what I have so far, I don't have any. Is it unsafe to use optinisation levels when still developing the kernel, driver etc etc in the first place.
srg
Re:GCC Optimisations
Posted: Wed Jun 09, 2004 2:10 am
by Solar
Optimizations should never break anything. Increasing optimization levels are not more risky, they usually just trade off more space for less execution time.
Higher optimization levels also tend to confuse debuggers, but unless you provide remote-gdb-stubs, that isn't an issue in kernel land.
Also note that not setting optimization levels explicitly simply tells gcc to use *default* optimizations.
Generally, -O2 is considered to be a "sane" setting. What that implies has changed significantly in recent GCC versions.
Re:GCC Optimisations
Posted: Wed Jun 09, 2004 2:48 am
by Candy
srg wrote:
Hi
I was just wondering what optimisation level in GCC you compile your OSs with.
With what I have so far, I don't have any. Is it unsafe to use optinisation levels when still developing the kernel, driver etc etc in the first place.
srg
Well, with my new configure system you just specify it yourself. Min is -O1 (so it at least inlines the inline funcs, otherwise it screws that up & produces multiple outputs) and max is -O3, although I usually run with -O2. O2 outputs the most readable code imo.
Re:GCC Optimisations
Posted: Wed Jun 09, 2004 3:23 am
by Pype.Clicker
i personnally use -O3 or -O2 to enforce small functions inlining. The reason why people generally don't want to debug optimized code is because debuggers like GDB will be completely confused if some variable have been moved to registers, etc.
But since GDB will be of little use for debugging your kernel anyway, you could enable optimizations right from the start
Re:GCC Optimisations
Posted: Wed Jun 09, 2004 3:52 am
by Neuromancer
I use -O0 because my own-written (s)printf functions do not work with a higher level of optimization. My code is ok, since at level 0 works and compiles with other compilers.
GCC is 3.2.2
Re:GCC Optimisations
Posted: Wed Jun 09, 2004 5:13 am
by Pype.Clicker
Neur0m'ancer wrote:
I use -O0 because my own-written (s)printf functions do not work with a higher level of optimization. My code is ok, since at level 0 works and compiles with other compilers.
GCC is 3.2.2
maybe needing volatiles here and there ?
Re:GCC Optimisations
Posted: Wed Jun 09, 2004 8:13 am
by proxy
I use -O0 because my own-written (s)printf functions do not work with a higher level of optimization. My code is ok, since at level 0 works and compiles with other compilers.
GCC is 3.2.2
while it may work, this is generally not a good thing to have in your code. I have seen code that breaks aliasing rules do things like that. (for example, taking an unsigned short and casting it to a char * so you can get the hi/low byte..clever, but technically the compiler is allowed to output garbage for that).
I would compile with as many warnings enabled as possible to find that. (-W -Wall for starters)
proxy
Re:GCC Optimisations
Posted: Wed Jun 09, 2004 8:25 am
by Solar
That's -Wextra for later versions of GCC; -W is deprecated if memory serves.
You might also consider adding -Werror, so that you do not fall into the trap of thinking "ah, it's just a warning".