One more thing. Can I say that Thumb (32-bit) is the same as ARM instructions which are also 32-bit?
No. (my comment answered this)
It is said that Thumb 2 supports 16-bit and 32-bit instructions. So is ARMv7M in fact supporting Thumb 2 instructions and not just Thumb?
This is correct in that ARMv7M support instructions beyond the initial ARM thumb. It is often called Thumb-2, but that itself is nebulous.
There seems to be a lot of confusion over this subject. The issue is that 'thumb' is an overloaded concept.
- It is an operating mode of some ARM CPUs.
- It is an ISA.
- It is a programmer model.
ARM has tried to create 'architecture' versions. That is the same CPUs from the same architecture version should run the same binary. A list can be found on wikipedia. An architecture is usually listed as ARMvN, where N is a number. ARMv1 to ARMv4 (approximately 1985-1998) are only ARM 32 bit ISA. In the CPSR or system mode register there is no thumb bit. With ARMv4, some CPUs did support thumb. This is listed at ARMv4t. An update in ARMv5 allowed something called 'inter-working' where a 32-bit ARM routine could call a 16-bit thumb routine. The call would switched the mode register. With ARMv6, some CPUs supported Thumb-2, which is a mixed 16/32bit ISA; but it only uses the same 'thumb' bit of the CPSR. With ARMv7, this mixed 16/32bit mode came standard with the thumb mode bit.
Some issues with nomenclature are that mixed 16/32 bit Thumb-2 code can have different op-codes added as the architectures change. Also, they can have extra instruction based on CPU configuration and modes.
Thumb original
This mode had limited use of high registers (r8-r15). It used a different register for stack. It did not allow conditional execution of instructions. All ALU instructions set condition codes; whereas ARM32 has an 's' bit to select whether condition codes are set. It was primarily meant to reduce code density. The instruction set had only 16bit opcodes. Some popular machines with this CPU set include Game Boy Advance.
Thumb-2
While Thumb-2 includes 32bit instructions, the binary of Thumb2 is NOT compatible with the original ARM 32 bit ISA. They are completely different. Also, the 'Thumb-2' has evolved over time. It is backwards compatible, but there are different versions of 'Thumb-2'.
UAL and Conditional execution
Along with 'Thumb-2', ARM corp added 'Unified assembler language'. With Thumb2, almost every ISA in ARM 32bit has an opcode mapping. The main oddity is the conditional execution. ARM 32bit tagged each opcode with a condition code field which consumed a lot of opcode space. This means that to achieve the same functionality (original C code) the assembler/object code is bigger. With Thumb-2, and 'it' instruction was introduced that primes the condition registers. The IT instruction can cause the next four instruction to execute conditionally. This is the biggest change to produce UAL (an assembler syntax which can produce traditional ARM 32bit or Thumb32 opcodes/binary).
See also: ARM it
conditional
System level
Thumb-2 also added instruction to access the co-processor and to handle exceptions in Thumb-2 mode. Earlier versions of Thumb/Thumb-2 did not allow some system level concepts, so ARM32 was required on this CPUs. These additions to the Thumb-2 ISA allowed the Cortex-M variant. cortex-m
Modern day
The Thumb-2 opcode in Cortex CPUs (ARMv7+) are more compact encoding than the traditional ARM 32 bit opcodes. They will execute faster (except some extremely pathologically cases) and have less code density. All ARM CPUs from 2004 onward are supporting this Thumb-2 variant. There is really no need to produce a traditional ARM 32 bit binary. Only CPUs designed before approximately 2005 would need this functionality.
CPUs using the original 'Thumb' are extremely limited as only eight registers are available for all opcodes. No cellphones or commercial products supporting dynamic execution for application programmers will use the 'Thumb' ISA. Only deeply embedded devices (probably for legacy product or upgrades) will use this ISA. The Thumb-2 shares encodings and could run Thumb binaries, but this is mainly a historical note. The conditional execution and mixed 16/32bit ISA allows Thumb2 to supplant the ARM32 opcodes.
The hallmark of ARM/Thumb is the mode bit. You must identify the CPU to know if Thumb/Thumb-2 is applicable. Cortex-M CPUs will only support Thumb2 opcodes. They do not support the traditional ARM32 opcodes. The Cortex-A CPUs support both modes in order to run legacy ARM32 binaries (or those produced by mis-informed developers).
From ARM in 2023,
The T32 instruction set, known as Thumb in pre-Armv8 architectures, is a mixed 32- and 16-bit length instruction set that offers the designer excellent code density for minimal system memory size and cost.
As ARM tries to redefine the nomenclature, programmers should be aware of the historical naming as other 3rd party tool, OS configuration, SOC documentation, etc. may have alternate meanings to the words 'Thumb' and 'Thumb-2'. Even this text is a misnomer as the mixed 32/16 bit ISA was known and introduced as 'Thumb-2'.