HI glad you clicked this topic well yeah
people dont talk to people clicking topics WHY? well lets get started. Ive
spent about 18 months testing and profiling GCC compiler flags for dreamcast
and pc. I think i do this more then any one people who dont use the compiler
to gain speed seem to think you should do it all with your code. Thats really
not right Your compiler is your best tool Learn to use it and gain speed
and info.
First flag is going to shock you it is a hidden not used flag what is it
Well heres the info
Internally, gcc translates these to a series of -f and -m options. You can
see exactly which -O levels map to which options by running gcc with this
flag -Q try it and watch your code
compile. also use -v and watch it compile it
will tell you things like
| Code: |
GNU CPP version 3.0.4 (cpplib) (Hitachi SH)
GNU C version 3.0.4 (sh-elf)
compiled by GNU C version 3.2 20020927
(prerelease). |
What does yours say ? thats using the -v flag
Using -v & -Q together gets you all the info for example it will tell
you all options and flags you have enabled
So lets show what every Level does from -O0 to -O4 shall we.
Notice any thing different from -O4 And between -O3 ?? well if you look
closely -O4 has -fomit-frame-pointer enabled and -O3 does not they are not
the same yet some Gcc freaks claim there is no change between any level
above -03 Wrong proof is right there to see. I would like to add this are
little changes between -O3 and -O2 can you spot them ? . There are a few
flags, -O1 there are a lot of changes. I wanted to do this to show you that
all levels are not that same and what not to include on your link line there
is not point including flags that a level your using has enabled from the
start.
This is -O4
| Code: |
-I/usr/local/dc/kos-1.1.9/kernel/arch/dreamcast/include
-D__GNUC__=3
-D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=4 -D__sh__ -D__ELF__
-D__sh__
-D__ELF__ -Acpu=sh -Amachine=sh -D__OPTIMIZE__ -D__STDC_HOSTED__=1
-D__LITTLE_ENDIAN__ -D__SH4_SINGLE_ONLY__ -DSDL -DLSB_FIRST
-DALIGN_LONG
-DINLINE -DDC -D_arch_dreamcast -ml -m4-single-only -O4
options enabled: -fdefer-pop -fomit-frame-pointer -foptimize-sibling-calls
-fcse-follow-jumps -fcse-skip-blocks -fexpensive-optimizations
-fthread-jumps -fstrength-reduce -fpeephole -fforce-mem -ffunction-cse
-finline-functions -finline -fkeep-static-consts -fcaller-saves
-freg-struct-return -fdelayed-branch -fgcse -frerun-cse-after-loop
-frerun-loop-opt -fdelete-null-pointer-checks -fschedule-insns2
-fsched-interblock -fsched-spec -fbranch-count-reg -freorder-blocks
-frename-registers -fcommon -fgnu-linker -fregmove
-foptimize-register-move -fargument-alias -fstrict-aliasing
-fident
-fpeephole2 -fguess-branch-probability -fmath-errno -m1 -m2
-m3 -m3e
-m4-single-only -m4-nofpu -ml |
This is -O3
| Code: |
GNU CPP version 3.0.4 (cpplib) (Hitachi SH)
GNU C version 3.0.4 (sh-elf)
compiled by GNU C version 3.2 20020927
(prerelease).
options passed: -lang-c -v -I/usr/local/dc/kos-1.1.9/include
-I/usr/local/dc/kos-1.1.9/libc/include
-I/usr/local/dc/kos-1.1.9/kernel/arch/dreamcast/include -D__GNUC__=3
-D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=4 -D__sh__ -D__ELF__
-D__sh__
-D__ELF__ -Acpu=sh -Amachine=sh -D__OPTIMIZE__ -D__STDC_HOSTED__=1
-D__LITTLE_ENDIAN__ -D__SH4_SINGLE_ONLY__ -DSDL -DLSB_FIRST
-DALIGN_LONG
-DINLINE -DDC -D_arch_dreamcast -ml -m4-single-only -O3
options enabled: -fdefer-pop -foptimize-sibling-calls -fcse-follow-jumps
-fcse-skip-blocks -fexpensive-optimizations -fthread-jumps
-fstrength-reduce -fpeephole -fforce-mem -ffunction-cse -finline-functions
-finline -fkeep-static-consts -fcaller-saves -freg-struct-return
-fdelayed-branch -fgcse -frerun-cse-after-loop -frerun-loop-opt
-fdelete-null-pointer-checks -fschedule-insns2 -fsched-interblock
-fsched-spec -fbranch-count-reg -freorder-blocks -frename-registers
-fcommon -fgnu-linker -fregmove -foptimize-register-move -fargument-alias
-fstrict-aliasing -fident -fpeephole2 -fguess-branch-probability
-fmath-errno -m1 -m2 -m3 -m3e -m4-single-only -m4-nofpu -ml |
This is -O2
| Code: |
GNU CPP version 3.0.4 (cpplib) (Hitachi
SH)
GNU C version 3.0.4 (sh-elf)
compiled by GNU C version 3.2 20020927
(prerelease).
options passed: -lang-c -v -I/usr/local/dc/kos-1.1.9/include
-I/usr/local/dc/kos-1.1.9/libc/include
-I/usr/local/dc/kos-1.1.9/kernel/arch/dreamcast/include -D__GNUC__=3
-D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=4 -D__sh__ -D__ELF__
-D__sh__
-D__ELF__ -Acpu=sh -Amachine=sh -D__OPTIMIZE__ -D__STDC_HOSTED__=1
-D__LITTLE_ENDIAN__ -D__SH4_SINGLE_ONLY__ -DSDL -DLSB_FIRST
-DALIGN_LONG
-DINLINE -DDC -D_arch_dreamcast -ml -m4-single-only -O2
options enabled: -fdefer-pop -foptimize-sibling-calls -fcse-follow-jumps
-fcse-skip-blocks -fexpensive-optimizations -fthread-jumps
-fstrength-reduce -fpeephole -fforce-mem -ffunction-cse -finline
-fkeep-static-consts -fcaller-saves -freg-struct-return -fdelayed-branch
-fgcse -frerun-cse-after-loop -frerun-loop-opt
-fdelete-null-pointer-checks -fschedule-insns2 -fsched-interblock
-fsched-spec -fbranch-count-reg -freorder-blocks -fcommon -fgnu-linker
-fregmove -foptimize-register-move -fargument-alias -fstrict-aliasing
-fident -fpeephole2 -fguess-branch-probability -fmath-errno
-m1 -m2 -m3
-m3e -m4-single-only -m4-nofpu -ml |
This is -O1
| Code: |
GNU CPP version 3.0.4 (cpplib) (Hitachi
SH)
GNU C version 3.0.4 (sh-elf)
compiled by GNU C version 3.2 20020927
(prerelease).
options passed: -lang-c -v -I/usr/local/dc/kos-1.1.9/include
-I/usr/local/dc/kos-1.1.9/libc/include
-I/usr/local/dc/kos-1.1.9/kernel/arch/dreamcast/include -D__GNUC__=3
-D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=4 -D__sh__ -D__ELF__
-D__sh__
-D__ELF__ -Acpu=sh -Amachine=sh -D__OPTIMIZE__ -D__STDC_HOSTED__=1
-D__LITTLE_ENDIAN__ -D__SH4_SINGLE_ONLY__ -DSDL -DLSB_FIRST
-DALIGN_LONG
-DINLINE -DDC -D_arch_dreamcast -ml -m4-single-only -O1
options enabled: -fdefer-pop -fthread-jumps -fpeephole -ffunction-cse
-finline -fkeep-static-consts -freg-struct-return -fdelayed-branch
-fsched-interblock -fsched-spec -fbranch-count-reg -fcommon
-fgnu-linker
-fargument-alias -fident -fguess-branch-probability -fmath-errno
-m1 -m2
-m3 -m3e -m4-single-only -m4-nofpu -ml |
This is -O0
| Code: |
GNU CPP version 3.0.4 (cpplib) (Hitachi
SH)
GNU C version 3.0.4 (sh-elf)
compiled by GNU C version 3.2 20020927
(prerelease).
options passed: -lang-c -v -I/usr/local/dc/kos-1.1.9/include
-I/usr/local/dc/kos-1.1.9/libc/include
-I/usr/local/dc/kos-1.1.9/kernel/arch/dreamcast/include -D__GNUC__=3
-D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=4 -D__sh__ -D__ELF__
-D__sh__
-D__ELF__ -Acpu=sh -Amachine=sh -D__NO_INLINE__ -D__STDC_HOSTED__=1
-D__LITTLE_ENDIAN__ -D__SH4_SINGLE_ONLY__ -DSDL -DLSB_FIRST
-DALIGN_LONG
-DINLINE -DDC -D_arch_dreamcast -ml -m4-single-only -O0
options enabled: -fpeephole -ffunction-cse -fkeep-static-consts
-freg-struct-return -fsched-interblock -fsched-spec -fbranch-count-reg
-fcommon -fgnu-linker -fargument-alias -fident -fmath-errno
-m1 -m2 -m3
-m3e -m4-single-only -m4-nofpu -ml |
Space saving flag -Os
| Code: |
GNU CPP version 3.0.4 (cpplib) (Hitachi
SH)
GNU C version 3.0.4 (sh-elf)
compiled by GNU C version 3.2 20020927
(prerelease).
options passed: -lang-c -v -I/usr/local/dc/kos-1.1.9/include
-I/usr/local/dc/kos-1.1.9/libc/include
-I/usr/local/dc/kos-1.1.9/kernel/arch/dreamcast/include -D__GNUC__=3
-D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=4 -D__sh__ -D__ELF__
-D__sh__
-D__ELF__ -Acpu=sh -Amachine=sh -D__OPTIMIZE_SIZE__ -D__OPTIMIZE__
-D__STDC_HOSTED__=1 -D__LITTLE_ENDIAN__ -D__SH4_SINGLE_ONLY__
-DSDL
-DLSB_FIRST -DALIGN_LONG -DINLINE -DDC -D_arch_dreamcast -ml
-m4-single-only -Os
options enabled: -fdefer-pop -foptimize-sibling-calls -fcse-follow-jumps
-fcse-skip-blocks -fexpensive-optimizations -fthread-jumps
-fstrength-reduce -fpeephole -fforce-mem -ffunction-cse -finline
-fkeep-static-consts -fcaller-saves -freg-struct-return -fdelayed-branch
-fgcse -frerun-cse-after-loop -frerun-loop-opt
-fdelete-null-pointer-checks -fschedule-insns2 -fsched-interblock
-fsched-spec -fbranch-count-reg -freorder-blocks -fcommon -fgnu-linker
-fregmove -foptimize-register-move -fargument-alias -fstrict-aliasing
-fident -fpeephole2 -fguess-branch-probability -fmath-errno
-m1 -m2 -m3
-m3e -m4-single-only -m4-nofpu -ml -mspace |
This lets you see what -0s really does and what -04 really does etc it shows
you hard proof of what these level flags do no more guess work. I think
this is handy ive been using it on mame for a while.
More later i will go through every option for you and a profile test on
an emulator and 3d program. Stay tuned for this topic.
Im going to show you how to gain up to 30% speed by using the compiler Now
who out there would not like that for there project.
Please ask permission to copy this tutorial to any site through email
or on my forum.
IMR Technology 2003
Your help is appreciated!
|
|