Commit Graph

3203 Commits

Author SHA1 Message Date
Brad Smith 52f7694ddd Use sched_getaffinity on Android
https://android.googlesource.com/platform/bionic/+/72e6fd42421dca80fb2776a9185c186d4a04e5f7

Android has had sched_getaffinity since Android 3.0. Builds need
to use _GNU_SOURCE.
2024-12-29 17:54:57 +00:00
Martin Storsjö 450946f96b ci: Test compiling for Android 2024-12-29 17:48:58 +00:00
Brad Smith a64111b1b3 Enable use of __sync_fetch_and_add() wherever detected instead of just X86
Use __sync_fetch_and_add() wherever detected instead of being limited to
just X86.
2024-12-29 12:13:33 -05:00
Brad Smith 938601b906 Use sysctlbyname(3) hw.logicalcpu on macOS
Use of hw.ncpu has long been deprecated.
2024-12-29 15:52:24 +00:00
Brad Smith 023112c6f2 aarch64: defines involving bit shifts should be unsigned 2024-11-03 23:44:35 -05:00
Brad Smith da14df5535 Make use of sysconf(3) _SC_NPROCESSORS_ONLN and _SC_NPROCESSORS_CONF
Make use of _SC_NPROCESSORS_ONLN if it exists and fallback to
_SC_NPROCESSORS_CONF for really old operating systems. This adds
support for retrieving the number of CPUs on a few OS's such as
NetBSD, DragonFly and a few others.
2024-10-27 12:28:19 -04:00
Brad Smith b1d2de88ec Use getauxval() on Linux and elf_aux_info() on FreeBSD/OpenBSD on arm/ppc 2024-10-26 06:34:32 +00:00
Anton Mitrofanov 3a21e97bf2 Fix build with Android NDK and API < 24 for 32-bit targets
fseeko() is not available before API 24 with _FILE_OFFSET_BITS=64.
x264.c: x264cli.h must be first as it contains _FILE_OFFSET_BITS define.
2024-10-22 22:59:00 +03:00
Brad Smith 80c1c47cb2 configure: Add DragonFly support 2024-10-20 08:50:55 +00:00
Brad Smith 1243d9ffb0 Provide x264_getauxval() wrapper for getauxvaul() and elf_aux_info() 2024-10-17 06:23:19 -04:00
Brad Smith 3a8b5be2a2 aarch64: Use elf_aux_info() for CPU feature detection on FreeBSD/OpenBSD 2024-10-07 15:58:28 -04:00
Martin Storsjö c24e06c2e1 configure: Check for SVE support in MS armasm64 via as_check
This is mostly supported in armasm64 since MSVC 2022 17.10.
2024-09-17 14:07:10 +03:00
Henrik Gramner 4613ac3c15 x86inc: Improve ELF PIC support for external function calls
PLT/GOT indirections are required in some cases. Most commonly when
calling functions from other shared libraries, but also in some
scenarios when calling functions with default symbol visibility
even within the same component on certain elf64 platforms.

On elf64 we can simply use PLT relocations for all calls to external
functions. Since the linker is able to eliminate unnecessary PLT
indirections with the final output binary being identical to non-PLT
relocations there isn't really any downside to doing so. This mimics
what regular compilers normally do for calls to external functions.

On elf32 with PIC we can use a function pointer from the GOT when
calling external functions, similar to what regular compilers do when
using -fno-plt. Since this both introduces overhead and clobbers one
register, which could potentially have been used for custom calling
conventions when calling other asm functions within the same library,
it's only performed for functions declared using 'cextern_naked'.
2024-05-13 17:54:15 +02:00
Xiwei Gu 7ed753b10a loongarch: Enhance ultrafast encoding performance
Using the following command, ultrafast encoding
has improved from 182fps to 189fps:
./x264 --preset ultrafast -o out.mkv yuv_1920x1080.yuv
2024-03-21 09:18:50 +08:00
Xiwei Gu 162622863a loongarch: Fixed pixel_sa8d_16x16_lasx
Save and restore FPR
2024-03-21 09:18:32 +08:00
Xiwei Gu 5a61afdbf1 loongarch: Add checkasm_call 2024-03-21 09:18:00 +08:00
Xiwei Gu 982d32400f loongarch: Update loongson_asm.S version to 0.4.0 2024-03-21 09:17:09 +08:00
Henrik Gramner 585e01997f x86inc: Improve XMM-spilling functionality on 64-bit Windows
Prior to this change dealing with the scenario where the number of
XMM registers spilled depends on if a branch is taken or not was
complicated to handle well. There was essentially three options:

