#16080 - DarkPhantom - Sat Feb 07, 2004 8:05 pm
The C compiler seems to generate ARM instructions by default. I know that ARM instructions execute faster than THUMB instructions however, I know that the GamePak ROM is connected to the mainboard by a bus with a width of only 16-bits. Therefore, I assume that if you want execute your program directly from the ROM it would be faster to use THUMB instructions because each thumb is 16 bits so one instruction won't require that the mainboard pull two requests from the ROM pack and then combine them to feed to the processor, right? In that spirit, anybody know how to get GCC to generate THUMB instructions instead of ARM?
(Tell me anyway, even if I am incorrect on the speed issue)
#16085 - torne - Sat Feb 07, 2004 9:03 pm
It's faster to use Thumb from ROM/EWRAM and ARM from IWRAM, yes, because of the bus widths. In practise the difference varies; with prefetching enabled, it's sometimes faster to use ARM code even from ROM purely because the ARM version is more efficient; the Thumb instruction set is rather limited. You might want to try both if you have a piece of performance critical code but no more space in IWRAM for it. Most of the problems come from GCC's pretty miserable Thumb code generation; ARM's own compiler seems to perform better at 16-bit code. I write most things in assembler so I prefer to use Thumb; my brain is a better optimiser in most cases than GCC. =)
To get GCC to generate Thumb code, add the argument -mthumb to the command line. However, if you want to be able to call Thumb code from ARM, and vice versa, then *all* modules involved, both ARM and Thumb, need to be compiled and linked with interworking support by adding -mthumb-interwork. You need both -mthumb-interwork and -mthumb to generate Thumb code with interworking. Also, any assembly code which you have written by hand (not inline, only standalone) needs to use interworking return sequences; read the ARM/Thumb procedure call standard for details, or search the assembly forum here for my previous explanations of the procedure calling standard.
Hope that's all the info you wanted.