Skip to content

dot4

Dot products of groups of four 8-bit elements accumulated in 32 bits: each 32-bit lane \(i\) of the accumulator vd0 receives \(\sum_{k=0}^{3} a_{4i+k} b_{4i+k}\), the products of the four 8-bit lanes of vd1 and vd2 at the same place (the registers have the same size: the accumulator has four times fewer lanes). Both operands are signed (int8 to int32) or both unsigned (uint8 to uint32); dot4us mixes an unsigned and a signed operand. Computed modulo \(2^{32}\), without saturation. Native on NEON with the dot product extension (sdot / udot, ARMv8.4 and the Apple chips), on SVE, and on x86 with AVX-VNNI-INT8 (vpdpbssd / vpdpbuud, 256 bits) or AVX10.2 (256 and 512 bits); with AVX-512 VNNI or AVX-VNNI, two vpdpbusd (the product of unsigned by signed bytes, with an operand shifted by 128 and the correction of its sum); two pmaddwd on the even and odd bytes otherwise (SSE2, AVX2, AVX-512 BW); elsewhere (as NEON without the extension and RVV), the four bytes of each 32-bit lane extended, multiplied and added.

Mathematical semantics: \(\text{res}_i = vd0_i + \sum_{k=0}^{3} vd1_{4i+k} \, vd2_{4i+k}\)

Open in the API Explorer →

Prototypes

