[FFmpeg-devel] Optimised math functions in FFMPEG?

Ronald S. Bultje rsbultje at gmail.com
Sun Aug 15 20:04:58 EEST 2021


Hi Paul,

On Sun, Aug 15, 2021 at 9:25 AM Paul Buxton <paulbuxton.mail at googlemail.com>
wrote:

> Specifically any of
> pow()
> exp()
> log()
>

pow(a, b) = exp(log(a) * b), so you only need exp/log.

As for exp/log optimized versions, there's two approaches that may work for
you. First, integer operation is critical (e.g. 16-bit signed, with all
non-sign bits being fractional). Then, some people re-implement integer
exp/log using a repeated linear approximation, same as what you'd do for
sqrt. I've tried this in the past, it works and precision can be quite
good, and SIMD'ed implementations will be faster than calling float
exp/log. Precision vs. speed is a trade-off of number of repetitions. It's
easily SIMD'ed. But... It tends to lose out vs. a much simpler (the second)
approach - at least in pure software implementations: look-up tables.This
can - optionally - be SIMD'ed using vpgatherdd in AVX2/512. You could in
theory even use float output in LUTs, although the input (index) obviously
still has to be integerized.

Hope that makes sense, feel free to ask more specific questions if needed.

Ronald


More information about the ffmpeg-devel mailing list