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.

194 lines
6.9KB

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