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.

179 lines
4.7KB

  1. ;******************************************************************************
  2. ;* V210 SIMD pack
  3. ;* Copyright (c) 2014 Kieran Kunhya <kierank@obe.tv>
  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 "libavutil/x86/x86util.asm"
  22. SECTION_RODATA 32
  23. v210_enc_min_10: times 32 dw 0x4
  24. v210_enc_max_10: times 32 dw 0x3fb
  25. v210_enc_luma_mult_10: times 2 dw 4,1,16,4,1,16,0,0
  26. v210_enc_luma_shuf_10: times 2 db -1,0,1,-1,2,3,4,5,-1,6,7,-1,8,9,10,11
  27. v210_enc_chroma_mult_10: times 2 dw 1,4,16,0,16,1,4,0
  28. v210_enc_chroma_shuf_10: times 2 db 0,1,8,9,-1,2,3,-1,10,11,4,5,-1,12,13,-1
  29. v210_enc_min_8: times 32 db 0x1
  30. v210_enc_max_8: times 32 db 0xfe
  31. v210_enc_luma_mult_8: times 2 dw 16,4,64,16,4,64,0,0
  32. v210_enc_luma_shuf_8: times 2 db 6,-1,7,-1,8,-1,9,-1,10,-1,11,-1,-1,-1,-1,-1
  33. v210_enc_chroma_mult_8: times 2 dw 4,16,64,0,64,4,16,0
  34. v210_enc_chroma_shuf1_8: times 2 db 0,-1,1,-1,2,-1,3,-1,8,-1,9,-1,10,-1,11,-1
  35. v210_enc_chroma_shuf2_8: times 2 db 3,-1,4,-1,5,-1,7,-1,11,-1,12,-1,13,-1,15,-1
  36. SECTION .text
  37. %macro v210_planar_pack_10 0
  38. ; v210_planar_pack_10(const uint16_t *y, const uint16_t *u, const uint16_t *v, uint8_t *dst, ptrdiff_t width)
  39. cglobal v210_planar_pack_10, 5, 5, 4+cpuflag(avx2), y, u, v, dst, width
  40. lea r0, [yq+2*widthq]
  41. add uq, widthq
  42. add vq, widthq
  43. neg widthq
  44. mova m2, [v210_enc_min_10]
  45. mova m3, [v210_enc_max_10]
  46. .loop:
  47. movu xm0, [yq+2*widthq]
  48. %if cpuflag(avx2)
  49. vinserti128 m0, m0, [yq+2*widthq+12], 1
  50. %endif
  51. CLIPW m0, m2, m3
  52. movq xm1, [uq+widthq]
  53. movhps xm1, [vq+widthq]
  54. %if cpuflag(avx2)
  55. movq xm4, [uq+widthq+6]
  56. movhps xm4, [vq+widthq+6]
  57. vinserti128 m1, m1, xm4, 1
  58. %endif
  59. CLIPW m1, m2, m3
  60. pmullw m0, [v210_enc_luma_mult_10]
  61. pshufb m0, [v210_enc_luma_shuf_10]
  62. pmullw m1, [v210_enc_chroma_mult_10]
  63. pshufb m1, [v210_enc_chroma_shuf_10]
  64. por m0, m1
  65. movu [dstq], m0
  66. add dstq, mmsize
  67. add widthq, (mmsize*3)/8
  68. jl .loop
  69. RET
  70. %endmacro
  71. %if HAVE_SSSE3_EXTERNAL
  72. INIT_XMM ssse3
  73. v210_planar_pack_10
  74. %endif
  75. %if HAVE_AVX2_EXTERNAL
  76. INIT_YMM avx2
  77. v210_planar_pack_10
  78. %endif
  79. %macro v210_planar_pack_8 0
  80. ; v210_planar_pack_8(const uint8_t *y, const uint8_t *u, const uint8_t *v, uint8_t *dst, ptrdiff_t width)
  81. cglobal v210_planar_pack_8, 5, 5, 7, y, u, v, dst, width
  82. add yq, widthq
  83. shr widthq, 1
  84. add uq, widthq
  85. add vq, widthq
  86. neg widthq
  87. mova m4, [v210_enc_min_8]
  88. mova m5, [v210_enc_max_8]
  89. pxor m6, m6
  90. .loop:
  91. movu xm1, [yq+2*widthq]
  92. %if cpuflag(avx2)
  93. vinserti128 m1, m1, [yq+2*widthq+12], 1
  94. %endif
  95. CLIPUB m1, m4, m5
  96. punpcklbw m0, m1, m6
  97. ; can't unpack high bytes in the same way because we process
  98. ; only six bytes at a time
  99. pshufb m1, [v210_enc_luma_shuf_8]
  100. pmullw m0, [v210_enc_luma_mult_8]
  101. pmullw m1, [v210_enc_luma_mult_8]
  102. pshufb m0, [v210_enc_luma_shuf_10]
  103. pshufb m1, [v210_enc_luma_shuf_10]
  104. movq xm3, [uq+widthq]
  105. movhps xm3, [vq+widthq]
  106. %if cpuflag(avx2)
  107. movq xm2, [uq+widthq+6]
  108. movhps xm2, [vq+widthq+6]
  109. vinserti128 m3, m3, xm2, 1
  110. %endif
  111. CLIPUB m3, m4, m5
  112. ; shuffle and multiply to get the same packing as in 10-bit
  113. pshufb m2, m3, [v210_enc_chroma_shuf1_8]
  114. pshufb m3, [v210_enc_chroma_shuf2_8]
  115. pmullw m2, [v210_enc_chroma_mult_8]
  116. pmullw m3, [v210_enc_chroma_mult_8]
  117. pshufb m2, [v210_enc_chroma_shuf_10]
  118. pshufb m3, [v210_enc_chroma_shuf_10]
  119. por m0, m2
  120. por m1, m3
  121. movu [dstq], xm0
  122. movu [dstq+16], xm1
  123. %if cpuflag(avx2)
  124. vextracti128 [dstq+32], m0, 1
  125. vextracti128 [dstq+48], m1, 1
  126. %endif
  127. add dstq, 2*mmsize
  128. add widthq, (mmsize*3)/8
  129. jl .loop
  130. RET
  131. %endmacro
  132. %if HAVE_SSSE3_EXTERNAL
  133. INIT_XMM ssse3
  134. v210_planar_pack_8
  135. %endif
  136. %if HAVE_AVX_EXTERNAL
  137. INIT_XMM avx
  138. v210_planar_pack_8
  139. %endif
  140. %if HAVE_AVX2_EXTERNAL
  141. INIT_YMM avx2
  142. v210_planar_pack_8
  143. %endif