1) Always spill the largest number of XMM register. Results in
   unnecessary spills.

2) Do the spilling after the branch. Results in code duplication
   for the shared subset of spills.

3) Do the spilling manually. Optimal, but overly complex and vexing.

This adds an additional optional argument to the WIN64_SPILL_XMM
and WIN64_PUSH_XMM macros to make it possible to allocate space
for a certain number of registers but initially only push a subset
of those, with the option of pushing additional register later.
2024-03-14 23:29:26 +00:00
Henrik Gramner 4df71a75bf x86inc: Restore the stack state between stack allocations
Allows the use of multiple independent stack allocations within
a function without having to manually fiddle with stack offsets.
2024-03-14 23:29:26 +00:00
Henrik Gramner 3d8aff7e26 x86inc: Fix warnings with old nasm versions 2024-03-14 23:29:26 +00:00
Anton Mitrofanov de1bea534f ppc: Fix incompatible pointer type errors
Use correct return type for pixel_sad_x3/x4 functions.
Bug report by Dominik 'Rathann' Mierzejewski .
2024-03-12 23:10:12 +03:00
Martin Storsjö be4f0200ed aarch64: Use regular hwcaps flags instead of HWCAP_CPUID for CPU feature detection on Linux
This makes the code much simpler (especially for adding support
for other instruction set extensions), avoids needing inline
assembly for this feature, and generally is more of the canonical
way to do this.

The CPU feature detection was added in
9c3c716882, using HWCAP_CPUID.

The argument for using that, was that HWCAP_CPUID was added much
earlier in the kernel (in Linux v4.11), while the HWCAP flags for
individual features always come later. This allows detecting support
for new CPU extensions before the kernel exposes information about
them via hwcap flags.

However in practice, there's probably quite little advantage in this.
E.g. HWCAP_SVE was added in Linux v4.15, and HWCAP2_SVE2 was added in
v5.10 - later than HWCAP_CPUID, but there's probably very little
practical cases where one would run a kernel older than that on a CPU
that supports those instructions.

Additionally, we provide our own definitions of the flag values to
check (as they are fixed constants anyway), with names not conflicting
with the ones from system headers. This reduces the number of ifdefs
needed, and allows detecting those features even if building with
userland headers that are lacking the definitions of those flags.

Also, slightly older versions of QEMU, e.g. 6.2 in Ubuntu 22.04,
do expose support for these features via HWCAP flags, but the
emulated cpuid registers are missing the bits for exposing e.g. SVE2
(This issue is fixed in later versions of QEMU though.)

Also drop the ifdef check for whether AT_HWCAP is defined; it was
added to glibc in 1997. AT_HWCAP2 was added in 2013, in glibc 2.18,
which also precedes when aarch64 was commonly used anyway, so
don't guard the use of that with an ifdef.
2024-02-28 22:26:17 +00:00
Anton Mitrofanov 7241d02011 CI: Switch 32/64-bit windows builds to LLVM
Use same Docker images as VLC for contrib compilation.
2024-02-28 23:23:15 +03:00
Anton Mitrofanov ea08f58648 CI: Add config.log to job artifacts 2024-02-28 23:19:23 +03:00
Henrik Gramner 12426f5f49 x86inc: Add support for ELF CET properties
Automatically flag x86-64 asm object files as SHSTK-compatible.

Shadow Stack (SHSTK) is a part of Control-flow Enforcement Technology
(CET) which is a feature aimed at defending against ROP attacks by
verifying that 'call' and 'ret' instructions are correctly matched.

For well-written code this works transparently without any code changes,
as return addresses popped from the shadow stack should match return
addresses popped from the normal stack for performance reasons anyway.
2024-02-20 00:03:09 +01:00
Henrik Gramner 6fc4480cf0 x86inc.asm: Add the crc32 SSE4.2 GPR instruction 2024-02-20 00:03:09 +01:00
Henrik Gramner 87476b4c4d x86inc: Add a cpu flag for the Ice Lake AVX-512 subset 2024-02-20 00:03:09 +01:00
Henrik Gramner a6b561792f x86inc: Add CLMUL cpu flag
Also make the GFNI cpu flag imply the presence of both AESNI and CLMUL.
2024-02-20 00:03:09 +01:00
Henrik Gramner 5207a74e77 x86inc: Add template defines for EVEX broadcasts
Broadcasting a memory operand is a binary flag, you either broadcast
or you don't, and there's only a single possible element size for
any given instruction.

