dot2¶
Dot products of pairs of 16-bit elements accumulated in 32 bits: each 32-bit lane \(i\) of the accumulator vd0 receives \(a_{2i} b_{2i} + a_{2i+1} b_{2i+1}\), the products of the two 16-bit lanes of vd1 and vd2 at the same place (the registers have the same size: the accumulator has half as many lanes). Computed modulo \(2^{32}\), without saturation. On x86: vpdpwssd (int16) with AVX-512 VNNI (and VL on 256 bits) or AVX-VNNI, vpdpwuud (uint16) with AVX-VNNI-INT16 or AVX10.2 (also on 512 bits), pmaddwd then an addition otherwise (int16); on AArch64, vmull and vpaddq; elsewhere, the two 16-bit halves of each 32-bit lane extended, multiplied and added.
Mathematical semantics: \(\text{res}_i = vd0_i + \sum_{k=0}^{1} vd1_{2i+k} \, vd2_{2i+k}\)
Prototypes¶
// LMUL = 1 (also without the _m1 suffix)
vd_int32_m1_t mipp_dot2_int16_int32_m1(const vd_int32_m1_t vd0, const vd_int16_m1_t vd1, const vd_int16_m1_t vd2);
vd_uint32_m1_t mipp_dot2_uint16_uint32_m1(const vd_uint32_m1_t vd0, const vd_uint16_m1_t vd1, const vd_uint16_m1_t vd2);
// LMUL = 2
vd_int32_m2_t mipp_dot2_int16_int32_m2(const vd_int32_m2_t vd0, const vd_int16_m2_t vd1, const vd_int16_m2_t vd2);
vd_uint32_m2_t mipp_dot2_uint16_uint32_m2(const vd_uint32_m2_t vd0, const vd_uint16_m2_t vd1, const vd_uint16_m2_t vd2);
// LMUL = 4
vd_int32_m4_t mipp_dot2_int16_int32_m4(const vd_int32_m4_t vd0, const vd_int16_m4_t vd1, const vd_int16_m4_t vd2);
vd_uint32_m4_t mipp_dot2_uint16_uint32_m4(const vd_uint32_m4_t vd0, const vd_uint16_m4_t vd1, const vd_uint16_m4_t vd2);
// LMUL = 8
vd_int32_m8_t mipp_dot2_int16_int32_m8(const vd_int32_m8_t vd0, const vd_int16_m8_t vd1, const vd_int16_m8_t vd2);
vd_uint32_m8_t mipp_dot2_uint16_uint32_m8(const vd_uint32_m8_t vd0, const vd_uint16_m8_t vd1, const vd_uint16_m8_t vd2);
// d2 (half-vector)
vd_int32_d2_t mipp_dot2_int16_int32_d2(const vd_int32_d2_t vd0, const vd_int16_d2_t vd1, const vd_int16_d2_t vd2);
vd_uint32_d2_t mipp_dot2_uint16_uint32_d2(const vd_uint32_d2_t vd0, const vd_uint16_d2_t vd1, const vd_uint16_d2_t vd2);
// LMUL = 1
vd<int32_t> dot2_int32(const vd<int32_t> vd0, const vd<int16_t> vd1, const vd<int16_t> vd2);
vd<uint32_t> dot2_uint32(const vd<uint32_t> vd0, const vd<uint16_t> vd1, const vd<uint16_t> vd2);
// LMUL = 2
vd<int32_t, 2> dot2_int32(const vd<int32_t, 2> vd0, const vd<int16_t, 2> vd1, const vd<int16_t, 2> vd2);
vd<uint32_t, 2> dot2_uint32(const vd<uint32_t, 2> vd0, const vd<uint16_t, 2> vd1, const vd<uint16_t, 2> vd2);
// LMUL = 4
vd<int32_t, 4> dot2_int32(const vd<int32_t, 4> vd0, const vd<int16_t, 4> vd1, const vd<int16_t, 4> vd2);
vd<uint32_t, 4> dot2_uint32(const vd<uint32_t, 4> vd0, const vd<uint16_t, 4> vd1, const vd<uint16_t, 4> vd2);
// LMUL = 8
vd<int32_t, 8> dot2_int32(const vd<int32_t, 8> vd0, const vd<int16_t, 8> vd1, const vd<int16_t, 8> vd2);
vd<uint32_t, 8> dot2_uint32(const vd<uint32_t, 8> vd0, const vd<uint16_t, 8> vd1, const vd<uint16_t, 8> vd2);
// d2 (half-vector)
vd<int32_t, -2> dot2_int32(const vd<int32_t, -2> vd0, const vd<int16_t, -2> vd1, const vd<int16_t, -2> vd2);
vd<uint32_t, -2> dot2_uint32(const vd<uint32_t, -2> vd0, const vd<uint16_t, -2> vd1, const vd<uint16_t, -2> vd2);
// LMUL = 1
Vd<int32_t> dot2(const Vd<int32_t>& vd0, const Vd<int16_t>& vd1, const Vd<int16_t>& vd2);
Vd<uint32_t> dot2(const Vd<uint32_t>& vd0, const Vd<uint16_t>& vd1, const Vd<uint16_t>& vd2);
// LMUL = 2
Vd<int32_t, 2> dot2(const Vd<int32_t, 2>& vd0, const Vd<int16_t, 2>& vd1, const Vd<int16_t, 2>& vd2);
Vd<uint32_t, 2> dot2(const Vd<uint32_t, 2>& vd0, const Vd<uint16_t, 2>& vd1, const Vd<uint16_t, 2>& vd2);
// LMUL = 4
Vd<int32_t, 4> dot2(const Vd<int32_t, 4>& vd0, const Vd<int16_t, 4>& vd1, const Vd<int16_t, 4>& vd2);
Vd<uint32_t, 4> dot2(const Vd<uint32_t, 4>& vd0, const Vd<uint16_t, 4>& vd1, const Vd<uint16_t, 4>& vd2);
// LMUL = 8
Vd<int32_t, 8> dot2(const Vd<int32_t, 8>& vd0, const Vd<int16_t, 8>& vd1, const Vd<int16_t, 8>& vd2);
Vd<uint32_t, 8> dot2(const Vd<uint32_t, 8>& vd0, const Vd<uint16_t, 8>& vd1, const Vd<uint16_t, 8>& vd2);
// d2 (half-vector)
Vd<int32_t, -2> dot2(const Vd<int32_t, -2>& vd0, const Vd<int16_t, -2>& vd1, const Vd<int16_t, -2>& vd2);
Vd<uint32_t, -2> dot2(const Vd<uint32_t, -2>& vd0, const Vd<uint16_t, -2>& vd1, const Vd<uint16_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/dot2.h> // all variants & LMULs
#include <mipp/c/fun/m/dot2.h> // 1D: 'm' variant only (*)
#include <mipp/c/fun/m2/dot2.h> // 1D: LMUL=2 only (*)
#include <mipp/c/fun/m/m2/dot2.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/dot2.hpp> // all variants & LMULs
#include <mipp/cpp/fun/m/dot2.hpp> // 1D: 'm' variant only (*)
#include <mipp/cpp/fun/m2/dot2.hpp> // 1D: LMUL=2 only (*)
#include <mipp/cpp/fun/m/m2/dot2.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/dot2.hpp> // all variants & LMULs
#include <mipp/obj/fun/m/dot2.hpp> // 1D: 'm' variant only (*)
#include <mipp/obj/fun/m2/dot2.hpp> // 1D: LMUL=2 only (*)
#include <mipp/obj/fun/m/m2/dot2.hpp> // 2D atomic: 'm' + LMUL=2 (fastest compilation) (*)
// (*) Fine-grained headers require MIPP generated with '--granularity fine'
Supported Datatypes¶
int16→int32uint16→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 accumulatorvd0(one lane per 32-bit lane of the result): the active lanes are computed; the inactive lanes keep the value ofvd0(nothing is accumulated). - Zero-Masked (
_maskz/<mipp::Z>): the mask has the type of the accumulatorvd0(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 accumulatorvd0(one lane per 32-bit lane of the result): the active lanes are computed; the inactive lanes take the value ofvdsrc.
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_dot2_int16_int32_maskm_m1(const vm_int32_m1_t vm0, const vd_int32_m1_t vd0, const vd_int16_m1_t vd1, const vd_int16_m1_t vd2);
vd_uint32_m1_t mipp_dot2_uint16_uint32_maskm_m1(const vm_uint32_m1_t vm0, const vd_uint32_m1_t vd0, const vd_uint16_m1_t vd1, const vd_uint16_m1_t vd2);
// Zero-Masked, LMUL = 1
vd_int32_m1_t mipp_dot2_int16_int32_maskz_m1(const vm_int32_m1_t vm0, const vd_int32_m1_t vd0, const vd_int16_m1_t vd1, const vd_int16_m1_t vd2);
vd_uint32_m1_t mipp_dot2_uint16_uint32_maskz_m1(const vm_uint32_m1_t vm0, const vd_uint32_m1_t vd0, const vd_uint16_m1_t vd1, const vd_uint16_m1_t vd2);
// Source-Masked, LMUL = 1
vd_int32_m1_t mipp_dot2_int16_int32_masks_m1(const vm_int32_m1_t vm0, const vd_int32_m1_t vdsrc, const vd_int32_m1_t vd0, const vd_int16_m1_t vd1, const vd_int16_m1_t vd2);
vd_uint32_m1_t mipp_dot2_uint16_uint32_masks_m1(const vm_uint32_m1_t vm0, const vd_uint32_m1_t vdsrc, const vd_uint32_m1_t vd0, const vd_uint16_m1_t vd1, const vd_uint16_m1_t vd2);
// Merge-Masked, and Zero-Masked with dot2<Z>(...), LMUL = 1
template <VARIANT V = M> vd<int32_t> dot2_int32(const vm<int32_t> vm0, const vd<int32_t> vd0, const vd<int16_t> vd1, const vd<int16_t> vd2);
template <VARIANT V = M> vd<uint32_t> dot2_uint32(const vm<uint32_t> vm0, const vd<uint32_t> vd0, const vd<uint16_t> vd1, const vd<uint16_t> vd2);
// Source-Masked, LMUL = 1
template <VARIANT V = S> vd<int32_t> dot2_int32(const vm<int32_t> vm0, const vd<int32_t> vdsrc, const vd<int32_t> vd0, const vd<int16_t> vd1, const vd<int16_t> vd2);
template <VARIANT V = S> vd<uint32_t> dot2_uint32(const vm<uint32_t> vm0, const vd<uint32_t> vdsrc, const vd<uint32_t> vd0, const vd<uint16_t> vd1, const vd<uint16_t> vd2);
// Merge-Masked, and Zero-Masked with dot2<Z>(...), LMUL = 1
template <VARIANT V = M> Vd<int32_t> dot2(const Vm<int32_t>& vm0, const Vd<int32_t>& vd0, const Vd<int16_t>& vd1, const Vd<int16_t>& vd2);
template <VARIANT V = M> Vd<uint32_t> dot2(const Vm<uint32_t>& vm0, const Vd<uint32_t>& vd0, const Vd<uint16_t>& vd1, const Vd<uint16_t>& vd2);
// Source-Masked, LMUL = 1
template <VARIANT V = S> Vd<int32_t> dot2(const Vm<int32_t>& vm0, const Vd<int32_t>& vdsrc, const Vd<int32_t>& vd0, const Vd<int16_t>& vd1, const Vd<int16_t>& vd2);
template <VARIANT V = S> Vd<uint32_t> dot2(const Vm<uint32_t>& vm0, const Vd<uint32_t>& vdsrc, const Vd<uint32_t>& vd0, const Vd<uint16_t>& vd1, const Vd<uint16_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 | i16→i32 | u16→u32 |
|---|---|---|
| SSE | L1 | L2 |
| AVX | L0 | L0 |
| AVX512 | L0 | L0 |
| NEON | L1 | L1 |
| RVV | L2 | L2 |
| SVE | L2 | L2 |
| Architecture | i16→i32 | u16→u32 |
|---|---|---|
| SSE | L2 | L2 |
| AVX | L2 | L2 |
| AVX512 | L2 | L2 |
| NEON | L2 | L2 |
| RVV | L2 | L2 |
| SVE | L2 | L2 |
| Architecture | i16→i32 | u16→u32 |
|---|---|---|
| SSE | L2 | L2 |
| AVX | L2 | L2 |
| AVX512 | L2 | L2 |
| NEON | L2 | L2 |
| RVV | L2 | L2 |
| SVE | L2 | L2 |
| Architecture | i16→i32 | u16→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_dot2_int16_int32_m1(const vd_scalar_int32_m1_t vd0, const vd_scalar_int16_m1_t vd1, const vd_scalar_int16_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 < 2; k++)
s += (uint32_t)(int32_t)vd1.vd[2 * i + k] * (uint32_t)(int32_t)vd2.vd[2 * i + k];
res.vd[i] = (int32_t)s;
}
return res;
}
vd_scalar_int32_m1_t mipp_scalar_dot2_int16_int32_maskm_m1(const vm_scalar_int32_m1_t vm0, const vd_scalar_int32_m1_t vd0, const vd_scalar_int16_m1_t vd1, const vd_scalar_int16_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 < 2; k++)
s += (uint32_t)(int32_t)vd1.vd[2 * i + k] * (uint32_t)(int32_t)vd2.vd[2 * i + k];
res.vd[i] = vm0.vm[i] ? ((int32_t)s) : vd0.vd[i];
}
return res;
}
vd_scalar_int32_m1_t mipp_scalar_dot2_int16_int32_maskz_m1(const vm_scalar_int32_m1_t vm0, const vd_scalar_int32_m1_t vd0, const vd_scalar_int16_m1_t vd1, const vd_scalar_int16_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 < 2; k++)
s += (uint32_t)(int32_t)vd1.vd[2 * i + k] * (uint32_t)(int32_t)vd2.vd[2 * i + k];
res.vd[i] = vm0.vm[i] ? ((int32_t)s) : 0;
}
return res;
}
vd_scalar_int32_m1_t mipp_scalar_dot2_int16_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_int16_m1_t vd1, const vd_scalar_int16_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 < 2; k++)
s += (uint32_t)(int32_t)vd1.vd[2 * i + k] * (uint32_t)(int32_t)vd2.vd[2 * i + k];
res.vd[i] = vm0.vm[i] ? ((int32_t)s) : vdsrc.vd[i];
}
return res;
}
vd_scalar_uint32_m1_t mipp_scalar_dot2_uint16_uint32_m1(const vd_scalar_uint32_m1_t vd0, const vd_scalar_uint16_m1_t vd1, const vd_scalar_uint16_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 < 2; k++)
s += (uint32_t)(uint32_t)vd1.vd[2 * i + k] * (uint32_t)(uint32_t)vd2.vd[2 * i + k];
res.vd[i] = (uint32_t)s;
}
return res;
}
vd_scalar_uint32_m1_t mipp_scalar_dot2_uint16_uint32_maskm_m1(const vm_scalar_uint32_m1_t vm0, const vd_scalar_uint32_m1_t vd0, const vd_scalar_uint16_m1_t vd1, const vd_scalar_uint16_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 < 2; k++)
s += (uint32_t)(uint32_t)vd1.vd[2 * i + k] * (uint32_t)(uint32_t)vd2.vd[2 * i + k];
res.vd[i] = vm0.vm[i] ? ((uint32_t)s) : vd0.vd[i];
}
return res;
}
vd_scalar_uint32_m1_t mipp_scalar_dot2_uint16_uint32_maskz_m1(const vm_scalar_uint32_m1_t vm0, const vd_scalar_uint32_m1_t vd0, const vd_scalar_uint16_m1_t vd1, const vd_scalar_uint16_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 < 2; k++)
s += (uint32_t)(uint32_t)vd1.vd[2 * i + k] * (uint32_t)(uint32_t)vd2.vd[2 * i + k];
res.vd[i] = vm0.vm[i] ? ((uint32_t)s) : 0;
}
return res;
}
vd_scalar_uint32_m1_t mipp_scalar_dot2_uint16_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_uint16_m1_t vd1, const vd_scalar_uint16_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 < 2; k++)
s += (uint32_t)(uint32_t)vd1.vd[2 * i + k] * (uint32_t)(uint32_t)vd2.vd[2 * 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).