Integer Arithmetic Operations for Streaming SIMD Extensions 2

The integer arithmetic operations for Streaming SIMD Extensions 2 are listed in the following table followed by their descriptions. The packed arithmetic intrinsics for Streaming SIMD Extensions 2 are listed in the Floating-point Arithmetic Operations topic.

The prototypes for Streaming SIMD Extensions 2 intrinsics are in the emmintrin.h header file.

Intrinsic Instruction Operation
_mm_add_epi8 PADDB Addition
_mm_add_epi16 PADDW Addition
_mm_add_epi32 PADDD Addition
_mm_add_si64 PADDQ Addition
_mm_add_epi64 PADDQ Addition
_mm_adds_epi8 PADDSB Addition
_mm_adds_epi16 PADDSW Addition
_mm_adds_epu8 PADDUSB Addition
_mm_adds_epu16 PADDUSW Addition
_mm_avg_epu8 PAVGB Computes Average
_mm_avg_epu16 PAVGW Computes Average
_mm_madd_epi16 PMADDWD Multiplication/Addition
_mm_max_epi16 PMAXSW Computes Maxima
_mm_max_epu8 PMAXUB Computes Maxima
_mm_min_epi16 PMINSW Computes Minima
_mm_min_epu8 PMINUB Computes Minima
_mm_mulhi_epi16 PMULHW Multiplication
_mm_mulhi_epu16 PMULHUW Multiplication
_mm_mullo_epi16 PMULLW Multiplication
_mm_mul_su32 PMULUDQ Multiplication
_mm_mul_epu32 PMULUDQ Multiplication
_mm_sad_epu8 PSADBW Computes Difference/Adds
_mm_sub_epi8 PSUBB Subtraction
_mm_sub_epi16 PSUBW Subtraction
_mm_sub_epi32 PSUBD Subtraction
_mm_sub_si64 PSUBQ Subtraction
_mm_sub_epi64 PSUBQ Subtraction
_mm_subs_epi8 PSUBSB Subtraction
_mm_subs_epi16 PSUBSW Subtraction
_mm_subs_epu8 PSUBUSB Subtraction
_mm_subs_epu16 PSUBUSW Subtraction

__mm128i _mm_add_epi8(__m128i a, __m128i b)

Adds the 16 signed or unsigned 8-bit integers in a to the 16 signed or unsigned 8-bit integers in b.
r0 := a0 + b0
r1 := a1 + b1
...
r15 := a15 + b15

__mm128i _mm_add_epi16(__m128i a, __m128i b)

Adds the 8 signed or unsigned 16-bit integers in a to the 8 signed or unsigned 16-bit integers in b.
r0 := a0 + b0
r1 := a1 + b1
...
r7 := a7 + b7

__m128i _mm_add_epi32(__m128i a, __m128i b)

Adds the 4 signed or unsigned 32-bit integers in a to the 4 signed or unsigned 32-bit integers in b.
r0 := a0 + b0
r1 := a1 + b1
r2 := a2 + b2
r3 := a3 + b3

__m64 _mm_add_si64(__m64 a, __m64 b)

Adds the signed or unsigned 64-bit integer a to the signed or unsigned 64-bit integer b.
r := a + b

__m128i _mm_add_epi64(__m128i a, __m128i b)

Adds the 2 signed or unsigned 64-bit integers in a to the 2 signed or unsigned 64-bit integers in b.
r0 := a0 + b0
r1 := a1 + b1

__m128i _mm_adds_epi8(__m128i a, __m128i b)

Adds the 16 signed 8-bit integers in a to the 16 signed 8-bit integers in b using saturating arithmetic.
r0 := SignedSaturate(a0 + b0)
r1 := SignedSaturate(a1 + b1)
...
r15 := SignedSaturate(a15 + b15)

__m128i _mm_adds_epi16(__m128i a, __m128i b)

Adds the 8 signed 16-bit integers in a to the 8 signed 16-bit integers in b using saturating arithmetic.
r0 := SignedSaturate(a0 + b0)
r1 := SignedSaturate(a1 + b1)
...
r7 := SignedSaturate(a7 + b7)