The instruction syntax however requires the broadcast semanticts
to be explicitly defined, which is an issue when using macros to
template code for multiple register widths.

Add some helper defines to alleviate the issue.
2024-02-20 00:02:59 +01:00
Henrik Gramner 436be41fc1 x86inc: Properly sort instructions in alphabetical order 2024-02-19 23:49:36 +01:00
Anton Mitrofanov 4815ccadb1 Bump dates to 2024 2024-01-13 14:45:39 +03:00
David Chen c1c9931dc8 Improve pixel-a.S Performance by Using SVE/SVE2
Imporve the performance of NEON functions of aarch64/pixel-a.S
by using the SVE/SVE2 instruction set. Below, the specific functions
are listed together with the improved performance results.

Command executed: ./checkasm8 --bench=ssd
Testbed: Alibaba g8y instance based on Yitian 710 CPU
Results:
ssd_4x4_c: 235
ssd_4x4_neon: 226
ssd_4x4_sve: 151
ssd_4x8_c: 409
ssd_4x8_neon: 363
ssd_4x8_sve: 201
ssd_4x16_c: 781
ssd_4x16_neon: 653
ssd_4x16_sve: 313
ssd_8x4_c: 402
ssd_8x4_neon: 192
ssd_8x4_sve: 192
ssd_8x8_c: 728
ssd_8x8_neon: 275
ssd_8x8_sve: 275

Command executed: ./checkasm10 --bench=ssd
Testbed: Alibaba g8y instance based on Yitian 710 CPU
Results:
ssd_4x4_c: 256
ssd_4x4_neon: 226
ssd_4x4_sve: 153
ssd_4x8_c: 460
ssd_4x8_neon: 369
ssd_4x8_sve: 215
ssd_4x16_c: 852
ssd_4x16_neon: 651
ssd_4x16_sve: 340

Command executed: ./checkasm8 --bench=ssd
Testbed: AWS Graviton3
Results:
ssd_4x4_c: 295
ssd_4x4_neon: 288
ssd_4x4_sve: 228
ssd_4x8_c: 454
ssd_4x8_neon: 431
ssd_4x8_sve: 294
ssd_4x16_c: 779
ssd_4x16_neon: 631
ssd_4x16_sve: 438
ssd_8x4_c: 463
ssd_8x4_neon: 247
ssd_8x4_sve: 246
ssd_8x8_c: 781
ssd_8x8_neon: 413
ssd_8x8_sve: 353

Command executed: ./checkasm10 --bench=ssd
Testbed: AWS Graviton3
Results:
ssd_4x4_c: 322
ssd_4x4_neon: 335
ssd_4x4_sve: 240
ssd_4x8_c: 522
ssd_4x8_neon: 448
ssd_4x8_sve: 294
ssd_4x16_c: 832
ssd_4x16_neon: 603
ssd_4x16_sve: 440

Command executed: ./checkasm8 --bench=sa8d
Testbed: Alibaba g8y instance based on Yitian 710 CPU
Results:
sa8d_8x8_c: 2103
sa8d_8x8_neon: 619
sa8d_8x8_sve: 617

Command executed: ./checkasm8 --bench=sa8d
Testbed: AWS Graviton3
Results:
sa8d_8x8_c: 2021
sa8d_8x8_neon: 597
sa8d_8x8_sve: 580

Command executed: ./checkasm8 --bench=var
Testbed: Alibaba g8y instance based on Yitian 710 CPU
Results:
var_8x8_c: 595
var_8x8_neon: 262
var_8x8_sve: 262
var_8x16_c: 1193
var_8x16_neon: 435
var_8x16_sve: 419

Command executed: ./checkasm8 --bench=var
Testbed: AWS Graviton3
Results:
var_8x8_c: 616
var_8x8_neon: 229
var_8x8_sve: 222
var_8x16_c: 1207
var_8x16_neon: 399
var_8x16_sve: 389

