optimization.txt 5.0 KB

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