Download ARM Instruction Set

Transcript
C Compiler
2.15
ARM/Thumb interworking
2.15.1 Introduction
Code compiled (or assembled) for ARM and Thumb can be freely mixed providing the code
conforms to the ARM Procedure Call Standard and Thumb Procedure Call Standard
respectively.
Compiled code automatically conforms to these standards. Assembler programmers must
ensure their code conforms to these standards.
The ARM linker automatically detects when you are mixing ARM and Thumb code and
generates small code segments called veneers, These veneers perform an ARM-Thumb state
change on function entry and exit when an ARM function is called from Thumb state and
vice-versa.
2.15.2 Compiling code for interworking
When interworking ARM and Thumb code, code may be compiled specially for interworking
using the -apcs 3/interwork option on both the ARM and Thumb compilers. Alternatively it
may be compiled as normal.
In both cases, interworking between ARM and Thumb will work. However, the following
trade-offs must be made when deciding whether to compile code specially for interworking or
not.
Code not compiled for interworking:
•
does not support ARM/Thumb interercalling via function pointers (ie. only direct calls
between ARM and Thumb are supported)
•
uses larger veneers than code compiled for interworking (the veneers are 20 bytes per
ARM/Thumb caller/called routine pair)
Code compiled for interworking:
•
•
generates slightly larger code for Thumb (typically 1% larger) and marginally larger
code for ARM
This will have a correspondingly small effect on performance.
cannot be used on non-Thumb ARMs
•
allows intercalling using function pointers
•
uses smaller veneers (8 or 12 bytes per called routine)
The trade-off depends on the number of intercalls made. If only a few direct intercalls are made,
it is best not to compile the code for interworking.
As the number of intercalls increases the larger size of the ARM/Thumb veneers will start to
dominate so it is better to compile the code for interworking.
Reference Manual
ARM DUI 0020D
2-57