Command executed: ./checkasm8 --bench=hadamard_ac
Testbed: Alibaba g8y instance based on Yitian 710 CPU
Results:
hadamard_ac_8x8_c: 2330
hadamard_ac_8x8_neon: 635
hadamard_ac_8x8_sve: 635
hadamard_ac_8x16_c: 4500
hadamard_ac_8x16_neon: 1152
hadamard_ac_8x16_sve: 1151
hadamard_ac_16x8_c: 4499
hadamard_ac_16x8_neon: 1151
hadamard_ac_16x8_sve: 1150
hadamard_ac_16x16_c: 8812
hadamard_ac_16x16_neon: 2187
hadamard_ac_16x16_sve: 2186

Command executed: ./checkasm8 --bench=hadamard_ac
Testbed: AWS Graviton3
Results:
hadamard_ac_8x8_c: 2266
hadamard_ac_8x8_neon: 517
hadamard_ac_8x8_sve: 513
hadamard_ac_8x16_c: 4444
hadamard_ac_8x16_neon: 867
hadamard_ac_8x16_sve: 849
hadamard_ac_16x8_c: 4443
hadamard_ac_16x8_neon: 880
hadamard_ac_16x8_sve: 868
hadamard_ac_16x16_c: 8595
hadamard_ac_16x16_neon: 1656
hadamard_ac_16x16_sve: 1622
2023-11-23 19:01:29 +02:00
David Chen 0ac52d2915 Create Common NEON pixel-a Macros and Constants
Place NEON pixel-a macros and constants that are intended
to be used by SVE/SVE2 functions as well in a common file.
2023-11-23 08:26:53 +02:00
David Chen 06dcf3f9cd Improve mc-a.S Performance by Using SVE/SVE2
Imporve the performance of NEON functions of aarch64/mc-a.S
by using the SVE/SVE2 instruction set. Below, the specific functions
are listed together with the improved performance results.

Command executed: ./checkasm8 --bench=avg
Testbed: Alibaba g8y instance based on Yitian 710 CPU
Results:
avg_4x2_c: 274
avg_4x2_neon: 215
avg_4x2_sve: 171
avg_4x4_c: 461
avg_4x4_neon: 343
avg_4x4_sve: 225
avg_4x8_c: 806
avg_4x8_neon: 619
avg_4x8_sve: 334
avg_4x16_c: 1523
avg_4x16_neon: 1168
avg_4x16_sve: 558

Command executed: ./checkasm8 --bench=avg
Testbed: AWS Graviton3
Results:
avg_4x2_c: 267
avg_4x2_neon: 213
avg_4x2_sve: 167
avg_4x4_c: 467
avg_4x4_neon: 350
avg_4x4_sve: 221
avg_4x8_c: 784
avg_4x8_neon: 624
avg_4x8_sve: 302
avg_4x16_c: 1445
avg_4x16_neon: 1182
avg_4x16_sve: 485
2023-11-23 08:24:16 +02:00
David Chen 21a788f159 Create Common NEON mc-a Macros and Functions
Place NEON mc-a macros and functions that are intended
to be used by SVE/SVE2 functions as well in a common file.
2023-11-23 08:24:13 +02:00
David Chen 5ad5e5d8f1 Improve deblock-a.S Performance by Using SVE/SVE2
Imporve the performance of NEON functions of aarch64/deblock-a.S
by using the SVE/SVE2 instruction set. Below, the specific functions
are listed together with the improved performance results.

Command executed: ./checkasm8 --bench=deblock
Testbed: Alibaba g8y instance based on Yitian 710 CPU
Results:
deblock_chroma[1]_c: 735
deblock_chroma[1]_neon: 427
deblock_chroma[1]_sve: 353

Command executed: ./checkasm8 --bench=deblock
Testbed: AWS Graviton3
Results:
deblock_chroma[1]_c: 719
deblock_chroma[1]_neon: 442
deblock_chroma[1]_sve: 345
2023-11-20 08:03:54 +02:00
David Chen 37949a994e Create Common NEON deblock-a Macros
Place NEON deblock-a macros that are intended to be
used by SVE/SVE2 functions as well in a common file.
2023-11-20 08:03:53 +02:00
David Chen 5c382660fb Improve dct-a.S Performance by Using SVE/SVE2
Imporve the performance of NEON functions of aarch64/dct-a.S
by using the SVE/SVE2 instruction set. Below, the specific functions
are listed together with the improved performance results.

