Skip to content

dot4us

dot4 with an unsigned operand vd1 (uint8) and a signed operand vd2 (int8), accumulated in int32: the form of the quantized neural networks (unsigned activations, signed weights), and the only 8-bit dot product of the AVX-512 VNNI and AVX-VNNI extensions of x86 (vpdpbusd). Computed modulo \(2^{32}\), without saturation.

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_dot4us_uint8_int32_m1(const vd_int32_m1_t vd0, const vd_uint8_m1_t vd1, const vd_int8_m1_t vd2);
// LMUL = 2
vd_int32_m2_t mipp_dot4us_uint8_int32_m2(const vd_int32_m2_t vd0, const vd_uint8_m2_t vd1, const vd_int8_m2_t vd2);
// LMUL = 4
vd_int32_m4_t mipp_dot4us_uint8_int32_m4(const vd_int32_m4_t vd0, const vd_uint8_m4_t vd1, const vd_int8_m4_t vd2);
// LMUL = 8
vd_int32_m8_t mipp_dot4us_uint8_int32_m8(const vd_int32_m8_t vd0, const vd_uint8_m8_t vd1, const vd_int8_m8_t vd2);
// d2 (half-vector)
vd_int32_d2_t mipp_dot4us_uint8_int32_d2(const vd_int32_d2_t vd0, const vd_uint8_d2_t vd1, const vd_int8_d2_t vd2);
// LMUL = 1
vd<int32_t> dot4us_int32(const vd<int32_t> vd0, const vd<uint8_t> vd1, const vd<int8_t> vd2);
// LMUL = 2
vd<int32_t, 2> dot4us_int32(const vd<int32_t, 2> vd0, const vd<uint8_t, 2> vd1, const vd<int8_t, 2> vd2);
// LMUL = 4
vd<int32_t, 4> dot4us_int32(const vd<int32_t, 4> vd0, const vd<uint8_t, 4> vd1, const vd<int8_t, 4> vd2);
// LMUL = 8
vd<int32_t, 8> dot4us_int32(const vd<int32_t, 8> vd0, const vd<uint8_t, 8> vd1, const vd<int8_t, 8> vd2);
// d2 (half-vector)
vd<int32_t, -2> dot4us_int32(const vd<int32_t, -2> vd0, const vd<uint8_t, -2> vd1, const vd<int8_t, -2> vd2);
// LMUL = 1
Vd<int32_t> dot4us(const Vd<int32_t>& vd0, const Vd<uint8_t>& vd1, const Vd<int8_t>& vd2);
// LMUL = 2
Vd<int32_t, 2> dot4us(const Vd<int32_t, 2>& vd0, const Vd<uint8_t, 2>& vd1, const Vd<int8_t, 2>& vd2);
// LMUL = 4
Vd<int32_t, 4> dot4us(const Vd<int32_t, 4>& vd0, const Vd<uint8_t, 4>& vd1, const Vd<int8_t, 4>& vd2);
// LMUL = 8
Vd<int32_t, 8> dot4us(const Vd<int32_t, 8>& vd0, const Vd<uint8_t, 8>& vd1, const Vd<int8_t, 8>& vd2);
// d2 (half-vector)
Vd<int32_t, -2> dot4us(const Vd<int32_t, -2>& vd0, const Vd<uint8_t, -2>& vd1, const Vd<int8_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/dot4us.h>                      // all variants & LMULs
#include <mipp/c/fun/m/dot4us.h>                    // 1D: 'm' variant only (*)
#include <mipp/c/fun/m2/dot4us.h>                   // 1D: LMUL=2 only (*)
#include <mipp/c/fun/m/m2/dot4us.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/dot4us.hpp>                  // all variants & LMULs
#include <mipp/cpp/fun/m/dot4us.hpp>                // 1D: 'm' variant only (*)
#include <mipp/cpp/fun/m2/dot4us.hpp>               // 1D: LMUL=2 only (*)
#include <mipp/cpp/fun/m/m2/dot4us.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/dot4us.hpp>                  // all variants & LMULs
#include <mipp/obj/fun/m/dot4us.hpp>                // 1D: 'm' variant only (*)
#include <mipp/obj/fun/m2/dot4us.hpp>               // 1D: LMUL=2 only (*)
#include <mipp/obj/fun/m/m2/dot4us.hpp>             // 2D atomic: 'm' + LMUL=2 (fastest compilation) (*)

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

Supported Datatypes

  • uint8 → int32

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_dot4us_uint8_int32_maskm_m1(const vm_int32_m1_t vm0, const vd_int32_m1_t vd0, const vd_uint8_m1_t vd1, const vd_int8_m1_t vd2);
// Zero-Masked, LMUL = 1
vd_int32_m1_t mipp_dot4us_uint8_int32_maskz_m1(const vm_int32_m1_t vm0, const vd_int32_m1_t vd0, const vd_uint8_m1_t vd1, const vd_int8_m1_t vd2);
// Source-Masked, LMUL = 1
vd_int32_m1_t mipp_dot4us_uint8_int32_masks_m1(const vm_int32_m1_t vm0, const vd_int32_m1_t vdsrc, const vd_int32_m1_t vd0, const vd_uint8_m1_t vd1, const vd_int8_m1_t vd2);
// Merge-Masked, and Zero-Masked with dot4us<Z>(...), LMUL = 1
template <VARIANT V = M> vd<int32_t> dot4us_int32(const vm<int32_t> vm0, const vd<int32_t> vd0, const vd<uint8_t> vd1, const vd<int8_t> vd2);
// Source-Masked, LMUL = 1
template <VARIANT V = S> vd<int32_t> dot4us_int32(const vm<int32_t> vm0, const vd<int32_t> vdsrc, const vd<int32_t> vd0, const vd<uint8_t> vd1, const vd<int8_t> vd2);
// Merge-Masked, and Zero-Masked with dot4us<Z>(...), LMUL = 1
template <VARIANT V = M> Vd<int32_t> dot4us(const Vm<int32_t>& vm0, const Vd<int32_t>& vd0, const Vd<uint8_t>& vd1, const Vd<int8_t>& vd2);
// Source-Masked, LMUL = 1
template <VARIANT V = S> Vd<int32_t> dot4us(const Vm<int32_t>& vm0, const Vd<int32_t>& vdsrc, const Vd<int32_t>& vd0, const Vd<uint8_t>& vd1, const Vd<int8_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 u8→i32
SSE L1
AVX L0
AVX512 L0
NEON L2
RVV L2
SVE L2
Architecture u8→i32
SSE L2
AVX L2
AVX512 L2
NEON L2
RVV L2
SVE L2
Architecture u8→i32
SSE L2
AVX L2
AVX512 L2
NEON L2
RVV L2
SVE L2
Architecture u8→i32
SSE L2
AVX L2
AVX512 L2
NEON L2
RVV L2
SVE 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_dot4us_uint8_int32_m1(const vd_scalar_int32_m1_t vd0, const vd_scalar_uint8_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_dot4us_uint8_int32_maskm_m1(const vm_scalar_int32_m1_t vm0, const vd_scalar_int32_m1_t vd0, const vd_scalar_uint8_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_dot4us_uint8_int32_maskz_m1(const vm_scalar_int32_m1_t vm0, const vd_scalar_int32_m1_t vd0, const vd_scalar_uint8_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_dot4us_uint8_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_uint8_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;
}

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
uint8 → int32 full range Exact

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