Statistics
| Branch: | Revision:

ffmpeg / doc / optimization.txt @ 8ea9ce41

History | View | Annotate | Download (5.08 KB)

1
optimization Tips (for libavcodec):
2

    
3
What to optimize:
4
If you plan to do non-x86 architecture specific optimiztions (SIMD normally)
5
then take a look in the i386/ directory, as most important functions are
6
already optimized for MMX.
7

    
8
If you want to do x86 optimizations then you can either try to finetune the
9
stuff in the i386 directory or find some other functions in the C source to
10
optimize, but there aren't many left.
11

    
12
Understanding these overoptimized functions:
13
As many functions, like the C ones tend to be a bit unreadable currently
14
because of optimizations it is difficult to understand them (and write
15
architecture specific versions, or optimize the C functions further) it is
16
recommended to look at older CVS versions of the interesting files (just use
17
ViewCVS at http://www1.mplayerhq.hu/cgi-bin/cvsweb.cgi/ffmpeg/?cvsroot=FFMpeg)
18
or perhaps look into the other architecture-specific versions in i386/, ppc/,
19
alpha/, ... Even if you don't understand the instructions exactly it could
20
help understanding the functions & how they can be optimized.
21

    
22
NOTE: If you still don't understand some function, ask at our mailing list!!!
23
(http://www1.mplayerhq.hu/mailman/listinfo/ffmpeg-devel)
24

    
25

    
26

    
27
WTF is that function good for ....:
28
The primary purpose of that list is to avoid wasting time to optimize functions
29
which are rarely used
30

    
31
put(_no_rnd)_pixels{,_x2,_y2,_xy2}
32
    Used in motion compensation (en/decoding).
33

    
34
avg_pixels{,_x2,_y2,_xy2}
35
    Used in motion compensation of B-frames.
36
    These are less important then the put*pixels functions.
37

    
38
avg_no_rnd_pixels*
39
    unused
40

    
41
pix_abs16x16{,_x2,_y2,_xy2}
42
    Used in motion estimation (encoding) with SAD.
43

    
44
pix_abs8x8{,_x2,_y2,_xy2}
45
    Used in motion estimation (encoding) with SAD of MPEG-4 4MV only.
46
    These are less important then the pix_abs16x16* functions.
47

    
48
put_mspel8_mc* / wmv2_mspel8*
49
    Used only in WMV2.
50
    it is not recommended that you waste your time with these, as WMV2
51
    is an ugly and relatively useless codec.
52

    
53
mpeg4_qpel* / *qpel_mc*
54
    Used in MPEG-4 qpel motion compensation (encoding & decoding).
55
    The qpel8 functions are used only for 4mv,
56
    the avg_* functions are used only for B-frames.
57
    Optimizing them should have a significant impact on qpel
58
    encoding & decoding.
59

    
60
qpel{8,16}_mc??_old_c / *pixels{8,16}_l4
61
    Just used to work around a bug in an old libavcodec encoder version.
62
    Don't optimize them.
63

    
64
tpel_mc_func {put,avg}_tpel_pixels_tab
65
    Used only for SVQ3, so only optimize them if you need fast SVQ3 decoding.
66

    
67
add_bytes/diff_bytes
68
    For huffyuv only, optimize if you want a faster ffhuffyuv codec.
69

    
70
get_pixels / diff_pixels
71
    Used for encoding, easy.
72

    
73
clear_blocks
74
    easiest to optimize
75

    
76
gmc
77
    Used for MPEG-4 gmc.
78
    Optimizing this should have a significant effect on the gmc decoding
79
    speed but it's very likely impossible to write in SIMD.
80

    
81
gmc1
82
    Used for chroma blocks in MPEG-4 gmc with 1 warp point
83
    (there are 4 luma & 2 chroma blocks per macroblock, so
84
    only 1/3 of the gmc blocks use this, the other 2/3
85
    use the normal put_pixel* code, but only if there is
86
    just 1 warp point).
87
    Note: DivX5 gmc always uses just 1 warp point.
88

    
89
pix_sum
90
    Used for encoding.
91

    
92
hadamard8_diff / sse / sad == pix_norm1 / dct_sad / quant_psnr / rd / bit
93
    Specific compare functions used in encoding, it depends upon the
94
    command line switches which of these are used.
95
    Don't waste your time with dct_sad & quant_psnr, they aren't
96
    really useful.
97

    
98
put_pixels_clamped / add_pixels_clamped
99
    Used for en/decoding in the IDCT, easy.
100
    Note, some optimized IDCTs have the add/put clamped code included and
101
    then put_pixels_clamped / add_pixels_clamped will be unused.
102

    
103
idct/fdct
104
    idct (encoding & decoding)
105
    fdct (encoding)
106
    difficult to optimize
107

    
108
dct_quantize_trellis
109
    Used for encoding with trellis quantization.
110
    difficult to optimize
111

    
112
dct_quantize
113
    Used for encoding.
114

    
115
dct_unquantize_mpeg1
116
    Used in MPEG-1 en/decoding.
117

    
118
dct_unquantize_mpeg2
119
    Used in MPEG-2 en/decoding.
120

    
121
dct_unquantize_h263
122
    Used in MPEG-4/H.263 en/decoding.
123

    
124
FIXME remaining functions?
125
BTW, most of these functions are in dsputil.c/.h, some are in mpegvideo.c/.h.
126

    
127

    
128

    
129
Alignment:
130
Some instructions on some architectures have strict alignment restrictions,
131
for example most SSE/SSE2 inctructios on x86.
132
The minimum guaranteed alignment is written in the .h files, for example:
133
    void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, UINT8 *pixels/*align 8*/, int line_size);
134

    
135

    
136

    
137
Links:
138
http://www.aggregate.org/MAGIC/
139

    
140
x86-specific:
141
http://developer.intel.com/design/pentium4/manuals/248966.htm
142

    
143
The IA-32 Intel Architecture Software Developer's Manual, Volume 2:
144
Instruction Set Reference
145
http://developer.intel.com/design/pentium4/manuals/245471.htm
146

    
147
http://www.agner.org/assem/
148

    
149
AMD Athlon Processor x86 Code Optimization Guide:
150
http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/22007.pdf
151

    
152
GCC asm links:
153
official doc but quite ugly
154
http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
155

    
156
a bit old (note "+" is valid for input-output, even though the next disagrees)
157
http://www.cs.virginia.edu/~clc5q/gcc-inline-asm.pdf