__m128i _mm_adds_epu8(__m128i a, __m128i b)

Adds the 16 unsigned 8-bit integers in a to the 16 unsigned 8-bit integers in b using saturating arithmetic.
r0 := UnsignedSaturate(a0 + b0)
r1 := UnsignedSaturate(a1 + b1)
...
r15 := UnsignedSaturate(a15 + b15)

__m128i _mm_adds_epu16(__m128i a, __m128i b)

Adds the 8 unsigned 16-bit integers in a to the 8 unsigned 16-bit integers in b using saturating arithmetic.
r0 := UnsignedSaturate(a0 + b0)
r1 := UnsignedSaturate(a1 + b1)
...
r15 := UnsignedSaturate(a7 + b7)

__m128i _mm_avg_epu8(__m128i a, __m128i b)

Computes the average of the 16 unsigned 8-bit integers in a and the 16 unsigned 8-bit integers in b and rounds.
r0 := (a0 + b0) / 2
r1 := (a1 + b1) / 2
...
r15 := (a15 + b15) / 2

__m128i _mm_avg_epu16(__m128i a, __m128i b)

Computes the average of the 8 unsigned 16-bit integers in a and the 8 unsigned 16-bit integers in b and rounds.
r0 := (a0 + b0) / 2
r1 := (a1 + b1) / 2
...
r7 := (a7 + b7) / 2

__m128i _mm_madd_epi16(__m128i a, __m128i b)

Multiplies the 8 signed 16-bit integers from a by the 8 signed 16-bit integers from b. Adds the signed 32-bit integer results pairwise and packs the 4 signed 32-bit integer results.
r0 := (a0 * b0) + (a1 * b1)
r1 := (a2 * b2) + (a3 * b3)
r2 := (a4 * b4) + (a5 * b5)
r3 := (a6 * b6) + (a7 * b7)

__m128i _mm_max_epi16(__m128i a, __m128i b)

Computes the pairwise maxima of the 8 signed 16-bit integers from a and the 8 signed 16-bit integers from b.
r0 := max(a0, b0)
r1 := max(a1, b1)
...
r7 := max(a7, b7)

__m128i _mm_max_epu8(__m128i a, __m128i b)

Computes the pairwise maxima of the 16 unsigned 8-bit integers from a and the 16 unsigned 8-bit integers from b.
r0 := max(a0, b0)
r1 := max(a1, b1)
...
r15 := max(a15, b15)

__m128i _mm_min_epi16(__m128i a, __m128i b)

Computes the pairwise minima of the 8 signed 16-bit integers from a and the 8 signed 16-bit integers from b.
r0 := min(a0, b0)
r1 := min(a1, b1)
...
r7 := min(a7, b7)

__m128i _mm_min_epu8(__m128i a, __m128i b)

Computes the pairwise minima of the 16 unsigned 8-bit integers from a and the 16 unsigned 8-bit integers from b.
r0 := min(a0, b0)
r1 := min(a1, b1)
...
r15 := min(a15, b15)

__m128i _mm_mulhi_epi16(__m128i a, __m128i b)

Multiplies the 8 signed 16-bit integers from a by the 8 signed 16-bit integers from b. Packs the upper 16-bits of the 8 signed 32-bit results.
r0 := (a0 * b0)[31:16]
r1 := (a1 * b1)[31:16]
...
r7 := (a7 * b7)[31:16]

__m128i _mm_mulhi_epu16(__m128i a, __m128i b)

Multiplies the 8 unsigned 16-bit integers from a by the 8 unsigned 16-bit integers from b. Packs the upper 16-bits of the 8 unsigned 32-bit results.

r0 := (a0 * b0)[31:16]
r1 := (a1 * b1)[31:16]
...
r7 := (a7 * b7)[31:16]

__m128i_mm_mullo_epi16(__m128i a, __m128i b)

Multiplies the 8 signed or unsigned 16-bit integers from a by the 8 signed or unsigned 16-bit integers from b. Packs the lower 16-bits of the 8 signed or unsigned 32-bit results.
r0 := (a0 * b0)[15:0]
r1 := (a1 * b1)[15:0]
...
r7 := (a7 * b7)[15:0]