// LMUL = 1 (also without the _m1 suffix)
vd_int32_m1_t mipp_dot4_int8_int32_m1(const vd_int32_m1_t vd0, const vd_int8_m1_t vd1, const vd_int8_m1_t vd2);
vd_uint32_m1_t mipp_dot4_uint8_uint32_m1(const vd_uint32_m1_t vd0, const vd_uint8_m1_t vd1, const vd_uint8_m1_t vd2);
// LMUL = 2
vd_int32_m2_t mipp_dot4_int8_int32_m2(const vd_int32_m2_t vd0, const vd_int8_m2_t vd1, const vd_int8_m2_t vd2);
vd_uint32_m2_t mipp_dot4_uint8_uint32_m2(const vd_uint32_m2_t vd0, const vd_uint8_m2_t vd1, const vd_uint8_m2_t vd2);
// LMUL = 4
vd_int32_m4_t mipp_dot4_int8_int32_m4(const vd_int32_m4_t vd0, const vd_int8_m4_t vd1, const vd_int8_m4_t vd2);
vd_uint32_m4_t mipp_dot4_uint8_uint32_m4(const vd_uint32_m4_t vd0, const vd_uint8_m4_t vd1, const vd_uint8_m4_t vd2);
// LMUL = 8
vd_int32_m8_t mipp_dot4_int8_int32_m8(const vd_int32_m8_t vd0, const vd_int8_m8_t vd1, const vd_int8_m8_t vd2);
vd_uint32_m8_t mipp_dot4_uint8_uint32_m8(const vd_uint32_m8_t vd0, const vd_uint8_m8_t vd1, const vd_uint8_m8_t vd2);
// d2 (half-vector)
vd_int32_d2_t mipp_dot4_int8_int32_d2(const vd_int32_d2_t vd0, const vd_int8_d2_t vd1, const vd_int8_d2_t vd2);
vd_uint32_d2_t mipp_dot4_uint8_uint32_d2(const vd_uint32_d2_t vd0, const vd_uint8_d2_t vd1, const vd_uint8_d2_t vd2);
// LMUL = 1
vd<int32_t> dot4_int32(const vd<int32_t> vd0, const vd<int8_t> vd1, const vd<int8_t> vd2);
vd<uint32_t> dot4_uint32(const vd<uint32_t> vd0, const vd<uint8_t> vd1, const vd<uint8_t> vd2);
// LMUL = 2
vd<int32_t, 2> dot4_int32(const vd<int32_t, 2> vd0, const vd<int8_t, 2> vd1, const vd<int8_t, 2> vd2);
vd<uint32_t, 2> dot4_uint32(const vd<uint32_t, 2> vd0, const vd<uint8_t, 2> vd1, const vd<uint8_t, 2> vd2);
// LMUL = 4
vd<int32_t, 4> dot4_int32(const vd<int32_t, 4> vd0, const vd<int8_t, 4> vd1, const vd<int8_t, 4> vd2);
vd<uint32_t, 4> dot4_uint32(const vd<uint32_t, 4> vd0, const vd<uint8_t, 4> vd1, const vd<uint8_t, 4> vd2);
// LMUL = 8
vd<int32_t, 8> dot4_int32(const vd<int32_t, 8> vd0, const vd<int8_t, 8> vd1, const vd<int8_t, 8> vd2);
vd<uint32_t, 8> dot4_uint32(const vd<uint32_t, 8> vd0, const vd<uint8_t, 8> vd1, const vd<uint8_t, 8> vd2);
// d2 (half-vector)
vd<int32_t, -2> dot4_int32(const vd<int32_t, -2> vd0, const vd<int8_t, -2> vd1, const vd<int8_t, -2> vd2);
vd<uint32_t, -2> dot4_uint32(const vd<uint32_t, -2> vd0, const vd<uint8_t, -2> vd1, const vd<uint8_t, -2> vd2);
// LMUL = 1
Vd<int32_t> dot4(const Vd<int32_t>& vd0, const Vd<int8_t>& vd1, const Vd<int8_t>& vd2);
Vd<uint32_t> dot4(const Vd<uint32_t>& vd0, const Vd<uint8_t>& vd1, const Vd<uint8_t>& vd2);
// LMUL = 2
Vd<int32_t, 2> dot4(const Vd<int32_t, 2>& vd0, const Vd<int8_t, 2>& vd1, const Vd<int8_t, 2>& vd2);
Vd<uint32_t, 2> dot4(const Vd<uint32_t, 2>& vd0, const Vd<uint8_t, 2>& vd1, const Vd<uint8_t, 2>& vd2);
// LMUL = 4
Vd<int32_t, 4> dot4(const Vd<int32_t, 4>& vd0, const Vd<int8_t, 4>& vd1, const Vd<int8_t, 4>& vd2);
Vd<uint32_t, 4> dot4(const Vd<uint32_t, 4>& vd0, const Vd<uint8_t, 4>& vd1, const Vd<uint8_t, 4>& vd2);
// LMUL = 8
Vd<int32_t, 8> dot4(const Vd<int32_t, 8>& vd0, const Vd<int8_t, 8>& vd1, const Vd<int8_t, 8>& vd2);
Vd<uint32_t, 8> dot4(const Vd<uint32_t, 8>& vd0, const Vd<uint8_t, 8>& vd1, const Vd<uint8_t, 8>& vd2);
// d2 (half-vector)
Vd<int32_t, -2> dot4(const Vd<int32_t, -2>& vd0, const Vd<int8_t, -2>& vd1, const Vd<int8_t, -2>& vd2);
Vd<uint32_t, -2> dot4(const Vd<uint32_t, -2>& vd0, const Vd<uint8_t, -2>& vd1, const Vd<uint8_t, -2>& vd2);

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/m/arithmetic.h>                // 1D: 'm' variant only (*)
#include <mipp/c/cat/m2/arithmetic.h>               // 1D: LMUL=2 only (*)
#include <mipp/c/cat/m/m2/arithmetic.h>             // 2D: 'm' + LMUL=2 (*)

// Option 3: Function level (recommended for minimal dependencies)
#include <mipp/c/fun/dot4.h>                        // all variants & LMULs
#include <mipp/c/fun/m/dot4.h>                      // 1D: 'm' variant only (*)
#include <mipp/c/fun/m2/dot4.h>                     // 1D: LMUL=2 only (*)
#include <mipp/c/fun/m/m2/dot4.h>                   // 2D atomic: 'm' + 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/m/arithmetic.hpp>            // 1D: 'm' variant only (*)
#include <mipp/cpp/cat/m2/arithmetic.hpp>           // 1D: LMUL=2 only (*)
#include <mipp/cpp/cat/m/m2/arithmetic.hpp>         // 2D: 'm' + LMUL=2 (*)

