Commit Graph

3985 Commits

Author SHA1 Message Date
Ganesh Ajjanagadde 5989add4ab lavu/x86/lls: add fma3 optimizations for update_lls
This improves accuracy (very slightly) and speed for processors having
fma3.

Sample benchmark (fate flac-16-lpc-cholesky, Haswell):
old:
5993610 decicycles in ff_lpc_calc_coefs,      64 runs,      0 skips
5951528 decicycles in ff_lpc_calc_coefs,     128 runs,      0 skips

new:
5252410 decicycles in ff_lpc_calc_coefs,      64 runs,      0 skips
5232869 decicycles in ff_lpc_calc_coefs,     128 runs,      0 skips

Tested with FATE and --disable-fma3, also examined contents of
lavu/lls-test.

Reviewed-by: James Almer <jamrial@gmail.com>
Reviewed-by: Henrik Gramner <henrik@gramner.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2016-01-15 16:46:13 -05:00
James Almer 36778627e2 x86/intmath: add missing early clobber to output operands
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-15 13:32:58 -03:00
Andreas Cadhalpun f8bc0137bd lavu: prevent overflow in av_clip_intp2_c
This fixes ubsan runtime error: signed integer overflow: 8388608 +
2140274688 cannot be represented in type 'int'

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
2016-01-15 00:32:54 +01:00
Ganesh Ajjanagadde a0a47a09b0 lavu/libm: add isfinite fallback
Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2016-01-13 20:00:19 -05:00
Michael Niedermayer 9ca64c31d2 avutil/common: Protect GET_BYTE in GET_UTF8() by ()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-01-13 03:09:08 +01:00
Timothy Gu d64d6edfc7 Correct two build/built typos
Found-by: Leo Izen <leo.izen@gmail.com> as thebombzen on IRC
Signed-off-by: Timothy Gu <timothygu99@gmail.com>
2016-01-11 20:53:11 -08:00
James Almer dc79824deb x86/float_dsp: zero extend offset from ff_scalarproduct_float_sse
Reviewed-by: Christophe Gisquet <christophe.gisquet@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-08 16:14:32 -03:00
James Almer 4ee38ed7f9 x86/float_dsp: zero extend len from ff_butterflies_float_sse implicitly
Reviewed-by: Christophe Gisquet <christophe.gisquet@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-08 16:14:27 -03:00
James Almer 7f520524f6 x86/float_dsp: remove len check from ff_butterflies_float_sse
The function documentation explicitly mentions it needs to be a multiple of 4.

Reviewed-by: Christophe Gisquet <christophe.gisquet@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-08 16:14:24 -03:00
James Almer 28d5a3a74a lavu: rename and move ff_parity to av_parity
av_popcount is not defined in intmath.h.

Reviewed-by: ubitux
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-07 20:04:24 -03:00
Clément Bœsch 2ce29d1765 lavu: add ff_parity() 2016-01-07 22:51:31 +01:00
Clément Bœsch 04826b7ff0 lavu/common: add an explanation to FF_CEIL_RSHIFT() 2016-01-07 22:34:04 +01:00
Clément Bœsch 84a967df03 lavu/common: fix FF_CEIL_RSHIFT() range comment 2016-01-07 22:20:22 +01:00
James Almer f4c1a48483 x86/intmath: add sse optimized av_clipf and av_clipd
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2016-01-07 14:24:01 -03:00
Hendrik Leppkes 957667d198 avutil/cpu: add missing entry for vfp_vm to av_parse_cpu_caps 2016-01-02 19:07:08 +01:00
Hendrik Leppkes e754c8e8ca Merge commit 'e2710e790c09e49e86baa58c6063af0097cc8cb0'
* commit 'e2710e790c09e49e86baa58c6063af0097cc8cb0':
  arm: add a cpu flag for the VFPv2 vector mode

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-01-02 11:01:29 +01:00
Hendrik Leppkes af2e6f3215 Merge commit '64034849dad8410bedbe1def4c533490fb85cc4a'
* commit '64034849dad8410bedbe1def4c533490fb85cc4a':
  arm64: add cycle counter support

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-01-02 10:26:42 +01:00
Hendrik Leppkes 4cf66a8193 Merge commit '50078c1c8070dd8d1c329e8117ff30ec72489039'
* commit '50078c1c8070dd8d1c329e8117ff30ec72489039':
  libavutil: move FFALIGN macro from common.h to macros.h

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-01-02 10:25:12 +01:00
Ganesh Ajjanagadde 0e9fe3e3c9 lavu/eval: replace pow(10,x) by ff_exp10(x)
Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-25 10:48:13 -08:00
Ganesh Ajjanagadde 11388b5a8f lavu/internal: add ff_exp10
Fast, reasonably accurate 10^x. Alternative of detection of libm exp10 at configure
time is not worth the trouble, since it is anyway not POSIX or ISO C,
and currently only the GNU libm has it. Furthermore, GNU libm's variant
is ~ 2x slower, and is ironically not correctly rounded (2 ulp off) to justify all
that slowdown.

