shsub16

Signed Halving Subtract 16

SHSUB16<c> <Rd>, <Rn>, <Rm>

Signed subtract and halving of 2 halfwords.

Details

Performs parallel subtraction of two signed 16-bit halfwords in Rm from Rn, then arithmetically shifts each result right by 1 bit (halving), storing in Rd. No saturation occurs; results are always in the range [−32768, 32767]. No condition flags are affected. Execution restricted to A32 with DSP extension; requires ARMv6 or later.

Pseudocode Operation

Rd[31:16] ← (SignExtend(Rn[31:16]) − SignExtend(Rm[31:16])) >> 1
Rd[15:0] ← (SignExtend(Rn[15:0]) − SignExtend(Rm[15:0])) >> 1

Example

SHSUB16 r0, r1, r2

Encoding

Binary Layout
cond
01100
011
Rn
Rd
1
1
1
1
0
11
1
Rm
 
Format SIMD Integer
Opcode 0x06300F70
Extension A32 (DSP)

Operands

  • Rd
    Destination general-purpose register
  • Rn
    First source / base general-purpose register
  • Rm
    Second source / offset general-purpose register

Reference (Arm AArch32 ISA)

Instruction Forms

Encoding Instruction ISA Bit pattern
0x06300F70 SHSUB16{<c>}{<q>} {<Rd>,} <Rn>, <Rm> A32 cond | 01100 | 011 | Rn | Rd | 1 | 1 | 1 | 1 | 0 | 11 | 1 | Rm
0xFAD0F020 SHSUB16{<c>}{<q>} {<Rd>,} <Rn>, <Rm> T32 111110101 | 101 | Rn | 1111 | Rd | 0 | 0 | 1 | 0 | Rm

Description

Signed Halving Subtract 16 performs two signed 16-bit integer subtractions, halves the results, and writes the results to the destination register.

Operation

if ConditionPassed() then
    EncodingSpecificOperations();
    diff1 = SInt(R[n]<15:0>) - SInt(R[m]<15:0>);
    diff2 = SInt(R[n]<31:16>) - SInt(R[m]<31:16>);
    R[d]<15:0>  = diff1<16:1>;
    R[d]<31:16> = diff2<16:1>;