本文介绍了Q(饱和标志)在 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):

位[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:

  • QADDQDADD 指令中的加法饱和结果
  • 减法饱和导致QSUBQDSUB指令
  • QDADDQDSUB 指令中加倍中间结果的饱和
  • SMLASMLAW 指令期间的有符号溢出
  • Saturation of the addition result in a QADD or QDADD instruction
  • Saturation of the subtraction result in a QSUB or QDSUB instruction
  • Saturation of the doubling intermediate result in a QDADD or QDSUB instruction
  • Signed overflow during an SMLA<x><y> or SMLAW<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:

  1. 使用 MSR CPSR_f,#0 指令清除 Q 标志(这也清除条件代码标志).
  2. 执行一系列计算.
  3. 使用MRS Rn,CPSR指令读取CPSR,然后测试Q标志的值.如果仍然为0,则在步骤2中没有发生上述类型的饱和或溢出.否则,至少会发生一个饱和或溢出的情况.
  1. Use an MSR CPSR_f,#0 instruction to clear the Q flag (this also clears the condition code flags).
  2. Peform a sequence of calculations.
  3. Use an MRS Rn,CPSR instruction to read the CPSR, 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.

示例:

mov     r2,#0x70000000
qadd    r3,r2,r2

0x70000000 + 0x70000000 会变成 0xE0000000,但是由于 qadd 是饱和的,结果饱和到 0x7FFFFFFFF(最大的 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 中的重要性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 05:36