Command executed: ./checkasm8 --bench=sub
Testbed: Alibaba g8y instance based on Yitian 710 CPU
Results:
sub4x4_dct_c: 528
sub4x4_dct_neon: 322
sub4x4_dct_sve: 247

Command executed: ./checkasm8 --bench=sub
Testbed: AWS Graviton3
Results:
sub4x4_dct_c: 562
sub4x4_dct_neon: 376
sub4x4_dct_sve: 255

Command executed: ./checkasm8 --bench=add
Testbed: Alibaba g8y instance based on Yitian 710 CPU
Results:
add4x4_idct_c: 698
add4x4_idct_neon: 386
add4x4_idct_sve2: 345

Command executed: ./checkasm8 --bench=zigzag
Testbed: Alibaba g8y instance based on Yitian 710 CPU
Results:
zigzag_interleave_8x8_cavlc_frame_c: 582
zigzag_interleave_8x8_cavlc_frame_neon: 273
zigzag_interleave_8x8_cavlc_frame_sve: 257

Command executed: ./checkasm8 --bench=zigzag
Testbed: AWS Graviton3
Results:
zigzag_interleave_8x8_cavlc_frame_c: 587
zigzag_interleave_8x8_cavlc_frame_neon: 257
zigzag_interleave_8x8_cavlc_frame_sve: 249
2023-11-20 08:03:51 +02:00
David Chen b6190c6fa1 Create Common NEON dct-a Macros
Place NEON dct-a macros that are intended to be
used by SVE/SVE2 functions as well in a common file.
2023-11-18 08:42:48 +02:00
Martin Storsjö c196240409 ci: Test the aarch64 build in QEMU with varying SVE sizes
The sve-default-vector-length property sets the maximum vector
length in bytes; the default is 64, i.e. handling up to 512
bit vectors. In order to be able to test 1024 and 2048 bit vectors,
this has to be raised separately from setting the sve<n>=on
property.
2023-11-14 12:44:15 +00:00
Martin Storsjö 9b3e653be4 ci: Update the build-debian-amd64 job to a new base image
In the new version, there's no longer any "wine64" executable,
but both i386 and x86_64 are handled with the same "wine" frontend.
2023-11-14 12:44:15 +00:00
Martin Storsjö 611b87b7a2 checkasm: Print the actual SVE vector length 2023-11-14 12:38:47 +02:00
Martin Storsjö a354f11f8f aarch64: Consistently use lowercase vector element specifiers 2023-11-02 23:34:23 +02:00
Martin Storsjö ef572b9f06 aarch64: Make the assembly indentation slightly more consistent
The assembly currently uses a mixture of different styles. Don't
make all of it entirely consistent now, but try to make functions
more consistent within themselves at least.

In particular, get rid of the convention to have braces hanging
outside of the alignment line.

Some functions have the whole content indented off by one char
compared to other functions; adjust those (but retain the functions
that are self-consistent and match either of the common styles).
2023-11-02 23:34:22 +02:00
Martin Storsjö 3bc7c36256 arm: Make the assembly indentation slightly more consistent
The assembly currently uses a mixture of different styles. Don't
make all of it entirely consistent now, but try to make functions
more consistent within themselves at least.

In particular, get rid of the convention to have braces hanging
outside of the alignment line.
2023-11-02 23:31:40 +02:00
Martin Storsjö dc755eabb9 aarch64: Use rounded right shifts in dequant
Don't manually add in the rounding constant (via a fused multiply-add
instruction) when we can just do a plain rounded right shift.

                     Cortex A53   A72   A73
8bpc:
Before:
dequant_4x4_cqm_neon:       515   246   267
dequant_4x4_dc_cqm_neon:    410   265   266
dequant_4x4_dc_flat_neon:   413   271   271
dequant_4x4_flat_neon:      519   254   274
dequant_8x8_cqm_neon:      1555   980  1002
dequant_8x8_flat_neon:     1562   994  1014
After:
dequant_4x4_cqm_neon:       499   246   255
dequant_4x4_dc_cqm_neon:    376   265   255
dequant_4x4_dc_flat_neon:   378   271   260
dequant_4x4_flat_neon:      500   254   262
dequant_8x8_cqm_neon:      1489   900   925
dequant_8x8_flat_neon:     1493   915   938

