Function Reference & Implementation Directory¶
This section contains complete API reference documentation, mathematical semantics, test specifications, and architecture acceleration matrices for all MIPP functions.
MIPP API Explorer
Search across all 197 primitives, perform reverse lookup on vendor hardware intrinsics (AVX, NEON, RVV, SVE), filter by guaranteed acceleration levels, and switch between the C, C++ Functional and C++ Object APIs in the MIPP API Explorer.
Implementation Levels & Acceleration Legend¶
Every MIPP function is resolved against a 4-level hierarchy (details and examples in Implementation Levels):
| Badge | Implementation Level | Meaning |
|---|---|---|
| L0 | Level 0 (Native Hardware) | A single hardware instruction (vendor intrinsic) for this datatype and variant; the constants it uses do not count. |
| L1 | Level 1 (Dedicated Emulation) | A sequence of intrinsics written for this ISA, where no single instruction does the job. |
| L2 | Level 2 (Generic Emulation) | Generic code shared by the ISAs, built on other MIPP functions (in a few cases a loop over the lanes, or the identity). |
| L3 | Level 3 (Scalar Fallback) | The registers are copied to the scalar target, which computes the elements one by one. |
| − | N/A (Not Applicable) | Operation is not defined for this element datatype or masking variant. |
Documentation Structure for Each Function¶
Each function reference page provides:
- Description & Semantics: Mathematical operation and vector execution behavior.
- Prototypes: C, C++ Functional and C++ Object API signatures across all LMUL ratios.
- Headers: Includes of each API, from the whole library down to one function.
- Supported Datatypes & Mask Execution Variants: Supported element types and masking execution modes.
- ISA & Variant Support Matrix: Per-architecture hardware capability breakdown across masking variants.
- Reference Algorithm: Scalar C reference implementation demonstrating exact arithmetic and masking semantics.
- Test & Verification Specifications: Values drawn by the unit tests and comparison with the scalar reference.
Function Directory by Category¶
Arithmetic¶
absdiff: Absolute difference of two registers element-wise, \(|a - b|\), without the overflow of \(a - b\) for the unsigned types. For the signed integers the result is \(|a - b|\) modulo \(2^n\): read as the unsigned type of the same size, it is exact (absdiffof-128and127inint8gives-1, that is255).add: Adds two vector registers element-wise. The integer additions wrap around (modulo \(2^n\):100 + 100is-56inint8);addssaturates instead. Scalar forms:vs.adds: Adds two integer vector registers element-wise with saturation to [MIN, MAX] on underflow/overflow. Scalar forms:vs.avg: Average of two integer registers element-wise, rounded up: \((a + b + 1) \gg 1\), computed without overflow (pavgbof x86,vrhaddof NEON). For the signed types the rounding is toward \(+\infty\): the average of-1and-2is-1.sub: Subtracts the second vector register from the first element-wise. The integer subtractions wrap around (modulo \(2^n\));subssaturates instead. Scalar forms:vs,sv.subs: Subtracts two integer vector registers element-wise with saturation to [MIN, MAX] on underflow/overflow. Scalar forms:vs,sv.mul: Multiplies two vector registers element-wise. The integer multiplications keep the low bits of the product (modulo \(2^n\)). Scalar forms:vs.mulhi: Multiplies two integer registers element-wise and returns the upper half of each product, of \(2n\) bits: \((a \cdot b) \gg n\), with \(n\) the number of bits of the type (the lower half ismul). The product is signed for the signed types, unsigned for the unsigned ones. It is the multiplication of the fixed-point formats and of the division by a constant.wmul: Widening multiplication: the product of two registers element-wise, in the type twice as wide, so without overflow nor rounding (int16xint16gives the exactint32product,float32xfloat32the exactfloat64one); the result has the next LMUL up, aswcvt. It ismul(wcvt(a), wcvt(b)), in a single instruction on RVV (vwmul,vfwmul), and in onevmullper half of the result on NEON for the integer types.wpadd: Adds the neighbors two by two into the integer type twice as wide: \(\text{res}_i = vd0_{2i} + vd0_{2i+1}\), without overflow (int8toint16,int16toint32,int32toint64, 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 withabsdiffthe sum of absolute differences of the motion estimation (wpadd(wpadd(wpadd(absdiff(a, b))))sums 8 bytes into 64 bits, aspsadbw). Native on NEON (vpaddl) and SVE2 (sadalp/uadalp); on x86,pmaddwd(int16) andpmaddubsw(8-bit types, SSSE3) with a register of ones; elsewhere a reinterpretation, a mask or a shift, and an addition.dot2: Dot products of pairs of 16-bit elements accumulated in 32 bits: each 32-bit lane \(i\) of the accumulatorvd0receives \(a_{2i} b_{2i} + a_{2i+1} b_{2i+1}\), the products of the two 16-bit lanes ofvd1andvd2at 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),pmaddwdthen an addition otherwise (int16); on AArch64,vmullandvpaddq; elsewhere, the two 16-bit halves of each 32-bit lane extended, multiplied and added.dot4: Dot products of groups of four 8-bit elements accumulated in 32 bits: each 32-bit lane \(i\) of the accumulatorvd0receives \(\sum_{k=0}^{3} a_{4i+k} b_{4i+k}\), the products of the four 8-bit lanes ofvd1andvd2at the same place (the registers have the same size: the accumulator has four times fewer lanes). Both operands are signed (int8toint32) or both unsigned (uint8touint32);dot4usmixes 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, twovpdpbusd(the product of unsigned by signed bytes, with an operand shifted by 128 and the correction of its sum); twopmaddwdon 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.dot4us:dot4with an unsigned operandvd1(uint8) and a signed operandvd2(int8), accumulated inint32: 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.div: Divides the first vector register by the second element-wise. On 32-bit ARM NEON (ARMv7,float32; AArch64 has the division), the division is a reciprocal estimate refined by two Newton-Raphson steps, then a multiplication: the last bits can differ from an IEEE division. Scalar forms:vs,sv.div2: Divides each element of a vector register by 2 (a right shift for the integers, arithmetic for the signed types and logical for the unsigned ones; a division for the floating-point types). For the negative integers the shift rounds toward \(-\infty\), where the C division rounds toward zero:-7gives-4, not-3.div4: Divides each element of a vector register by 4 (a right shift for the integers, arithmetic for the signed types and logical for the unsigned ones; a division for the floating-point types). For the negative integers the shift rounds toward \(-\infty\), where the C division rounds toward zero:-7gives-2, not-1.fmadd: Computes the fused multiply-add of three vector registers (\(a \times b + c\)). The operation is fused (a single rounding) on the targets that have the instruction. Without it (SSE and AVX without FMA, ARMv7 NEON without VFPv4 forfloat32, and the scalar target depending on the compiler) the product is rounded before the addition, and the last bits of the result can differ. Inint32, the product and the sum wrap around (modulo \(2^{32}\)). Scalar forms:vsv,vvs.fmsub: Computes the fused multiply-subtract of three vector registers (\(a \times b - c\)). The operation is fused (a single rounding) on the targets that have the instruction. Without it (SSE and AVX without FMA, ARMv7 NEON without VFPv4 forfloat32, and the scalar target depending on the compiler) the product is rounded before the addition, and the last bits of the result can differ. Inint32, the product and the sum wrap around (modulo \(2^{32}\)). Scalar forms:vsv,vvs.fnmadd: Computes the fused negative multiply-add of three vector registers (\(-(a \times b) + c\)). The operation is fused (a single rounding) on the targets that have the instruction. Without it (SSE and AVX without FMA, ARMv7 NEON without VFPv4 forfloat32, and the scalar target depending on the compiler) the product is rounded before the addition, and the last bits of the result can differ. Inint32, the product and the sum wrap around (modulo \(2^{32}\)). Scalar forms:vsv,vvs.fnmsub: Computes the fused negative multiply-subtract of three vector registers (\(-(a \times b) - c\)). The operation is fused (a single rounding) on the targets that have the instruction. Without it (SSE and AVX without FMA, ARMv7 NEON without VFPv4 forfloat32, and the scalar target depending on the compiler) the product is rounded before the addition, and the last bits of the result can differ. Inint32, the product and the sum wrap around (modulo \(2^{32}\)). Scalar forms:vsv,vvs.
Combine¶
lo: Returns the lower half of a vector register as a register of the LMUL below (m2tom1,m1tod2, ...).lo_k: Returns the lower half of a mask register as a mask of the LMUL below (m2tom1,m1tod2, ...).hi: Returns the upper half of a vector register as a register of the LMUL below (m2tom1,m1tod2, ...).hi_k: Returns the upper half of a mask register as a mask of the LMUL below (m2tom1,m1tod2, ...).combine: Joins two vector registers into a register of the LMUL above (d2tom1,m1tom2, ...): the first one gives the lower half, the second one the upper half.combine_k: Joins two mask registers into a mask of the LMUL above (d2tom1,m1tom2, ...): the first one gives the lower half, the second one the upper half.
Comparison¶
cmpeq: Compares two vector registers element-wise for equality (\(a = b\)). False when one of the two elements is NaN. Scalar forms:vs.cmpneq: Compares two vector registers element-wise for inequality (\(a \ne b\)). True when one of the two elements is NaN. Scalar forms:vs.cmple: Compares two vector registers element-wise for less-than-or-equal (\(a \le b\)). False when one of the two elements is NaN. Scalar forms:vs,sv.cmplt: Compares two vector registers element-wise for less-than (\(a < b\)). False when one of the two elements is NaN. Scalar forms:vs,sv.cmpge: Compares two vector registers element-wise for greater-than-or-equal (\(a \ge b\)). False when one of the two elements is NaN. Scalar forms:vs,sv.cmpgt: Compares two vector registers element-wise for greater-than (\(a > b\)). False when one of the two elements is NaN. Scalar forms:vs,sv.isfinite: Returns the mask of the elements that are finite: neither infinite nor NaN. Zeros and subnormal values are finite.isinf: Returns the mask of the elements that are infinite, \(+\infty\) or \(-\infty\).isnan: Returns the mask of the elements that are NaN (quiet or signaling, of either sign).signbit: Returns the mask of the elements whose sign bit is set: the negative values, and for the floating-point types also-0.0and the NaN with a negative sign.
Complex¶
cmul: Complex product of the complex numbers (re, im) of the pairs of lanes of the two registers (interleaved layout: the real part in the even lane, the imaginary part in the odd lane).cmulconj: Complex product of the complex numbers ofvd0by the conjugates of the complex numbers ofvd1(interleaved layout).cfmadd: Complex fused multiply-add:vd0*vd1+vd2, with complex numbers in the interleaved layout.conj: Complex conjugate: the imaginary parts (odd lanes) negated (interleaved layout).cnorm: Squared modulus of the complex numbers (interleaved layout), in both lanes of each pair.cabs: Modulus of the complex numbers (interleaved layout), in both lanes of each pair, without intermediate overflow: computed as \(m \sqrt{(a_r/m)^2 + (a_i/m)^2}\) with \(m\) the largest absolute value of the two parts.cdiv: Complex division of the complex numbers ofvd0by the ones ofvd1(interleaved layout), with the algorithm of Smith: the division by the part of the largest absolute value avoids the overflows and the losses of \(b_r^2 + b_i^2\).
Convert¶
cvt: Converts elements of a vector register to another datatype with numerical casting. A floating-point element converted to an integer is truncated toward zero, as a C cast:2.7gives2(cvtround,cvtroundeven,cvtfloorandcvtceilround instead). An integer without an exact floating-point representation is rounded to the nearest one. The conversion to an integer of a NaN, or of a value out of the range of the destination, gives a result that depends on the target.cvtceil: Converts the floating-point elements to integers of the same size, rounded toward plus infinity:2.1gives3,-2.9gives-2, ascvt(ceil(vd0)). The result is exactly the one ofcvtapplied to the rounded register, in one instruction on AVX-512 (AVX-512 DQ forfloat64), NEON from ARMv8 (float64on AArch64) and RVV; elsewhere (SSE, AVX, SVE), the rounding then the conversion. The conversion of a NaN, or of a value whose rounding is out of the range of the destination, gives a result that depends on the target.cvtfloor: Converts the floating-point elements to integers of the same size, rounded toward minus infinity:2.9gives2,-2.1gives-3, ascvt(floor(vd0)). The result is exactly the one ofcvtapplied to the rounded register, in one instruction on AVX-512 (AVX-512 DQ forfloat64), NEON from ARMv8 (float64on AArch64) and RVV; elsewhere (SSE, AVX, SVE), the rounding then the conversion. The conversion of a NaN, or of a value whose rounding is out of the range of the destination, gives a result that depends on the target.cvtround: Converts the floating-point elements to integers of the same size, rounded to the nearest integer with the ties away from zero:2.5gives3,-2.5gives-3, ascvt(round(vd0)). The result is exactly the one ofcvtapplied to the rounded register, in one instruction on NEON from ARMv8 (vcvta;float64on AArch64) and RVV (vfcvtin the rounding modermm); elsewhere (SSE, AVX, AVX-512, which has no rounding of the ties away from zero, and SVE), the rounding then the conversion. The conversion of a NaN, or of a value whose rounding is out of the range of the destination, gives a result that depends on the target.cvtroundeven: Converts the floating-point elements to integers of the same size, rounded to the nearest integer with the ties to the even neighbor:2.5gives2,3.5gives4, ascvt(roundeven(vd0)). The result is exactly the one ofcvtapplied to the rounded register, in one instruction on AVX-512 (AVX-512 DQ forfloat64), NEON from ARMv8 (float64on AArch64), RVV, and on SSE and AVX forfloat32toint32(cvtps2dq, which rounds with the rounding mode of the environment, MXCSR, to the nearest even by default); elsewhere, the rounding then the conversion. The conversion of a NaN, or of a value whose rounding is out of the range of the destination, gives a result that depends on the target.ncvt: Narrowing conversion: converts each element to the type twice as narrow, keeping the lanes in a register one LMUL below. The integers keep their low bits (modulo \(2^n\):70000gives4464inint16), without saturation (ncvtssaturates). Afloat64is rounded to the nearestfloat32, and a value out of its range gives \(\pm\infty\).ncvts: Converts each integer element to the type twice as narrow with saturation to its range; the result has the next LMUL down.ncvtsrshiftround: Shifts each element right bys0bits with a rounding to the nearest (ties up), then converts it to the integer type of half the size with a saturation:ncvts(rshiftround(vd0, s0))in one operation, the requantization of the fixed-point arithmetic and of the quantized neural networks (anint32accumulator scaled down toint16, anint16toint8). The result has half the LMUL of the argument, asncvts. Counts from 0 to the number of bits of the source type minus 1. One instruction on RVV (vnclipin the rounding modernu), two on NEON (vrshl, thenvqmovn); the shift then the narrowing elsewhere.wcvt: Widening conversion: converts each element to the type twice as wide (int8toint16, ...,uint32touint64,float32tofloat64), exactly (sign or zero extension for the integers); the result has the next LMUL up (the inverse ofncvt).
Load¶
firstn: Returns the mask of the first \(n\) lanes: the lane \(i\) is active when \(i < n\). No lane is active for \(n \le 0\), every lane for \(n \ge N\). It is the mask of the last iteration of a loop:firstn(len - i).iota: Returns the sequence that starts ats0: the lane \(i\) holds \(s_0 + i\) (iota(2)gives \(2, 3, 4, \ldots\)), asstd::iota. For the integers the sequence wraps around modulo \(2^n\) (beyond 127 forint8from 0).load: Loads elements from an aligned memory address into a vector register. The masked variants read only the memory of the active lanes: the memory of the inactive lanes can be out of bounds (the tail of an array).loadu: Loads elements from an unaligned memory address into a vector register. The masked variants read only the memory of the active lanes: the memory of the inactive lanes can be out of bounds (the tail of an array).set: Initializes a vector register from a scalar array.set_k: Initializes a mask register from one value per lane: an array ofint32_tin C (a lane is active when its value is not 0), ofboolin the C++ APIs.set1: Broadcasts a single scalar value to all elements of a vector register.set1_k: Broadcasts a boolean to all elements of a mask register: anint32_tin C (active when not 0), aboolin the C++ APIs.set0: Initializes a vector register with all zeros.set0_k: Clears all elements of a mask register (all inactive).gather: Loads elements from non-contiguous memory locations into a vector register using an index vector (unsigned indices counted in elements, of the width of the data or 32/64-bit: then at their own LMUL; 32-bit indices lower than \(2^{31}\), and than \(2^{30}\) on RVV for 32-bit data). The masked variants read only the elements of the active lanes: the index of an inactive lane is not used.loadu_expand: Loads as many elements fromp0(no alignment required) as there are active lanes (maskvm0) and puts them in the active lanes, in order; the inactive lanes are zero. Only these elements are read.loadu_ff: First-faulting load: loads the lanes fromp0that can be read without a fault and writes their numbernto*s0(whens0is not null:NULLin C,nullptrby default in C++). On every target, at least the first lane is read (p0must be accessible, as for any load), the next lanes never fault, \(1 \le n \le N\), and the lanes after the firstnare unspecified.nsays how far the load could go without risk, not where the data ends: it can be lower thanNwhile the memory after is readable. It reads a buffer whose length is unknown and whose end is marked in the data (the0of a string, a sentinel): the loop looks for the sentinel in thenlanes; when it is not there, the buffer goes on, sop0 + nis accessible and the loop continues from there. Native on RVV (vle<n>ff) and SVE (ldff1and the first-fault register): in practice the lanes up to the first one that would fault, though both architectures allow a core to stop earlier. Elsewhere, the lanes up to the end of the page ofp0, ofMIPP_PAGE_SIZEbytes (4096 by default, which can be raised to the page size of the machine, e.g.-DMIPP_PAGE_SIZE=16384on Apple Silicon): a load that crosses a page boundary is cut there, even when the next page is readable. For a pointer aligned on the size of its elements, this happens at most once per traversal: the next load starts at the beginning of a page, and the following ones never straddle two pages.loadu_unzip: Loads \(N\) elements (no alignment required) and separates the even and the odd ones: the even elements in the lower half of the register, the odd ones in the upper half (unzip(loadu(p0)); with LMUL 2, the two LMUL 1 halves are the even and the odd elements of \(2N\) elements, as ARMvld2).loadu_unzip2: Loads \(N\) structures of 2 fields (\(2N\) elements, no alignment required; complex numbers, (x, y) points) and separates the fields:vd0andvd1receive the fields 0 and 1, the lane \(i\) ofvd{k}being the element \(2i + k\) (array of structures to structure of arrays, the inverse ofstoreu_zip2). The registers are written through pointers in C and references in C++.loadu_unzipdoes the same in a single register (the two fields in its two halves). Native on NEON (vld2q), SVE (svld2) and RVV (vlseg2e; at LMUL 8, a strided loadvlseper field); elsewhere, two loads thenunziploandunziphi.loadu_unzip3: Loads \(N\) structures of 3 fields (\(3N\) elements, no alignment required; RGB pixels, xyz points) and separates the fields:vd0,vd1andvd2receive the fields 0 to 2, the lane \(i\) ofvd{k}being the element \(3i + k\) (array of structures to structure of arrays, the inverse ofstoreu_zip3). The registers are written through pointers in C and references in C++. Native on NEON (vld3q), SVE (svld3) and RVV (vlseg3e; from LMUL 4, a strided loadvlseper field); gathers elsewhere.loadu_unzip4: Loads \(N\) structures of 4 fields (\(4N\) elements, no alignment required; RGBA pixels) and separates the fields:vd0,vd1,vd2andvd3receive the fields 0 to 3, the lane \(i\) ofvd{k}being the element \(4i + k\) (array of structures to structure of arrays, the inverse ofstoreu_zip4). The registers are written through pointers in C and references in C++. Native on NEON (vld4q), SVE (svld4) and RVV (vlseg4e; from LMUL 4, a strided loadvlseper field); gathers elsewhere.loadu_strided: Loads a register from memory with a constant stride: the lane i is the elementp0[i * s0],s0a number of elements, from 0 (every lane getsp0[0]) to any positive value (s0 = 1isloadu); the negative strides are undefined behavior. The elements between the lanes and after the last one are not accessed, except as follows. Native on RVV (vlse). Elsewhere:s0 = 1is aloadu;s0 = 2,3and4are the field 0 ofloadu_unzip2/3/4(contiguous loads, then the lanes of the field:vld2q/vld3q/vld4qon NEON,ld2/ld3/ld4on SVE), when thes0 - 1elements read after the last lane are in the same page as it (MIPP_PAGE_SIZEbytes, 4096 by default), so that they cannot fault (a memory checker such as ASan may report them); the other strides, or a last lane near the end of a page, use a gather for the 32-bit and 64-bit types (the indicesi * s0, which must stay below \(2^{31}\), in a register of unsigned integers) and an element by element copy for the 8-bit and 16-bit types. With a constant stride, the choice is made at compile time. A field of an array of structures isloadu_stridedwith the size of the structure as stride (loadu_unzip2toloadu_unzip4read every field of 2 to 4 at once).
Logic¶
andb: Computes the bitwise AND of two vector registers. Scalar forms:vs.andb_k: Computes the bitwise AND of two mask registers.andnb: Computes the bitwise AND-NOT of two vector registers (~a & b). Scalar forms:vs,sv.andnb_k: Computes the bitwise AND-NOT of two mask registers (~vm0&vm1).byteswap: Reverses the order of the bytes of each integer element (endianness conversion, asstd::byteswapof C++23). The 8-bit elements are unchanged.clz: Counts the leading zero bits of each integer element, from the most significant bit: \(n\) for0,0for the negative values. The count is returned in an element of the same type.ctz: Counts the trailing zero bits of each integer element, from the least significant bit: \(n\) for0. The count is returned in an element of the same type.orb: Computes the bitwise OR of two vector registers. Scalar forms:vs.orb_k: Computes the bitwise OR of two mask registers.popcount: Counts the bits set to 1 in each integer element (population count). The count is returned in an element of the same type.rotl: Rotates the bits of each integer element left by the number of bits of the same lane of the second register: the bits that leave on the left enter on the right. The count is taken modulo the number of bits \(n\) of the type. Not to be confused withrotate, which rotates the lanes of a register. Scalar forms:vs.rotr: Rotates the bits of each integer element right by the number of bits of the same lane of the second register: the bits that leave on the right enter on the left. The count is taken modulo the number of bits \(n\) of the type. Not to be confused withrotate, which rotates the lanes of a register. Scalar forms:vs.xorb: Computes the bitwise XOR of two vector registers. Scalar forms:vs.xorb_k: Computes the bitwise XOR of two mask registers.msb: Masks out all bits except the most significant bit (sign bit) for each vector element.notb: Computes the bitwise NOT (inversion) of a vector register.notb_k: Computes the bitwise NOT (inversion) of a mask register.lshift: Shifts each element left by the number of bits of the same lane of the second register (from 0 to the number of bits of the type minus 1; any other count is undefined behavior). The shift by the same count for every lane islshift_vs(mipp::lshift(vd0, s0)in C++).lshift_vsalso accepts the floating-point types: their bits are shifted as an integer of the same size. Scalar forms:vs.rshift: Shifts each element right by the number of bits of the same lane of the second register: arithmetic shift (copies of the sign bit) for the signed types, logical shift (zeros) for the unsigned ones. Counts from 0 to the number of bits of the type minus 1; any other count is undefined behavior. The shift by the same count for every lane isrshift_vs(mipp::rshift(vd0, s0)in C++), and the logical shift of the signed types isrshiftl.rshift_vsalso accepts the floating-point types: their bits are shifted logically, as an unsigned integer of the same size (-1.0fshifted by 4 gives the bits0x0bf80000). Scalar forms:vs.rshiftl: Shifts each element right by the number of bits of the same lane of the second register, with a logical shift (zeros enter on the left) for all the types: the signed elements are shifted as the unsigned integer of the same size, like(int32_t)((uint32_t)a >> n)in C. Same result asrshifton the unsigned types. Counts from 0 to the number of bits of the type minus 1; any other count is undefined behavior. The shift by the same count for every lane isrshiftl_vs(mipp::rshiftl(vd0, s0)in C++).rshiftl_vsalso accepts the floating-point types: their bits are shifted as an unsigned integer of the same size. Scalar forms:vs.rshiftround: Shifts each element right by the number of bits of the same lane of the second register, rounded to the nearest integer with the ties up: \((vd0_i + 2^{n-1}) \gg n\) computed without overflow, arithmetic for the signed types and logical for the unsigned ones (7shifted by 1 gives4,-7gives-3). A count of 0 gives the element itself. Counts from 0 to the number of bits of the type minus 1; any other count is undefined behavior. The fixed-point arithmetic uses it to divide by a power of 2 with a rounding instead of a truncation (rshift). One instruction on RVV (vssra/vssrlin the rounding modernu), two on NEON and SVE2 (the negated count, thenvrshl/srshl/urshl), a few elsewhere, aroundrshift, which x86 computes element by element for the 8-bit types, and for the other types without the variable shifts of AVX2 or AVX-512. The shift by the same count for every lane isrshiftround_vs(mipp::rshiftround(vd0, s0)in C++). Scalar forms:vs.all: Tests if every element of a mask register is active: 1 if all active, 0 otherwise (int32_tin C,boolin the C++ APIs).none: Tests if every element in a mask register is inactive: 1 if all inactive, 0 otherwise (int32_tin C,boolin the C++ APIs).any: Tests if at least one element of a mask register is active: 1 if any active, 0 otherwise (int32_tin C,boolin the C++ APIs).testz: Tests if the bitwise AND of two mask registers is all zero: 1 if disjoint, 0 otherwise (int32_tin C,boolin the C++ APIs).
Math¶
abs: Computes the absolute value of each element in a vector register. The most negative integer has no positive counterpart: its absolute value is itself (-128inint8).acos: Computes the arc cosine of each floating-point element in radians. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 3e-7 infloat32and 5e-16 infloat64. The scalar target calls the C library.acosh: Computes the inverse hyperbolic cosine of each floating-point element. On the SIMD targets (measured on SSE, AVX and NEON), it uses the formula of fdlibm, \(\operatorname{log1p}(t + \sqrt{t (t + 2)})\) with \(t = x - 1\), accurate near 1, and \(\ln x + \ln 2\) from \(x = 2^{24}\) infloat32/ \(2^{53}\) infloat64, where \(x^2\) would overflow: the relative error is below 3e-7 infloat32and 5e-16 infloat64. The special values are the ones of the C library: \(x < 1\) and NaN give NaN, and \(+\infty\) gives \(+\infty\). The scalar target calls the C library.asin: Computes the arc sine of each floating-point element in radians. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 3e-7 infloat32and 5e-16 infloat64. The scalar target calls the C library.asinh: Computes the inverse hyperbolic sine of each floating-point element. On the SIMD targets (measured on SSE, AVX and NEON), it uses the formula of fdlibm, \(\operatorname{log1p}(a + a^2 / (1 + \sqrt{1 + a^2}))\) with \(a = |x|\), accurate near 0, and \(\ln a + \ln 2\) from \(a = 2^{24}\) infloat32/ \(2^{53}\) infloat64, where \(a^2\) would overflow, then the sign of \(x\): the relative error is below 3e-7 infloat32and 5e-16 infloat64, tiny \(x\) included (the result is then \(x\)). The special values are the ones of the C library: \(\pm\infty\) gives \(\pm\infty\) and a NaN gives NaN. The scalar target calls the C library.atan: Computes the arc tangent of each floating-point element in radians. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 3e-7 infloat32and 5e-16 infloat64. The scalar target calls the C library.atan2: Computes the four-quadrant arc tangent of y and x floating-point vector elements. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 3e-7 infloat32and 4e-11 infloat64, andatan2(0, -0)andatan2(-0, -0)give \(\pm 0\) instead of \(\pm\pi\). The scalar target calls the C library. Scalar forms:vs,sv.atanh: Computes the inverse hyperbolic tangent of each floating-point element. On the SIMD targets (measured on SSE, AVX and NEON), it uses the formula of fdlibm, \(\operatorname{log1p}(2a + 2a \cdot a / (1 - a)) / 2\) with \(a = |x|\), accurate near 0, then the sign of \(x\): the relative error is below 3e-7 infloat32and 5e-16 infloat64, tiny \(x\) included (the result is then \(x\)). The special values are the ones of the C library: \(\pm 1\) gives \(\pm\infty\), and \(|x| > 1\) (the infinities included) and NaN give NaN. The scalar target calls the C library.cbrt: Computes the cube root of each floating-point element, negative elements included. On the SIMD targets (measured on SSE, AVX and NEON), it uses the algorithm of the C library (fdlibm, musl): a first estimate from the bits of \(|x|\) (its exponent divided by 3), a polynomial, then one Newton-like step, with the sign of \(x\), withoutexpnorlog: the relative error is below 1.2e-7 infloat32(one unit in the last place, checked on everyfloat32) and 2.3e-16 infloat64, the subnormals included. \(\pm 0\), \(\pm\infty\) and NaN are returned as they are. The scalar target calls the C library.ceil: Rounds each floating-point element up, toward \(+\infty\), as the C functionceil:2.3gives3and-2.7gives-2. The sign of a zero is kept:-0.5gives-0.0. The integers are returned unchanged.cos: Computes the trigonometric cosine of each floating-point element in radians. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 2e-7 infloat32and 5e-16 infloat64, for any argument: the lanes with \(|x| > 8192\) (float32) or \(|x| > 2^{50}\) (float64), the infinities and NaN are computed by the C library. The scalar target calls the C library.cosh: Computes the hyperbolic cosine of each floating-point element. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 4e-7 infloat32and 5e-16 infloat64. It is computed as \(h \cdot h/2 + 1/(4 \, h \cdot h/2)\) with \(h = e^{|x|/2}\), so that it overflows to \(+\infty\) where the C library does (\(|x| \approx 89.42\) infloat32, \(710.48\) infloat64), and not where \(e^{|x|}\) does; \(\pm\infty\) gives \(+\infty\) and a NaN gives NaN. The scalar target calls the C library.erf: Computes the error function of each element: \(\operatorname{erf}(x) = \frac{2}{\sqrt{\pi}} \int_0^x e^{-t^2} \, dt\), odd, from \(-1\) to \(1\) (the cumulative distribution of the normal law is \(\frac{1}{2}(1 + \operatorname{erf}(x / \sqrt{2}))\), the GELU activation \(\frac{x}{2}(1 + \operatorname{erf}(x / \sqrt{2}))\)). Two polynomials, written in MIPP: \(x \, P(x^2)\) for \(|x| \le 1\) (float32) or \(2\) (float64), \(1 - e^{-x^2} Q(1/|x|)\) beyond, and \(\pm 1\) from \(3.92\) / \(5.93\), where the result rounds to 1. The maximum relative error measured againsterfof the C library is about 2e-7 infloat32and 1e-15 infloat64.erf(+-inf)is+-1,erf(NaN)is a NaN. No target has an instruction for it.exp: Computes the base-e exponential of each floating-point element. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 2e-7 infloat32and 3e-16 infloat64(one unit in the last place). The special values are the ones of the C library: the result overflows to \(+\infty\) from \(x \approx 88.72\) infloat32and \(709.78\) infloat64, decreases through the subnormals below \(x \approx -87.3\) / \(-708.4\) down to 0 from \(-103.97\) / \(-745.13\), \(-\infty\) gives 0 and a NaN gives NaN. When every lane is in \([-87, 87]\) infloat32or \([-708, 708]\) infloat64(the usual case), \(2^n\) is built in the exponent field; otherwise it is applied in two factors, a few more operations for the whole register. On NEON of ARMv7, which flushes the subnormals to zero, a subnormal result is 0. The scalar target calls the C library.expm1: Computes \(e^x - 1\) for each floating-point element, without the loss of precision ofexp(x) - 1near 0. On the SIMD targets (measured on SSE, AVX and NEON), it uses the identity \((u - 1)\,x / \ln u\) with \(u = e^x\) for \(|x| < 0.5\) (W. Kahan) and \(u - 1\) elsewhere: the relative error is below 3e-7 infloat32and 4e-16 infloat64, tiny \(x\) included (the result is then \(x\)). The special values followexp: \(+\infty\) gives \(+\infty\), \(-\infty\) gives \(-1\), and a NaN gives NaN. The scalar target calls the C library.floor: Rounds each floating-point element down, toward \(-\infty\), as the C functionfloor:2.7gives2and-2.3gives-3. The sign of a zero is kept (-0.0gives-0.0). The integers are returned unchanged.frexp: Splits each element into a mantissa and an exponent, asfrexpin C: \(x = m \cdot 2^e\) with \(|m|\) in \([0.5, 1)\) and the sign of \(x\). The mantissa is returned, the exponent is written to the output registervd1, signed integers of the width of the data (int32forfloat32,int64forfloat64):frexp(8.0)gives0.5and4.+-0,+-infand NaN give themselves as mantissa and an exponent of 0. The subnormals give their true exponent.ldexp(m, e)gives backx;getexp(x)ise - 1for the finite non-zero values. Generic on every target (the exponent field of the bits). On NEON of ARMv7, which flushes the subnormals to zero, a subnormal input counts as 0.getexp: Returns the exponent of each element as a floating-point value: \(\lfloor \log_2 |x| \rfloor\), aslogbin C (getexp(10.0)gives3.0,getexp(0.75)gives-1.0). The subnormals give their true exponent (down to-149infloat32).getexp(+-0)is-inf,getexp(+-inf)is+infandgetexp(NaN)is a NaN. Native on AVX-512 (vgetexp); elsewhere, the exponent field of the bits minus the bias. Withldexp, it scales a value by a power of 2 without a division, and it gives the range reduction oflogandexp. On NEON of ARMv7, which flushes the subnormals to zero, a subnormal input counts as 0 (the result is-inf).hypot: Computes \(\sqrt{x^2 + y^2}\) element-wise without overflow nor underflow in the squares: it is computed as \(m \sqrt{1 + (n / m)^2}\) with \(m = \max(|x|, |y|)\) and \(n = \min(|x|, |y|)\). On the SIMD targets (measured on SSE, AVX, AVX-512, NEON, SVE and RVV), the relative error is below 3e-7 infloat32and 4e-16 infloat64, from the subnormals to the largest values, and an infinite argument gives \(+\infty\). A NaN followsminandmax: it gives NaN on NEON and SVE, and may give a number elsewhere (hypot(NaN, 1)is \(\sqrt{2}\) on SSE, AVX, AVX-512 and RVV). The scalar target calls the C library. Scalar forms:vs,sv.ldexp: Multiplies each element by 2 to the power of the same lane of the second register, signed integers of the same size (int32forfloat32,int64forfloat64): \(x \cdot 2^n\) asldexpin C, with a single rounding when the result is subnormal,+-infbeyond the largest value,+-0below the smallest one.+-0,+-infand NaN are returned unchanged. Native on SVE (fscale), two instructions on AVX-512 (the conversion ofn, thenvscalef); elsewhere, the exponent field is replaced. Withgetexp, it scales a value by a power of 2 without a multiplication by a constant computed at run time. On NEON of ARMv7, which flushes the subnormals to zero, a subnormal input counts as 0 and a subnormal result is 0.log: Computes the natural (base-e) logarithm of each floating-point element. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 2e-7 infloat32and 3e-16 infloat64(one unit in the last place), the subnormals included; thefloat64version uses the algorithm of fdlibm. The special values are the ones of the C library: \(\pm 0\) gives \(-\infty\), \(+\infty\) gives \(+\infty\), and a negative element or a NaN gives NaN. When every element is a positive normal number (the usual case), the subnormals and the special values are not looked at; otherwise, the computation is done again with the subnormals scaled, a few more operations for the whole register. On NEON of ARMv7, which flushes the subnormals to zero, a subnormal element counts as 0. The scalar target calls the C library.log10: Computes the base-10 logarithm of each floating-point element, as \(\ln x / \ln 10\). On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 2e-7 infloat32and 3e-16 infloat64, the subnormals included; the special values followlog(those of the C library: \(\pm 0\) gives \(-\infty\), \(+\infty\) gives \(+\infty\), a negative element or a NaN gives NaN). The scalar target calls the C library.log1p: Computes \(\ln(1 + x)\) for each floating-point element, without the loss of precision oflog(1 + x)near 0. On the SIMD targets (measured on SSE, AVX and NEON), it uses the identity \(\ln(u)\,x / (u - 1)\) with \(u = 1 + x\) for \(|x| < 0.5\) (D. Goldberg) and \(\ln u\) elsewhere: the relative error is below 3e-7 infloat32and 4e-16 infloat64, tiny \(x\) included (the result is then \(x\)). The special values are the ones of the C library:log1p(-1)gives \(-\infty\), \(+\infty\) gives \(+\infty\), and \(x < -1\) or a NaN gives NaN. The scalar target calls the C library.log2: Computes the base-2 logarithm of each floating-point element, as \(\ln x / \ln 2\). On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 2e-7 infloat32and 3e-16 infloat64, the subnormals included; the special values followlog(those of the C library: \(\pm 0\) gives \(-\infty\), \(+\infty\) gives \(+\infty\), a negative element or a NaN gives NaN). The scalar target calls the C library.neg: Negates each element of a vector register. The most negative integer has no positive counterpart: its negation is itself (-128inint8).rcp: Computes an estimate of the reciprocal of each floating-point element (\(1 / a\)). Its precision is the one of the instruction of the target: about two significant digits with the 7- or 8-bit estimates of NEON, SVE and RVV, three with the 12 bits of SSE and AVX (float32), four with the 14 bits of AVX-512, and the exact value forfloat64on SSE and AVX (a division). Divide bydivwhen the last digits matter.xorsign: Negates each element of the first register where the sign bit of the element of the second register is set (negative values, and also-0.0and the negative NaN for the floating-point types). Scalar forms:vs.copysign: Builds each element with the magnitude of the first register and the sign of the second one (IEEE copysign). Scalar forms:vs.pow: Computes the first vector register raised to the power of the second element-wise. On the SIMD targets (measured on SSE, AVX and NEON), it is computed as \(e^{y \ln x}\): a zero base gives 0 or \(+\infty\) by the sign of \(y\), and the infinities and NaN follow the C library, exceptpow(0, 0),pow(1, \pm\infty)andpow(1, NaN), which give NaN instead of 1; a negative base gives NaN, even with an integer exponent (pow(-2, 3)). The relative error grows with \(|y \ln x|\) (the error of \(\ln x\) is multiplied by it): below 5e-6 infloat32and 1e-14 infloat64for results between 1e-17 and 1e17. On the unsigned types, the integer power wraps around (modulo \(2^n\)) andpow(0, 0)is 1. Scalar forms:vs,sv.pow2: Computes 2 raised to the power of each vector element. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 2e-7 infloat32and 3e-16 infloat64(one unit in the last place): \(2^x = 2^n \, 2^f\) with \(n\) the nearest integer and \(f = x - n\), both exact, \(2^f\) by the polynomial ofexp, and an integer \(x\) gives an exact power of 2. The special values are the ones of the C library: \(+\infty\) from \(x = 128\) / \(1024\), the subnormals below \(x = -126\) / \(-1022\) and 0 from \(-150\) / \(-1075\), \(-\infty\) gives 0 and a NaN gives NaN. On the unsigned types, the result is1 << x: 0 when \(x\) is at least the number of bits of the type, undefined from \(x = 64\).round: Rounds each floating-point element to the nearest integer. A tie is rounded away from zero, as the C functionround:2.5gives3and-2.5gives-3. The rounding of a tie to the even integer isroundeven. The sign of a zero result depends on the target:-0.3and-0.0give-0.0on NEON, SVE and the scalar target, and+0.0on SSE, AVX, AVX-512 and RVV. The integers are returned unchanged.roundeven: Rounds each floating-point element to the nearest integer. A tie is rounded to the even integer, as the C23 functionroundevenand the default rounding of IEEE 754:2.5gives2,3.5gives4and-0.5gives-0.0. Unlikeround, it does not move the ties away from zero, so it does not bias a sum of rounded values. The integers are returned unchanged.rsqrt: Computes an estimate of the reciprocal square root of each floating-point element (\(1 / \sqrt{a}\)). Its precision is the one of the instruction of the target: about two significant digits with the 7- or 8-bit estimates of NEON and RVV, three with the 12 bits of SSE and AVX (float32), four with the 14 bits of AVX-512, and the exact value on SVE and forfloat64on SSE and AVX (a division by the square root). Divide bysqrtwhen the last digits matter.sin: Computes the trigonometric sine of each floating-point element in radians. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 2e-7 infloat32and 5e-16 infloat64, for any argument: the lanes with \(|x| > 8192\) (float32) or \(|x| > 2^{50}\) (float64), the infinities and NaN are computed by the C library. The scalar target calls the C library.sinh: Computes the hyperbolic sine of each floating-point element. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 5e-7 infloat32and 1e-15 infloat64. It is computed as \(h \cdot h/2 - 1/(4 \, h \cdot h/2)\) with \(h = e^{|x|/2}\), so that it overflows to \(\pm\infty\) where the C library does (\(|x| \approx 89.42\) infloat32, \(710.48\) infloat64), and with a Taylor polynomial for \(|x| < 0.5\), where this difference cancels (a tiny \(x\) gives \(x\)); \(\pm\infty\) gives \(\pm\infty\) and a NaN gives NaN. The scalar target calls the C library.sqrt: Computes the square root of each element in a vector register, correctly rounded. On ARMv7 NEON before ARMv8 (float32), it is a reciprocal square root estimate refined by two Newton-Raphson steps: the last bits can differ.tan: Computes the trigonometric tangent of each floating-point element in radians. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 2e-7 infloat32and 5e-16 infloat64, for any argument: the lanes with \(|x| > 8192\) (float32) or \(|x| > 2^{50}\) (float64), the infinities and NaN are computed by the C library. Infloat64on NEON,tan(-0.0)gives+0.0. The scalar target calls the C library.tanh: Computes the hyperbolic tangent of each floating-point element. On the SIMD targets (measured on SSE, AVX and NEON), the relative error is below 1e-6 infloat32for \(|x| \ge 0.1\), and 2e-15 infloat64. Near 0, the error is absolute (a few 1e-8 infloat32): below \(|x| = 0.1\) the relative error grows (about 1e-4 at \(|x| = 0.001\) infloat32), and a tiny \(x\) (1e-30) gives 0. The scalar target calls the C library.trunc: Truncates each floating-point element toward zero:-2.7gives-2. The integers are returned unchanged.
Rearrangement¶
reverse: Reverses the order of the lanes of the register (of the whole LMUL group).swap2: Swaps the lanes of each pair (lanes \(2k\) and \(2k+1\)). A register of a single lane is unchanged.dupeven: Copies each even lane to the next odd lane: lanes \(2k\) and \(2k+1\) both receive the lane \(2k\).dupodd: Copies each odd lane to the previous even lane: lanes \(2k\) and \(2k+1\) both receive the lane \(2k+1\). A register of a single lane is unchanged.ziplo: Interleaves the lanes of the lower halves of the two registers:vd0[0],vd1[0],vd0[1],vd1[1]... (the first half ofzip).ziphi: Interleaves the lanes of the upper halves of the two registers:vd0[N/2],vd1[N/2],vd0[N/2+1]... (the second half ofzip).bcast: Copies the lanes0to every lane (\(0 \le s0 < N\), with \(N\) the number of lanes of the LMUL group; other values are undefined behavior).insert: Returns the register with its lanes1replaced by the scalars0(the inverse ofget);s1must be in \([0, N)\), a value out of the range is undefined behavior. With a variables1: a broadcast ofs0under the mask of the lane on AVX-512 (2 instructions), a mergingdupon SVE,vmv.s.xthen avslideupofvl = s1 + 1lanes on RVV, and elsewhere aselectof the broadcasts0where the indices of the lanes equals1(no round trip through memory). With a constants1(insert<S>(v, x), or a constant argument once inlined): the insertion instructions on SSE (pinsrw, andpinsrb/pinsrd/pinsrq/insertpswith SSE4.1;movsd/unpcklpdforfloat64),vpinsror a blend on AVX,ins(vsetq_lane) on NEON, when the compiler optimizes.rotate: Rotates the lanes down bys0(\(0 \le s0 < N\)): the lane \(i\) receives the lane \((i + s0) \bmod N\).slide: Window of \(N\) lanes at the positions0(\(0 \le s0 \le N\)) of the concatenation of the two registers: the lanes \(s0\) to \(N-1\) ofvd0, then the lanes \(0\) to \(s0-1\) ofvd1(x86alignr, ARMext).slideup: Moves the lanes up bys0(\(0 \le s0 \le N\)): the lane \(i\) receives the lane \(i - s0\), the lanes below \(s0\) are zero.slidedown: Moves the lanes down bys0(\(0 \le s0 \le N\)): the lane \(i\) receives the lane \(i + s0\), the lanes from \(N - s0\) are zero.reverse_b128: Reverses the order of the lanes in each block of 128 bits (the whole register when it is smaller).ziplo_b128:ziploin each block of 128 bits: interleaves the lanes of the lower halves of the blocks (x86unpacklo).ziphi_b128:ziphiin each block of 128 bits: interleaves the lanes of the upper halves of the blocks (x86unpackhi).bcast_b128: Copies the lanes0of each block of 128 bits to the lanes of the block (\(0 \le s0 < B\), with \(B\) the number of lanes of a block).rotate_b128:rotatein each block of 128 bits (\(0 \le s0 < B\), with \(B\) the number of lanes of a block).slide_b128:slidein each block of 128 bits: the window ats0of the concatenation of the blocks ofvd0andvd1(\(0 \le s0 \le B\), with \(B\) the number of lanes of a block; x86alignr).slideup_b128:slideupin each block of 128 bits, zeros entering at the bottom of each block (x86pslldq).slidedown_b128:slidedownin each block of 128 bits, zeros entering at the top of each block (x86psrldq).unziplo: Even lanes of the concatenation of the two registers:vd0[0],vd0[2]... thenvd1[0],vd1[2]... (withlo/hi, the even lanes of a register of twice the LMUL; ARMuzp1).unziphi: Odd lanes of the concatenation of the two registers:vd0[1],vd0[3]... thenvd1[1],vd1[3]... (ARMuzp2).unziplo_b128:unziploin each block of 128 bits (x86shufpswith the even lanes).unziphi_b128:unziphiin each block of 128 bits.zip: Interleaves the two halves of the register: the lane \(2k\) receives the lane \(k\), the lane \(2k+1\) the lane \(N/2 + k\) (planar to interleaved layout; the inverse ofunzip).unzip: Separates the even and the odd lanes: the even lanes in the lower half, the odd lanes in the upper half (interleaved to planar layout).loadu_unzip: Loads \(N\) elements (no alignment required) and separates the even and the odd ones: the even elements in the lower half of the register, the odd ones in the upper half (unzip(loadu(p0)); with LMUL 2, the two LMUL 1 halves are the even and the odd elements of \(2N\) elements, as ARMvld2).loadu_unzip2: Loads \(N\) structures of 2 fields (\(2N\) elements, no alignment required; complex numbers, (x, y) points) and separates the fields:vd0andvd1receive the fields 0 and 1, the lane \(i\) ofvd{k}being the element \(2i + k\) (array of structures to structure of arrays, the inverse ofstoreu_zip2). The registers are written through pointers in C and references in C++.loadu_unzipdoes the same in a single register (the two fields in its two halves). Native on NEON (vld2q), SVE (svld2) and RVV (vlseg2e; at LMUL 8, a strided loadvlseper field); elsewhere, two loads thenunziploandunziphi.loadu_unzip3: Loads \(N\) structures of 3 fields (\(3N\) elements, no alignment required; RGB pixels, xyz points) and separates the fields:vd0,vd1andvd2receive the fields 0 to 2, the lane \(i\) ofvd{k}being the element \(3i + k\) (array of structures to structure of arrays, the inverse ofstoreu_zip3). The registers are written through pointers in C and references in C++. Native on NEON (vld3q), SVE (svld3) and RVV (vlseg3e; from LMUL 4, a strided loadvlseper field); gathers elsewhere.loadu_unzip4: Loads \(N\) structures of 4 fields (\(4N\) elements, no alignment required; RGBA pixels) and separates the fields:vd0,vd1,vd2andvd3receive the fields 0 to 3, the lane \(i\) ofvd{k}being the element \(4i + k\) (array of structures to structure of arrays, the inverse ofstoreu_zip4). The registers are written through pointers in C and references in C++. Native on NEON (vld4q), SVE (svld4) and RVV (vlseg4e; from LMUL 4, a strided loadvlseper field); gathers elsewhere.storeu_zip: Interleaves the two halves of the register and stores the \(N\) elements (no alignment required):storeu(p0, zip(vd0)), the inverse ofloadu_unzip(ARMvst2).storeu_zip2: Storesvd0andvd1as \(N\) structures of 2 fields (\(2N\) elements, no alignment required): the lane \(i\) ofvd{k}goes to the element \(2i + k\) (structure of arrays to array of structures, the inverse ofloadu_unzip2).storeu_zipdoes the same from a single register (the two fields in its two halves). Native on NEON (vst2q), SVE (svst2) and RVV (vsseg2e; at LMUL 8, a strided storevsseper field); elsewhere,ziploandziphithen two stores.storeu_zip3: Storesvd0,vd1andvd2as \(N\) structures of 3 fields (\(3N\) elements, no alignment required): the lane \(i\) ofvd{k}goes to the element \(3i + k\) (structure of arrays to array of structures, the inverse ofloadu_unzip3). Native on NEON (vst3q), SVE (svst3) and RVV (vsseg3e; from LMUL 4, a strided storevsseper field); scatters elsewhere.storeu_zip4: Storesvd0,vd1,vd2andvd3as \(N\) structures of 4 fields (\(4N\) elements, no alignment required): the lane \(i\) ofvd{k}goes to the element \(4i + k\) (structure of arrays to array of structures, the inverse ofloadu_unzip4). Native on NEON (vst4q), SVE (svst4) and RVV (vsseg4e; from LMUL 4, a strided storevsseper field); scatters elsewhere.permute: Lane \(i\) receives the lanevd1[i]ofvd0(vd1: unsigned indices of the width of the elements, each below \(N\), the number of lanes of the LMUL group; other values are undefined behavior).permute2: Lane i receives the lanevd2[i]of the concatenation ofvd0andvd1(indices below 2N; other values are undefined behavior).permute_b128:permutein each block of 128 bits: lane \(i\) receives the lanevd1[i]of its block (indices below the number of lanes of a block; x86vpermilps,pshufb).compress: The active lanes ofvd0(maskvm0), in order, packed at the beginning of the register; the other lanes are zero.expand: The inverse ofcompress: the first lanes ofvd0, in order, go to the active lanes (maskvm0); the inactive lanes are zero.
Reduction¶
findfirst: Returns the index of the first active lane of a mask register, or \(-1\) when no lane is active.findlast: Returns the index of the last active lane of a mask register, or \(-1\) when no lane is active.hadd: Computes the horizontal addition (reduction sum) of all elements in a vector register. The integer sum wraps around (modulo \(2^n\)), so its result depends on the number of lanes;haddssaturates instead. For the floating-point types, the order of the additions depends on the target: the last bits of the result can differ from one target to another, and from a sequential sum.hadds: Computes the horizontal addition with saturation of all elements in an integer vector register. For the 8-, 16- and 32-bit types, the sum is exact and saturated once at the end:100 + 100 - 100 - 100gives0inint8. For the 64-bit types, each addition saturates, in the order of the lanes:MAX + 1 - 1givesMAX - 1.hmul: Computes the horizontal multiplication (reduction product) of all elements in a vector register. The integer product keeps the low bits (modulo \(2^n\)). For the floating-point types, the order of the multiplications depends on the target: the last bits of the result can differ from one target to another, and from a sequential product.hmin: Computes the horizontal minimum (reduction minimum) of all elements in a vector register. With a NaN element, the result depends on the target (measured): NEON and SVE return NaN; RVV and the scalar target ignore the NaN elements (and returnFLT_MAX/DBL_MAXwhen all the elements are NaN); on SSE, AVX and AVX-512, the result depends on the position of the NaN in the register (in the measures: NaN with the NaN in the last lane, the minimum of the other elements with the NaN in the first or a middle lane, NaN when all the elements are NaN). To get a NaN whenever an element is NaN, testany(isnan(v))first.hmax: Computes the horizontal maximum (reduction maximum) of all elements in a vector register. With a NaN element, the result depends on the target (measured): NEON and SVE return NaN; RVV and the scalar target ignore the NaN elements (and return-FLT_MAX/-DBL_MAXwhen all the elements are NaN); on SSE, AVX and AVX-512, the result depends on the position of the NaN in the register (in the measures: NaN with the NaN in the last lane, the maximum of the other elements with the NaN in the first or a middle lane, NaN when all the elements are NaN). To get a NaN whenever an element is NaN, testany(isnan(v))first.argmin: Returns the index of the first lane holding the minimum of the register (the lane ofhmin): with equal values, the lowest index. With a NaN, the result depends on the ISA (seehmin), and may be \(-1\) when the NaN reacheshminand no lane is equal to it; on the scalar target, which compares the lanes in order, a NaN is ignored, except in the first lane, which is then the result (with NaN as minimum). Whens0is not null (NULLin C,nullptrby default in C++), the minimum is also written to*s0: the result ofhmin, computed anyway to find the lane, which saves a second reduction (to compare blocks in a loop over an array, for example).argmax: Returns the index of the first lane holding the maximum of the register (the lane ofhmax): with equal values, the lowest index. With a NaN, the result depends on the ISA (seehmax), and may be \(-1\) when the NaN reacheshmaxand no lane is equal to it; on the scalar target, which compares the lanes in order, a NaN is ignored, except in the first lane, which is then the result (with NaN as maximum). Whens0is not null (NULLin C,nullptrby default in C++), the maximum is also written to*s0: the result ofhmax, computed anyway to find the lane, which saves a second reduction (to compare blocks in a loop over an array, for example).testz: Tests if the bitwise AND of two mask registers is all zero: 1 if disjoint, 0 otherwise (int32_tin C,boolin the C++ APIs).none: Tests if every element in a mask register is inactive: 1 if all inactive, 0 otherwise (int32_tin C,boolin the C++ APIs).any: Tests if at least one element of a mask register is active: 1 if any active, 0 otherwise (int32_tin C,boolin the C++ APIs).all: Tests if every element of a mask register is active: 1 if all active, 0 otherwise (int32_tin C,boolin the C++ APIs).count: Number of active lanes of a mask register.
Reinterpret¶
cast: In-register bitcast/reinterpretation of a vector register to another datatype with zero runtime instructions: the register keeps its size and its bits, so the number of lanes changes with the element size.cast_k: In-register bitcast/reinterpretation of a mask register to another datatype of the same element size with zero runtime instructions: the mask keeps its lanes.tovd: Expands a mask register into an all-ones (~0) / all-zeros (0) vector register.tovm: Converts vector elements to mask elements: a lane is active when its element has at least one non-zero bit (so-0.0is active), and the resulting mask lane has all its bits set.
Selection¶
select: Selects elements between two vector registers based on a mask (vd0in the active lanes ofvm0,vd1in the others). Scalar forms:vs,sv.min: Selects the minimum value element-wise between two vector registers. With a NaN, the result depends on the target (measured): SSE, AVX, AVX-512 and the scalar target return the second element when one of the two is NaN (min(NaN, 1)is 1,min(1, NaN)is NaN), NEON and SVE return NaN, RVV returns the other element (vfmin, IEEE 754-2019minimumNumber: NaN only when both are NaN); on ARMv7,float64(emulated) behaves as the scalar target. The sign of the zero returned for-0.0and0.0depends on the target too. Scalar forms:vs.max: Selects the maximum value element-wise between two vector registers. With a NaN, the result depends on the target (measured): SSE, AVX, AVX-512 and the scalar target return the second element when one of the two is NaN (max(NaN, 1)is 1,max(1, NaN)is NaN), NEON and SVE return NaN, RVV returns the other element (vfmax, IEEE 754-2019maximumNumber: NaN only when both are NaN); on ARMv7,float64(emulated) behaves as the scalar target. The sign of the zero returned for-0.0and0.0depends on the target too. Scalar forms:vs.clamp: Clamps each element between the elements of the same lane of the second (lower bound) and third (upper bound) registers:min(max(vd0, vd1), vd2). With a lower bound greater than the upper bound, the result is the upper bound. The formvsstakes scalar bounds:clamp(vd0, s0, s1). Scalar forms:vss.
Store¶
store: Stores vector elements into an aligned memory address.storent: Stores a vector register to aligned memory with a non-temporal hint: the data bypasses the caches when the target allows it, for the large arrays that are written once and not read soon (the caches keep the data that is reused). The address must be aligned as forstore. On x86, the non-temporal stores are weakly ordered: callmipp_storent_fence()/mipp::storent_fence()before another thread reads the data. Where the target has no such store (NEON with GCC, RVV), it is an ordinarystore.storeu: Stores vector elements into an unaligned memory address.get: Extracts a single scalar element at indexs0from a vector register.get_k: Returns the lanes0of a mask register. In C, a value of the element type: all bits set for an active lane (-1for the signed integers, the maximum for the unsigned ones, NaN for the floating-point types), 0 for an inactive lane, on every target; test it with!= 0, and do not convert a floating-point result to an integer. In the C++ APIs (mipp::get(vm, idx)), abool.getfirst: Extracts the first scalar element (element 0) from a vector register with minimal latency.scatter: Stores vector elements into non-contiguous memory locations using an index vector (unsigned indices counted in elements, of the width of the data or 32/64-bit: then at their own LMUL; 32-bit indices lower than \(2^{31}\), and than \(2^{30}\) on RVV for 32-bit data). Two active lanes with the same index write the same element: undefined behavior (the value that remains depends on the target).storeu_compress: Stores the active lanes ofvd0(maskvm0), in order, atp0(no alignment required) and returns their number. Exactly this number of elements is written.storeuf_compress:storeu_compressthat may write a whole register: the active lanes ofvd0atp0, then up to \(N - c\) unspecified elements, with \(c\) the number of active lanes (the memory of \(N\) elements fromp0must be writable). Faster thanstoreu_compresswithout a native masked store: a filter loop overwrites the unspecified elements with the next call (keep \(N\) elements of margin at the end of the output).storeu_zip: Interleaves the two halves of the register and stores the \(N\) elements (no alignment required):storeu(p0, zip(vd0)), the inverse ofloadu_unzip(ARMvst2).storeu_zip2: Storesvd0andvd1as \(N\) structures of 2 fields (\(2N\) elements, no alignment required): the lane \(i\) ofvd{k}goes to the element \(2i + k\) (structure of arrays to array of structures, the inverse ofloadu_unzip2).storeu_zipdoes the same from a single register (the two fields in its two halves). Native on NEON (vst2q), SVE (svst2) and RVV (vsseg2e; at LMUL 8, a strided storevsseper field); elsewhere,ziploandziphithen two stores.storeu_zip3: Storesvd0,vd1andvd2as \(N\) structures of 3 fields (\(3N\) elements, no alignment required): the lane \(i\) ofvd{k}goes to the element \(3i + k\) (structure of arrays to array of structures, the inverse ofloadu_unzip3). Native on NEON (vst3q), SVE (svst3) and RVV (vsseg3e; from LMUL 4, a strided storevsseper field); scatters elsewhere.storeu_zip4: Storesvd0,vd1,vd2andvd3as \(N\) structures of 4 fields (\(4N\) elements, no alignment required): the lane \(i\) ofvd{k}goes to the element \(4i + k\) (structure of arrays to array of structures, the inverse ofloadu_unzip4). Native on NEON (vst4q), SVE (svst4) and RVV (vsseg4e; from LMUL 4, a strided storevsseper field); scatters elsewhere.storeu_strided: Stores a register to memory with a constant stride: the lane i goes top0[i * s0],s0a positive number of elements (s0 = 1isstoreu). Only theseNelements are written: the ones between them are left unchanged.s0must be positive:s0 = 0(every lane to the same element, the value that remains would depend on the target) and the negative strides are undefined behavior. Native on RVV (vsse); a scatter on SVE and on the other targets for the 32-bit and 64-bit types; an element by element copy otherwise.