Microsoft Specific

Generates the addsubps instruction.

__m128 _mm_addsub_ps(
   __m128 a,
   __m128 b,


  • [in] a
    The first operand.

  • [in] b
    The second operand.





Intel SSE3

Header file <intrin.h>


The addsubps instruction performs a packed operation involving single-precision addition and subtraction on 128-bit data. Each 128-bit operand consists of four 32-bit data elements, numbered from 0 to 3, with 3 being the high-order element. The operation subtracts the numbers in the even data elements and adds the numbers in the odd data elements. Thus, if the input is { A0, A1, A2, A3 } and { B0, B1, B2, B3 }, then the output is { A0-B0, A1+B1, A2-B2, A3+B3 }.

This routine is only available as an intrinsic.


// processor: x86 with SSE3
// Execute the addsub_ps instruction using the PNI intrinsic
// _mm_addsub_ps 

#include <stdio.h>
#include <intrin.h>

#pragma intrinsic ( _mm_addsub_ps )

int main( )
    __m128 u, v, w;
    __declspec(align(16)) float a[4] = { 0.1, 0.2, 0.3, 0.4 };
    __declspec(align(16)) float b[4] = { 0.0001, 0.002, 0.003, 0.004 };

    printf_s("Loading floating-point values\n"
             "%5.3f %5.3f %5.3f %5.3f into XMM register.\n",
             a[0], a[1], a[2], a[3] );
    u = _mm_load_ps(a);
    printf_s("Loading floating-point values\n "
             "%5.3f %5.3f %5.3f %5.3f into XMM register.\n",
             b[0], b[1], b[2], b[3] );
    v = _mm_load_ps(b);

    printf_s("Calling _mm_addsub_ps to modify these values.\n");
    w = _mm_addsub_ps ( u , v);

    printf_s("Result: %5.3f %5.3f %5.3f %5.3f\n",
             w.m128_f32[0], w.m128_f32[1],
             w.m128_f32[2], w.m128_f32[3] );
Loading floating-point values
0.100 0.200 0.300 0.400 into XMM register.
Loading floating-point values
0.000 0.002 0.003 0.004 into XMM register.
Calling _mm_addsub_ps to modify these values.
Result: 0.100 0.202 0.297 0.404

See Also


Compiler Intrinsics