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.

219 lines
7.9KB

  1. /*
  2. * MMX optimized DSP utils
  3. * Copyright (c) 2007 Aurelien Jacobs <aurel@gnuage.org>
  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. #ifndef AVCODEC_X86_DSPUTIL_MMX_H
  22. #define AVCODEC_X86_DSPUTIL_MMX_H
  23. #include <stdint.h>
  24. #include "libavcodec/dsputil.h"
  25. #include "libavutil/x86_cpu.h"
  26. typedef struct { uint64_t a, b; } xmm_reg;
  27. extern const uint64_t ff_bone;
  28. extern const uint64_t ff_wtwo;
  29. extern const uint64_t ff_pdw_80000000[2];
  30. extern const xmm_reg ff_pw_3;
  31. extern const xmm_reg ff_pw_4;
  32. extern const xmm_reg ff_pw_5;
  33. extern const xmm_reg ff_pw_8;
  34. extern const uint64_t ff_pw_15;
  35. extern const xmm_reg ff_pw_16;
  36. extern const xmm_reg ff_pw_18;
  37. extern const uint64_t ff_pw_20;
  38. extern const xmm_reg ff_pw_27;
  39. extern const xmm_reg ff_pw_28;
  40. extern const xmm_reg ff_pw_32;
  41. extern const uint64_t ff_pw_42;
  42. extern const uint64_t ff_pw_53;
  43. extern const xmm_reg ff_pw_63;
  44. extern const xmm_reg ff_pw_64;
  45. extern const uint64_t ff_pw_96;
  46. extern const uint64_t ff_pw_128;
  47. extern const uint64_t ff_pw_255;
  48. extern const xmm_reg ff_pb_1;
  49. extern const xmm_reg ff_pb_3;
  50. extern const uint64_t ff_pb_7;
  51. extern const uint64_t ff_pb_1F;
  52. extern const uint64_t ff_pb_3F;
  53. extern const uint64_t ff_pb_81;
  54. extern const xmm_reg ff_pb_A1;
  55. extern const xmm_reg ff_pb_F8;
  56. extern const uint64_t ff_pb_FC;
  57. extern const xmm_reg ff_pb_FE;
  58. extern const double ff_pd_1[2];
  59. extern const double ff_pd_2[2];
  60. #define LOAD4(stride,in,a,b,c,d)\
  61. "movq 0*"#stride"+"#in", "#a"\n\t"\
  62. "movq 1*"#stride"+"#in", "#b"\n\t"\
  63. "movq 2*"#stride"+"#in", "#c"\n\t"\
  64. "movq 3*"#stride"+"#in", "#d"\n\t"
  65. #define STORE4(stride,out,a,b,c,d)\
  66. "movq "#a", 0*"#stride"+"#out"\n\t"\
  67. "movq "#b", 1*"#stride"+"#out"\n\t"\
  68. "movq "#c", 2*"#stride"+"#out"\n\t"\
  69. "movq "#d", 3*"#stride"+"#out"\n\t"
  70. /* in/out: mma=mma+mmb, mmb=mmb-mma */
  71. #define SUMSUB_BA( a, b ) \
  72. "paddw "#b", "#a" \n\t"\
  73. "paddw "#b", "#b" \n\t"\
  74. "psubw "#a", "#b" \n\t"
  75. #define SBUTTERFLY(a,b,t,n,m)\
  76. "mov" #m " " #a ", " #t " \n\t" /* abcd */\
  77. "punpckl" #n " " #b ", " #a " \n\t" /* aebf */\
  78. "punpckh" #n " " #b ", " #t " \n\t" /* cgdh */\
  79. #define TRANSPOSE4(a,b,c,d,t)\
  80. SBUTTERFLY(a,b,t,wd,q) /* a=aebf t=cgdh */\
  81. SBUTTERFLY(c,d,b,wd,q) /* c=imjn b=kolp */\
  82. SBUTTERFLY(a,c,d,dq,q) /* a=aeim d=bfjn */\
  83. SBUTTERFLY(t,b,c,dq,q) /* t=cgko c=dhlp */
  84. static inline void transpose4x4(uint8_t *dst, uint8_t *src, x86_reg dst_stride, x86_reg src_stride){
  85. __asm__ volatile( //FIXME could save 1 instruction if done as 8x4 ...
  86. "movd (%1), %%mm0 \n\t"
  87. "add %3, %1 \n\t"
  88. "movd (%1), %%mm1 \n\t"
  89. "movd (%1,%3,1), %%mm2 \n\t"
  90. "movd (%1,%3,2), %%mm3 \n\t"
  91. "punpcklbw %%mm1, %%mm0 \n\t"
  92. "punpcklbw %%mm3, %%mm2 \n\t"
  93. "movq %%mm0, %%mm1 \n\t"
  94. "punpcklwd %%mm2, %%mm0 \n\t"
  95. "punpckhwd %%mm2, %%mm1 \n\t"
  96. "movd %%mm0, (%0) \n\t"
  97. "add %2, %0 \n\t"
  98. "punpckhdq %%mm0, %%mm0 \n\t"
  99. "movd %%mm0, (%0) \n\t"
  100. "movd %%mm1, (%0,%2,1) \n\t"
  101. "punpckhdq %%mm1, %%mm1 \n\t"
  102. "movd %%mm1, (%0,%2,2) \n\t"
  103. : "+&r" (dst),
  104. "+&r" (src)
  105. : "r" (dst_stride),
  106. "r" (src_stride)
  107. : "memory"
  108. );
  109. }
  110. // e,f,g,h can be memory
  111. // out: a,d,t,c
  112. #define TRANSPOSE8x4(a,b,c,d,e,f,g,h,t)\
  113. "punpcklbw " #e ", " #a " \n\t" /* a0 e0 a1 e1 a2 e2 a3 e3 */\
  114. "punpcklbw " #f ", " #b " \n\t" /* b0 f0 b1 f1 b2 f2 b3 f3 */\
  115. "punpcklbw " #g ", " #c " \n\t" /* c0 g0 c1 g1 c2 g2 d3 g3 */\
  116. "punpcklbw " #h ", " #d " \n\t" /* d0 h0 d1 h1 d2 h2 d3 h3 */\
  117. SBUTTERFLY(a, b, t, bw, q) /* a= a0 b0 e0 f0 a1 b1 e1 f1 */\
  118. /* t= a2 b2 e2 f2 a3 b3 e3 f3 */\
  119. SBUTTERFLY(c, d, b, bw, q) /* c= c0 d0 g0 h0 c1 d1 g1 h1 */\
  120. /* b= c2 d2 g2 h2 c3 d3 g3 h3 */\
  121. SBUTTERFLY(a, c, d, wd, q) /* a= a0 b0 c0 d0 e0 f0 g0 h0 */\
  122. /* d= a1 b1 c1 d1 e1 f1 g1 h1 */\
  123. SBUTTERFLY(t, b, c, wd, q) /* t= a2 b2 c2 d2 e2 f2 g2 h2 */\
  124. /* c= a3 b3 c3 d3 e3 f3 g3 h3 */
  125. #if ARCH_X86_64
  126. // permutes 01234567 -> 05736421
  127. #define TRANSPOSE8(a,b,c,d,e,f,g,h,t)\
  128. SBUTTERFLY(a,b,%%xmm8,wd,dqa)\
  129. SBUTTERFLY(c,d,b,wd,dqa)\
  130. SBUTTERFLY(e,f,d,wd,dqa)\
  131. SBUTTERFLY(g,h,f,wd,dqa)\
  132. SBUTTERFLY(a,c,h,dq,dqa)\
  133. SBUTTERFLY(%%xmm8,b,c,dq,dqa)\
  134. SBUTTERFLY(e,g,b,dq,dqa)\
  135. SBUTTERFLY(d,f,g,dq,dqa)\
  136. SBUTTERFLY(a,e,f,qdq,dqa)\
  137. SBUTTERFLY(%%xmm8,d,e,qdq,dqa)\
  138. SBUTTERFLY(h,b,d,qdq,dqa)\
  139. SBUTTERFLY(c,g,b,qdq,dqa)\
  140. "movdqa %%xmm8, "#g" \n\t"
  141. #else
  142. #define TRANSPOSE8(a,b,c,d,e,f,g,h,t)\
  143. "movdqa "#h", "#t" \n\t"\
  144. SBUTTERFLY(a,b,h,wd,dqa)\
  145. "movdqa "#h", 16"#t" \n\t"\
  146. "movdqa "#t", "#h" \n\t"\
  147. SBUTTERFLY(c,d,b,wd,dqa)\
  148. SBUTTERFLY(e,f,d,wd,dqa)\
  149. SBUTTERFLY(g,h,f,wd,dqa)\
  150. SBUTTERFLY(a,c,h,dq,dqa)\
  151. "movdqa "#h", "#t" \n\t"\
  152. "movdqa 16"#t", "#h" \n\t"\
  153. SBUTTERFLY(h,b,c,dq,dqa)\
  154. SBUTTERFLY(e,g,b,dq,dqa)\
  155. SBUTTERFLY(d,f,g,dq,dqa)\
  156. SBUTTERFLY(a,e,f,qdq,dqa)\
  157. SBUTTERFLY(h,d,e,qdq,dqa)\
  158. "movdqa "#h", 16"#t" \n\t"\
  159. "movdqa "#t", "#h" \n\t"\
  160. SBUTTERFLY(h,b,d,qdq,dqa)\
  161. SBUTTERFLY(c,g,b,qdq,dqa)\
  162. "movdqa 16"#t", "#g" \n\t"
  163. #endif
  164. #define MOVQ_WONE(regd) \
  165. __asm__ volatile ( \
  166. "pcmpeqd %%" #regd ", %%" #regd " \n\t" \
  167. "psrlw $15, %%" #regd ::)
  168. void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx);
  169. void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx);
  170. void ff_add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
  171. void ff_put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
  172. void ff_put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size);
  173. void ff_put_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride);
  174. void ff_avg_cavs_qpel8_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride);
  175. void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride);
  176. void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride);
  177. void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd);
  178. void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd);
  179. void ff_mmx_idct(DCTELEM *block);
  180. void ff_mmxext_idct(DCTELEM *block);
  181. void ff_deinterlace_line_mmx(uint8_t *dst,
  182. const uint8_t *lum_m4, const uint8_t *lum_m3,
  183. const uint8_t *lum_m2, const uint8_t *lum_m1,
  184. const uint8_t *lum,
  185. int size);
  186. void ff_deinterlace_line_inplace_mmx(const uint8_t *lum_m4,
  187. const uint8_t *lum_m3,
  188. const uint8_t *lum_m2,
  189. const uint8_t *lum_m1,
  190. const uint8_t *lum, int size);
  191. #endif /* AVCODEC_X86_DSPUTIL_MMX_H */