__m64 _mm_mul_su32(__m64 a, __m64 b)

Multiplies the lower 32-bit integer from a by the lower 32-bit integer from b, and returns the 64-bit integer result.
r := a0 * b0

__m128i _mm_mul_epu32(__m128i a, __m128i b)

Multiplies 2 unsigned 32-bit integers from a by 2 unsigned 32-bit integers from b. Packs the 2 unsigned 64-bit integer results.
r0 := a0 * b0
r1 := a2 * b2

__m128i _mm_sad_epu8(__m128i a, __m128i b)

Computes the absolute difference of the 16 unsigned 8-bit integers from a and the 16 unsigned 8-bit integers from b. Sums the upper 8 differences and lower 8 differences, and packs the resulting 2 unsigned 16-bit integers into the upper and lower 64-bit elements.
r0 := abs(a0 - b0) + abs(a1 - b1) +...+ abs(a7 - b7)
r1 := 0x0 ; r2 := 0x0 ; r3 := 0x0
r4 := abs(a8 - b8) + abs(a9 - b9) +...+ abs(a15 - b15)
r5 := 0x0 ; r6 := 0x0 ; r7 := 0x0

__m128i _mm_sub_epi8(__m128i a, __m128i b)

Subtracts the 16 signed or unsigned 8-bit integers of b from the 16 signed or unsigned 8-bit integers of a.
r0 := a0 - b0
r1 := a1 - b1
...
r15 := a15 - b15

__m128i_mm_sub_epi16(__m128i a, __m128i b)

Subtracts the 8 signed or unsigned 16-bit integers of b from the 8 signed or unsigned 16-bit integers of a.
r0 := a0 - b0
r1 := a1 - b1
...
r7 := a7 - b7

__m128i _mm_sub_epi32(__m128i a, __m128i b)

Subtracts the 4 signed or unsigned 32-bit integers of b from the 4 signed or unsigned 32-bit integers of a.
r0 := a0 - b0
r1 := a1 - b1
r2 := a2 - b2
r3 := a3 - b3

__m64 _mm_sub_si64 (__m64 a, __m64 b)

Subtracts the signed or unsigned 64-bit integer b from the signed or unsigned 64-bit integer a.
r := a - b

__m128i _mm_sub_epi64(__m128i a, __m128i b)

Subtracts the 2 signed or unsigned 64-bit integers in b from the 2 signed or unsigned 64-bit integers in a.
r0 := a0 - b0
r1 := a1 - b1

__m128i _mm_subs_epi8(__m128i a, __m128i b)

Subtracts the 16 signed 8-bit integers of b from the 16 signed 8-bit integers of a using saturating arithmetic.
r0 := SignedSaturate(a0 - b0)
r1 := SignedSaturate(a1 - b1)
...
r15 := SignedSaturate(a15 - b15)

__m128i _mm_subs_epi16(__m128i a, __m128i b)

Subtracts the 8 signed 16-bit integers of b from the 8 signed 16-bit integers of a using saturating arithmetic.
r0 := SignedSaturate(a0 - b0)
r1 := SignedSaturate(a1 - b1)
...
r7 := SignedSaturate(a7 - b7)

__m128i _mm_subs_epu8(__m128i a, __m128i b)

Subtracts the 16 unsigned 8-bit integers of b from the 16 unsigned 8-bit integers of a using saturating arithmetic.
r0 := UnsignedSaturate(a0 - b0)
r1 := UnsignedSaturate(a1 - b1)
...
r15 := UnsignedSaturate(a15 - b15)

__m128i _mm_subs_epu16(__m128i a, __m128i b)

Subtracts the 8 unsigned 16-bit integers of b from the 8 unsigned 16-bit integers of a using saturating arithmetic.
r0 := UnsignedSaturate(a0 - b0)
r1 := UnsignedSaturate(a1 - b1)
...
r7 := UnsignedSaturate(a7 - b7)