I read in a research paper that when thumb instruction is used the code size reduces but sometimes this leads to an increased number of instructions thus making thumb slower to execute. But how does the instruction count increase? Is it something like the instructions which are too complex for thumb are split into multiple instructions? This is my intuition. Wanted to verify if I am thinking in the right way.
1 Answers
The paper Profile Guided Selection of ARM and Thumb Instructions by Arvind Krishnaswamy and Rajiv Gupta at The University of Arizona gives a good study; although it is outdated. In the mean time, ARM has released the Thumb2 instruction set which has again changed the game.
To summarize some of the paper, there are algorithms (like hashing) which need a lot of registers. The traditional thumb ISAnote limited register to R0-R8
. If an algorithm causes a spill, it will be significantly slower. So there are always pathological cases were either ISA can win. It is also fairly common wisdom on the game boy advance, that thumb mode was faster from normal (slower) memory. However, from faster internal RAM (one or zero wait state), the ARM mode would run faster.
For the Thumb2 (an improved Thumb ISA), many of the limitations have been removed and it is almost always as fast as (or faster than) ARM mode. Everything is always relative to,
- The memory system in use.
- How you measure (power, run time, memory consumption).
- What it is your code is doing.
There can be no clear answer. You need to give more details of a system and the task at hand.
Note: ISA is instruction set architecture or the type of assembler/machine code available.