summaryrefslogtreecommitdiffstats
path: root/libavutil/libm.h
Commit message (Collapse)AuthorAgeFilesLines
* lavu/libm: add isfinite fallbackGanesh Ajjanagadde2016-01-131-0/+19
| | | | | Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* lavu/libm,configure: remove exp10, exp10f detectionGanesh Ajjanagadde2015-12-251-18/+0
| | | | | | Subsequent commit introduces ff_exp10 instead. Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* lavu/libm: misc, minor changesGanesh Ajjanagadde2015-12-251-14/+13
| | | | | | | Addition of comments marking the end of ifdef blocks, correction of an incorrect (at double precision) M_LN2, removal of an unnecessary undef. Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* lavu/libm: add exp10 supportGanesh Ajjanagadde2015-12-231-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | exp10 is a function available in GNU libm. Looks like no other common libm has it. This adds support for it to FFmpeg. There are essentially 2 ways of handling the fallback: 1. Using pow(10, x) 2. Using exp2(M_LOG2_10 * x). First one represents a Pareto improvement, with no speed or accuracy regression anywhere, but speed improvement limited to GNU libm. Second one represents a slight accuracy loss (relative error ~ 1e-13) for non GNU libm. Speedup of > 2x is obtained on non GNU libm platforms, ~30% on GNU libm. These are "average case numbers", another benefit is the lack of triggering of the well-known terrible worst case paths through pow. Based on reviews, second one chosen. Comment added accordingly. Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com> Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* lavu/libm: add erf hack and make dynaudnorm available everywhereGanesh Ajjanagadde2015-12-211-0/+201
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Source code is from Boost: http://www.boost.org/doc/libs/1_46_1/boost/math/special_functions/erf.hpp with appropriate modifications for FFmpeg. Tested on interval -6 to 6 (beyond which it saturates), +/-NAN, +/-INFINITY under -fsanitize=undefined on clang to test for possible undefined behavior. This function turns out to actually be essentially as accurate and faster than the libm (GNU/BSD's/Mac OS X), and I can think of 3 reasons why upstream does not use this: 1. They are not aware of it. 2. They are concerned about licensing - this applies especially to GNU libm. 3. They do not know and/or appreciate the benefits of rational approximations over polynomial approximations. Boost uses them to great effect, see e.g swr/resample for bessel derived from them, which is also similarly superior to libm variants. First, performance. sample benchmark (clang -O3, Haswell, GNU/Linux): 3e8 values evenly spaced from 0 to 6 time (libm): ./test 13.39s user 0.00s system 100% cpu 13.376 total time (boost based): ./test 9.20s user 0.00s system 100% cpu 9.190 total Second, accuracy. 1e8 eval pts from 0 to 6 maxdiff (absolute): 2.2204460492503131e-16 occuring at point where libm erf is correctly rounded, this is not. Illustration of superior rounding of this function: arg : 0.83999999999999997 erf : 0.76514271145499457 boost : 0.76514271145499446 real : 0.76514271145499446 i.e libm is actually incorrectly rounded. Note that this is clear from: https://github.com/JuliaLang/openlibm/blob/master/src/s_erf.c (the Sun implementation used by both BSD and GNU libm's), where only 1 ulp is guaranteed. Reasons it is not easy/worthwhile to create a "correctly rounded" variant of this function (i.e 0.5ulp): 1. Upstream libm's don't do it anyway, so we can't guarantee this unless we force this implementation on all platforms. This is not easy, as the linker would complain unless measures are taken. 2. Nothing in FFmpeg cares or can care about such things, due to the above and FFmpeg's nature. 3. Creating a correctly rounded function will in practice need some use of long double/fma. long double, although C89/C90, unfortunately has problems on ppc. This needs fixing of toolchain flags/configure. In any case this will be slower for miniscule gain. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* lavu/libm: add copysign hackGanesh Ajjanagadde2015-12-191-0/+9
| | | | | | | | | | | | For systems with broken libms. Tested with NAN, -NAN, INFINITY, -INFINITY, +/-x for regular double x and combinations of these. Old versions of MSVC need some UINT64_C hackery. Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com> Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* avutil/libm: fix isnan compatibility hackGanesh Ajjanagadde2015-11-241-1/+1
| | | | | | | | | | | | | Commit 14ea4151d7c3c26500193f11ac661ed20c7c2b9c had a bug in that the conversion of the uint64_t result to an int (the return signature) would lead to implementation defined behavior, and in this case simply returned 0 for NAN. A fix via AND'ing the result with 1 does the trick, simply by ensuring a 0 or 1 return value. Patch tested with FATE on x86-64, GNU/Linux by forcing the compatibility code via an ifdef hack suggested by Michael. Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* configure+libm.h: add hypot emulationGanesh Ajjanagadde2015-11-211-0/+23
| | | | | | | | | | | | | | It is known that the naive sqrt(x*x + y*y) approach for computing the hypotenuse suffers from overflow and accuracy issues, see e.g http://www.johndcook.com/blog/2010/06/02/whats-so-hard-about-finding-a-hypotenuse/. This adds hypot support to FFmpeg, a C99 function. On platforms without hypot, this patch does a reaonable workaround, that although not as accurate as GNU libm, is readable and does not suffer from the overflow issue. Improvements can be made separately. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* avutil/libm: correct isnan, isinf compat hacksGanesh Ajjanagadde2015-11-211-2/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | isnan and isinf are actually macros as per the standard. In particular, the existing implementation has incorrect signature. Furthermore, this results in undefined behavior for e.g double values outside float range as per the standard. This patch corrects the undefined behavior for all usage within FFmpeg. Note that long double is not handled as it is not used in FFmpeg. Furthermore, even if at some point long double gets used, it is likely not needed to modify the macro in practice for usage in FFmpeg. See below for analysis. Getting long double to work strictly per the spec is significantly harder since a long double may be an IEEE 128 bit quad (very rare), 80 bit extended precision value (on GCC/Clang), or simply double (on recent Microsoft). On the other hand, any potential future usage of long double is likely for precision (when a platform offers extra precision) and not for range, since the range anyway varies and is not as portable as IEEE 754 single/double precision. In such cases, the implicit cast to a double is well defined and isinf and isnan should work as intended. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* Remove fminf() emulation.Carl Eugen Hoyos2014-11-081-10/+0
| | | | | | The emulation is unused and causes compilation trouble on systems where fminf() is defined in <math.h> but missing from libm. This should fix compilation on Debian powerpcspe.
* avutil/libm: fix fminf() emulation build failure due to undefined FFMINMichael Niedermayer2014-06-061-1/+3
| | | | | Found-by: James Almer <jamrial@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* avutil/libm: Replace macro based fminf() by functionMichael Niedermayer2014-06-061-1/+4
| | | | | | | | This avoids issues when the FFMIN parameter evaluation has side effects Reviewed-by: Clément Bœsch <u@pkh.me> Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* avutil/libm: use FFMIN instead of fmin()Michael Niedermayer2014-06-061-1/+1
| | | | | | | MSVC apparently doesnt support fmin() either Suggested/Found-by: ubitux, Daemon404, nevcairiel Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* avutil/libm: fix fminf typoMichael Niedermayer2014-06-061-1/+1
| | | | | Found-by: ubitux Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* build: add fminf() emulationMichael Niedermayer2014-06-061-0/+5
| | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* libm: Add fallback definition for cbrt() using pow()James Almer2013-01-221-0/+7
| | | | | | | The function is known to be missing in at least one target (MSVC). Signed-off-by: James Almer <jamrial@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* Merge commit '80521c1997a23e148edf89e11b939ab8646297ca'Michael Niedermayer2012-10-241-0/+40
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * commit '80521c1997a23e148edf89e11b939ab8646297ca': build: allow targets to specify extra objects to link with executables swscale: avoid pointless use of compound literals libm: add fallbacks for various single-precision functions network: use getservbyport() only if available network: add fallbacks for INADDR_LOOPBACK and INET_ADDRSTRLEN Include sys/time.h before sys/resource.h Conflicts: Makefile configure libavutil/libm.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * libm: add fallbacks for various single-precision functionsMans Rullgard2012-10-231-0/+40
| | | | | | | | Signed-off-by: Mans Rullgard <mans@mansr.com>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2012-07-111-0/+7
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: configure: Check for the math function rint TechSmith Screen Codec 2 decoder rtsp: Add listen mode rtsp: Make rtsp_open_transport_ctx() non-static rtsp: Move rtsp_read_close rtsp: Parse the mode=receive/record parameter in transport lines Conflicts: Changelog libavcodec/avcodec.h libavcodec/version.h libavformat/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * configure: Check for the math function rintRonald S. Bultje2012-07-111-0/+7
| | | | | | | | | | | | Add a fallback implementation if it doesn't exist. Signed-off-by: Martin Storsjö <martin@martin.st>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2012-06-281-0/+21
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: mss1: validate number of changeable palette entries mss1: report palette changed when some additional colours were decoded x86: fft: replace call to memcpy by a loop udp: Support IGMPv3 source specific multicast and source blocking dxva2: include dxva.h if found libm: Provide fallback definitions for isnan() and isinf() tcp: Pass NULL as hostname to getaddrinfo if the string is empty tcp: Set AI_PASSIVE when the socket will be used for listening Conflicts: configure libavcodec/mss1.c libavformat/udp.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * libm: Provide fallback definitions for isnan() and isinf()Martin Storsjö2012-06-271-0/+21
| | | | | | | | Signed-off-by: Martin Storsjö <martin@martin.st>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2012-06-271-3/+5
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: avconv: add an assert to silence an uninitialized variable warning. avconv: shut up an uninitialized variable warning. avfiltergraph: shut up uninitialized variable warning. af_join: initialize a variable to shut up gcc warning. amix: fix format specifier for AVFilterLink.sample_rate. lavfi: make filters less verbose. mpc8: read APE tags. lavr: x86: fix ff_conv_fltp_to_flt_6ch function prototypes libm: provide fallback definition for cbrtf() using powf() network: Don't redefine error codes if they already exist in errno.h configure: Check for sys/time.h network: Include unistd.h from network.h avconv: don't include vsrc_buffer.h, which doesn't exist anymore lavfi: reorder AVFilterLink fields. lavfi: reorder AVFilterContext fields. lavfi: reorder AVFilter fields. lavfi: reorder AVFilterBufferRef fields. lavfi: reorder AVFilterBuffer fields. Conflicts: configure libavcodec/v210dec.h libavfilter/asrc_anullsrc.c libavfilter/avfilter.h libavfilter/buffersrc.c libavfilter/src_movie.c libavfilter/vf_aspect.c libavfilter/vf_crop.c libavfilter/vf_drawbox.c libavfilter/vf_fade.c libavfilter/vf_overlay.c libavfilter/vf_pad.c libavfilter/vf_scale.c libavfilter/vsrc_color.c libavformat/network.h libavutil/libm.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * libm: provide fallback definition for cbrtf() using powf()Mans Rullgard2012-06-261-0/+7
| | | | | | | | | | | | | | | | This adds a fallback for cbrtf() using powf(x, 1/3). Since powf() with a non-integer exponent requires a non-negative base, special handling of negative inputs is needed. Signed-off-by: Mans Rullgard <mans@mansr.com>
* | Optimization of AMR NB and WB decoders for MIPSNedeljko Babic2012-06-111-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | AMR NB and WB decoders are optimized for MIPS architecture. Appropriate Makefiles are changed accordingly. Cnfigure script is changed in order to support optimizations. Optimizations are enabled by default when compiling is done for mips architecture. Appropriate cflags are automatically set. Support for several mips CPUs is added in configure script. New ffmpeg options are added for disabling optimizations. The FFMPEG option --disable-mipsfpu disables MIPS floating point optimizations. The FFMPEG option --disable-mips32r2 disables MIPS32R2 optimizations. The FFMPEG option --disable-mipsdspr1 disables MIPS DSP ASE R1 optimizations. The FFMPEG option --disable-mipsdspr2 disables MIPS DSP ASE R2 optimizations. Signed-off-by: Nedeljko Babic <nbabic@mips.com> Reviewed-by: Vitor Sessak <vitor1001@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Check for cbrtf() and provide fallbackMans Rullgard2011-10-221-0/+5
| | | | | | | | | | | | (cherry picked from commit bfb37d7db1c6394099f6b177e10d6e769e678f6a) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge remote branch 'qatar/master'Michael Niedermayer2011-04-221-0/+7
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: APIChanges: document git revision for CODEC_CAP_SLICE_THREADS addition. Introduce slice threads flag. FATE: allow forcing thread-type when doing threaded fate runs. Use av_log_ask_for_sample() where appropriate. error: sort, pack, and align error code and string definitions The stabilization period after version bumps should be one month, not one week. applehttp: Expose the stream bitrate via metadata doc: Add some initial docs on the applehttp demuxer Provide a fallback version of the libm function trunc libavdevice: Define _XOPEN_SOURCE for usleep lavc: provide deprecated avcodec_thread_init until next major version lavc: provide the opt.h header until the next bump error: change AVERROR_EOF value error: remove AVERROR_NUMEXPECTED error: add error code AVERROR_OPTION_NOT_FOUND, and use it in opt.c Conflicts: libavcodec/h264.c libavutil/error.c libavutil/error.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * Provide a fallback version of the libm function truncMartin Storsjö2011-04-211-0/+7
| | | | | | | | | | | | This fixes compilation on DOS. Signed-off-by: Martin Storsjö <martin@martin.st>
| * Replace FFmpeg with Libav in licence headersMans Rullgard2011-03-191-4/+4
|/ | | | Signed-off-by: Mans Rullgard <mans@mansr.com>
* Workaround for missing llrintf()Måns Rullgård2010-04-231-0/+5
| | | | Originally committed as revision 22954 to svn://svn.ffmpeg.org/ffmpeg/trunk
* Remove explicit filename from Doxygen @file commands.Diego Biurrun2010-04-201-1/+1
| | | | | | | | Passing an explicit filename to this command is only necessary if the documentation in the @file block refers to a file different from the one the block resides in. Originally committed as revision 22921 to svn://svn.ffmpeg.org/ffmpeg/trunk
* libm.h needs attributes.hMåns Rullgård2010-03-091-0/+1
| | | | Originally committed as revision 22405 to svn://svn.ffmpeg.org/ffmpeg/trunk
* Move libm replacements to new header libm.hMåns Rullgård2010-03-091-0/+90
ffmpeg.c uses lrintf(), which is missing on some systems. Previously it picked up the replacement via libavutil/internal.h due to HAVE_AV_CONFIG_H being erroneously defined. Moving these replacements to a separate header enables ffmpeg.c to use them without being exposed to internal interfaces. This use of a non-public header is justified by the header in question not being part of the internal interface either. It should rather be considered as part of the build system, which is shared between the libraries and the applications. This header cannot be installed since the tested conditions depend on the compiler. Originally committed as revision 22399 to svn://svn.ffmpeg.org/ffmpeg/trunk
OpenPOWER on IntegriCloud