Statistics
| Branch: | Revision:

ffmpeg / doc / optimization.txt @ 5e123bd3

History | View | Annotate | Download (7.24 KB)

1
optimization Tips (for libavcodec):
2
===================================
3

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

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

    
14

    
15
Understanding these overoptimized functions:
16
--------------------------------------------
17
As many functions tend to be a bit difficult to understand because
18
of optimizations, it can be hard to optimize them further, or write
19
architecture-specific versions. It is recommened to look at older
20
revisions of the interesting files (for a web frontend try ViewVC at
21
http://svn.mplayerhq.hu/ffmpeg/trunk/).
22
Alternatively, look into the other architecture-specific versions in
23
the i386/, ppc/, alpha/ subdirectories. Even if you don't exactly
24
comprehend the instructions, it could help understanding the functions
25
and how they can be optimized.
26

    
27
NOTE: If you still don't understand some function, ask at our mailing list!!!
28
(http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel)
29

    
30

    
31
What speedup justifies an optimizetion?
32
---------------------------------------
33
Normaly with clean&simple optimizations and widely used codecs a overall
34
speedup of the affected codec of 0.1% is enough. These speedups accumulate
35
and can make a big difference after a while ...
36
Also if none of the following gets worse and at least one gets better then an
37
optimization is always a good idea even if the overall gain is less than 0.1%
38
(speed, binary code size, source size, source readability)
39
For obscure codecs noone uses, the goal is more toward keeping the code clean
40
small and readable than to make it 1% faster.
41

    
42

    
43
WTF is that function good for ....:
44
-----------------------------------
45
The primary purpose of that list is to avoid wasting time to optimize functions
46
which are rarely used
47

    
48
put(_no_rnd)_pixels{,_x2,_y2,_xy2}
49
    Used in motion compensation (en/decoding).
50

    
51
avg_pixels{,_x2,_y2,_xy2}
52
    Used in motion compensation of B-frames.
53
    These are less important than the put*pixels functions.
54

    
55
avg_no_rnd_pixels*
56
    unused
57

    
58
pix_abs16x16{,_x2,_y2,_xy2}
59
    Used in motion estimation (encoding) with SAD.
60

    
61
pix_abs8x8{,_x2,_y2,_xy2}
62
    Used in motion estimation (encoding) with SAD of MPEG-4 4MV only.
63
    These are less important than the pix_abs16x16* functions.
64

    
65
put_mspel8_mc* / wmv2_mspel8*
66
    Used only in WMV2.
67
    it is not recommended that you waste your time with these, as WMV2
68
    is an ugly and relatively useless codec.
69

    
70
mpeg4_qpel* / *qpel_mc*
71
    Used in MPEG-4 qpel motion compensation (encoding & decoding).
72
    The qpel8 functions are used only for 4mv,
73
    the avg_* functions are used only for B-frames.
74
    Optimizing them should have a significant impact on qpel
75
    encoding & decoding.
76

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

    
81
tpel_mc_func {put,avg}_tpel_pixels_tab
82
    Used only for SVQ3, so only optimize them if you need fast SVQ3 decoding.
83

    
84
add_bytes/diff_bytes
85
    For huffyuv only, optimize if you want a faster ffhuffyuv codec.
86

    
87
get_pixels / diff_pixels
88
    Used for encoding, easy.
89

    
90
clear_blocks
91
    easiest to optimize
92

    
93
gmc
94
    Used for MPEG-4 gmc.
95
    Optimizing this should have a significant effect on the gmc decoding
96
    speed.
97

    
98
gmc1
99
    Used for chroma blocks in MPEG-4 gmc with 1 warp point
100
    (there are 4 luma & 2 chroma blocks per macroblock, so
101
    only 1/3 of the gmc blocks use this, the other 2/3
102
    use the normal put_pixel* code, but only if there is
103
    just 1 warp point).
104
    Note: DivX5 gmc always uses just 1 warp point.
105

    
106
pix_sum
107
    Used for encoding.
108

    
109
hadamard8_diff / sse / sad == pix_norm1 / dct_sad / quant_psnr / rd / bit
110
    Specific compare functions used in encoding, it depends upon the
111
    command line switches which of these are used.
112
    Don't waste your time with dct_sad & quant_psnr, they aren't
113
    really useful.
114

    
115
put_pixels_clamped / add_pixels_clamped
116
    Used for en/decoding in the IDCT, easy.
117
    Note, some optimized IDCTs have the add/put clamped code included and
118
    then put_pixels_clamped / add_pixels_clamped will be unused.
119

    
120
idct/fdct
121
    idct (encoding & decoding)
122
    fdct (encoding)
123
    difficult to optimize
124

    
125
dct_quantize_trellis
126
    Used for encoding with trellis quantization.
127
    difficult to optimize
128

    
129
dct_quantize
130
    Used for encoding.
131

    
132
dct_unquantize_mpeg1
133
    Used in MPEG-1 en/decoding.
134

    
135
dct_unquantize_mpeg2
136
    Used in MPEG-2 en/decoding.
137

    
138
dct_unquantize_h263
139
    Used in MPEG-4/H.263 en/decoding.
140

    
141
FIXME remaining functions?
142
BTW, most of these functions are in dsputil.c/.h, some are in mpegvideo.c/.h.
143

    
144

    
145

    
146
Alignment:
147
Some instructions on some architectures have strict alignment restrictions,
148
for example most SSE/SSE2 instructions on x86.
149
The minimum guaranteed alignment is written in the .h files, for example:
150
    void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, UINT8 *pixels/*align 8*/, int line_size);
