Skip to content

wpadd

Adds the neighbors two by two into the integer type twice as wide: \(\text{res}_i = vd0_{2i} + vd0_{2i+1}\), without overflow (int8 to int16, int16 to int32, int32 to int64, and the same for the unsigned types). The result has the same size, so the same LMUL, and half the lanes. It is the first step of the horizontal sums of narrow types (histograms, sums of bytes), and with absdiff the sum of absolute differences of the motion estimation (wpadd(wpadd(wpadd(absdiff(a, b)))) sums 8 bytes into 64 bits, as psadbw). Native on NEON (vpaddl) and SVE2 (sadalp / uadalp); on x86, pmaddwd (int16) and pmaddubsw (8-bit types, SSSE3) with a register of ones; elsewhere a reinterpretation, a mask or a shift, and an addition.

Mathematical semantics: \(\text{res}_i = vd0_{2i} + vd0_{2i+1}\)

Open in the API Explorer →

Prototypes

// LMUL = 1 (also without the _m1 suffix)
vd_int64_m1_t mipp_wpadd_int32_int64_m1(const vd_int32_m1_t vd0);
vd_int32_m1_t mipp_wpadd_int16_int32_m1(const vd_int16_m1_t vd0);
vd_int16_m1_t mipp_wpadd_int8_int16_m1(const vd_int8_m1_t vd0);
vd_uint64_m1_t mipp_wpadd_uint32_uint64_m1(const vd_uint32_m1_t vd0);
vd_uint32_m1_t mipp_wpadd_uint16_uint32_m1(const vd_uint16_m1_t vd0);
vd_uint16_m1_t mipp_wpadd_uint8_uint16_m1(const vd_uint8_m1_t vd0);
// LMUL = 2
vd_int64_m2_t mipp_wpadd_int32_int64_m2(const vd_int32_m2_t vd0);
vd_int32_m2_t mipp_wpadd_int16_int32_m2(const vd_int16_m2_t vd0);
vd_int16_m2_t mipp_wpadd_int8_int16_m2(const vd_int8_m2_t vd0);
vd_uint64_m2_t mipp_wpadd_uint32_uint64_m2(const vd_uint32_m2_t vd0);
vd_uint32_m2_t mipp_wpadd_uint16_uint32_m2(const vd_uint16_m2_t vd0);
vd_uint16_m2_t mipp_wpadd_uint8_uint16_m2(const vd_uint8_m2_t vd0);
// LMUL = 4
vd_int64_m4_t mipp_wpadd_int32_int64_m4(const vd_int32_m4_t vd0);
vd_int32_m4_t mipp_wpadd_int16_int32_m4(const vd_int16_m4_t vd0);
vd_int16_m4_t mipp_wpadd_int8_int16_m4(const vd_int8_m4_t vd0);
vd_uint64_m4_t mipp_wpadd_uint32_uint64_m4(const vd_uint32_m4_t vd0);
vd_uint32_m4_t mipp_wpadd_uint16_uint32_m4(const vd_uint16_m4_t vd0);
vd_uint16_m4_t mipp_wpadd_uint8_uint16_m4(const vd_uint8_m4_t vd0);
// LMUL = 8
vd_int64_m8_t mipp_wpadd_int32_int64_m8(const vd_int32_m8_t vd0);
vd_int32_m8_t mipp_wpadd_int16_int32_m8(const vd_int16_m8_t vd0);
vd_int16_m8_t mipp_wpadd_int8_int16_m8(const vd_int8_m8_t vd0);
vd_uint64_m8_t mipp_wpadd_uint32_uint64_m8(const vd_uint32_m8_t vd0);
vd_uint32_m8_t mipp_wpadd_uint16_uint32_m8(const vd_uint16_m8_t vd0);
vd_uint16_m8_t mipp_wpadd_uint8_uint16_m8(const vd_uint8_m8_t vd0);
// d2 (half-vector)
vd_int64_d2_t mipp_wpadd_int32_int64_d2(const vd_int32_d2_t vd0);
vd_int32_d2_t mipp_wpadd_int16_int32_d2(const vd_int16_d2_t vd0);
vd_int16_d2_t mipp_wpadd_int8_int16_d2(const vd_int8_d2_t vd0);
vd_uint64_d2_t mipp_wpadd_uint32_uint64_d2(const vd_uint32_d2_t vd0);
vd_uint32_d2_t mipp_wpadd_uint16_uint32_d2(const vd_uint16_d2_t vd0);
vd_uint16_d2_t mipp_wpadd_uint8_uint16_d2(const vd_uint8_d2_t vd0);
// LMUL = 1
vd<int64_t> wpadd_int64(const vd<int32_t> vd0);
vd<int32_t> wpadd_int32(const vd<int16_t> vd0);
vd<int16_t> wpadd_int16(const vd<int8_t> vd0);
vd<uint64_t> wpadd_uint64(const vd<uint32_t> vd0);
vd<uint32_t> wpadd_uint32(const vd<uint16_t> vd0);
vd<uint16_t> wpadd_uint16(const vd<uint8_t> vd0);
// LMUL = 2
vd<int64_t, 2> wpadd_int64(const vd<int32_t, 2> vd0);
vd<int32_t, 2> wpadd_int32(const vd<int16_t, 2> vd0);
vd<int16_t, 2> wpadd_int16(const vd<int8_t, 2> vd0);
vd<uint64_t, 2> wpadd_uint64(const vd<uint32_t, 2> vd0);
vd<uint32_t, 2> wpadd_uint32(const vd<uint16_t, 2> vd0);
vd<uint16_t, 2> wpadd_uint16(const vd<uint8_t, 2> vd0);
// LMUL = 4
vd<int64_t, 4> wpadd_int64(const vd<int32_t, 4> vd0);
vd<int32_t, 4> wpadd_int32(const vd<int16_t, 4> vd0);
vd<int16_t, 4> wpadd_int16(const vd<int8_t, 4> vd0);
vd<uint64_t, 4> wpadd_uint64(const vd<uint32_t, 4> vd0);
vd<uint32_t, 4> wpadd_uint32(const vd<uint16_t, 4> vd0);
vd<uint16_t, 4> wpadd_uint16(const vd<uint8_t, 4> vd0);
// LMUL = 8
vd<int64_t, 8> wpadd_int64(const vd<int32_t, 8> vd0);
vd<int32_t, 8> wpadd_int32(const vd<int16_t, 8> vd0);
vd<int16_t, 8> wpadd_int16(const vd<int8_t, 8> vd0);
vd<uint64_t, 8> wpadd_uint64(const vd<uint32_t, 8> vd0);
vd<uint32_t, 8> wpadd_uint32(const vd<uint16_t, 8> vd0);
vd<uint16_t, 8> wpadd_uint16(const vd<uint8_t, 8> vd0);
// d2 (half-vector)
vd<int64_t, -2> wpadd_int64(const vd<int32_t, -2> vd0);
vd<int32_t, -2> wpadd_int32(const vd<int16_t, -2> vd0);
vd<int16_t, -2> wpadd_int16(const vd<int8_t, -2> vd0);
vd<uint64_t, -2> wpadd_uint64(const vd<uint32_t, -2> vd0);
vd<uint32_t, -2> wpadd_uint32(const vd<uint16_t, -2> vd0);
vd<uint16_t, -2> wpadd_uint16(const vd<uint8_t, -2> vd0);
// LMUL = 1
template <typename T_DST, typename T_SRC> Vd<T_DST> wpadd(const Vd<T_SRC>& vd0);
// LMUL = 2
template <typename T_DST, typename T_SRC> Vd<T_DST, 2> wpadd(const Vd<T_SRC, 2>& vd0);
// LMUL = 4
template <typename T_DST, typename T_SRC> Vd<T_DST, 4> wpadd(const Vd<T_SRC, 4>& vd0);
// LMUL = 8
template <typename T_DST, typename T_SRC> Vd<T_DST, 8> wpadd(const Vd<T_SRC, 8>& vd0);
// d2 (half-vector)
template <typename T_DST, typename T_SRC> Vd<T_DST, -2> wpadd(const Vd<T_SRC, -2>& vd0);