Reviewed-by: James Almer <jamrial@gmail.com>
Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-25 10:12:49 -08:00
Ganesh Ajjanagadde 73616b1f21 lavu/libm,configure: remove exp10, exp10f detection
Subsequent commit introduces ff_exp10 instead.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-25 10:12:49 -08:00
Ganesh Ajjanagadde 5630ed5be6 lavu/libm: misc, minor changes
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>
2015-12-25 09:25:20 -08:00
Ganesh Ajjanagadde e29db08cf7 lavu/libm: add exp10 support
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>
2015-12-23 09:22:59 -08:00
Ganesh Ajjanagadde dd68cde28a lavu/libm: add erf hack and make dynaudnorm available everywhere
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>
2015-12-21 09:03:11 -08:00
Ganesh Ajjanagadde 062e3e2382 lavu/libm: add copysign hack
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>
2015-12-19 14:05:49 -08:00
Ganesh Ajjanagadde 0dd8a3d71e lavu/intmath: add faster clz support
This should be useful for the sofalizer filter.

Reviewed-by: Kieran Kunhya <kierank@ob-encoder.com>
Reviewed-by: Clément Bœsch <u@pkh.me>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-19 09:35:34 -08:00
Marton Balint 752ab408b4 lavu/error: add missing error messages for errors supported on all platforms
We need these if we have no strerror_r.

Descriptions are taken from doc/errno.txt except for ENOMEM.

Signed-off-by: Marton Balint <cus@passwd.hu>
2015-12-18 04:04:14 +01:00
Ganesh Ajjanagadde 39f8c7961d lavu/random_seed: use arc4random() when available
arc4random() was designed as a superior interface for system random
number generation, designed for OpenBSD and subsequently incorporated by
other BSD's, Mac OS X, and some non-standard libc's. It is thus an improvement to
use it whenever available.

As a side note, this may or may not get included in glibc, and there is
a proposal to create a posix_random family based on these ideas:
http://austingroupbugs.net/view.php?id=859.

Tested on Mac OS X.

Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-17 08:12:41 -08:00
Ganesh Ajjanagadde 4fa6f09c2c lavu/eval: remove pow and exp2 for postfixes
These postfixes can be computed statically, and there is no need to
waste runtime resources.

Tested with FATE.

Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-16 07:56:54 -05:00
erankor 23ac99dc17 libavutil: add aes-ctr support
for supporting mp4 cenc encoding/decoding

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-15 14:16:28 +01:00
Janne Grunau e2710e790c arm: add a cpu flag for the VFPv2 vector mode
The vector mode was deprecated in ARMv7-A/VFPv3 and various cpu
implementations do not support it in hardware. Vector mode code will
depending the OS either be emulated in software or result in an illegal
instruction on cpus which does not support it. This was not really
problem in practice since NEON implementations of the same functions are
preferred. It will however become a problem for checkasm which tests
every cpu flag separately.

Since this is a cpu feature newer cpu do not support anymore the
behaviour of this flag differs from the other flags. It can be only
activated by runtime cpu feature selection.
2015-12-14 16:42:35 +01:00
Janne Grunau 64034849da arm64: add cycle counter support
The ISB (instruction synchronization barrier) might be too heavy for
START/STOPTIMER use but should be more accurate in checkasm where the
timing overhead is subtracted.
2015-12-14 16:42:35 +01:00
Janne Grunau 50078c1c80 libavutil: move FFALIGN macro from common.h to macros.h
Include macros.h explicitly in common.h so that external code using
FFALIGN does not break. It was already implicitly included through
version.h. Include macros.h in lls.h and internal.h for FFALIGN.
lls.h was including common.h only for FFALIGN and internal.h was
missing the include for FFALIGN. `make checkheaders` did not catch it
because it's an internal header.
2015-12-14 16:16:55 +01:00
Michael Niedermayer 5e8b9e746f avutil/softfloat: Assert that the exponent did not overflow the legal range in av_normalize1_sf()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-11 13:39:21 +01:00
Michael Niedermayer bc8b1e694c avutil/mathematics: Fix division by 0
Fixes: CID1341571

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-09 17:39:38 +01:00
Clément Bœsch 503d8bf74a lavu/frame: use AVPALETTE_SIZE instead of 1024 2015-12-08 17:50:40 +01:00
Clément Bœsch dd1d9b80c9 lavu/opencl: restore #if HAVE_THREADS
Fix regression since a8bb81a.

