13 ms·
The 16 bit "thumb" instructions are still all fixed size - 16 bits. They do this by limiting the available options in the instructions. For instance, the regist
by gvb 10y ago
The 16 bit "thumb" instructions are still all fixed size - 16 bits. They do this by limiting the available options in the instructions. For instance, the register selection field will be 3 bits so only 8 registers can be directly accessed by the thumb instructions. They also drop some instructions IIRC.
The 16 bit instructions map 1:1 to the 32 bit instructions, so decoding is unchanged, The difference is a pre-decoding transmogrificaiton stage where some of the resulting fields in the transmogrified 32 bit instruction are fixed (e.g. 0) and some are filled in from the original 16 bit instruction fields.
Switching between 32 bit and "thumb" is fairly painless but the instructions cannot be intermingled. When you do a call, you have the opportunity to switch 32/thumb. When you return, the processor switches back as appropriate.
The resulting thumb code is more compact than full 32 bit instructions, but it isn't 2x more compact because you still need some 32 bit instructions (subroutines) and the 16 bit instructions are not as powerful as the full 32 bit instructions.
- baobrien 10y agoThat's why I'm a fan of the RISC-V compressed ISA extension. Compressed instructions are 16 bits long and a subset of the 32 bit instructions, but can be mixed freely with 32 bit. The extension also relaxes the alignment requirements, so that 32 bit instructions can be aligned to 16 bit boundaries.
- oshepherd 10y agoThumb-2 (about 13 years old at this point) extended Thumb to cover the entirety of instruction set. That is, every* ARM instruction has a corresponding Thumb instruction (The converse is not quite the case) There is very little reason to use ARM code in ARMv7 and up. Incidentally, ARMv8's 64-bit mode (AArch64) adds a whole new instruction set, called A64. It's fixed width 32-bit per instruction, and the only option for 64-bit code. * Excluding some really obscure, mostly long deprecated ones
- oshepherd 10y agoI noticed that I missed out mentioning that, yes, Thumb-2 made Thumb variable length (it already sorta-was, branches were always kinda 32-bit) Any halfword where bit[15:13]=='111' && bit[12:11]!='00' is the leading half of a 32-bit Thumb instruction