qdsub
Saturating Double and Subtract
QDSUB<c> <Rd>, <Rm>, <Rn>
Doubles the second operand, subtracts from first, and saturates.
Details
Saturates the doubling of Rm, then subtracts the result from Rn with saturation, writing the saturated difference to Rd. The Q flag is set if saturation occurred during either the doubling or subtraction; other flags are unaffected. A32-only instruction requiring the Saturating Arithmetic extension; must be executed in privileged mode for certain CPSR modifications.
Pseudocode Operation
doubled ← SignedSat(Rm << 1, 32)
result ← SignedSat(Rn - doubled, 32)
Rd ← result
if (overflow during doubling or subtraction) then Q ← 1
Example
QDSUB r0, r2, r1
Encoding
Binary Layout
cond
00010
11
0
Rn
Rd
0
0
0
0
0101
Rm
Operands
-
Rd
Destination general-purpose register -
Rm
Second source / offset general-purpose register -
Rn
First source / base general-purpose register
Reference (Arm AArch32 ISA)
Instruction Forms
| Encoding | Instruction | ISA | Bit pattern | ||
|---|---|---|---|---|---|
| 0x01600050 | QDSUB{<c>}{<q>} {<Rd>,} <Rm>, <Rn> | A32 | cond | 00010 | 11 | 0 | Rn | Rd | 0 | 0 | 0 | 0 | 0101 | Rm | ||
| 0xFA80F0B0 | QDSUB{<c>}{<q>} {<Rd>,} <Rm>, <Rn> | T32 | 111110101 | 000 | Rn | 1111 | Rd | 10 | 11 | Rm |
Description
Saturating Double and Subtract subtracts a doubled register value from another register value, and writes the result to the destination register. Both the doubling and the subtraction have their results saturated to the 32-bit signed integer range -231 <= x <= 231 - 1. If saturation occurs in either operation, it sets PSTATE.Q to 1.
Operation
if ConditionPassed() then
EncodingSpecificOperations();
(doubled, sat1) = SignedSatQ(2 * SInt(R[n]), 32);
boolean sat2;
(R[d], sat2) = SignedSatQ(SInt(R[m]) - SInt(doubled), 32);
if sat1 || sat2 then
PSTATE.Q = '1';