[FFmpeg-devel] [PATCH] configure, avutil/libm: add fmax, fmaxf, fmin, fminf support

Ganesh Ajjanagadde gajjanag at mit.edu
Thu Oct 15 15:19:34 CEST 2015


On Thu, Oct 15, 2015 at 9:10 AM, Ganesh Ajjanagadde <gajjanag at mit.edu> wrote:
> On Thu, Oct 15, 2015 at 8:31 AM, Clément Bœsch <u at pkh.me> wrote:
>> On Thu, Oct 15, 2015 at 08:18:02AM -0400, Ganesh Ajjanagadde wrote:
>>> It has been demonstrated that using libc provided floating point
>>> functions is beneficial, in the context of fabs() vs FFABS.
>>>
>>> Unfortunately, MSVC 2012 (and earlier) lack the ISO C99 fmax, fmaxf,
>>> fmin, fminf functions. This patch adds them, thus making their usage in
>>> FFmpeg safe.
>>>
>>
>> Do we have any use of fmax/fmin? The functions don't exist to make
>> FFMAX-like faster, it actually is more complex:
>>
>>        These functions return the maximum of x and y.
>>
>>        If one argument is a NaN, the other argument is returned.
>>
>>        If both arguments are NaN, a NaN is returned.
>>
>> Which means it's likely slower but will do more. Not that I mind, but in this
>> case, if we happen to use them, you will want to fix your local implementation
>> to match this behaviour.
>
> 2 comments:
> 1. There is a tradeoff: the gain from possible better optimization of
>>=, versus the nan handling.
> 2. NaN handling is not being done currently (by FFMAX and the like) -
> so I don't know and can't comment whether we want it. You are right
> that if we change to a fmax, we should make it consistent everywhere
> on all platforms . Anyone else has comments on this?

If we don't care about NaN, Inf behavior, we should strongly consider
enabling of (on GCC):
-ffinite-math-only
Allow optimizations for floating-point arithmetic that assume that
arguments and results are not NaNs or +-Infs.

This option should never be turned on by any -O option since it can
result in incorrect output for programs which depend on an exact
implementation of IEEE or ISO rules/specifications.

The default is -fno-finite-math-only.

As stated above, -O3 does not automatically enable it.

Thinking about it, if we actually care about NaN's/Infs etc I will
drop this patch. If we don't, we can enable -ffinite-math-only, then I
am pretty sure a good libc will no-op the isnan checks in fmin, fmax,
etc.

>
>>
>> [...]
>>
>> --
>> Clément B.
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>


More information about the ffmpeg-devel mailing list