This library provides high-performance approximation functions for array operations involving logarithm (std::logf
) and exponential (std::expf
) calculations.
The implementation prioritizes speed while maintaining practical accuracy.
Note: This version is not backward compatible with previous releases.
void (*fmath_logf_v)(float *dst, const float *src, size_t n);
void (*fmath_expf_v)(float *dst, const float *src, size_t n);
dst
: Output array that stores the computed resultsf(src[i])
src
: Input array containing source valuesn
: Array length (number of elements to process)
#include "fmath.h"
const size_t n = 1000;
float src[n] = {1.0f, 2.0f, 3.0f, /* ... */};
float dst[n];
fmath_init(); // Required initialization on Windows (It is automatically called on Linux)
// Calculate natural logarithm for array
fmath_logf_v(dst, src, n); // dst[i] = log(src[i])
// Calculate exponential for array
fmath_expf_v(dst, src, n); // dst[i] = exp(src[i])
- x86-64 CPU with AVX2 support
- Automatically utilizes AVX-512 if available
Average cycles per 32 elements
Function | fmath | std | Speedup |
---|---|---|---|
logf_v | 6.72 | 105.20 | 15.7x |
expf_v | 5.60 | 103.80 | 18.5x |
Function | fmath | std | Speedup |
---|---|---|---|
logf_v | 15.22 | 257.46 | 16.9x |
expf_v | 12.58 | 246.04 | 19.5x |
Function | fmath | std | Speedup |
---|---|---|---|
logf_v | 25.90 | 244.19 | 9.4x |
expf_v | 17.52 | 225.42 | 12.9x |
Note: Don't use these functions for small n
because they are slow.
- modified new BSD License
- http://opensource.org/licenses/BSD-3-Clause
MITSUNARI Shigeo(herumi@nifty.com)