// Option 3: Function level (recommended for minimal dependencies)
#include <mipp/cpp/fun/dot4.hpp>                    // all variants & LMULs
#include <mipp/cpp/fun/m/dot4.hpp>                  // 1D: 'm' variant only (*)
#include <mipp/cpp/fun/m2/dot4.hpp>                 // 1D: LMUL=2 only (*)
#include <mipp/cpp/fun/m/m2/dot4.hpp>               // 2D atomic: 'm' + 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/m/arithmetic.hpp>            // 1D: 'm' variant only (*)
#include <mipp/obj/cat/m2/arithmetic.hpp>           // 1D: LMUL=2 only (*)
#include <mipp/obj/cat/m/m2/arithmetic.hpp>         // 2D: 'm' + LMUL=2 (*)

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

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

Supported Datatypes

  • int8 → int32
  • uint8 → uint32

Mask Execution Variants

  • Unmasked (no suffix / <mipp::U>): every lane is computed, no mask argument.
  • Merge-Masked (_maskm / <mipp::M>): the mask has the type of the accumulator vd0 (one lane per 32-bit lane of the result): the active lanes are computed; the inactive lanes keep the value of vd0 (nothing is accumulated).
  • Zero-Masked (_maskz / <mipp::Z>): the mask has the type of the accumulator vd0 (one lane per 32-bit lane of the result): the active lanes are computed; the inactive lanes are set to 0.
  • Source-Masked (_masks / <mipp::S>): the mask has the type of the accumulator vd0 (one lane per 32-bit lane of the result): the active lanes are computed; the inactive lanes take the value of vdsrc.

The mask comes first, then vdsrc for Source-Masked, then the arguments of the unmasked function:

// Merge-Masked, LMUL = 1
vd_int32_m1_t mipp_dot4_int8_int32_maskm_m1(const vm_int32_m1_t vm0, const vd_int32_m1_t vd0, const vd_int8_m1_t vd1, const vd_int8_m1_t vd2);
vd_uint32_m1_t mipp_dot4_uint8_uint32_maskm_m1(const vm_uint32_m1_t vm0, const vd_uint32_m1_t vd0, const vd_uint8_m1_t vd1, const vd_uint8_m1_t vd2);
// Zero-Masked, LMUL = 1
vd_int32_m1_t mipp_dot4_int8_int32_maskz_m1(const vm_int32_m1_t vm0, const vd_int32_m1_t vd0, const vd_int8_m1_t vd1, const vd_int8_m1_t vd2);
vd_uint32_m1_t mipp_dot4_uint8_uint32_maskz_m1(const vm_uint32_m1_t vm0, const vd_uint32_m1_t vd0, const vd_uint8_m1_t vd1, const vd_uint8_m1_t vd2);
// Source-Masked, LMUL = 1
vd_int32_m1_t mipp_dot4_int8_int32_masks_m1(const vm_int32_m1_t vm0, const vd_int32_m1_t vdsrc, const vd_int32_m1_t vd0, const vd_int8_m1_t vd1, const vd_int8_m1_t vd2);
vd_uint32_m1_t mipp_dot4_uint8_uint32_masks_m1(const vm_uint32_m1_t vm0, const vd_uint32_m1_t vdsrc, const vd_uint32_m1_t vd0, const vd_uint8_m1_t vd1, const vd_uint8_m1_t vd2);
// Merge-Masked, and Zero-Masked with dot4<Z>(...), LMUL = 1
template <VARIANT V = M> vd<int32_t> dot4_int32(const vm<int32_t> vm0, const vd<int32_t> vd0, const vd<int8_t> vd1, const vd<int8_t> vd2);
template <VARIANT V = M> vd<uint32_t> dot4_uint32(const vm<uint32_t> vm0, const vd<uint32_t> vd0, const vd<uint8_t> vd1, const vd<uint8_t> vd2);
// Source-Masked, LMUL = 1
template <VARIANT V = S> vd<int32_t> dot4_int32(const vm<int32_t> vm0, const vd<int32_t> vdsrc, const vd<int32_t> vd0, const vd<int8_t> vd1, const vd<int8_t> vd2);
template <VARIANT V = S> vd<uint32_t> dot4_uint32(const vm<uint32_t> vm0, const vd<uint32_t> vdsrc, const vd<uint32_t> vd0, const vd<uint8_t> vd1, const vd<uint8_t> vd2);
// Merge-Masked, and Zero-Masked with dot4<Z>(...), LMUL = 1
template <VARIANT V = M> Vd<int32_t> dot4(const Vm<int32_t>& vm0, const Vd<int32_t>& vd0, const Vd<int8_t>& vd1, const Vd<int8_t>& vd2);
template <VARIANT V = M> Vd<uint32_t> dot4(const Vm<uint32_t>& vm0, const Vd<uint32_t>& vd0, const Vd<uint8_t>& vd1, const Vd<uint8_t>& vd2);
// Source-Masked, LMUL = 1
template <VARIANT V = S> Vd<int32_t> dot4(const Vm<int32_t>& vm0, const Vd<int32_t>& vdsrc, const Vd<int32_t>& vd0, const Vd<int8_t>& vd1, const Vd<int8_t>& vd2);
template <VARIANT V = S> Vd<uint32_t> dot4(const Vm<uint32_t>& vm0, const Vd<uint32_t>& vdsrc, const Vd<uint32_t>& vd0, const Vd<uint8_t>& vd1, const Vd<uint8_t>& vd2);

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 i8→i32 u8→u32
SSE L1 L1
AVX L0 L0
AVX512 L0 L0
NEON L0 L0
RVV L2 L2
SVE L0 L0
Architecture i8→i32 u8→u32
SSE L2 L2
AVX L2 L2
AVX512 L2 L2
NEON L2 L2
RVV L2 L2
SVE L2 L2
Architecture i8→i32 u8→u32
SSE L2 L2
AVX L2 L2
AVX512 L2 L2
NEON L2 L2
RVV L2 L2
SVE L2 L2
Architecture i8→i32 u8→u32
SSE L2 L2
AVX L2 L2
AVX512 L2 L2
NEON L2 L2
RVV L2 L2
SVE L2 L2

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_int32_m1_t mipp_scalar_dot4_int8_int32_m1(const vd_scalar_int32_m1_t vd0, const vd_scalar_int8_m1_t vd1, const vd_scalar_int8_m1_t vd2) {
    // computed modulo 2^32 (the bits of the products of the sign-extended elements)
    vd_scalar_int32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_INT32; i++){
        uint32_t s = (uint32_t)vd0.vd[i];
        for (size_t k = 0; k < 4; k++)
            s += (uint32_t)(int32_t)vd1.vd[4 * i + k] * (uint32_t)(int32_t)vd2.vd[4 * i + k];
        res.vd[i] = (int32_t)s;
    }
    return res;
}
vd_scalar_int32_m1_t mipp_scalar_dot4_int8_int32_maskm_m1(const vm_scalar_int32_m1_t vm0, const vd_scalar_int32_m1_t vd0, const vd_scalar_int8_m1_t vd1, const vd_scalar_int8_m1_t vd2) {
    // computed modulo 2^32 (the bits of the products of the sign-extended elements)
    vd_scalar_int32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_INT32; i++){
        uint32_t s = (uint32_t)vd0.vd[i];
        for (size_t k = 0; k < 4; k++)
            s += (uint32_t)(int32_t)vd1.vd[4 * i + k] * (uint32_t)(int32_t)vd2.vd[4 * i + k];
        res.vd[i] = vm0.vm[i] ? ((int32_t)s) : vd0.vd[i];
    }
    return res;
}
vd_scalar_int32_m1_t mipp_scalar_dot4_int8_int32_maskz_m1(const vm_scalar_int32_m1_t vm0, const vd_scalar_int32_m1_t vd0, const vd_scalar_int8_m1_t vd1, const vd_scalar_int8_m1_t vd2) {
    // computed modulo 2^32 (the bits of the products of the sign-extended elements)
    vd_scalar_int32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_INT32; i++){
        uint32_t s = (uint32_t)vd0.vd[i];
        for (size_t k = 0; k < 4; k++)
            s += (uint32_t)(int32_t)vd1.vd[4 * i + k] * (uint32_t)(int32_t)vd2.vd[4 * i + k];
        res.vd[i] = vm0.vm[i] ? ((int32_t)s) : 0;
    }
    return res;
}
vd_scalar_int32_m1_t mipp_scalar_dot4_int8_int32_masks_m1(const vm_scalar_int32_m1_t vm0, const vd_scalar_int32_m1_t vdsrc, const vd_scalar_int32_m1_t vd0, const vd_scalar_int8_m1_t vd1, const vd_scalar_int8_m1_t vd2) {
    // computed modulo 2^32 (the bits of the products of the sign-extended elements)
    vd_scalar_int32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_INT32; i++){
        uint32_t s = (uint32_t)vd0.vd[i];
        for (size_t k = 0; k < 4; k++)
            s += (uint32_t)(int32_t)vd1.vd[4 * i + k] * (uint32_t)(int32_t)vd2.vd[4 * i + k];
        res.vd[i] = vm0.vm[i] ? ((int32_t)s) : vdsrc.vd[i];
    }
    return res;
}
vd_scalar_uint32_m1_t mipp_scalar_dot4_uint8_uint32_m1(const vd_scalar_uint32_m1_t vd0, const vd_scalar_uint8_m1_t vd1, const vd_scalar_uint8_m1_t vd2) {
    // computed modulo 2^32 (the bits of the products of the sign-extended elements)
    vd_scalar_uint32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_UINT32; i++){
        uint32_t s = (uint32_t)vd0.vd[i];
        for (size_t k = 0; k < 4; k++)
            s += (uint32_t)(uint32_t)vd1.vd[4 * i + k] * (uint32_t)(uint32_t)vd2.vd[4 * i + k];
        res.vd[i] = (uint32_t)s;
    }
    return res;
}
vd_scalar_uint32_m1_t mipp_scalar_dot4_uint8_uint32_maskm_m1(const vm_scalar_uint32_m1_t vm0, const vd_scalar_uint32_m1_t vd0, const vd_scalar_uint8_m1_t vd1, const vd_scalar_uint8_m1_t vd2) {
    // computed modulo 2^32 (the bits of the products of the sign-extended elements)
    vd_scalar_uint32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_UINT32; i++){
        uint32_t s = (uint32_t)vd0.vd[i];
        for (size_t k = 0; k < 4; k++)
            s += (uint32_t)(uint32_t)vd1.vd[4 * i + k] * (uint32_t)(uint32_t)vd2.vd[4 * i + k];
        res.vd[i] = vm0.vm[i] ? ((uint32_t)s) : vd0.vd[i];
    }
    return res;
}
vd_scalar_uint32_m1_t mipp_scalar_dot4_uint8_uint32_maskz_m1(const vm_scalar_uint32_m1_t vm0, const vd_scalar_uint32_m1_t vd0, const vd_scalar_uint8_m1_t vd1, const vd_scalar_uint8_m1_t vd2) {
    // computed modulo 2^32 (the bits of the products of the sign-extended elements)
    vd_scalar_uint32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_UINT32; i++){
        uint32_t s = (uint32_t)vd0.vd[i];
        for (size_t k = 0; k < 4; k++)
            s += (uint32_t)(uint32_t)vd1.vd[4 * i + k] * (uint32_t)(uint32_t)vd2.vd[4 * i + k];
        res.vd[i] = vm0.vm[i] ? ((uint32_t)s) : 0;
    }
    return res;
}
vd_scalar_uint32_m1_t mipp_scalar_dot4_uint8_uint32_masks_m1(const vm_scalar_uint32_m1_t vm0, const vd_scalar_uint32_m1_t vdsrc, const vd_scalar_uint32_m1_t vd0, const vd_scalar_uint8_m1_t vd1, const vd_scalar_uint8_m1_t vd2) {
    // computed modulo 2^32 (the bits of the products of the sign-extended elements)
    vd_scalar_uint32_m1_t res;
    for (size_t i = 0; i < MIPP_SCALAR_N_UINT32; i++){
        uint32_t s = (uint32_t)vd0.vd[i];
        for (size_t k = 0; k < 4; k++)
            s += (uint32_t)(uint32_t)vd1.vd[4 * i + k] * (uint32_t)(uint32_t)vd2.vd[4 * i + k];
        res.vd[i] = vm0.vm[i] ? ((uint32_t)s) : vdsrc.vd[i];
    }
    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

Input masks: random (each lane active with probability 1/2).