10bpc:
Before:
dequant_4x4_cqm_neon:       483   275   275
dequant_4x4_dc_cqm_neon:    429   256   261
dequant_4x4_dc_flat_neon:   435   267   267
dequant_4x4_flat_neon:      487   283   288
dequant_8x8_cqm_neon:      1511  1112  1076
dequant_8x8_flat_neon:     1518  1139  1089
After:
dequant_4x4_cqm_neon:       472   255   239
dequant_4x4_dc_cqm_neon:    404   256   232
dequant_4x4_dc_flat_neon:   406   267   234
dequant_4x4_flat_neon:      472   255   239
dequant_8x8_cqm_neon:      1462   922   978
dequant_8x8_flat_neon:     1462   922   978

This makes it around 3% faster on the Cortex A53, around 8% faster
for 8bpc on Cortex A72/A73, and around 10-20% faster for 10bpp
on A72/A73.
2023-11-02 21:26:03 +00:00
Martin Storsjö 4664f5aa66 aarch64: Improve scheduling in sad_x3/sad_x4
Cortex A53    A72    A73
8 bpc:
Before:
sad_x3_4x4_neon:      580    303    204
sad_x3_4x8_neon:     1065    516    323
sad_x3_8x4_neon:      668    262    282
sad_x3_8x8_neon:     1238    454    471
sad_x3_8x16_neon:    2378    842    847
sad_x3_16x8_neon:    2136    738    776
sad_x3_16x16_neon:   4162   1378   1463
After:
sad_x3_4x4_neon:      477    298    206
sad_x3_4x8_neon:      842    515    327
sad_x3_8x4_neon:      603    260    279
sad_x3_8x8_neon:     1110    451    464
sad_x3_8x16_neon:    2125    841    843
sad_x3_16x8_neon:    2124    730    766
sad_x3_16x16_neon:   4145   1370   1434

10 bpc:
Before:
sad_x3_4x4_neon:      632    247    254
sad_x3_4x8_neon:     1162    419    443
sad_x3_8x4_neon:      890    358    416
sad_x3_8x8_neon:     1670    632    759
sad_x3_8x16_neon:    3230   1179   1458
sad_x3_16x8_neon:    3070   1209   1403
sad_x3_16x16_neon:   6030   2333   2699

After:
sad_x3_4x4_neon:      522    253    255
sad_x3_4x8_neon:      932    443    431
sad_x3_8x4_neon:      880    354    406
sad_x3_8x8_neon:     1660    626    736
sad_x3_8x16_neon:    3220   1170   1397
sad_x3_16x8_neon:    3060   1184   1362
sad_x3_16x16_neon:   6020   2272   2579

Thus, this is around a 20-25% speedup on Cortex A53 for the small
sizes (much smaller difference for bigger sizes though), while it
doesn't make much of a difference at all (mostly within measurement
noise) for the out-of-order cores (A72 and A73).
2023-11-02 13:27:08 +02:00
Anton Mitrofanov d46938dec1 Fix VBV with sliced threads 2023-10-24 22:07:14 +03:00
Martin Storsjö 9c3c716882 Add cpu flags and runtime detection of SVE and SVE2
We could also use HWCAP_SVE and HWCAP2_SVE2 for detecting this,
but these might not be available in all userland headers, while
HWCAP_CPUID is available much earlier.

The register ID_AA64ZFR0_EL1, which indicates if SVE2 is available,
can only be accessed if SVE is available. If not building all the
C code with SVE enabled (which could make it impossible to run on
on HW without SVE), binutils refuses to assemble an instruction
reading ID_AA64ZFR0_EL1 - but if referring to it with the technical
name S3_0_C0_C4_4, it can be assembled even without any extra
extensions enabled.
2023-10-19 22:58:11 +03:00
Martin Storsjö db9bc75b0b configure: Check for support for AArch64 SVE and SVE2
We don't expect the user to build the whole x264 codebase with
SVE/SVE2 enabled, as we only enable this feature for the assembly
files that use it, in order to have binaries that are portable
and enable the SVE codepaths at runtime if supported.
2023-10-18 11:23:47 +03:00