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.

578 lines
26KB

  1. /*
  2. * Optimized for ia32 CPUs by Nick Kurshev <nickols_k@mail.ru>
  3. * h263, mpeg1, mpeg2 dequantizer & draw_edges by Michael Niedermayer <michaelni@gmx.at>
  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/attributes.h"
  22. #include "libavutil/cpu.h"
  23. #include "libavutil/x86/asm.h"
  24. #include "libavutil/x86/cpu.h"
  25. #include "libavcodec/avcodec.h"
  26. #include "libavcodec/mpegvideo.h"
  27. #include "dsputil_x86.h"
  28. #if HAVE_INLINE_ASM
  29. static void dct_unquantize_h263_intra_mmx(MpegEncContext *s,
  30. int16_t *block, int n, int qscale)
  31. {
  32. x86_reg level, qmul, qadd, nCoeffs;
  33. qmul = qscale << 1;
  34. assert(s->block_last_index[n]>=0 || s->h263_aic);
  35. if (!s->h263_aic) {
  36. if (n < 4)
  37. level = block[0] * s->y_dc_scale;
  38. else
  39. level = block[0] * s->c_dc_scale;
  40. qadd = (qscale - 1) | 1;
  41. }else{
  42. qadd = 0;
  43. level= block[0];
  44. }
  45. if(s->ac_pred)
  46. nCoeffs=63;
  47. else
  48. nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
  49. __asm__ volatile(
  50. "movd %1, %%mm6 \n\t" //qmul
  51. "packssdw %%mm6, %%mm6 \n\t"
  52. "packssdw %%mm6, %%mm6 \n\t"
  53. "movd %2, %%mm5 \n\t" //qadd
  54. "pxor %%mm7, %%mm7 \n\t"
  55. "packssdw %%mm5, %%mm5 \n\t"
  56. "packssdw %%mm5, %%mm5 \n\t"
  57. "psubw %%mm5, %%mm7 \n\t"
  58. "pxor %%mm4, %%mm4 \n\t"
  59. ".p2align 4 \n\t"
  60. "1: \n\t"
  61. "movq (%0, %3), %%mm0 \n\t"
  62. "movq 8(%0, %3), %%mm1 \n\t"
  63. "pmullw %%mm6, %%mm0 \n\t"
  64. "pmullw %%mm6, %%mm1 \n\t"
  65. "movq (%0, %3), %%mm2 \n\t"
  66. "movq 8(%0, %3), %%mm3 \n\t"
  67. "pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
  68. "pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
  69. "pxor %%mm2, %%mm0 \n\t"
  70. "pxor %%mm3, %%mm1 \n\t"
  71. "paddw %%mm7, %%mm0 \n\t"
  72. "paddw %%mm7, %%mm1 \n\t"
  73. "pxor %%mm0, %%mm2 \n\t"
  74. "pxor %%mm1, %%mm3 \n\t"
  75. "pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0
  76. "pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0
  77. "pandn %%mm2, %%mm0 \n\t"
  78. "pandn %%mm3, %%mm1 \n\t"
  79. "movq %%mm0, (%0, %3) \n\t"
  80. "movq %%mm1, 8(%0, %3) \n\t"
  81. "add $16, %3 \n\t"
  82. "jng 1b \n\t"
  83. ::"r" (block+nCoeffs), "rm"(qmul), "rm" (qadd), "r" (2*(-nCoeffs))
  84. : "memory"
  85. );
  86. block[0]= level;
  87. }
  88. static void dct_unquantize_h263_inter_mmx(MpegEncContext *s,
  89. int16_t *block, int n, int qscale)
  90. {
  91. x86_reg qmul, qadd, nCoeffs;
  92. qmul = qscale << 1;
  93. qadd = (qscale - 1) | 1;
  94. assert(s->block_last_index[n]>=0 || s->h263_aic);
  95. nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ];
  96. __asm__ volatile(
  97. "movd %1, %%mm6 \n\t" //qmul
  98. "packssdw %%mm6, %%mm6 \n\t"
  99. "packssdw %%mm6, %%mm6 \n\t"
  100. "movd %2, %%mm5 \n\t" //qadd
  101. "pxor %%mm7, %%mm7 \n\t"
  102. "packssdw %%mm5, %%mm5 \n\t"
  103. "packssdw %%mm5, %%mm5 \n\t"
  104. "psubw %%mm5, %%mm7 \n\t"
  105. "pxor %%mm4, %%mm4 \n\t"
  106. ".p2align 4 \n\t"
  107. "1: \n\t"
  108. "movq (%0, %3), %%mm0 \n\t"
  109. "movq 8(%0, %3), %%mm1 \n\t"
  110. "pmullw %%mm6, %%mm0 \n\t"
  111. "pmullw %%mm6, %%mm1 \n\t"
  112. "movq (%0, %3), %%mm2 \n\t"
  113. "movq 8(%0, %3), %%mm3 \n\t"
  114. "pcmpgtw %%mm4, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
  115. "pcmpgtw %%mm4, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
  116. "pxor %%mm2, %%mm0 \n\t"
  117. "pxor %%mm3, %%mm1 \n\t"
  118. "paddw %%mm7, %%mm0 \n\t"
  119. "paddw %%mm7, %%mm1 \n\t"
  120. "pxor %%mm0, %%mm2 \n\t"
  121. "pxor %%mm1, %%mm3 \n\t"
  122. "pcmpeqw %%mm7, %%mm0 \n\t" // block[i] == 0 ? -1 : 0
  123. "pcmpeqw %%mm7, %%mm1 \n\t" // block[i] == 0 ? -1 : 0
  124. "pandn %%mm2, %%mm0 \n\t"
  125. "pandn %%mm3, %%mm1 \n\t"
  126. "movq %%mm0, (%0, %3) \n\t"
  127. "movq %%mm1, 8(%0, %3) \n\t"
  128. "add $16, %3 \n\t"
  129. "jng 1b \n\t"
  130. ::"r" (block+nCoeffs), "rm"(qmul), "rm" (qadd), "r" (2*(-nCoeffs))
  131. : "memory"
  132. );
  133. }
  134. static void dct_unquantize_mpeg1_intra_mmx(MpegEncContext *s,
  135. int16_t *block, int n, int qscale)
  136. {
  137. x86_reg nCoeffs;
  138. const uint16_t *quant_matrix;
  139. int block0;
  140. assert(s->block_last_index[n]>=0);
  141. nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]+1;
  142. if (n < 4)
  143. block0 = block[0] * s->y_dc_scale;
  144. else
  145. block0 = block[0] * s->c_dc_scale;
  146. /* XXX: only mpeg1 */
  147. quant_matrix = s->intra_matrix;
  148. __asm__ volatile(
  149. "pcmpeqw %%mm7, %%mm7 \n\t"
  150. "psrlw $15, %%mm7 \n\t"
  151. "movd %2, %%mm6 \n\t"
  152. "packssdw %%mm6, %%mm6 \n\t"
  153. "packssdw %%mm6, %%mm6 \n\t"
  154. "mov %3, %%"REG_a" \n\t"
  155. ".p2align 4 \n\t"
  156. "1: \n\t"
  157. "movq (%0, %%"REG_a"), %%mm0 \n\t"
  158. "movq 8(%0, %%"REG_a"), %%mm1 \n\t"
  159. "movq (%1, %%"REG_a"), %%mm4 \n\t"
  160. "movq 8(%1, %%"REG_a"), %%mm5 \n\t"
  161. "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
  162. "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
  163. "pxor %%mm2, %%mm2 \n\t"
  164. "pxor %%mm3, %%mm3 \n\t"
  165. "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
  166. "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
  167. "pxor %%mm2, %%mm0 \n\t"
  168. "pxor %%mm3, %%mm1 \n\t"
  169. "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
  170. "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
  171. "pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
  172. "pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
  173. "pxor %%mm4, %%mm4 \n\t"
  174. "pxor %%mm5, %%mm5 \n\t" // FIXME slow
  175. "pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
  176. "pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
  177. "psraw $3, %%mm0 \n\t"
  178. "psraw $3, %%mm1 \n\t"
  179. "psubw %%mm7, %%mm0 \n\t"
  180. "psubw %%mm7, %%mm1 \n\t"
  181. "por %%mm7, %%mm0 \n\t"
  182. "por %%mm7, %%mm1 \n\t"
  183. "pxor %%mm2, %%mm0 \n\t"
  184. "pxor %%mm3, %%mm1 \n\t"
  185. "psubw %%mm2, %%mm0 \n\t"
  186. "psubw %%mm3, %%mm1 \n\t"
  187. "pandn %%mm0, %%mm4 \n\t"
  188. "pandn %%mm1, %%mm5 \n\t"
  189. "movq %%mm4, (%0, %%"REG_a") \n\t"
  190. "movq %%mm5, 8(%0, %%"REG_a") \n\t"
  191. "add $16, %%"REG_a" \n\t"
  192. "js 1b \n\t"
  193. ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "g" (-2*nCoeffs)
  194. : "%"REG_a, "memory"
  195. );
  196. block[0]= block0;
  197. }
  198. static void dct_unquantize_mpeg1_inter_mmx(MpegEncContext *s,
  199. int16_t *block, int n, int qscale)
  200. {
  201. x86_reg nCoeffs;
  202. const uint16_t *quant_matrix;
  203. assert(s->block_last_index[n]>=0);
  204. nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ]+1;
  205. quant_matrix = s->inter_matrix;
  206. __asm__ volatile(
  207. "pcmpeqw %%mm7, %%mm7 \n\t"
  208. "psrlw $15, %%mm7 \n\t"
  209. "movd %2, %%mm6 \n\t"
  210. "packssdw %%mm6, %%mm6 \n\t"
  211. "packssdw %%mm6, %%mm6 \n\t"
  212. "mov %3, %%"REG_a" \n\t"
  213. ".p2align 4 \n\t"
  214. "1: \n\t"
  215. "movq (%0, %%"REG_a"), %%mm0 \n\t"
  216. "movq 8(%0, %%"REG_a"), %%mm1 \n\t"
  217. "movq (%1, %%"REG_a"), %%mm4 \n\t"
  218. "movq 8(%1, %%"REG_a"), %%mm5 \n\t"
  219. "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
  220. "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
  221. "pxor %%mm2, %%mm2 \n\t"
  222. "pxor %%mm3, %%mm3 \n\t"
  223. "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
  224. "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
  225. "pxor %%mm2, %%mm0 \n\t"
  226. "pxor %%mm3, %%mm1 \n\t"
  227. "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
  228. "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
  229. "paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
  230. "paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
  231. "paddw %%mm7, %%mm0 \n\t" // abs(block[i])*2 + 1
  232. "paddw %%mm7, %%mm1 \n\t" // abs(block[i])*2 + 1
  233. "pmullw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
  234. "pmullw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
  235. "pxor %%mm4, %%mm4 \n\t"
  236. "pxor %%mm5, %%mm5 \n\t" // FIXME slow
  237. "pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
  238. "pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
  239. "psraw $4, %%mm0 \n\t"
  240. "psraw $4, %%mm1 \n\t"
  241. "psubw %%mm7, %%mm0 \n\t"
  242. "psubw %%mm7, %%mm1 \n\t"
  243. "por %%mm7, %%mm0 \n\t"
  244. "por %%mm7, %%mm1 \n\t"
  245. "pxor %%mm2, %%mm0 \n\t"
  246. "pxor %%mm3, %%mm1 \n\t"
  247. "psubw %%mm2, %%mm0 \n\t"
  248. "psubw %%mm3, %%mm1 \n\t"
  249. "pandn %%mm0, %%mm4 \n\t"
  250. "pandn %%mm1, %%mm5 \n\t"
  251. "movq %%mm4, (%0, %%"REG_a") \n\t"
  252. "movq %%mm5, 8(%0, %%"REG_a") \n\t"
  253. "add $16, %%"REG_a" \n\t"
  254. "js 1b \n\t"
  255. ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "g" (-2*nCoeffs)
  256. : "%"REG_a, "memory"
  257. );
  258. }
  259. static void dct_unquantize_mpeg2_intra_mmx(MpegEncContext *s,
  260. int16_t *block, int n, int qscale)
  261. {
  262. x86_reg nCoeffs;
  263. const uint16_t *quant_matrix;
  264. int block0;
  265. assert(s->block_last_index[n]>=0);
  266. if(s->alternate_scan) nCoeffs= 63; //FIXME
  267. else nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
  268. if (n < 4)
  269. block0 = block[0] * s->y_dc_scale;
  270. else
  271. block0 = block[0] * s->c_dc_scale;
  272. quant_matrix = s->intra_matrix;
  273. __asm__ volatile(
  274. "pcmpeqw %%mm7, %%mm7 \n\t"
  275. "psrlw $15, %%mm7 \n\t"
  276. "movd %2, %%mm6 \n\t"
  277. "packssdw %%mm6, %%mm6 \n\t"
  278. "packssdw %%mm6, %%mm6 \n\t"
  279. "mov %3, %%"REG_a" \n\t"
  280. ".p2align 4 \n\t"
  281. "1: \n\t"
  282. "movq (%0, %%"REG_a"), %%mm0 \n\t"
  283. "movq 8(%0, %%"REG_a"), %%mm1 \n\t"
  284. "movq (%1, %%"REG_a"), %%mm4 \n\t"
  285. "movq 8(%1, %%"REG_a"), %%mm5 \n\t"
  286. "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
  287. "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
  288. "pxor %%mm2, %%mm2 \n\t"
  289. "pxor %%mm3, %%mm3 \n\t"
  290. "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
  291. "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
  292. "pxor %%mm2, %%mm0 \n\t"
  293. "pxor %%mm3, %%mm1 \n\t"
  294. "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
  295. "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
  296. "pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*q
  297. "pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*q
  298. "pxor %%mm4, %%mm4 \n\t"
  299. "pxor %%mm5, %%mm5 \n\t" // FIXME slow
  300. "pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
  301. "pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
  302. "psraw $3, %%mm0 \n\t"
  303. "psraw $3, %%mm1 \n\t"
  304. "pxor %%mm2, %%mm0 \n\t"
  305. "pxor %%mm3, %%mm1 \n\t"
  306. "psubw %%mm2, %%mm0 \n\t"
  307. "psubw %%mm3, %%mm1 \n\t"
  308. "pandn %%mm0, %%mm4 \n\t"
  309. "pandn %%mm1, %%mm5 \n\t"
  310. "movq %%mm4, (%0, %%"REG_a") \n\t"
  311. "movq %%mm5, 8(%0, %%"REG_a") \n\t"
  312. "add $16, %%"REG_a" \n\t"
  313. "jng 1b \n\t"
  314. ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "g" (-2*nCoeffs)
  315. : "%"REG_a, "memory"
  316. );
  317. block[0]= block0;
  318. //Note, we do not do mismatch control for intra as errors cannot accumulate
  319. }
  320. static void dct_unquantize_mpeg2_inter_mmx(MpegEncContext *s,
  321. int16_t *block, int n, int qscale)
  322. {
  323. x86_reg nCoeffs;
  324. const uint16_t *quant_matrix;
  325. assert(s->block_last_index[n]>=0);
  326. if(s->alternate_scan) nCoeffs= 63; //FIXME
  327. else nCoeffs= s->intra_scantable.raster_end[ s->block_last_index[n] ];
  328. quant_matrix = s->inter_matrix;
  329. __asm__ volatile(
  330. "pcmpeqw %%mm7, %%mm7 \n\t"
  331. "psrlq $48, %%mm7 \n\t"
  332. "movd %2, %%mm6 \n\t"
  333. "packssdw %%mm6, %%mm6 \n\t"
  334. "packssdw %%mm6, %%mm6 \n\t"
  335. "mov %3, %%"REG_a" \n\t"
  336. ".p2align 4 \n\t"
  337. "1: \n\t"
  338. "movq (%0, %%"REG_a"), %%mm0 \n\t"
  339. "movq 8(%0, %%"REG_a"), %%mm1 \n\t"
  340. "movq (%1, %%"REG_a"), %%mm4 \n\t"
  341. "movq 8(%1, %%"REG_a"), %%mm5 \n\t"
  342. "pmullw %%mm6, %%mm4 \n\t" // q=qscale*quant_matrix[i]
  343. "pmullw %%mm6, %%mm5 \n\t" // q=qscale*quant_matrix[i]
  344. "pxor %%mm2, %%mm2 \n\t"
  345. "pxor %%mm3, %%mm3 \n\t"
  346. "pcmpgtw %%mm0, %%mm2 \n\t" // block[i] < 0 ? -1 : 0
  347. "pcmpgtw %%mm1, %%mm3 \n\t" // block[i] < 0 ? -1 : 0
  348. "pxor %%mm2, %%mm0 \n\t"
  349. "pxor %%mm3, %%mm1 \n\t"
  350. "psubw %%mm2, %%mm0 \n\t" // abs(block[i])
  351. "psubw %%mm3, %%mm1 \n\t" // abs(block[i])
  352. "paddw %%mm0, %%mm0 \n\t" // abs(block[i])*2
  353. "paddw %%mm1, %%mm1 \n\t" // abs(block[i])*2
  354. "pmullw %%mm4, %%mm0 \n\t" // abs(block[i])*2*q
  355. "pmullw %%mm5, %%mm1 \n\t" // abs(block[i])*2*q
  356. "paddw %%mm4, %%mm0 \n\t" // (abs(block[i])*2 + 1)*q
  357. "paddw %%mm5, %%mm1 \n\t" // (abs(block[i])*2 + 1)*q
  358. "pxor %%mm4, %%mm4 \n\t"
  359. "pxor %%mm5, %%mm5 \n\t" // FIXME slow
  360. "pcmpeqw (%0, %%"REG_a"), %%mm4 \n\t" // block[i] == 0 ? -1 : 0
  361. "pcmpeqw 8(%0, %%"REG_a"), %%mm5\n\t" // block[i] == 0 ? -1 : 0
  362. "psrlw $4, %%mm0 \n\t"
  363. "psrlw $4, %%mm1 \n\t"
  364. "pxor %%mm2, %%mm0 \n\t"
  365. "pxor %%mm3, %%mm1 \n\t"
  366. "psubw %%mm2, %%mm0 \n\t"
  367. "psubw %%mm3, %%mm1 \n\t"
  368. "pandn %%mm0, %%mm4 \n\t"
  369. "pandn %%mm1, %%mm5 \n\t"
  370. "pxor %%mm4, %%mm7 \n\t"
  371. "pxor %%mm5, %%mm7 \n\t"
  372. "movq %%mm4, (%0, %%"REG_a") \n\t"
  373. "movq %%mm5, 8(%0, %%"REG_a") \n\t"
  374. "add $16, %%"REG_a" \n\t"
  375. "jng 1b \n\t"
  376. "movd 124(%0, %3), %%mm0 \n\t"
  377. "movq %%mm7, %%mm6 \n\t"
  378. "psrlq $32, %%mm7 \n\t"
  379. "pxor %%mm6, %%mm7 \n\t"
  380. "movq %%mm7, %%mm6 \n\t"
  381. "psrlq $16, %%mm7 \n\t"
  382. "pxor %%mm6, %%mm7 \n\t"
  383. "pslld $31, %%mm7 \n\t"
  384. "psrlq $15, %%mm7 \n\t"
  385. "pxor %%mm7, %%mm0 \n\t"
  386. "movd %%mm0, 124(%0, %3) \n\t"
  387. ::"r" (block+nCoeffs), "r"(quant_matrix+nCoeffs), "rm" (qscale), "r" (-2*nCoeffs)
  388. : "%"REG_a, "memory"
  389. );
  390. }
  391. static void denoise_dct_mmx(MpegEncContext *s, int16_t *block){
  392. const int intra= s->mb_intra;
  393. int *sum= s->dct_error_sum[intra];
  394. uint16_t *offset= s->dct_offset[intra];
  395. s->dct_count[intra]++;
  396. __asm__ volatile(
  397. "pxor %%mm7, %%mm7 \n\t"
  398. "1: \n\t"
  399. "pxor %%mm0, %%mm0 \n\t"
  400. "pxor %%mm1, %%mm1 \n\t"
  401. "movq (%0), %%mm2 \n\t"
  402. "movq 8(%0), %%mm3 \n\t"
  403. "pcmpgtw %%mm2, %%mm0 \n\t"
  404. "pcmpgtw %%mm3, %%mm1 \n\t"
  405. "pxor %%mm0, %%mm2 \n\t"
  406. "pxor %%mm1, %%mm3 \n\t"
  407. "psubw %%mm0, %%mm2 \n\t"
  408. "psubw %%mm1, %%mm3 \n\t"
  409. "movq %%mm2, %%mm4 \n\t"
  410. "movq %%mm3, %%mm5 \n\t"
  411. "psubusw (%2), %%mm2 \n\t"
  412. "psubusw 8(%2), %%mm3 \n\t"
  413. "pxor %%mm0, %%mm2 \n\t"
  414. "pxor %%mm1, %%mm3 \n\t"
  415. "psubw %%mm0, %%mm2 \n\t"
  416. "psubw %%mm1, %%mm3 \n\t"
  417. "movq %%mm2, (%0) \n\t"
  418. "movq %%mm3, 8(%0) \n\t"
  419. "movq %%mm4, %%mm2 \n\t"
  420. "movq %%mm5, %%mm3 \n\t"
  421. "punpcklwd %%mm7, %%mm4 \n\t"
  422. "punpckhwd %%mm7, %%mm2 \n\t"
  423. "punpcklwd %%mm7, %%mm5 \n\t"
  424. "punpckhwd %%mm7, %%mm3 \n\t"
  425. "paddd (%1), %%mm4 \n\t"
  426. "paddd 8(%1), %%mm2 \n\t"
  427. "paddd 16(%1), %%mm5 \n\t"
  428. "paddd 24(%1), %%mm3 \n\t"
  429. "movq %%mm4, (%1) \n\t"
  430. "movq %%mm2, 8(%1) \n\t"
  431. "movq %%mm5, 16(%1) \n\t"
  432. "movq %%mm3, 24(%1) \n\t"
  433. "add $16, %0 \n\t"
  434. "add $32, %1 \n\t"
  435. "add $16, %2 \n\t"
  436. "cmp %3, %0 \n\t"
  437. " jb 1b \n\t"
  438. : "+r" (block), "+r" (sum), "+r" (offset)
  439. : "r"(block+64)
  440. );
  441. }
  442. static void denoise_dct_sse2(MpegEncContext *s, int16_t *block){
  443. const int intra= s->mb_intra;
  444. int *sum= s->dct_error_sum[intra];
  445. uint16_t *offset= s->dct_offset[intra];
  446. s->dct_count[intra]++;
  447. __asm__ volatile(
  448. "pxor %%xmm7, %%xmm7 \n\t"
  449. "1: \n\t"
  450. "pxor %%xmm0, %%xmm0 \n\t"
  451. "pxor %%xmm1, %%xmm1 \n\t"
  452. "movdqa (%0), %%xmm2 \n\t"
  453. "movdqa 16(%0), %%xmm3 \n\t"
  454. "pcmpgtw %%xmm2, %%xmm0 \n\t"
  455. "pcmpgtw %%xmm3, %%xmm1 \n\t"
  456. "pxor %%xmm0, %%xmm2 \n\t"
  457. "pxor %%xmm1, %%xmm3 \n\t"
  458. "psubw %%xmm0, %%xmm2 \n\t"
  459. "psubw %%xmm1, %%xmm3 \n\t"
  460. "movdqa %%xmm2, %%xmm4 \n\t"
  461. "movdqa %%xmm3, %%xmm5 \n\t"
  462. "psubusw (%2), %%xmm2 \n\t"
  463. "psubusw 16(%2), %%xmm3 \n\t"
  464. "pxor %%xmm0, %%xmm2 \n\t"
  465. "pxor %%xmm1, %%xmm3 \n\t"
  466. "psubw %%xmm0, %%xmm2 \n\t"
  467. "psubw %%xmm1, %%xmm3 \n\t"
  468. "movdqa %%xmm2, (%0) \n\t"
  469. "movdqa %%xmm3, 16(%0) \n\t"
  470. "movdqa %%xmm4, %%xmm6 \n\t"
  471. "movdqa %%xmm5, %%xmm0 \n\t"
  472. "punpcklwd %%xmm7, %%xmm4 \n\t"
  473. "punpckhwd %%xmm7, %%xmm6 \n\t"
  474. "punpcklwd %%xmm7, %%xmm5 \n\t"
  475. "punpckhwd %%xmm7, %%xmm0 \n\t"
  476. "paddd (%1), %%xmm4 \n\t"
  477. "paddd 16(%1), %%xmm6 \n\t"
  478. "paddd 32(%1), %%xmm5 \n\t"
  479. "paddd 48(%1), %%xmm0 \n\t"
  480. "movdqa %%xmm4, (%1) \n\t"
  481. "movdqa %%xmm6, 16(%1) \n\t"
  482. "movdqa %%xmm5, 32(%1) \n\t"
  483. "movdqa %%xmm0, 48(%1) \n\t"
  484. "add $32, %0 \n\t"
  485. "add $64, %1 \n\t"
  486. "add $32, %2 \n\t"
  487. "cmp %3, %0 \n\t"
  488. " jb 1b \n\t"
  489. : "+r" (block), "+r" (sum), "+r" (offset)
  490. : "r"(block+64)
  491. XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
  492. "%xmm4", "%xmm5", "%xmm6", "%xmm7")
  493. );
  494. }
  495. #endif /* HAVE_INLINE_ASM */
  496. av_cold void ff_MPV_common_init_x86(MpegEncContext *s)
  497. {
  498. #if HAVE_INLINE_ASM
  499. int cpu_flags = av_get_cpu_flags();
  500. if (INLINE_MMX(cpu_flags)) {
  501. s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_mmx;
  502. s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_mmx;
  503. s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_mmx;
  504. s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_mmx;
  505. if(!(s->flags & CODEC_FLAG_BITEXACT))
  506. s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_mmx;
  507. s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_mmx;
  508. s->denoise_dct = denoise_dct_mmx;
  509. }
  510. if (INLINE_SSE2(cpu_flags)) {
  511. s->denoise_dct = denoise_dct_sse2;
  512. }
  513. #endif /* HAVE_INLINE_ASM */
  514. }