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.
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.
Copyright © 2021 Jogjafile Inc.
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:QADD
orQDADD
instructionQSUB
orQDSUB
instructionQDADD
orQDSUB
instructionSMLA<x><y>
orSMLAW<y>
instructionThe 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
instruction to clear the Q flag (this also clears the condition code flags).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:
0x70000000 + 0x70000000
would become0xE0000000
, but sinceqadd
is saturating, the result is saturated to0x7FFFFFFF
(the largest positive 32-bit integer) and the Q flag is set.