56 Commits

Author SHA1 Message Date
Pranav Kant 7d4b789f55 Mark C globals with small code model
We have new option in clang (https://github.com/llvm/llvm-project/pull/124834)
to mark globals to be allocated in non-large sections. We can mark all globals
that are referenced from hardcoded assembly (which implicitly references globals
assuming they are in non-large sections) with this attribute to avoid running
into problems when dav1d is built with -mcmodel=medium with clang.
2025-02-21 15:55:00 +00:00
Kyle Siefring 4385e7e161 Improve density of group context setting macros
Shared object binary size reduction:
x84_64           : 16112 bytes
ARM64            : 16008 bytes
ARM64(+Os)       : 21592 bytes
ARMv7(+Os+mthumb): 18480 bytes

Size reduction of symbols:
x84_64           : 15712 bytes
ARM64            : 18688 bytes
ARM64(+Os)       : 18404 bytes
ARMv7(+Os+mthumb): 17322 bytes

Compiles were done with clang version 18.1.8 and symbol sizes were
obtained using nm on the shared object.

Provides speed ups on older ARM64 cpus with very little impact on other
cpus.

Speedup:

c7i (skylake)
 Nature1080p      : x0.999
 Chimera          : x0.998

odroid C4
 Nature1080p      : x1.007
 Chimera          : x1.016
 Models1080p      : x1.005
 MountainBike1080p: x1.009
 Balloons1080p    : x1.008

Raspberry Pi 4
 Nature1080p      : x1.005
 Chimera          : x0.999
 Models1080p      : x0.999
 MountainBike1080p: x1.004
 Balloons1080p    : x1.003

Raspberry Pi 2 (Cortex-A7):
 (using size optimized build)
 Nature1080p      : x1.003
 Models1080p      : x0.997
2024-09-06 22:12:56 +00:00
Martin Storsjö 0d8abee540 Fix the macro parameter name for the CHECK_SIZE macro 2024-08-29 23:29:30 +03:00
Cameron Cawley 0255c2b227 Ensure that the refmvs_refpair union is packed 2024-08-29 20:17:51 +00:00
Nathan E. Egge a6878be7e0 Alphabetize architecture defines and usage 2024-01-31 06:04:21 -05:00
yuanhecai 2e952f300f Add loongarch support 2024-01-21 15:06:52 +08:00
Henrik Gramner 233a424c38 Use pixel instead of uint16_t for palette buffers
Reduces memory usage by 6 kB per sb128 in 8bpc streams that
uses screen content tools when frame-threading is enabled.
2023-07-06 23:10:22 +02:00
Henrik Gramner 47e2e672d1 Eliminate validate_input() printf calls in release mode 2023-06-07 13:35:06 +02:00
Henrik Gramner 5aef96407b Fix the printf format attribute on MinGW
The default __printf__ format attribute doesn't match what printf
functions actually support. Using __gnu_printf__ fixes it.
2023-05-31 18:12:20 +02:00
Henrik Gramner e4c4af02f3 Specify hidden visibility for global data symbol declarations
'-fvisibility=hidden' only applies to definitions, not declarations,
so the compiler has to be conservative about how references to global
data symbols are performed.

Explicitly specifying the visibility allows for better code generation.
2022-09-30 15:04:20 +00:00
Henrik Gramner 820bf51563 cpu: Inline dav1d_get_cpu_flags() 2022-07-06 14:56:24 +02:00
Christophe Gisquet 3bae53c0b6 refmvs: Pack the refmvs_block struct
Reduces size from 16B to 12B, while maintaining a 4-byte alignment.
2021-08-19 21:29:46 +02:00
Henrik Gramner a336f470ed Use the 'noclone function attribute in addition to 'noinline
We use the 'noinline' attribute in order to reduce code size, but that
doesn't prevent gcc from cloning the function, which is something that
goes against the purpose of preventing inlining in the first place.

Adding the 'noclone' attribute reduces the (stripped) binary size by
around 45 kB on x86-64.
2021-06-20 19:02:56 +02:00
Martin Storsjö 5407eaf2e6 attributes: Add a CHECK_OFFSET macro for verifying struct offsets
A static_assert is used if available, otherwise a custom
construct.
2021-04-14 14:57:30 +00:00
Henrik Gramner 1d6aae4795 build: Fix compilation with clang-cl 2021-02-16 16:00:47 +01:00
Matthias Dressel 6361e88d4d src: Replace check for intra-/key-frame with dedicated macro
Should make the code more readable.
2021-01-28 21:26:40 +01:00
Matthias Dressel 54747d42e2 src: Use a macro for testing frame_type
Replace checks for INTER or SWITCH frames with a simple macro for
increased readability and maintainability.
2021-01-28 21:26:40 +01:00
Henrik Gramner 236e1122da Add more buffer pools
Add buffer pools for miscellaneous smaller buffers that are
repeatedly being freed and reallocated.

Also improve dav1d_ref_create() by consolidating two separate
memory allocations into a single one.
2020-11-22 14:51:03 +01:00
Janne Grunau ef990c9d82 memory sanitizer: mask all CPU flags
Memory sanitizer depends on compiler instrumentation which makes it
inherently incompatible with asm DSP functions. Refs #336
2020-04-10 22:07:20 +02:00
Wan-Teh Chang ab350c2f29 Update a stale comment for dav1d_alloc_aligned()
Also, the assertion that 'align'  is a power of 2 can be used by all
cases in dav1d_alloc_aligned().
2020-04-03 00:38:56 +02:00
Martin Storsjö e3dbf92664 arm64: looprestoration: NEON implementation of SGR for 10 bpc
This only supports 10 bpc, not 12 bpc, as the sum and tmp buffers can
be int16_t for 10 bpc, but need to be int32_t for 12 bpc.

Make actual templates out of the functions in looprestoration_tmpl.S,
and add box3/5_h to looprestoration16.S.

Extend dav1d_sgr_calc_abX_neon with a mandatory bitdepth_max parameter
(which is passed even in 8bpc mode), add a define to bitdepth.h for
passing such a parameter in all modes. This makes this function
a few instructions slower in 8bpc mode than it was before (overall impact
seems to be around 1% of the total runtime of SGR), but allows using the
same actual function instantiation for all modes, saving a bit of code
size.

Examples of checkasm runtimes:
                           Cortex A53        A72        A73
selfguided_3x3_10bpc_neon:   516755.8   389412.7   349058.7
selfguided_5x5_10bpc_neon:   380699.9   293486.6   254591.6
selfguided_mix_10bpc_neon:   878142.3   667495.9   587844.6

Corresponding 8 bpc numbers for comparison:
selfguided_3x3_8bpc_neon:    491058.1   361473.4   347705.9
selfguided_5x5_8bpc_neon:    352655.0   266423.7   248192.2
selfguided_mix_8bpc_neon:    826094.1   612372.2   581943.1
2020-02-11 10:45:29 +02:00
Martin Storsjö a285204a5d arm: mc: Prepare the init file for higher bitdepths 2020-02-04 07:33:26 +01:00
Henrik Gramner fbc1b4204c Avoid masking the lsb in high bit-depth stride calculations
We specify most strides in bytes, but since C defines offsets
in multiples of sizeof(type) we use the PXSTRIDE() macro to
downshift the strides by one in high-bit depth templated files.

This however means that the compiler is required to mask away
the least significant bit, because it could in theory be non-zero.

Avoid that by telling the compiler (when compiled in release mode)
that the lsb is in fact guaranteed to always be zero.
2020-02-01 14:17:35 +01:00
Henrik Gramner 9c29f229c5 checkasm: Increase buffer alignment to 64-byte on x86-64
Required for AVX-512.
2020-01-29 14:11:38 +01:00
Henrik Gramner c192e0db24 Add a workaround for -fsanitize=cfi + dlsym() issue
CFI will SIGILL when calling a function pointer obtained through
dlsym(), regardless of whether or not the signature is correct.

See https://bugs.llvm.org/show_bug.cgi?id=44500
2020-01-10 03:08:18 +01:00
Henrik Gramner c0e1988b01 Prefer __builtin_unreachable() over __assume() on clang-cl
__assume() doesn't work correctly in clang-cl versions prior to 7.0.0
which causes bogus warnings regarding use of uninitialized variables
to be printed. Avoid that by using __builtin_unreachable() instead.
2019-09-04 14:51:34 +02:00
Henrik Gramner 70b66ff13f Optimize coef ctx calculations 2019-08-23 21:31:42 +02:00
Henrik Gramner 6751c98036 Utilize the constraints in assertions to improve code generation
When compiling in release mode, instead of just deleting assertions,
use them to give hints to the compiler. This allows for slightly
better code generation in some cases.
2019-08-19 00:02:29 +02:00
Luca Barbato d12418b3fb vsx: Set the correct alignment constraints 2019-07-27 15:41:39 +02:00
Martin Storsjö 13a7d78655 checkasm: cdef: Add verbose prints for output data (and relevant input)
For the cdef_filter tests, one could also extend the buffer to
contain 16*11 pixels, to simplify printing it as one rectangular
section.

Extend the common hex_dump function to allow dumping to an arbitrary
FILE* pointer, to reuse it for printing the source pixel buffer in
case of errors.
2019-06-30 11:59:36 +03:00
Martin Storsjö c950e7101b checkasm: Add functions for printing pixel buffers 2019-06-25 00:16:28 +03:00
Henrik Gramner 8d2dd43900 Add __attribute__((cold)) to rarely used functions 2019-05-09 23:35:04 +02:00
Martin Storsjö c45f6b379d Remove leading double underscores from include guard defines
A symbol starting with two leading underscores is reserved for
the compiler/standard library implementation.

Also remove the trailing two double underscores for consistency
and symmetry.
2019-02-13 16:09:03 +02:00
Martin Storsjö 53025a2b32 Make include guards consistent; don't define any value for the include guard symbol 2019-02-13 16:04:54 +02:00
James Almer c98bbeb3cf add a logging callback mechanism 2019-01-28 12:16:54 -03:00
Henrik Gramner 0f25db1ab9 Use 16-byte stack alignment on 32-bit x86
We don't support AVX2 on x86-32 so having 32-byte alignment is redundant.
2018-12-20 21:24:33 +01:00
Ronald S. Bultje c3980e394d 12 bits/component support 2018-12-05 18:21:05 -05:00
Ronald S. Bultje ec53ec6d5b Add support for scaled references
Fixes #121.
2018-11-13 22:38:08 +01:00
Ronald S. Bultje e3b5d4d044 Use grouped context setting
Decreases runtime of decoding first 1000 frames of Chimera (1080p, 8bit)
from 12.227 to 12.075s (average of 6 runs) after changing decode.c, and
further down to 12.027s (1.67%) with the changes to recon_tmpl.c included.
After the changes to lf_mask.c, it goes down to 11.842s.
2018-11-06 16:22:28 -05:00
Janne Grunau d439328844 move rl32() to its only user tools/dav1d/input/ivf.c
Replace it with the version used in dav1d_fuzzer to avoid an integer
promotion.
2018-11-04 22:28:02 +01:00
Janne Grunau 8e5f126f8f mem: use memalign as fallback for posix_memalign and _aligned_malloc
posix_memalign is not available in Android <= 4.1 (API level 16 and
below). Fixes #140
2018-11-01 23:31:50 +01:00
Martin Storsjö 6cb362d015 attributes: Don't align to more than what assembly needs/benefits from
For arm/arm64, there's no need to align any buffer to 32 bytes
as the assembly doesn't need it and doesn't benefit from it.

This would be much more elegant if defined like this:

    #define MAX_ALIGN 16
    #define ALIGN(align) __attribute__((aligned(MIN(align, MAX_ALIGN))))

This works for GCC and Clang, but the MSVC alignment __declspec
needs a literal alignment value, it can't handle an expression.
2018-10-25 16:50:40 +02:00
Martin Storsjö 2cce1d2615 attributes: Fix leftover mismatched else/endif comments
These went out of sync in 227b7eae7a.
2018-10-25 11:54:55 +03:00
Martin Storsjö 227b7eae7a attributes: Don't try to use _BitScanReverse64 on MSVC/ARM
Despite what MSDN says, this intrinsic doesn't exist for ARM,
only for ARM64.
2018-10-19 11:51:59 +03:00
James Almer 41fb5ec5bb attributes: fix clzll on 32-bit MSVC 2018-10-02 12:01:41 -03:00
Thierry Foucu b3397e4184 Add Macro to make it clear the variable is intended to not be initialized 2018-09-29 19:24:25 +02:00
Steve Lhomme 18b69609a2 attributes: define the ALIGN() macro for MSVC 2018-09-28 16:24:02 +02:00
Steve Lhomme 449a81e7ba Don't use hardcoded __attribute__((noinline)) 2018-09-28 13:13:44 +02:00
Steve Lhomme e2d329fbeb define builtin clz/ctz calls MSVC equivalents
__builtin_ctz:
Returns the number of trailing 0-bits in x, starting at the least significant
bit position. If x is 0, the result is undefined.

_BitScanForward:
Search the mask data from least significant bit (LSB) to the most significant
bit (MSB) for a set bit (1). If a set bit is found, the bit position of the
first set bit found is returned in the first parameter. If no set bit is found,
0 is returned; otherwise, 1 is returned.

__builtin_clz:
Returns the number of leading 0-bits in x, starting at the most significant
bit position. If x is 0, the result is undefined.

_BitScanReverse:
Search the mask data from most significant bit (MSB) to least significant bit
(LSB) for a set bit (1). Returns Nonzero if Index was set, or 0 if no set bits
were found. Index is loaded with the bit position of the first set bit (1) found.
2018-09-28 12:10:45 +02:00
Steve Lhomme d262a6ae9a replace direct calls to __builtin_clz/ctz with generic functions 2018-09-28 12:09:42 +02:00