Fast Approximation Functions for std::logf and std::expf Operations on Arrays

January 14, 2025 ยท View on GitHub

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.

Core Functions

void (*fmath_logf_v)(float *dst, const float *src, size_t n);
void (*fmath_expf_v)(float *dst, const float *src, size_t n);

Parameters

  • dst: Output array that stores the computed results f(src[i])
  • src: Input array containing source values
  • n: Array length (number of elements to process)

Quick Start

#include "fmath.h"

const size_t n = 1000;
float src[n] = {1.0f, 2.0f, 3.0f, /* ... */};
float dst[n];

// 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])

System Requirements

  • x86-64 CPU with AVX2 support
  • Automatically utilizes AVX-512 if available

Performance Benchmarks

Average cycles per 32 elements

Linux (Xeon w9-3495X w/ AVX-512)

FunctionfmathstdSpeedup
logf_v6.72105.2015.7x
expf_v5.60103.8018.5x

Windows (Core i7-1165G7 w/ AVX-512)

FunctionfmathstdSpeedup
logf_v15.22257.4616.9x
expf_v12.58246.0419.5x

Windows (Core i7-1255U w/o AVX-512)

FunctionfmathstdSpeedup
logf_v25.90244.199.4x
expf_v17.52225.4212.9x

Note: Don't use these functions for small n (< 16) because they are slow.

License

Author

MITSUNARI Shigeo(herumi@nifty.com)

Support the Project

GitHub Sponsor