optimization.txt 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. optimization Tips (for libavcodec):
  2. What to optimize:
  3. If you plan to do non-x86 architecture specific optimizations (SIMD normally),
  4. then take a look in the i386/ directory, as most important functions are
  5. already optimized for MMX.
  6. If you want to do x86 optimizations then you can either try to finetune the
  7. stuff in the i386 directory or find some other functions in the C source to
  8. optimize, but there aren't many left.
  9. Understanding these overoptimized functions:
  10. As many functions tend to be a bit difficult to understand because
  11. of optimizations, it can be hard to optimize them further, or write
  12. architecture-specific versions. It is recommened to look at older
  13. CVS versions of the interesting files (just use ViewCVS at
  14. http://www1.mplayerhq.hu/cgi-bin/cvsweb.cgi/ffmpeg/?cvsroot=FFMpeg).
  15. Alternatively, look into the other architecture-specific versions in
  16. the i386/, ppc/, alpha/ subdirectories. Even if you don't exactly
  17. comprehend the instructions, it could help understanding the functions
  18. and how they can be optimized.
  19. NOTE: If you still don't understand some function, ask at our mailing list!!!
  20. (http://www1.mplayerhq.hu/mailman/listinfo/ffmpeg-devel)
  21. WTF is that function good for ....:
  22. The primary purpose of that list is to avoid wasting time to optimize functions
  23. which are rarely used
  24. put(_no_rnd)_pixels{,_x2,_y2,_xy2}
  25. Used in motion compensation (en/decoding).
  26. avg_pixels{,_x2,_y2,_xy2}
  27. Used in motion compensation of B-frames.
  28. These are less important than the put*pixels functions.
  29. avg_no_rnd_pixels*
  30. unused
  31. pix_abs16x16{,_x2,_y2,_xy2}
  32. Used in motion estimation (encoding) with SAD.
  33. pix_abs8x8{,_x2,_y2,_xy2}
  34. Used in motion estimation (encoding) with SAD of MPEG-4 4MV only.
  35. These are less important than the pix_abs16x16* functions.
  36. put_mspel8_mc* / wmv2_mspel8*
  37. Used only in WMV2.
  38. it is not recommended that you waste your time with these, as WMV2
  39. is an ugly and relatively useless codec.
  40. mpeg4_qpel* / *qpel_mc*
  41. Used in MPEG-4 qpel motion compensation (encoding & decoding).
  42. The qpel8 functions are used only for 4mv,
  43. the avg_* functions are used only for B-frames.
  44. Optimizing them should have a significant impact on qpel
  45. encoding & decoding.
  46. qpel{8,16}_mc??_old_c / *pixels{8,16}_l4
  47. Just used to work around a bug in an old libavcodec encoder version.
  48. Don't optimize them.
  49. tpel_mc_func {put,avg}_tpel_pixels_tab
  50. Used only for SVQ3, so only optimize them if you need fast SVQ3 decoding.
  51. add_bytes/diff_bytes
  52. For huffyuv only, optimize if you want a faster ffhuffyuv codec.
  53. get_pixels / diff_pixels
  54. Used for encoding, easy.
  55. clear_blocks
  56. easiest to optimize
  57. gmc
  58. Used for MPEG-4 gmc.
  59. Optimizing this should have a significant effect on the gmc decoding
  60. speed but it's very likely impossible to write in SIMD.
  61. gmc1
  62. Used for chroma blocks in MPEG-4 gmc with 1 warp point
  63. (there are 4 luma & 2 chroma blocks per macroblock, so
  64. only 1/3 of the gmc blocks use this, the other 2/3
  65. use the normal put_pixel* code, but only if there is
  66. just 1 warp point).
  67. Note: DivX5 gmc always uses just 1 warp point.
  68. pix_sum
  69. Used for encoding.
  70. hadamard8_diff / sse / sad == pix_norm1 / dct_sad / quant_psnr / rd / bit
  71. Specific compare functions used in encoding, it depends upon the
  72. command line switches which of these are used.
  73. Don't waste your time with dct_sad & quant_psnr, they aren't
  74. really useful.
  75. put_pixels_clamped / add_pixels_clamped
  76. Used for en/decoding in the IDCT, easy.
  77. Note, some optimized IDCTs have the add/put clamped code included and
  78. then put_pixels_clamped / add_pixels_clamped will be unused.
  79. idct/fdct
  80. idct (encoding & decoding)
  81. fdct (encoding)
  82. difficult to optimize
  83. dct_quantize_trellis
  84. Used for encoding with trellis quantization.
  85. difficult to optimize
  86. dct_quantize
  87. Used for encoding.
  88. dct_unquantize_mpeg1
  89. Used in MPEG-1 en/decoding.
  90. dct_unquantize_mpeg2
  91. Used in MPEG-2 en/decoding.
  92. dct_unquantize_h263
  93. Used in MPEG-4/H.263 en/decoding.
  94. FIXME remaining functions?
  95. BTW, most of these functions are in dsputil.c/.h, some are in mpegvideo.c/.h.
  96. Alignment:
  97. Some instructions on some architectures have strict alignment restrictions,
  98. for example most SSE/SSE2 instructions on x86.
  99. The minimum guaranteed alignment is written in the .h files, for example:
  100. void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, UINT8 *pixels/*align 8*/, int line_size);
  101. Links:
  102. http://www.aggregate.org/MAGIC/
  103. x86-specific:
  104. http://developer.intel.com/design/pentium4/manuals/248966.htm
  105. The IA-32 Intel Architecture Software Developer's Manual, Volume 2:
  106. Instruction Set Reference
  107. http://developer.intel.com/design/pentium4/manuals/245471.htm
  108. http://www.agner.org/assem/
  109. AMD Athlon Processor x86 Code Optimization Guide:
  110. http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/22007.pdf
  111. GCC asm links:
  112. official doc but quite ugly
  113. http://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html
  114. a bit old (note "+" is valid for input-output, even though the next disagrees)
  115. http://www.cs.virginia.edu/~clc5q/gcc-inline-asm.pdf