array.c file
Functions
-
void vm_array_add_avx2(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) -
void vm_array_sub_avx2(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) -
void vm_array_mul_avx2(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) -
void vm_array_div_avx2(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) -
void vm_array_fma_avx2(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, const vm_ float_ t* c, int n) -
void vm_axpy_avx2(vm_
float_ t* y, vm_ float_ t alpha, const vm_ float_ t* x, int n) -
void vm_rsqrt_array_avx2(vm_
float_ t* res, const vm_ float_ t* x, int n) -
void vm_array_add_neon(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) -
void vm_array_sub_neon(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) -
void vm_array_mul_neon(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) -
void vm_array_div_neon(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) -
void vm_array_fma_neon(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, const vm_ float_ t* c, int n) -
void vm_axpy_neon(vm_
float_ t* y, vm_ float_ t alpha, const vm_ float_ t* x, int n) -
void vm_rsqrt_array_neon(vm_
float_ t* res, const vm_ float_ t* x, int n) -
static auto array_nan(void) -> vm_
float_ t - Quiet NaN in the active width.
-
void vm_array_add(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) res[i] = a[i] + b[i].-
void vm_array_sub(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) res[i] = a[i] - b[i].-
void vm_array_mul(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) res[i] = a[i] * b[i].-
void vm_array_div(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, int n) res[i] = a[i] / b[i].-
void vm_array_fma(vm_
float_ t* res, const vm_ float_ t* a, const vm_ float_ t* b, const vm_ float_ t* c, int n) res[i] = fma(a[i], b[i], c[i]).-
void vm_axpy(vm_
float_ t* y, vm_ float_ t alpha, const vm_ float_ t* x, int n) y[i] += alpha * x[i].-
static auto asum_step(const vm_
float_ t sum, vm_ float_ t* comp, const vm_ float_ t x) -> vm_ float_ t -
auto vm_nrm2(const vm_
float_ t* x, int n) -> vm_ float_ t - Euclidean norm of
x, scaled so a finite result does not overflow early. -
auto vm_asum(const vm_
float_ t* x, int n) -> vm_ float_ t - Sum of absolute values, Neumaier compensated.
-
void vm_rsqrt_array(vm_
float_ t* res, const vm_ float_ t* x, int n) res[i] = 1 / sqrt(x[i]).-
auto vm_array_silu(vm_
float_ t* y, const vm_ float_ t* x, int n) -> bool y[i] = x[i] * sigmoid(x[i]).
Function documentation
void vm_array_add(vm_ float_ t* res,
const vm_ float_ t* a,
const vm_ float_ t* b,
int n)
res[i] = a[i] + b[i].
| Parameters | |
|---|---|
| res | Output; length n. May exactly alias a or b. |
| a | Left input; length n. |
| b | Right input; length n. |
| n | |
One rounding. Finite results are within 1 ULP of the correctly rounded sum.
void vm_array_sub(vm_ float_ t* res,
const vm_ float_ t* a,
const vm_ float_ t* b,
int n)
res[i] = a[i] - b[i].
| Parameters | |
|---|---|
| res | Output; length n. May exactly alias a or b. |
| a | Left input; length n. |
| b | Right input; length n. |
| n | |
One rounding. Finite results are within 1 ULP of the correctly rounded difference.
void vm_array_mul(vm_ float_ t* res,
const vm_ float_ t* a,
const vm_ float_ t* b,
int n)
res[i] = a[i] * b[i].
| Parameters | |
|---|---|
| res | Output; length n. May exactly alias a or b. |
| a | Left input; length n. |
| b | Right input; length n. |
| n | |
One rounding. Finite results are within 1 ULP of the correctly rounded product.
void vm_array_div(vm_ float_ t* res,
const vm_ float_ t* a,
const vm_ float_ t* b,
int n)
res[i] = a[i] / b[i].
| Parameters | |
|---|---|
| res | Output; length n. May exactly alias a or b. |
| a | Dividend; length n. |
| b | Divisor; length n. |
| n | |
One rounding. Finite results are within 1 ULP of the correctly rounded quotient. Division by zero follows IEEE (finite nonzero → signed inf, 0/0 → NaN).
void vm_array_fma(vm_ float_ t* res,
const vm_ float_ t* a,
const vm_ float_ t* b,
const vm_ float_ t* c,
int n)
res[i] = fma(a[i], b[i], c[i]).
| Parameters | |
|---|---|
| res | Output; length n. May exactly alias a, b, or c. |
| a | Factor; length n. |
| b | Factor; length n. |
| c | Addend; length n. |
| n | |
One rounding, through VECMAT_ (fma / fmaf). This is not a license to contract other expressions. Finite results are within 1 ULP of the correctly rounded fused operation.
void vm_axpy(vm_ float_ t* y,
vm_ float_ t alpha,
const vm_ float_ t* x,
int n)
y[i] += alpha * x[i].
| Parameters | |
|---|---|
| y | Input and output; length n. |
| alpha | Scale applied to x. |
| x | |
| n | |
A multiply, then an add. Not a fused multiply-add. x may exactly alias y. For finite inputs the forward error is at most 8 eps × (|y_old| + |alpha * x|).
vm_ float_ t vm_nrm2(const vm_ float_ t* x,
int n)
Euclidean norm of x, scaled so a finite result does not overflow early.
| Returns | sqrt(sum x[i]^2), or +0 when n <= 0. |
|---|
n <= 0 or a null x returns +0 and does not read. A NaN in x returns a NaN. An infinity returns +inf. No allocation.
vm_ float_ t vm_asum(const vm_ float_ t* x,
int n)
Sum of absolute values, Neumaier compensated.
| Returns | Compensated sum |x[i]|, or +0 when n <= 0. |
|---|
n <= 0 or a null x returns +0 and does not read. No allocation.
void vm_rsqrt_array(vm_ float_ t* res,
const vm_ float_ t* x,
int n)
res[i] = 1 / sqrt(x[i]).
| Parameters | |
|---|---|
| res | Output; length n. |
| x | |
| n | |
Strict reciprocal square root. The SIMD path uses hardware sqrt then div (not an estimate). +0 → +inf, −0 → −inf, +inf → +0, a negative nonzero (including −inf) → NaN, and a NaN stays a NaN. Positive finite normals whose reciprocal square root is finite are within 2 ULP of the correctly rounded value. res may exactly alias x.
bool vm_array_silu(vm_ float_ t* y,
const vm_ float_ t* x,
int n)
y[i] = x[i] * sigmoid(x[i]).
| Parameters | |
|---|---|
| y | Output; length n. May exactly alias x. Unchanged on failure. |
| x | |
| n | |
| Returns | false when a pointer or the count is invalid. |
sigmoid(x) = 1 / (1 + exp(-x)), evaluated with VECMAT_. The reciprocal is one rounding, then the multiply is another. y may exactly alias x. A partial overlap is caller error. No allocation.
A null pointer or n <= 0 returns false and does not write y.
On a finite input, the result differs from the same steps in IEEE-754 double by less than 16 * VECMAT_ absolute. +inf stays +inf. -inf and a NaN yield a NaN.