ARM7 IT (if then) 指令的真正作用是什么?
What does the ARM7 IT (if then) instruction really do?
我无法理解 IT
指令的功能(如果有的话)。 quick reference card 有这个:
Operation: If-Then
Assembler: IT{pattern} {cond}
Action: Makes up to four following instructions conditional, according to pattern. pattern is a string of up to three letters. Each letter can be T (Then) or E (Else). The first instruction after IT has condition cond. The following instructions have condition cond if the corresponding letter is T, or the inverse of cond if the corresponding letter is E.
实际上,这个大纲有点道理。架构 manual entry 并没有让我在理解的过程中走到任何地方:
If-Then condition instruction.
Syntax
IT{x{y{z}}} cond
Where:
x
specifies the condition switch for the second instruction in the IT block.
y
Specifies the condition switch for the third instruction in the IT block.
z
Specifies the condition switch for the fourth instruction in the IT block.
cond
Specifies the condition for the first instruction in the IT block.
The condition switch for the second, third and fourth instruction in the IT block can be either:
T
Then. Applies the condition cond to the instruction.
E
Else. Applies the inverse condition of cond to the instruction.
Note
It is possible to use AL (the always condition) for cond in an IT instruction. If this is done, all of the instructions in the IT block must be unconditional, and each of x, y, and z must be T or omitted but not E.
Operation
The IT instruction makes up to four following instructions conditional. The conditions can be all the same, or some of them can be the logical inverse of the others. The conditional instructions following the IT instruction form the IT block.
The instructions in the IT block, including any branches, must specify the condition in the {cond} part of their syntax.
既然(大多数)每条指令都可以轻松指定条件,那么 IT
指令有什么用?
首先请注意,大多数指令可以在 ARM 指令中指定条件代码,而不是在 Thumb 中。
使用IT
指令,最多可以为4条指令指定条件码。对于每条指令,您指定它是 If (T) 还是 Else (E) 的一部分。
例如:
ITTET EQ
ADD r0,r0,r0
ADD r1,r0,r0
ADD r2,r0,r0
ADD r3,r0,r0
实际上会翻译成:
ADDEQ r0,r0,r0 (Always if for 1st one)
ADDEQ r1,r0,r0 (T for 2nd one)
ADDNE r2,r0,r0 (E for 3rd one)
ADDEQ r3,r0,r0 (T for 4th one)
IT
实际上所做的是encode 8 bits of information into the ITSTATE
field of the CPSR非常巧妙的。原始的 Thumb 指令集除了分支之外没有条件指令,因为在 16 位中根本没有空间来在足够多的操作码和操作数之上放置 4 位条件代码以供使用。 Thumb-2 扩展所做的是 改造 有条件地执行那些现有的 16 位编码,以及新的 32 位编码。
如果您查看 ARM 条件代码,您会注意到 3 个最高有效位代表特定的标志测试,而 lsb 表示一种解释或其完全相反的解释 - 最初甚至 0xF 也是 'never' 对应于 0xE 的 'always' - 因此您可以将基本条件编码为 3 位,并使用其他 5 位来编码下一条指令应评估测试的方式加上停止位以指示指令数留给条件。因此,在它被完全消耗之前,ITSTATE 值可以被解包到 ARM 条件代码中,并与 Thumb 指令编码被解包到它们等效的 ARM 指令一起馈入管道。
从架构的角度来看,这是一个非常酷的功能,尽管编译器工程师和 CPU 设计师可能不同意 ;)
我无法理解 IT
指令的功能(如果有的话)。 quick reference card 有这个:
Operation: If-Then
Assembler:IT{pattern} {cond}
Action: Makes up to four following instructions conditional, according to pattern. pattern is a string of up to three letters. Each letter can be T (Then) or E (Else). The first instruction after IT has condition cond. The following instructions have condition cond if the corresponding letter is T, or the inverse of cond if the corresponding letter is E.
实际上,这个大纲有点道理。架构 manual entry 并没有让我在理解的过程中走到任何地方:
If-Then condition instruction.
SyntaxIT{x{y{z}}} cond
Where:
x
specifies the condition switch for the second instruction in the IT block.
y
Specifies the condition switch for the third instruction in the IT block.
z
Specifies the condition switch for the fourth instruction in the IT block.
cond
Specifies the condition for the first instruction in the IT block.The condition switch for the second, third and fourth instruction in the IT block can be either:
T
Then. Applies the condition cond to the instruction.
E
Else. Applies the inverse condition of cond to the instruction.Note
It is possible to use AL (the always condition) for cond in an IT instruction. If this is done, all of the instructions in the IT block must be unconditional, and each of x, y, and z must be T or omitted but not E. Operation
The IT instruction makes up to four following instructions conditional. The conditions can be all the same, or some of them can be the logical inverse of the others. The conditional instructions following the IT instruction form the IT block.
The instructions in the IT block, including any branches, must specify the condition in the {cond} part of their syntax.
既然(大多数)每条指令都可以轻松指定条件,那么 IT
指令有什么用?
首先请注意,大多数指令可以在 ARM 指令中指定条件代码,而不是在 Thumb 中。
使用IT
指令,最多可以为4条指令指定条件码。对于每条指令,您指定它是 If (T) 还是 Else (E) 的一部分。
例如:
ITTET EQ
ADD r0,r0,r0
ADD r1,r0,r0
ADD r2,r0,r0
ADD r3,r0,r0
实际上会翻译成:
ADDEQ r0,r0,r0 (Always if for 1st one)
ADDEQ r1,r0,r0 (T for 2nd one)
ADDNE r2,r0,r0 (E for 3rd one)
ADDEQ r3,r0,r0 (T for 4th one)
IT
实际上所做的是encode 8 bits of information into the ITSTATE
field of the CPSR非常巧妙的。原始的 Thumb 指令集除了分支之外没有条件指令,因为在 16 位中根本没有空间来在足够多的操作码和操作数之上放置 4 位条件代码以供使用。 Thumb-2 扩展所做的是 改造 有条件地执行那些现有的 16 位编码,以及新的 32 位编码。
如果您查看 ARM 条件代码,您会注意到 3 个最高有效位代表特定的标志测试,而 lsb 表示一种解释或其完全相反的解释 - 最初甚至 0xF 也是 'never' 对应于 0xE 的 'always' - 因此您可以将基本条件编码为 3 位,并使用其他 5 位来编码下一条指令应评估测试的方式加上停止位以指示指令数留给条件。因此,在它被完全消耗之前,ITSTATE 值可以被解包到 ARM 条件代码中,并与 Thumb 指令编码被解包到它们等效的 ARM 指令一起馈入管道。
从架构的角度来看,这是一个非常酷的功能,尽管编译器工程师和 CPU 设计师可能不同意 ;)