summaryrefslogtreecommitdiff
path: root/libavutil/mathematics.c
Commit message (Collapse)AuthorAgeFilesLines
* avutil/avassert: Don't include avutil.hAndreas Rheinhardt2022-02-241-0/+1
| | | | | Reviewed-by: Martin Storsjö <martin@martin.st> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* Remove obsolete version.h inclusionsAndreas Rheinhardt2021-07-221-1/+0
| | | | | | | These have mostly been added because of FF_API_*; yet when these were removed, removing the header has been forgotten. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avutil/mathematics: Fix undefined negation in av_compare_ts()Michael Niedermayer2021-02-101-1/+1
| | | | | | | | Fixes: negation of -9223372036854775808 cannot be represented in type 'int64_t' (aka 'long'); cast to an unsigned type to negate this value to itself Fixes: 29437/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-4748510022991872 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/mathematics: Use av_sat_add64() for the last addition in av_add_stable()Michael Niedermayer2020-10-251-1/+1
| | | | | | | | Fixes: signed integer overflow: 9223372036854770375 + 5450 cannot be represented in type 'long' Fixes: 26471/clusterfuzz-testcase-minimized-ffmpeg_dem_MXG_fuzzer-6229617557635072 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/mathematics: Fix overflow with NaN in av_add_stable()Dale Curtis2020-06-061-1/+1
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/mathematics: Fix 2 overflows in av_add_stable()Michael Niedermayer2019-08-311-1/+5
| | | | | | | | Fixes: signed integer overflow: 9223372036854775807 + 1 cannot be represented in type 'long' Fixes: 16022/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5759796759756800 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavu/mathematics: split closing bracket out of ifdeferyClément Bœsch2017-03-181-2/+1
|
* lavu/mathematics: document so-called "cruft"Clément Bœsch2017-03-181-0/+1
|
* avutil/mathematics: Fix division by 0Michael Niedermayer2015-12-091-1/+1
| | | | | | Fixes: CID1341571 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/mathematics: return INT64_MIN (=AV_NOPTS_VALUE) from av_rescale_rnd() ↵Michael Niedermayer2015-12-021-3/+10
| | | | | | | | | | for overflows Fixes integer overflow Fixes: mozilla bug 1229167 Found-by: Tyson Smith Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/mathematics: Do not treat INT64_MIN as positive in av_rescale_rndMichael Niedermayer2015-12-011-2/+2
| | | | | | | | | The code expects actual positive numbers and gives completely wrong results if INT64_MIN is treated as positive Instead clip it into the valid range that is add 1 and treat it as negative Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avutil/mathematics: make av_gcd more robustGanesh Ajjanagadde2015-10-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | This ensures that no undefined behavior is invoked, while retaining identical return values in all cases and at no loss of performance (identical asm on clang and gcc). Essentially, this patch exchanges undefined behavior with implementation defined behavior, a strict improvement. Rationale: 1. The ideal solution is to have the return type a uint64_t. This unfortunately requires an API change. 2. The only pathological behavior happens if both arguments are INT64_MIN, to the best of my knowledge. In such a case, the implementation defined behavior is invoked in the sense that UINT64_MAX is interpreted as INT64_MIN, which any reasonable implementation will do. In any case, any usage where both arguments are INT64_MIN is a fuzzer anyway. 3. Alternatives of checking, etc require branching and lose performance for no concrete gain - no client cares about av_gcd's actual value when both args are INT64_MIN. Even if it did, on sane platforms (e.g all the ones FFmpeg cares about), it produces a correct gcd, namely INT64_MIN. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* avutil/mathematics: speed up av_gcd by using Stein's binary GCD algorithmGanesh Ajjanagadde2015-10-111-5/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This uses Stein's binary GCD algorithm: https://en.wikipedia.org/wiki/Binary_GCD_algorithm to get a roughly 4x speedup over Euclidean GCD on standard architectures with a compiler intrinsic for ctzll, and a roughly 2x speedup otherwise. At the moment, the compiler intrinsic is used on GCC and Clang due to its easy availability. Quick note regarding overflow: yes, subtractions on int64_t can, but the llabs takes care of that. The llabs is also guaranteed to be safe, with no annoying INT64_MIN business since INT64_MIN being a power of 2, is shifted down before being sent to llabs. The binary GCD needs ff_ctzll, an extension of ff_ctz for long long (int64_t). On GCC, this is provided by a built-in. On Microsoft, there is a BitScanForward64 analog of BitScanForward that should work; but I can't confirm. Apparently it is not available on 32 bit builds; so this may or may not work correctly. On Intel, per the documentation there is only an intrinsic for _bit_scan_forward and people have posted on forums regarding _bit_scan_forward64, but often their documentation is woeful. Again, I don't have it, so I can't test. As such, to be safe, for now only the GCC/Clang intrinsic is added, the rest use a compiled version based on the De-Bruijn method of Leiserson et al: http://supertech.csail.mit.edu/papers/debruijn.pdf. Tested with FATE, sample benchmark (x86-64, GCC 5.2.0, Haswell) with a START_TIMER and STOP_TIMER in libavutil/rationsl.c, followed by a make fate. aac-am00_88.err: builtin: 714 decicycles in av_gcd, 4095 runs, 1 skips de-bruijn: 1440 decicycles in av_gcd, 4096 runs, 0 skips previous: 2889 decicycles in av_gcd, 4096 runs, 0 skips Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* Merge commit 'cdfe45ad371b7a8e6135b6c063b6b2a93152cb3a'Hendrik Leppkes2015-09-051-21/+0
|\ | | | | | | | | | | | | * commit 'cdfe45ad371b7a8e6135b6c063b6b2a93152cb3a': lavu: Drop deprecated av_reverse function Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
| * lavu: Drop deprecated av_reverse functionVittorio Giovara2015-08-281-21/+0
| | | | | | | | Deprecated in 10/2012.
* | avutil/mathematics/av_add_stable: Avoid av_cmp_q() callMichael Niedermayer2014-06-021-4/+3
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | av_add_stable: Add fast special case where step can be represented exactlyMichael Niedermayer2014-06-021-0/+8
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avutil/mathematics/av_add_stable: check for the common case of inc=1Michael Niedermayer2014-06-021-1/+2
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avutil/mathematics/av_add_stable: avoid unneeded variableMichael Niedermayer2014-06-021-5/+5
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge commit 'de69aedf9935631b7f78e8b8da6e460422a9bc5f'Michael Niedermayer2014-05-031-43/+54
|\ \ | |/ | | | | | | | | | | | | | | | | * commit 'de69aedf9935631b7f78e8b8da6e460422a9bc5f': mathematics: K&R formatting cosmetics Conflicts: libavutil/mathematics.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * mathematics: K&R formatting cosmeticsLuca Barbato2014-05-031-42/+53
| |
* | avutil/mathematics: add av_add_stable()Michael Niedermayer2014-01-041-0/+14
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge commit '94a417acc05cc5151b473abc0bf51fad26f8c5a0'Michael Niedermayer2014-01-041-0/+3
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | * commit '94a417acc05cc5151b473abc0bf51fad26f8c5a0': mathematics: remove asserts from av_rescale_rnd() Conflicts: libavutil/mathematics.c The asserts are left in place for now as no code checks the return value, but we sure can change this if application developers prefer Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * mathematics: remove asserts from av_rescale_rnd()Anton Khirnov2014-01-031-4/+3
| | | | | | | | It is a public function, it must not assert on its parameters.
* | av_rescale: support passing MIN/MAX throughMichael Niedermayer2013-01-031-1/+7
| | | | | | | | | | Reviewed-by: Clément Bœsch <ubitux@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | lavu: add av_rescale_delta()Michael Niedermayer2012-10-271-0/+23
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | mathemathics: update copyright yearsMichael Niedermayer2012-10-271-1/+1
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge commit 'd5c62122a7b26704bf867a1262df358623bf5edf'Michael Niedermayer2012-10-131-0/+4
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | * commit 'd5c62122a7b26704bf867a1262df358623bf5edf': Move av_reverse table to libavcodec Conflicts: libavcodec/asvenc.c libavcodec/vble.c libavutil/common.h libavutil/mathematics.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * Move av_reverse table to libavcodecDiego Biurrun2012-10-121-0/+4
| | | | | | | | It is only used in that library.
* | Merge commit '930c9d4373e0f3cb7c64fcfc129127a309f6d066'Michael Niedermayer2012-10-131-11/+0
|\ \ | |/ | | | | | | | | | | * commit '930c9d4373e0f3cb7c64fcfc129127a309f6d066': avutil: Duplicate ff_log2_tab instead of sharing it across libs Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * avutil: Duplicate ff_log2_tab instead of sharing it across libsDiego Biurrun2012-10-121-11/+0
| | | | | | | | | | The table is so small that the space gain is not worth the performance overhead of cross-library access.
* | Merge commit '9734b8ba56d05e970c353dfd5baafa43fdb08024'Michael Niedermayer2012-10-121-11/+0
|\ \ | |/ | | | | | | | | | | | | | | | | | | * commit '9734b8ba56d05e970c353dfd5baafa43fdb08024': Move avutil tables only used in libavcodec to libavcodec. Conflicts: libavcodec/mathtables.c libavutil/intmath.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * Move avutil tables only used in libavcodec to libavcodec.Diego Biurrun2012-10-111-11/+0
| |
* | libavutil/mathematics: use av_assert()Michael Niedermayer2012-06-061-4/+4
| | | | | | | | Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2012-02-211-2/+9
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: (36 commits) adpcmenc: Use correct frame_size for Yamaha ADPCM. avcodec: add ff_samples_to_time_base() convenience function to internal.h adx parser: set duration mlp parser: set duration instead of frame_size gsm parser: set duration mpegaudio parser: set duration instead of frame_size (e)ac3 parser: set duration instead of frame_size flac parser: set duration instead of frame_size avcodec: add duration field to AVCodecParserContext avutil: add av_rescale_q_rnd() to allow different rounding pnmdec: remove useless .pix_fmts libmp3lame: support float and s32 sample formats libmp3lame: renaming, rearrangement, alignment, and comments libmp3lame: use the LAME default bit rate libmp3lame: use avpriv_mpegaudio_decode_header() for output frame parsing libmp3lame: cosmetics: remove some pointless comments libmp3lame: convert some debugging code to av_dlog() libmp3lame: remove outdated comment. libmp3lame: do not set coded_frame->key_frame. libmp3lame: improve error handling in MP3lame_encode_init() ... Conflicts: doc/APIchanges libavcodec/libmp3lame.c libavcodec/pcxenc.c libavcodec/pnmdec.c libavcodec/pnmenc.c libavcodec/sgienc.c libavcodec/utils.c libavformat/hls.c libavutil/avutil.h libswscale/x86/swscale_mmx.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * avutil: add av_rescale_q_rnd() to allow different roundingJustin Ruggles2012-02-201-2/+9
| |
* | Merge remote-tracking branch 'qatar/master'Michael Niedermayer2011-06-291-29/+0
|\ \ | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * qatar/master: (21 commits) swscale: Add Doxygen for hyscale_fast/hScale. fate: enable lavfi-pixmt tests on big endian systems PPC: swscale: disable altivec functions for unsupported formats fate: merge identical pixdesc_be/le tests swscale: Add Doxygen for yuv2planar*/yuv2packed* functions. build: call texi2pod.pl with full path instead of symlink build: include sub-makefiles using full path instead of symlinks swscale: update big endian reference values after dff5a835. wavpack: skip blocks with no samples cosmetics: remove outdated comment that is no longer true build: replace some addprefix/addsuffix with substitution refs avutil: Remove unused arbitrary precision integer code. configure: Drop check for availability of ten assembler operands. aacenc: Save channel configuration for later use. aacenc: Fix codebook trellising for zeroed bands. swscale: change prototypes of scaled YUV output functions. swscale: re-add support for non-native endianness. swscale: disentangle yuv2rgbX_c_full() into small functions. swscale: split yuv2packed[12X]_c() remainders into small functions. swscale: split yuv2packedX_altivec in smaller functions. ... Conflicts: Makefile configure libavcodec/x86/dsputil_mmx.c libavfilter/Makefile libavformat/Makefile libavutil/integer.c libavutil/integer.h libswscale/swscale.c libswscale/swscale_internal.h libswscale/x86/swscale_template.c tests/ref/lavfi/pixdesc_le tests/ref/lavfi/pixfmts_scale Merged-by: Michael Niedermayer <michaelni@gmx.at>
| * avutil: Remove unused arbitrary precision integer code.Diego Biurrun2011-06-281-29/+0
| |
| * Replace FFmpeg with Libav in licence headersMans Rullgard2011-03-191-4/+4
| | | | | | | | Signed-off-by: Mans Rullgard <mans@mansr.com>
* | av_compare_ts: Improve speed when calculations fit in 64bit.Michael Niedermayer2011-05-111-0/+3
|/ | | | | about 110 cpu cycles before 60 cpu cycles afterwards. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* Silence "comparison of unsigned expression >= 0 is always true" warning.Eli Friedman2010-07-031-1/+1
| | | | | | Patch by Eli Friedman, eli d friedman a gmail Originally committed as revision 24022 to svn://svn.ffmpeg.org/ffmpeg/trunk
* Add av_compare_mod()Michael Niedermayer2010-06-091-0/+7
| | | | Originally committed as revision 23551 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
* Replace many includes of libavutil/common.h with what is actually neededMåns Rullgård2010-03-091-2/+2
| | | | | | | This reduces the number of false dependencies on header files and speeds up compilation. Originally committed as revision 22407 to svn://svn.ffmpeg.org/ffmpeg/trunk
* av_compare_ts()Michael Niedermayer2010-02-071-0/+8
| | | | Originally committed as revision 21671 to svn://svn.ffmpeg.org/ffmpeg/trunk
* Move ff_reverse in libavcodec to av_reverse in libavutil.Francesco Lavra2009-11-091-0/+19
| | | | | | Patch by Francesco Lavra, francescolavra interfree it Originally committed as revision 20484 to svn://svn.ffmpeg.org/ffmpeg/trunk
* Remove all remaining code that was disabled through the major version bump.Diego Biurrun2009-03-091-6/+0
| | | | Originally committed as revision 17903 to svn://svn.ffmpeg.org/ffmpeg/trunk
* Use full internal pathname in doxygen @file directives.Diego Biurrun2009-02-011-1/+1
| | | | | | | Otherwise doxygen complains about ambiguous filenames when files exist under the same name in different subdirectories. Originally committed as revision 16912 to svn://svn.ffmpeg.org/ffmpeg/trunk
* spelling/grammar/consistency review part IDiego Biurrun2009-01-281-1/+1
| | | | Originally committed as revision 16840 to svn://svn.ffmpeg.org/ffmpeg/trunk
* add a ff_gcd() function again, for compatibility with old libavcodecAurelien Jacobs2009-01-271-0/+7
| | | | Originally committed as revision 16814 to svn://svn.ffmpeg.org/ffmpeg/trunk