Importance of Q(Saturation Flag) in ARM

我的梦境 提交于 2021-01-19 06:45:29

问题


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.

Please explain me.

Thank you


回答1:


This is explained in the "ARM Architecture Reference Manual" (ARM DDI 0100E):

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:

  • 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

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. 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.

An example:

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

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.



来源:https://stackoverflow.com/questions/19557338/importance-of-qsaturation-flag-in-arm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!