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++ > THUMB instructions

#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.

#16355 - x86asm - Fri Feb 13, 2004 3:37 am

torne wrote:
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.


That step seems to be done by default in Visual HAM, maybe you can show the keyword (if there is one) that makes the compiler, compile a function in THUMB code instead of ARM code?

Thanks
_________________
Hello Everyone :D

#16361 - tom - Fri Feb 13, 2004 8:01 am

x86asm wrote:
maybe you can show the keyword (if there is one) that makes the compiler, compile a function in THUMB code instead of ARM code?


you can't switch between arm/thumb in a source file, you can only compile whole files as thumb, using the -mthumb switch, as torne said.

(if you're writing asm code with as you can switch between arm/thumb code generation using the .arm/.thumb or .code 32/.code 16 directives)