Headers

// Option 1: Monolithic (entire library)
#include <mipp.h>

// Option 2: Category level
#include <mipp/c/cat/arithmetic.h>                  // all variants & LMULs
#include <mipp/c/cat/u/arithmetic.h>                // 1D: 'u' variant only (*)
#include <mipp/c/cat/m2/arithmetic.h>               // 1D: LMUL=2 only (*)
#include <mipp/c/cat/u/m2/arithmetic.h>             // 2D: 'u' + LMUL=2 (*)

// Option 3: Function level (recommended for minimal dependencies)
#include <mipp/c/fun/wpadd.h>                       // all variants & LMULs
#include <mipp/c/fun/u/wpadd.h>                     // 1D: 'u' variant only (*)
#include <mipp/c/fun/m2/wpadd.h>                    // 1D: LMUL=2 only (*)
#include <mipp/c/fun/u/m2/wpadd.h>                  // 2D atomic: 'u' + LMUL=2 (fastest compilation) (*)

// (*) Fine-grained headers require MIPP generated with '--granularity fine'
// Option 1: Monolithic (entire library)
#include <mipp.hpp>

// Option 2: Category level
#include <mipp/cpp/cat/arithmetic.hpp>              // all variants & LMULs
#include <mipp/cpp/cat/u/arithmetic.hpp>            // 1D: 'u' variant only (*)
#include <mipp/cpp/cat/m2/arithmetic.hpp>           // 1D: LMUL=2 only (*)
#include <mipp/cpp/cat/u/m2/arithmetic.hpp>         // 2D: 'u' + LMUL=2 (*)

// Option 3: Function level (recommended for minimal dependencies)
#include <mipp/cpp/fun/wpadd.hpp>                   // all variants & LMULs
#include <mipp/cpp/fun/u/wpadd.hpp>                 // 1D: 'u' variant only (*)
#include <mipp/cpp/fun/m2/wpadd.hpp>                // 1D: LMUL=2 only (*)
#include <mipp/cpp/fun/u/m2/wpadd.hpp>              // 2D atomic: 'u' + LMUL=2 (fastest compilation) (*)

