1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-12 19:18:44 +02:00
FFmpeg/libavutil
Lynne 119a3f7e8d
lavu/x86: add FFT assembly
This commit adds a pure x86 assembly SIMD version of the FFT in libavutil/tx.
The design of this pure assembly FFT is pretty unconventional.

On the lowest level, instead of splitting the complex numbers into
real and imaginary parts, we keep complex numbers together but split
them in terms of parity. This saves a number of shuffles in each transform,
but more importantly, it splits each transform into two independent
paths, which we process using separate registers in parallel.
This allows us to keep all units saturated and lets us use all available
registers to avoid dependencies.
Moreover, it allows us to double the granularity of our per-load permutation,
skipping many expensive lookups and allowing us to use just 4 loads per register,
rather than 8, or in case FMA3 (and by extension, AVX2), use the vgatherdpd
instruction, which is at least as fast as 4 separate loads on old hardware,
and quite a bit faster on modern CPUs).

Higher up, we go for a bottom-up construction of large transforms, foregoing
the traditional per-transform call-return recursion chains. Instead, we always
start at the bottom-most basis transform (in this case, a 32-point transform),
and continue constructing larger and larger transforms until we return to the
top-most transform.
This way, we only touch the stack 3 times per a complete target transform:
once for the 1/2 length transform and two times for the 1/4 length transform.

The combination algorithm we use is a standard Split-Radix algorithm,
as used in our C code. Although a version with less operations exists
(Steven G. Johnson and Matteo Frigo's "A modified split-radix FFT with fewer
arithmetic operations", IEEE Trans. Signal Process. 55 (1), 111–119 (2007),
which is the one FFTW uses), it only has 2% less operations and requires at least 4x
the binary code (due to it needing 4 different paths to do a single transform).
That version also has other issues which prevent it from being implemented
with SIMD code as efficiently, which makes it lose the marginal gains it offered,
and cannot be performed bottom-up, requiring many recursive call-return chains,
whose overhead adds up.

We go through a lot of effort to minimize load/stores by keeping as much in
registers in between construcring transforms. This saves us around 32 cycles,
on paper, but in reality a lot more due to load/store aliasing (a load from a
memory location cannot be issued while there's a store pending, and there are
only so many (2 for Zen 3) load/store units in a CPU).
Also, we interleave coefficients during the last stage to save on a store+load
per register.

Each of the smallest, basis transforms (4, 8 and 16-point in our case)
has been extremely optimized. Our 8-point transform is barely 20 instructions
in total, beating our old implementation 8-point transform by 1 instruction.
Our 2x8-point transform is 23 instructions, beating our old implementation by
6 instruction and needing 50% less cycles. Our 16-point transform's combination
code takes slightly more instructions than our old implementation, but makes up
for it by requiring a lot less arithmetic operations.

Overall, the transform was optimized for the timings of Zen 3, which at the
time of writing has the most IPC from all documented CPUs. Shuffles were
preferred over arithmetic operations due to their 1/0.5 latency/throughput.

