shsub8

Signed Halving Subtract 8

SHSUB8<c> <Rd>, <Rn>, <Rm>

Signed subtract and halving of 4 bytes.

Details

Performs parallel subtraction of four signed 8-bit bytes 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 [−128, 127]. No condition flags are affected. Execution restricted to A32 with DSP extension; requires ARMv6 or later.

Pseudocode Operation

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

Example

SHSUB8 r0, r1, r2

Encoding

Binary Layout
cond
01100
011
Rn
Rd
1
1
1
1
1
11
1
Rm
 
Format SIMD Integer
Opcode 0x06300FF0
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
0x06300FF0 SHSUB8{<c>}{<q>} {<Rd>,} <Rn>, <Rm> A32 cond | 01100 | 011 | Rn | Rd | 1 | 1 | 1 | 1 | 1 | 11 | 1 | Rm
0xFAC0F020 SHSUB8{<c>}{<q>} {<Rd>,} <Rn>, <Rm> T32 111110101 | 100 | Rn | 1111 | Rd | 0 | 0 | 1 | 0 | Rm

Description

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

Operation

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