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.

197 lines
4.4KB

  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 + r6 + 0]
  31. movh m5, [%4 + r6 + 0]
  32. %if %0 == 4
  33. %define OFFSET r6 + mmsize / 2
  34. %else
  35. ; 8x8 block and sse2, stride was provided
  36. %define OFFSET r6
  37. add r6, r5
  38. %endif
  39. movh m6, [%3 + OFFSET]
  40. movh m7, [%4 + OFFSET]
  41. %if %1 == 0
  42. ; 14bits weights
  43. punpcklbw m4, m0
  44. punpcklbw m5, m0
  45. punpcklbw m6, m0
  46. punpcklbw m7, m0
  47. psllw m4, 7
  48. psllw m5, 7
  49. psllw m6, 7
  50. psllw m7, 7
  51. pmulhw m4, m3
  52. pmulhw m5, m2
  53. pmulhw m6, m3
  54. pmulhw m7, m2
  55. paddw m4, m5
  56. paddw m6, m7
  57. %else
  58. ; 5bits weights
  59. %if cpuflag(ssse3)
  60. punpcklbw m4, m5
  61. punpcklbw m6, m7
  62. pmaddubsw m4, m3
  63. pmaddubsw m6, m3
  64. %else
  65. punpcklbw m4, m0
  66. punpcklbw m5, m0
  67. punpcklbw m6, m0
  68. punpcklbw m7, m0
  69. pmullw m4, m3
  70. pmullw m5, m2
  71. pmullw m6, m3
  72. pmullw m7, m2
  73. paddw m4, m5
  74. paddw m6, m7
  75. %endif
  76. %endif
  77. ; bias and shift down
  78. %if cpuflag(ssse3)
  79. pmulhrsw m4, m1
  80. pmulhrsw m6, m1
  81. %else
  82. paddw m4, m1
  83. paddw m6, m1
  84. psrlw m4, 5
  85. psrlw m6, 5
  86. %endif
  87. packuswb m4, m6
  88. %if %0 == 5
  89. ; Only called for 8x8 blocks and sse2
  90. sub r6, r5
  91. movh [%2 + r6], m4
  92. add r6, r5
  93. movhps [%2 + r6], m4
  94. %else
  95. mova [%2 + r6], m4
  96. %endif
  97. %endmacro
  98. %macro MAIN_LOOP 2
  99. %if mmsize == 8
  100. RV40_WCORE %2, r0, r1, r2
  101. %if %1 == 16
  102. RV40_WCORE %2, r0 + 8, r1 + 8, r2 + 8
  103. %endif
  104. ; Prepare for next loop
  105. add r6, r5
  106. %else
  107. %ifidn %1, 8
  108. RV40_WCORE %2, r0, r1, r2, r5
  109. ; Prepare 2 next lines
  110. add r6, r5
  111. %else
  112. RV40_WCORE %2, r0, r1, r2
  113. ; Prepare single next line
  114. add r6, r5
  115. %endif
  116. %endif
  117. %endmacro
  118. ; rv40_weight_func_%1(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w1, int w2, int stride)
  119. ; %1=size %2=num of xmm regs
  120. ; The weights are FP0.14 notation of fractions depending on pts.
  121. ; For timebases without rounding error (i.e. PAL), the fractions
  122. ; can be simplified, and several operations can be avoided.
  123. ; Therefore, we check here whether they are multiples of 2^9 for
  124. ; those simplifications to occur.
  125. %macro RV40_WEIGHT 3
  126. cglobal rv40_weight_func_%1_%2, 6, 7, 8
  127. %if cpuflag(ssse3)
  128. mova m1, [shift_round]
  129. %else
  130. mova m1, [pw_16]
  131. %endif
  132. pxor m0, m0
  133. ; Set loop counter and increments
  134. mov r6, r5
  135. shl r6, %3
  136. add r0, r6
  137. add r1, r6
  138. add r2, r6
  139. neg r6
  140. movd m2, r3
  141. movd m3, r4
  142. %ifidn %1,rnd
  143. %define RND 0
  144. SPLATW m2, m2
  145. %else
  146. %define RND 1
  147. %if cpuflag(ssse3)
  148. punpcklbw m3, m2
  149. %else
  150. SPLATW m2, m2
  151. %endif
  152. %endif
  153. SPLATW m3, m3
  154. .loop:
  155. MAIN_LOOP %2, RND
  156. jnz .loop
  157. REP_RET
  158. %endmacro
  159. INIT_MMX mmx
  160. RV40_WEIGHT rnd, 8, 3
  161. RV40_WEIGHT rnd, 16, 4
  162. RV40_WEIGHT nornd, 8, 3
  163. RV40_WEIGHT nornd, 16, 4
  164. INIT_XMM sse2
  165. RV40_WEIGHT rnd, 8, 3
  166. RV40_WEIGHT rnd, 16, 4
  167. RV40_WEIGHT nornd, 8, 3
  168. RV40_WEIGHT nornd, 16, 4
  169. INIT_XMM ssse3
  170. RV40_WEIGHT rnd, 8, 3
  171. RV40_WEIGHT rnd, 16, 4
  172. RV40_WEIGHT nornd, 8, 3
  173. RV40_WEIGHT nornd, 16, 4