libavutil: add saturating addition functions

Fixed-point audio codecs often use saturating arithmetic, and
special instructions for these operations are common.

Signed-off-by: Mans Rullgard <mans@mansr.com>
celp: optimise ff_celp_lp_synthesis_filter()

Adding instead of subtracting the products in the loop allows the
compiler to generate more efficient multiply-accumulate instructions
when 16-bit multiply-subtract is not available. ARM has only
multiply-accumulate for 16-bit operands.  In general, if only one
variant exists, it is usually accumulate rather than subtract.

In the same spirit, using the dedicated saturation function enables
use of any special optimised versions of this.

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: deobfuscate "(x << 4) - x" to "15 * x"

The compiler performs this optimisation.

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: remove unnecessary argument 'shift' from dot_product()

The 'shift' argument is always 1 so there is no need to pass it
explicitly in every call.

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: remove useless uses of MUL64()

The operands in both cases are 16-bit so cannot overflow a 32-bit
destination.  In gain_scale() the inputs are reduced to 14-bit,
so even the shift cannot overflow.

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: optimise scale_vector()

Firstly, nothing in this function can overflow 32 bits so the use
of a 64-bit type is completely unnecessary.  Secondly, the scale
is either a power of two or 0x7fff.  Doing separate loops for these
cases avoids using multiplications.  Finally, since only the number
of bits, not the actual value, of the maximum value is needed, the
bitwise or of all the values serves the purpose while being faster.

It is worth noting that even if overflow could happen, it was not
handled correctly anyway.

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: use saturating addition functions

Use saturating addition functions instead of 64-bit intermediates
and separate clipping.  This is much faster when dedicated
instructions are available.

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: do not needlessly use int64_t

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: make autocorr_max() work on an arbitrary buffer

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: make scale_vector() output to a separate buffer

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: drop unnecessary variable buf_ptr in formant_postfilter()

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: make postfilter write directly to output buffer

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: avoid unnecessary memcpy() in residual_interp()

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: avoid saving/restoring excitation

Writing the scaled excitation to a scratch buffer (borrowing the
'audio' array) instead of modifying it in place avoids the need
to save and restore the unscaled values.

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: declare a variable in the block it is used

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: do not bounce intermediate values via memory

Although a reasonable compiler will probably optimise out the
actual store and load, this operation still implies a truncation
to 16 bits which the compiler will probably not realise is not
necessary here.

Signed-off-by: Mans Rullgard <mans@mansr.com>
g723.1: do not pass large structs by value

Signed-off-by: Mans Rullgard <mans@mansr.com>
ARM: intmath: use native-size return types for clipping functions

This avoids having the compiler redundantly mask the values to
the smaller size.

Signed-off-by: Mans Rullgard <mans@mansr.com>
x86: mlpdsp: avoid taking address of void

This code contains a C array of addresses of labels defined in
inline asm.  To do this, the names must be declared as external
in C.  The declared type does not matter since only the address is
used, and for some reason, the author of the code used the 'void'
type despite taking the address of a void expression being invalid.

Changing the type to char, a reasonable choice since the alignment
of the code labels cannot be known or guaranteed, eliminates gcc
warnings and allows building with suncc.

Signed-off-by: Mans Rullgard <mans@mansr.com>
x86: cabac: allow building with suncc

This fixes two issues preventing suncc from building this code.

The undocumented 'a' operand modifier, causing gcc to omit a $ in
front of immediate operands (as required in addresses), is not
supported by suncc.  Luckily, the also undocumented 'c' modifer
has the same effect and is supported.

On some asm statements with a large number of operands, suncc for no
obvious reason fails to correctly substitute some of the operands.
Fortunately, some of the operands in these statements are plain
numbers which can be inserted directly into the code block instead
of passed as operands.

With these changes, the code builds correctly with both gcc and
suncc.

Signed-off-by: Mans Rullgard <mans@mansr.com>