151

    
152

    
153

    
154
Links:
155
======
156
http://www.aggregate.org/MAGIC/
157

    
158
x86-specific:
159
-------------
160
http://developer.intel.com/design/pentium4/manuals/248966.htm
161

    
162
The IA-32 Intel Architecture Software Developer's Manual, Volume 2:
163
Instruction Set Reference
164
http://developer.intel.com/design/pentium4/manuals/245471.htm
165

    
166
http://www.agner.org/assem/
167

    
168
AMD Athlon Processor x86 Code Optimization Guide:
169
http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/22007.pdf
170

    
171

    
172
ARM-specific:
173
-------------
174
ARM Architecture Reference Manual (up to ARMv5TE):
175
http://www.arm.com/community/university/eulaarmarm.html
176

    
177
Procedure Call Standard for the ARM Architecture:
178
http://www.arm.com/pdfs/aapcs.pdf
179

    
180
Optimization guide for ARM9E (used in Nokia 770 Internet Tablet):
181
http://infocenter.arm.com/help/topic/com.arm.doc.ddi0240b/DDI0240A.pdf
182
Optimization guide for ARM11 (used in Nokia N800 Internet Tablet):
183
http://infocenter.arm.com/help/topic/com.arm.doc.ddi0211j/DDI0211J_arm1136_r1p5_trm.pdf
184
Optimization guide for Intel XScale (used in Sharp Zaurus PDA):
185
http://download.intel.com/design/intelxscale/27347302.pdf
186

    
187
PowerPC-specific:
188
-----------------
189
PowerPC32/AltiVec PIM:
190
www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPEM.pdf
191

    
192
PowerPC32/AltiVec PEM:
193
www.freescale.com/files/32bit/doc/ref_manual/ALTIVECPIM.pdf
194

    
195
CELL/SPU:
196
http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/30B3520C93F437AB87257060006FFE5E/$file/Language_Extensions_for_CBEA_2.4.pdf
197
http://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/9F820A5FFA3ECE8C8725716A0062585F/$file/CBE_Handbook_v1.1_24APR2007_pub.pdf
198

    
199
SPARC-specific:
200
---------------
201
SPARC Joint Programming Specification (JPS1): Commonality
202
http://www.fujitsu.com/downloads/PRMPWR/JPS1-R1.0.4-Common-pub.pdf
203

    
204
UltraSPARC III Processor User's Manual (contains instruction timings)
205
http://www.sun.com/processors/manuals/USIIIv2.pdf
206

    
207
VIS Whitepaper (contains optimization guidelines)
208
http://www.sun.com/processors/vis/download/vis/vis_whitepaper.pdf
209

    
210
GCC asm links:
211
--------------
212
official doc but quite ugly
213
http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
214

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