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.

208 lines
4.6KB

  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. %macro RV40_WEIGHT 2
  125. cglobal rv40_weight_func_%1, 6, 7, %2
  126. %if cpuflag(ssse3)
  127. mova m1, [shift_round]
  128. %else
  129. mova m1, [pw_16]
  130. %endif
  131. pxor m0, m0
  132. mov r6, r3
  133. or r6, r4
  134. ; The weights are FP0.14 notation of fractions depending on pts.
  135. ; For timebases without rounding error (i.e. PAL), the fractions
  136. ; can be simplified, and several operations can be avoided.
  137. ; Therefore, we check here whether they are multiples of 2^9 for
  138. ; those simplifications to occur.
  139. and r6, 0x1FF
  140. ; Set loop counter and increments
  141. %if mmsize == 8
  142. mov r6, %1
  143. %else
  144. mov r6, (%1 * %1) / mmsize
  145. %endif
  146. ; Use result of test now
  147. jz .loop_512
  148. movd m2, r3
  149. movd m3, r4
  150. SPLATW m2, m2
  151. SPLATW m3, m3
  152. .loop:
  153. MAIN_LOOP %1, 0
  154. jnz .loop
  155. REP_RET
  156. ; Weights are multiple of 512, which allows some shortcuts
  157. .loop_512:
  158. sar r3, 9
  159. sar r4, 9
  160. movd m2, r3
  161. movd m3, r4
  162. %if cpuflag(ssse3)
  163. punpcklbw m3, m2
  164. SPLATW m3, m3
  165. %else
  166. SPLATW m2, m2
  167. SPLATW m3, m3
  168. %endif
  169. .loop2:
  170. MAIN_LOOP %1, 1
  171. jnz .loop2
  172. REP_RET
  173. %endmacro
  174. INIT_MMX mmx
  175. RV40_WEIGHT 8, 0
  176. RV40_WEIGHT 16, 0
  177. INIT_XMM sse2
  178. RV40_WEIGHT 8, 8
  179. RV40_WEIGHT 16, 8
  180. INIT_XMM ssse3
  181. RV40_WEIGHT 8, 8
  182. RV40_WEIGHT 16, 8