You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
4.5KB

  1. ;******************************************************************************
  2. ;* MMX/SSE2-optimized functions for the RV40 decoder
  3. ;* Copyright (C) 2012 Christophe Gisquet <christophe.gisquet@gmail.com>
  4. ;*
  5. ;* This file is part of Libav.
  6. ;*
  7. ;* Libav is free software; you can redistribute it and/or
  8. ;* modify it under the terms of the GNU Lesser General Public
  9. ;* License as published by the Free Software Foundation; either
  10. ;* version 2.1 of the License, or (at your option) any later version.
  11. ;*
  12. ;* Libav is distributed in the hope that it will be useful,
  13. ;* but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. ;* Lesser General Public License for more details.
  16. ;*
  17. ;* You should have received a copy of the GNU Lesser General Public
  18. ;* License along with Libav; if not, write to the Free Software
  19. ;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. ;******************************************************************************
  21. %include "x86inc.asm"
  22. %include "x86util.asm"
  23. SECTION_RODATA
  24. align 16
  25. shift_round: times 8 dw 1 << (16 - 6)
  26. cextern pw_16
  27. SECTION .text
  28. ; %1=5bits weights?, %2=dst %3=src1 %4=src3 %5=stride if sse2
  29. %macro RV40_WCORE 4-5
  30. movh m4, [%3 + 0]
  31. movh m5, [%4 + 0]
  32. %if %0 == 4
  33. %define OFFSET mmsize / 2
  34. %else
  35. ; 8x8 block and sse2, stride was provided
  36. %define OFFSET %5
  37. %endif
  38. movh m6, [%3 + OFFSET]
  39. movh m7, [%4 + OFFSET]
  40. %if %1 == 0
  41. ; 14bits weights
  42. punpcklbw m4, m0
  43. punpcklbw m5, m0
  44. punpcklbw m6, m0
  45. punpcklbw m7, m0
  46. psllw m4, 7
  47. psllw m5, 7
  48. psllw m6, 7
  49. psllw m7, 7
  50. pmulhw m4, m3
  51. pmulhw m5, m2
  52. pmulhw m6, m3
  53. pmulhw m7, m2
  54. paddw m4, m5
  55. paddw m6, m7
  56. %else
  57. ; 5bits weights
  58. %if cpuflag(ssse3)
  59. punpcklbw m4, m5
  60. punpcklbw m6, m7
  61. pmaddubsw m4, m3
  62. pmaddubsw m6, m3
  63. %else
  64. punpcklbw m4, m0
  65. punpcklbw m5, m0
  66. punpcklbw m6, m0
  67. punpcklbw m7, m0
  68. pmullw m4, m3
  69. pmullw m5, m2
  70. pmullw m6, m3
  71. pmullw m7, m2
  72. paddw m4, m5
  73. paddw m6, m7
  74. %endif
  75. %endif
  76. ; bias and shift down
  77. %if cpuflag(ssse3)
  78. pmulhrsw m4, m1
  79. pmulhrsw m6, m1
  80. %else
  81. paddw m4, m1
  82. paddw m6, m1
  83. psrlw m4, 5
  84. psrlw m6, 5
  85. %endif
  86. packuswb m4, m6
  87. %if %0 == 5
  88. ; Only called for 8x8 blocks and sse2
  89. movh [%2 + 0], m4
  90. movhps [%2 + %5], m4
  91. %else
  92. mova [%2], m4
  93. %endif
  94. %endmacro
  95. %macro MAIN_LOOP 2
  96. %if mmsize == 8
  97. RV40_WCORE %2, r0, r1, r2
  98. %if %1 == 16
  99. RV40_WCORE %2, r0 + 8, r1 + 8, r2 + 8
  100. %endif
  101. ; Prepare for next loop
  102. add r0, r5
  103. add r1, r5
  104. add r2, r5
  105. %else
  106. %ifidn %1, 8
  107. RV40_WCORE %2, r0, r1, r2, r5
  108. ; Prepare 2 next lines
  109. lea r0, [r0 + 2 * r5]
  110. lea r1, [r1 + 2 * r5]
  111. lea r2, [r2 + 2 * r5]
  112. %else
  113. RV40_WCORE %2, r0, r1, r2
  114. ; Prepare single next line
  115. add r0, r5
  116. add r1, r5
  117. add r2, r5
  118. %endif
  119. %endif
  120. dec r6
  121. %endmacro
  122. ; rv40_weight_func_%1(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w1, int w2, int stride)
  123. ; %1=size %2=num of xmm regs
  124. ; The weights are FP0.14 notation of fractions depending on pts.
  125. ; For timebases without rounding error (i.e. PAL), the fractions
  126. ; can be simplified, and several operations can be avoided.
  127. ; Therefore, we check here whether they are multiples of 2^9 for
  128. ; those simplifications to occur.
  129. %macro RV40_WEIGHT 3
  130. cglobal rv40_weight_func_%1_%2, 6, 7, %3
  131. %if cpuflag(ssse3)
  132. mova m1, [shift_round]
  133. %else
  134. mova m1, [pw_16]
  135. %endif
  136. pxor m0, m0
  137. ; Set loop counter and increments
  138. %if mmsize == 8
  139. mov r6, %2
  140. %else
  141. mov r6, (%2 * %2) / mmsize
  142. %endif
  143. movd m2, r3
  144. movd m3, r4
  145. %ifidn %1,rnd
  146. %define RND 0
  147. SPLATW m2, m2
  148. %else
  149. %define RND 1
  150. %if cpuflag(ssse3)
  151. punpcklbw m3, m2
  152. %else
  153. SPLATW m2, m2
  154. %endif
  155. %endif
  156. SPLATW m3, m3
  157. .loop:
  158. MAIN_LOOP %2, RND
  159. jnz .loop
  160. REP_RET
  161. %endmacro
  162. INIT_MMX mmx
  163. RV40_WEIGHT rnd, 8, 3
  164. RV40_WEIGHT rnd, 16, 4
  165. RV40_WEIGHT nornd, 8, 3
  166. RV40_WEIGHT nornd, 16, 4
  167. INIT_XMM sse2
  168. RV40_WEIGHT rnd, 8, 3
  169. RV40_WEIGHT rnd, 16, 4
  170. RV40_WEIGHT nornd, 8, 3
  171. RV40_WEIGHT nornd, 16, 4
  172. INIT_XMM ssse3
  173. RV40_WEIGHT rnd, 8, 3
  174. RV40_WEIGHT rnd, 16, 4
  175. RV40_WEIGHT nornd, 8, 3
  176. RV40_WEIGHT nornd, 16, 4