// (*) Fine-grained headers require MIPP generated with '--granularity fine'
// Option 1: Monolithic (entire library)
#include <mipp_obj.hpp>

// Option 2: Category level
#include <mipp/obj/cat/arithmetic.hpp>              // all variants & LMULs
#include <mipp/obj/cat/u/arithmetic.hpp>            // 1D: 'u' variant only (*)
#include <mipp/obj/cat/m2/arithmetic.hpp>           // 1D: LMUL=2 only (*)
#include <mipp/obj/cat/u/m2/arithmetic.hpp>         // 2D: 'u' + LMUL=2 (*)

// Option 3: Function level (recommended for minimal dependencies)
#include <mipp/obj/fun/wpadd.hpp>                   // all variants & LMULs
#include <mipp/obj/fun/u/wpadd.hpp>                 // 1D: 'u' variant only (*)
#include <mipp/obj/fun/m2/wpadd.hpp>                // 1D: LMUL=2 only (*)
#include <mipp/obj/fun/u/m2/wpadd.hpp>              // 2D atomic: 'u' + LMUL=2 (fastest compilation) (*)

// (*) Fine-grained headers require MIPP generated with '--granularity fine'

Supported Datatypes

  • int32 → int64
  • int16 → int32
  • int8 → int16
  • uint32 → uint64
  • uint16 → uint32
  • uint8 → uint16

Architecture & Implementation Matrix

Legend: L0 Native Hardware • L1 Dedicated Emulation • L2 Generic Emulation • L3 Scalar Fallback • − N/A  —  Full details. When the level depends on a compiler flag, the best level is shown.

Architecture i32→i64 i16→i32 i8→i16 u32→u64 u16→u32 u8→u16
SSE L2 L0 L0 L2 L2 L0
AVX L2 L0 L0 L2 L2 L0
AVX512 L2 L0 L0 L2 L2 L0
NEON L0 L0 L0 L0 L0 L0
RVV L2 L2 L2 L2 L2 L2
SVE L0 L0 L0 L0 L0 L0

Reference Algorithm

The scalar reference of MIPP defines the expected result of the function, for each datatype and mask variant: the unit tests compare the SIMD implementations of every target with it.

vd_scalar_int64_m1_t mipp_scalar_wpadd_int32_int64_m1(const vd_scalar_int32_m1_t vd0) {
    // the sum of the neighbors 2i and 2i + 1, in the type twice as wide
    vd_scalar_int64_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_INT64; i++)
        res.vd[i] = (int64_t)vd0.vd[2 * i] + (int64_t)vd0.vd[2 * i + 1];
    return res;
}
vd_scalar_int32_m1_t mipp_scalar_wpadd_int16_int32_m1(const vd_scalar_int16_m1_t vd0) {
    // the sum of the neighbors 2i and 2i + 1, in the type twice as wide
    vd_scalar_int32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_INT32; i++)
        res.vd[i] = (int32_t)vd0.vd[2 * i] + (int32_t)vd0.vd[2 * i + 1];
    return res;
}
vd_scalar_int16_m1_t mipp_scalar_wpadd_int8_int16_m1(const vd_scalar_int8_m1_t vd0) {
    // the sum of the neighbors 2i and 2i + 1, in the type twice as wide
    vd_scalar_int16_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_INT16; i++)
        res.vd[i] = (int16_t)vd0.vd[2 * i] + (int16_t)vd0.vd[2 * i + 1];
    return res;
}
vd_scalar_uint64_m1_t mipp_scalar_wpadd_uint32_uint64_m1(const vd_scalar_uint32_m1_t vd0) {
    // the sum of the neighbors 2i and 2i + 1, in the type twice as wide
    vd_scalar_uint64_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_UINT64; i++)
        res.vd[i] = (uint64_t)vd0.vd[2 * i] + (uint64_t)vd0.vd[2 * i + 1];
    return res;
}
vd_scalar_uint32_m1_t mipp_scalar_wpadd_uint16_uint32_m1(const vd_scalar_uint16_m1_t vd0) {
    // the sum of the neighbors 2i and 2i + 1, in the type twice as wide
    vd_scalar_uint32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_UINT32; i++)
        res.vd[i] = (uint32_t)vd0.vd[2 * i] + (uint32_t)vd0.vd[2 * i + 1];
    return res;
}
vd_scalar_uint16_m1_t mipp_scalar_wpadd_uint8_uint16_m1(const vd_scalar_uint8_m1_t vd0) {
    // the sum of the neighbors 2i and 2i + 1, in the type twice as wide
    vd_scalar_uint16_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_UINT16; i++)
        res.vd[i] = (uint16_t)vd0.vd[2 * i] + (uint16_t)vd0.vd[2 * i + 1];
    return res;
}

Test & Verification Specifications

How the unit tests draw the inputs (random values) and compare each lane of the result with the scalar reference, as in the generated C API tests.

Datatypes Inputs Comparison with the reference
All full range Exact