On average, this code is 30% faster than our old libavcodec implementation.
It's able to trade blows with the previously-untouchable FFTW on small transforms,
and due to its tiny size and better prediction, outdoes FFTW on larger transforms
by 11% on the largest currently supported size.
2021-04-24 17:19:18 +02:00
..
aarch64 arm/aarch64: Use mach_absolute_time as timer on apple platforms 2021-02-21 22:41:34 +02:00
arm arm/aarch64: Use mach_absolute_time as timer on apple platforms 2021-02-21 22:41:34 +02:00
avr32
bfin
mips Include attributes.h directly 2021-04-19 14:34:10 +02:00
ppc
sh4
tests lavu/mem: move the DECLARE_ALIGNED macro family to mem_internal on next+1 bump 2021-01-01 14:14:57 +01:00
tomi
x86 lavu/x86: add FFT assembly 2021-04-24 17:19:18 +02:00
.gitignore
adler32.c avutil/adler32: Switch av_adler32_update() to size_t on bump 2021-03-19 04:19:53 +01:00
adler32.h avutil/adler32: Switch av_adler32_update() to size_t on bump 2021-03-19 04:19:53 +01:00
aes_ctr.c
aes_ctr.h
aes_internal.h All: update names in copyright headers 2021-01-20 01:02:56 -06:00
aes.c
aes.h
attributes.h avutil/attributes: Fix too many warning: false is not defined [-Wundef] 2020-05-30 17:29:23 +08:00
audio_fifo.c
audio_fifo.h
avassert.h
avsscanf.c avutil/avsscanf: fix possible overreads when dealing with %c or %s 2020-12-02 13:54:53 +01:00
avstring.c avutil/avstring: Check for memory allocation error in av_escape 2021-03-15 06:45:07 +01:00
avstring.h avutil/{avstring,bprint}: add XML escaping from ffprobe to avutil 2021-03-05 19:45:00 +02:00
avutil.h
avutilres.rc
base64.c avutil/base64: Fix undefined NULL + 0 2021-04-01 14:47:00 +02:00
base64.h
blowfish.c
blowfish.h
bprint.c avutil/{avstring,bprint}: add XML escaping from ffprobe to avutil 2021-03-05 19:45:00 +02:00
bprint.h
bswap.h
buffer_internal.h avutil/buffer_internal: Include internal for buffer_size_t 2021-03-11 14:07:15 +01:00
buffer.c avutil/buffer: change public function and struct size parameter types to size_t 2021-03-10 20:26:36 -03:00
buffer.h avutil/buffer: change public function and struct size parameter types to size_t 2021-03-10 20:26:36 -03:00
camellia.c
camellia.h
cast5.c
cast5.h
channel_layout.c avutil/channel_layout: add 22.2 layout 2020-08-04 00:17:56 +03:00
channel_layout.h avutil/channel_layout: add 22.2 layout 2020-08-04 00:17:56 +03:00
color_utils.c
color_utils.h
colorspace.h
common.h avutil/common: Move everything inside inclusion guards 2021-02-11 09:07:10 +01:00
cpu_internal.h libavutil: Detect MMI and MSA flags for MIPS 2020-07-23 17:21:58 +02:00
cpu.c avutil/cpu: Schedule deprecated functions for removal 2021-04-19 14:34:19 +02:00
cpu.h avutil/cpu: Schedule deprecated functions for removal 2021-04-19 14:34:19 +02:00
crc.c
crc.h
cuda_check.h avutil/cuda_check: add missing dynlink_loader.h include 2020-09-15 19:29:37 -03:00
des.c
des.h
detection_bbox.c lavu: add side data AV_FRAME_DATA_DETECTION_BBOXES for object detection/classification 2021-04-17 17:27:02 +08:00
detection_bbox.h lavu/detection_bbox.h: use AV_NUM_DETECTION_BBOX_CLASSIFY to replace AV_NUM_BBOX_CLASSIFY 2021-04-18 10:41:17 +08:00
dict.c avutil/dict: av_realloc -> av_realloc_array() 2020-06-06 10:32:07 +08:00
dict.h
display.c
display.h
dovi_meta.c lavutil: add DOVI related header 2020-04-23 08:05:15 +08:00
dovi_meta.h lavutil: add DOVI related header 2020-04-23 08:05:15 +08:00
downmix_info.c
downmix_info.h
dynarray.h
encryption_info.c
encryption_info.h
error.c
error.h
eval.c libavutil/eval: Remove CONFIG_TRAPV special handling 2021-02-10 12:28:29 +01:00
eval.h avutil/eval: Add av_expr_count_func() similar to av_expr_count_vars() 2019-12-28 11:20:48 +01:00
ffmath.h
fifo.c
fifo.h
file_open.c
file.c
file.h
film_grain_params.c libavutil: introduce AVFilmGrainParams side data 2020-11-25 23:06:33 +01:00
film_grain_params.h avutil/film_grain_params: fix doxy for ar_coeff_* fields 2020-12-03 13:25:21 -03:00
fixed_dsp.c avutil/fixed_dsp: Fix integer overflows in butterflies_fixed_c() 2020-09-19 00:37:45 +02:00
fixed_dsp.h
float_dsp.c
float_dsp.h
frame.c lavu: add side data AV_FRAME_DATA_DETECTION_BBOXES for object detection/classification 2021-04-17 17:27:02 +08:00
frame.h lavu: add side data AV_FRAME_DATA_DETECTION_BBOXES for object detection/classification 2021-04-17 17:27:02 +08:00
hash.c lavu: add missing stddef.h includes for size_t. 2020-11-20 15:20:24 +01:00
hash.h lavu: add missing stddef.h includes for size_t. 2020-11-20 15:20:24 +01:00
hdr_dynamic_metadata.c
hdr_dynamic_metadata.h
hmac.c
hmac.h
hwcontext_cuda_internal.h avutil/hwcontext_cuda: allow using primary CUDA device context 2019-11-26 16:24:40 +01:00
hwcontext_cuda.c avutil: use the buffer_size_t typedef where required 2021-03-10 20:26:37 -03:00
hwcontext_cuda.h avutil/hwcontext_cuda: allow using primary CUDA device context 2019-11-26 16:24:40 +01:00
hwcontext_d3d11va.c avutil: use the buffer_size_t typedef where required 2021-03-10 20:26:37 -03:00
hwcontext_d3d11va.h
hwcontext_drm.c hwcontext_drm: make dependency on Linux kernel headers optional 2020-12-30 23:14:46 +01:00
hwcontext_drm.h
hwcontext_dxva2.c avutil: use the buffer_size_t typedef where required 2021-03-10 20:26:37 -03:00
hwcontext_dxva2.h
hwcontext_internal.h hwcontext: add av_hwdevice_ctx_create_derived_opts 2020-05-23 19:07:26 +01:00
hwcontext_mediacodec.c
hwcontext_mediacodec.h
hwcontext_opencl.c avutil: use the buffer_size_t typedef where required 2021-03-10 20:26:37 -03:00
hwcontext_opencl.h
hwcontext_qsv.c avutil: use the buffer_size_t typedef where required 2021-03-10 20:26:37 -03:00
hwcontext_qsv.h
hwcontext_vaapi.c avutil: use the buffer_size_t typedef where required 2021-03-10 20:26:37 -03:00
hwcontext_vaapi.h
hwcontext_vdpau.c avutil: use the buffer_size_t typedef where required 2021-03-10 20:26:37 -03:00
hwcontext_vdpau.h
hwcontext_videotoolbox.c
hwcontext_videotoolbox.h
hwcontext_vulkan.c avutil: use the buffer_size_t typedef where required 2021-03-10 20:26:37 -03:00
hwcontext_vulkan.h hwcontext_vulkan: fix make checkheaders fail 2020-06-04 21:26:21 +08:00
hwcontext.c hwcontext: add av_hwdevice_ctx_create_derived_opts 2020-05-23 19:07:26 +01:00
hwcontext.h hwcontext: add av_hwdevice_ctx_create_derived_opts 2020-05-23 19:07:26 +01:00
imgutils_internal.h
imgutils.c avutil/imgutils: always zero data pointers in av_image_fill_pointers() 2020-07-26 21:51:24 -03:00
imgutils.h avutil/imgutils: add utility to get plane sizes 2020-07-22 11:41:57 -03:00
integer.c
integer.h
internal.h avutil/common: Add FF_PTR_ADD() 2021-03-31 23:09:35 +02:00
intfloat.h
intmath.c
intmath.h
intreadwrite.h
lfg.c
lfg.h avutil/lfg: Correct index increment type to avoid undefined behavior 2019-11-24 22:58:59 +01:00
libavutil.v
libm.h
lls.c
lls.h lavu/mem: move the DECLARE_ALIGNED macro family to mem_internal on next+1 bump 2021-01-01 14:14:57 +01:00
log2_tab.c
log.c avutil/log: update text requesting samples 2020-04-17 00:08:56 +02:00
log.h lavu/opt: add a more general child class iteration API 2020-06-10 12:36:42 +02:00
lzo.c
lzo.h
macros.h
Makefile lavu: add side data AV_FRAME_DATA_DETECTION_BBOXES for object detection/classification 2021-04-17 17:27:02 +08:00
mastering_display_metadata.c
mastering_display_metadata.h
mathematics.c avutil/mathematics: Fix undefined negation in av_compare_ts() 2021-02-10 12:28:29 +01:00
mathematics.h
md5.c
md5.h
mem_internal.h lavu/mem: move the DECLARE_ALIGNED macro family to mem_internal on next+1 bump 2021-01-01 14:14:57 +01:00
mem.c avutil/mem: Use max_alloc_size as-is 2020-05-26 06:47:31 +02:00
mem.h lavu/mem: move the DECLARE_ALIGNED macro family to mem_internal on next+1 bump 2021-01-01 14:14:57 +01:00
motion_vector.h
murmur3.c lavu: add missing stddef.h includes for size_t. 2020-11-20 15:20:24 +01:00
murmur3.h lavu: add missing stddef.h includes for size_t. 2020-11-20 15:20:24 +01:00
opt.c avutil/opt: add AV_OPT_FLAG_DEPRECATED option 2020-12-05 09:00:53 +08:00
opt.h lavu/opt: add a more general child class iteration API 2020-06-10 12:36:42 +02:00
parseutils.c avutil/parseutils: Check sign in av_parse_time() 2021-03-03 16:54:20 +01:00
parseutils.h
pca.c
pca.h
pixdesc.c avutil/pixdesc: Fix 1 << 32 2021-04-01 14:52:18 +02:00
pixdesc.h avutil/pixdesc: add missing FF_API_PSEUDOPAL check 2020-10-02 00:18:13 -03:00
pixelutils.c
pixelutils.h
pixfmt.h avutil/pixfmt: improve definition of AVColorRange 2020-09-23 19:14:45 +03:00
qsort.h
random_seed.c
random_seed.h
rational.c lavu: add av_gcd_q(). 2020-05-23 15:51:44 +02:00
rational.h lavu: add av_gcd_q(). 2020-05-23 15:51:44 +02:00
rc4.c
rc4.h
replaygain.h
reverse.c
reverse.h
ripemd.c lavu: add missing stddef.h includes for size_t. 2020-11-20 15:20:24 +01:00
ripemd.h lavu: add missing stddef.h includes for size_t. 2020-11-20 15:20:24 +01:00
samplefmt.c
samplefmt.h
sha512.c
sha512.h
sha.c
sha.h
slicethread.c
slicethread.h
softfloat_ieee754.h
softfloat_tables.h
softfloat.h
spherical.c avutil/spherical: Use av_strstart instead of strncmp 2021-02-28 17:14:21 +01:00
spherical.h
stereo3d.c avutil/stereo3d: Use av_strstart instead of strncmp 2021-02-28 17:14:21 +01:00
stereo3d.h
tablegen.h
tea.c
tea.h
thread.h avutil/thread: fix strict_pthread_cond_timedwait 2020-01-25 23:16:18 +01:00
threadmessage.c
threadmessage.h
time_internal.h
time.c lavu: use address-of operator checking clock_gettime 2020-12-28 01:12:26 -03:00
time.h
timecode.c avutil/timecode: Avoid fps overflow 2021-03-14 23:29:51 +01:00
timecode.h avutil/timecode: add av_timecode_init_from_components 2020-12-03 18:32:54 +01:00
timer.h libavutil/timer: Fix clang reserved-user-defined-literal 2021-03-13 11:47:43 -03:00
timestamp.h
tree.c
tree.h
twofish.c
twofish.h
tx_double.c
tx_float.c
tx_int32.c lavu/tx: implement 32 bit fixed point FFT and MDCT 2020-02-13 17:10:34 +00:00
tx_priv.h lavu/x86: add FFT assembly 2021-04-24 17:19:18 +02:00
tx_template.c checkasm: add av_tx FFT SIMD testing code 2021-04-24 17:19:17 +02:00
tx.c lavu/x86: add FFT assembly 2021-04-24 17:19:18 +02:00
tx.h lavu/tx: add full-sized iMDCT transform flag 2021-04-24 17:17:27 +02:00
utils.c Silence "string-plus-int" warning shown by clang. 2020-01-06 22:38:56 +01:00
version.h lavu: bump minor and add APIchanges entry for the lavu/tx changes 2021-04-24 17:17:28 +02:00
video_enc_params.c avutil/video_enc_params: Check for truncation before creating buffer 2021-02-19 07:45:39 +01:00
video_enc_params.h mpegvideo: use the AVVideoEncParams API for exporting QP tables 2021-01-01 14:23:19 +01:00
wchar_filename.h
xga_font_data.c
xga_font_data.h
xtea.c
xtea.h