Q(饱和标志)在ARM中的重要性 [英] Importance of Q(Saturation Flag) in ARM
问题描述
我想了解Q标记在ARM处理器中的重要性.我知道有某些说明,例如QADD,QSUB等.
I want to understand the importance of Q flag in ARM Processor. I know there are certain instructions like QADD,QSUB etc.
但是我需要通过一些例子来理解这一点,以阐明这个概念.
But I need to understand this with some examples which will clarify the concept.
请给我解释.
谢谢
推荐答案
《 ARM体系结构参考手册》(ARM DDI 0100E)中对此进行了解释:
This is explained in the "ARM Architecture Reference Manual" (ARM DDI 0100E):
Bit [27]是粘性溢出标志,也称为Q标志.如果发生以下任何情况,则此标志设置为1:
Bit[27] of the CPSR
is a sticky overflow flag, also known as the Q flag. This flag is set to 1 if any of the following occurs:
-
QADD
或QDADD
指令中的加法结果饱和 -
QSUB
或QDSUB
指令中的减法结果饱和 -
QDADD
或QDSUB
指令中加倍中间结果的饱和度 - 在
SMLA< x>< y>
或SMLAW< y>
指令期间发生签名溢出
- Saturation of the addition result in a
QADD
orQDADD
instruction - Saturation of the subtraction result in a
QSUB
orQDSUB
instruction - Saturation of the doubling intermediate result in a
QDADD
orQDSUB
instruction - Signed overflow during an
SMLA<x><y>
orSMLAW<y>
instruction
Q标志为 sticky ,因为一旦将其设置为1,它就不受后续计算是否饱和和/或溢出的影响.其预期用途是:
The Q flag is sticky in that once it has been set to 1, it is not affected by whether subsequent calculations saturate and/or overflow. Its intended usage is:
- 使用
MSR CPSR_f,#0
指令清除Q标志(这还将清除条件代码标志). - 执行一系列计算.
- 使用
MRS Rn,CPSR
指令读取CPSR
,然后测试Q标志的值.如果仍为0,则在第2步中没有发生任何上述类型的饱和或溢出.否则,至少发生了一次断断续续或溢出的情况.
- Use an
MSR CPSR_f,#0
instruction to clear the Q flag (this also clears the condition code flags). - Peform a sequence of calculations.
- Use an
MRS Rn,CPSR
instruction to read theCPSR
, then test the value of the Q flag. If it is still 0, none of the above types of saturation or overflow occured during step 2. Otherwise, at least one instance of stauration or overflow occured.
一个例子:
An example:
mov r2,#0x70000000
qadd r3,r2,r2
0x70000000 + 0x70000000
将变为 0xE0000000
,但是由于 qadd
处于饱和状态,结果将饱和为 0x7FFFFFFF
(最大的32位正整数)并设置了Q标志.
0x70000000 + 0x70000000
would become 0xE0000000
, but since qadd
is saturating, the result is saturated to 0x7FFFFFFF
(the largest positive 32-bit integer) and the Q flag is set.
这篇关于Q(饱和标志)在ARM中的重要性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!