Spotted-by: RiCON
2015-12-07 20:28:30 +01:00
Timothy Gu 006d3e97fc cosmetics: Fix weird indentations 2015-12-07 10:43:43 -08:00
Clément Bœsch a8bb81a05c lavc, lavu: use avutil/thread.h instead of redundant conditional includes 2015-12-07 17:25:51 +01:00
Clément Bœsch 5e0c47d41c avutil/threadmessage: fix build without HAVE_THREADS, new attempt 2015-12-07 16:39:57 +01:00
Clément Bœsch d4b1b33e69 avutil/threadmessage: fix build without HAVE_THREADS 2015-12-07 14:28:34 +01:00
Clément Bœsch bd5c860fdb avutil/threadmessage: split the pthread condition in two
Fix a dead lock under certain conditions. Let's assume we have a queue of 1
message max, 2 senders, and 1 receiver.

Scenario (real record obtained with debug added):
    [...]
    SENDER #0: acquired lock
    SENDER #0: queue is full, wait
    SENDER #1: acquired lock
    SENDER #1: queue is full, wait
    RECEIVER: acquired lock
    RECEIVER: reading a msg from the queue
    RECEIVER: signal the cond
    RECEIVER: acquired lock
    RECEIVER: queue is empty, wait
    SENDER #0: writing a msg the queue
    SENDER #0: signal the cond
    SENDER #0: acquired lock
    SENDER #0: queue is full, wait
    SENDER #1: queue is full, wait

Translated:
 - initially the queue contains 1/1 message with 2 senders blocking on
   it, waiting to push another message.
 - Meanwhile the receiver is obtaining the lock, read the message,
   signal & release the lock. For some reason it is able to acquire the
   lock again before the signal wakes up one of the sender. Since it
   just emptied the queue, the reader waits for the queue to fill up
   again.
 - The signal finally reaches one of the sender, which writes a message
   and then signal the condition. Unfortunately, instead of waking up
   the reader, it actually wakes up the other worker (signal = notify
   the condition just for 1 waiter), who can't push another message in
   the queue because it's full.
 - Meanwhile, the receiver is still waiting. Deadlock.

This scenario can be triggered with for example:
    tests/api/api-threadmessage-test 1 2 100 100 1 1000 1000

One working solution is to make av_thread_message_queue_{send,recv}()
call pthread_cond_broadcast() instead of pthread_cond_signal() so both
senders and receivers are unlocked when work is done (be it reading or
writing).

This second solution replaces the condition with two: one to notify the
senders, and one to notify the receivers. This prevents senders from
notifying other senders instead of a reader, and the other way around.
It also avoid broadcasting to everyone like the first solution, and is,
as a result in theory more optimized.
2015-12-07 11:39:28 +01:00
Clément Bœsch f98abe0ee7 avutil/threadmessage: add av_thread_message_flush() 2015-12-07 11:39:28 +01:00
Reynaldo H. Verdejo Pinochet 21c34cb261 libavutil: add version component accessor macros
Pretty standard macros, these should help libav*
users avoid repeating ver.si.on parsing code,
which aids in compatibility-checking tasks like
identifying FFmpeg from Libav (_MICRO >= 100 check).
Something many are doing since we are not
intercompatible anymore.

Signed-off-by: Reynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>
2015-12-06 01:01:51 -08:00
Hendrik Leppkes d6b988b505 libavutil/tablegen: add missing math.h include 2015-12-04 14:49:35 +01:00
Michael Niedermayer b46dcd5209 avutil/timecode: Fix fps check
The fps variable is explicitly set to -1 in case of some errors, the check must
thus be signed or the code setting it needs to use 0 as error code
the type of the field could be changed as well but its in an installed header

Fixes: integer overflow
Fixes: 9982cc157b1ea90429435640a989122f/asan_generic_3ad004a_3799_22cf198d9cd09928e2d9ad250474fa58.mov

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-03 04:09:48 +01:00
Ganesh Ajjanagadde 1bb7db217d avutil/crc: avoid needless space wastage of hardcoded crc table
There was no reason AFAIK for making AV_CRC_24_IEEE 12. This simply
resulted in wasted space under --enable-hardcoded-tables:
dynamic: 1318672 libavutil/libavutil.so.55
old    : 1330680 libavutil/libavutil.so.55
new    : 1326488 libavutil/libavutil.so.55

Minor version number is bumped, with ifdefry due to API breakage.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-02 18:31:56 -05:00
Michael Niedermayer 97b8db334a avutil/rational: Test av_rescale_rnd() with combinations of "special" values
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-02 21:38:11 +01:00
Michael Niedermayer f03c2ceec1 avutil/mathematics: return INT64_MIN (=AV_NOPTS_VALUE) from av_rescale_rnd() for overflows
Fixes integer overflow
Fixes: mozilla bug 1229167

Found-by: Tyson Smith
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-12-02 21:38:11 +01:00
Ganesh Ajjanagadde 538e8ab512 avutil/tablegen: add tablegen libm compatibility shims
This is useful for build-time table generation (--enable-hardcoded-tables),
by providing compat shims for hosts that have broken libms.

This file is deliberately kept minimal; functions can always be added on
an as-needed basis.

Reviewed-by: Clément Bœsch <u@pkh.me>
Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com>
Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
2015-12-01 19:05:19 -05:00