Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of W suffix for thumb-2 instruction?

Tags:

arm

thumb

There is a w suffix for thumb-2 instruction as below, how does it change the semantic of the instruction without it? The search result is very noisy and I didn't get the answer.

addw r0, r1, #0

like image 411
Thomson Avatar asked Mar 05 '14 16:03

Thomson


2 Answers

Simply enough, W means "wide". It is the 32-bit version of the instruction, whereas most Thumb instructions are 16 bits wide. The wide instructions often have bigger immediates or can address more registers.

Edit: Some of the comments seem confused about the difference between addw and add.w. The only essential difference is how the immediate is encoded.

add.w:  imm32 = ThumbExpandImm(i:imm3:imm8);
addw:   imm32 = ZeroExtend(i:imm3:imm8, 32);
like image 57
Variable Length Coder Avatar answered Oct 04 '22 15:10

Variable Length Coder


I see ADDW in Cortex-M3 TRM Table 2-5

Data operations with large immediate
ADDW and SUBW have a 12-bit immediate. This means they can replace many from memory literal loads.

It is also mentioned in Quick Reference

add wide T2 ADD Rd, Rn, #<imm12>

Looks like the assembler would recognize the immediate constant <= 12 bits, and do the needful.

In the context where you see it, it is an ordinary "add".

like image 30
Joe Kul Avatar answered Oct 04 '22 16:10

Joe Kul