dsputilenc_mmx.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. /*
  2. * MMX optimized DSP utils
  3. * Copyright (c) 2000, 2001 Fabrice Bellard
  4. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. *
  6. * MMX optimization by Nick Kurshev <nickols_k@mail.ru>
  7. *
  8. * This file is part of FFmpeg.
  9. *
  10. * FFmpeg is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * FFmpeg is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with FFmpeg; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #include "libavutil/attributes.h"
  25. #include "libavutil/cpu.h"
  26. #include "libavutil/x86/asm.h"
  27. #include "libavutil/x86/cpu.h"
  28. #include "libavcodec/dct.h"
  29. #include "libavcodec/dsputil.h"
  30. #include "libavcodec/mpegvideo.h"
  31. #include "libavcodec/mathops.h"
  32. #include "dsputil_x86.h"
  33. void ff_get_pixels_mmx(int16_t *block, const uint8_t *pixels, int line_size);
  34. void ff_get_pixels_sse2(int16_t *block, const uint8_t *pixels, int line_size);
  35. void ff_diff_pixels_mmx(int16_t *block, const uint8_t *s1, const uint8_t *s2, int stride);
  36. int ff_pix_sum16_mmx(uint8_t * pix, int line_size);
  37. int ff_pix_norm1_mmx(uint8_t *pix, int line_size);
  38. #if HAVE_INLINE_ASM
  39. static int sse8_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
  40. int tmp;
  41. __asm__ volatile (
  42. "movl %4,%%ecx\n"
  43. "shr $1,%%ecx\n"
  44. "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
  45. "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
  46. "1:\n"
  47. "movq (%0),%%mm1\n" /* mm1 = pix1[0][0-7] */
  48. "movq (%1),%%mm2\n" /* mm2 = pix2[0][0-7] */
  49. "movq (%0,%3),%%mm3\n" /* mm3 = pix1[1][0-7] */
  50. "movq (%1,%3),%%mm4\n" /* mm4 = pix2[1][0-7] */
  51. /* todo: mm1-mm2, mm3-mm4 */
  52. /* algo: subtract mm1 from mm2 with saturation and vice versa */
  53. /* OR the results to get absolute difference */
  54. "movq %%mm1,%%mm5\n"
  55. "movq %%mm3,%%mm6\n"
  56. "psubusb %%mm2,%%mm1\n"
  57. "psubusb %%mm4,%%mm3\n"
  58. "psubusb %%mm5,%%mm2\n"
  59. "psubusb %%mm6,%%mm4\n"
  60. "por %%mm1,%%mm2\n"
  61. "por %%mm3,%%mm4\n"
  62. /* now convert to 16-bit vectors so we can square them */
  63. "movq %%mm2,%%mm1\n"
  64. "movq %%mm4,%%mm3\n"
  65. "punpckhbw %%mm0,%%mm2\n"
  66. "punpckhbw %%mm0,%%mm4\n"
  67. "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
  68. "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
  69. "pmaddwd %%mm2,%%mm2\n"
  70. "pmaddwd %%mm4,%%mm4\n"
  71. "pmaddwd %%mm1,%%mm1\n"
  72. "pmaddwd %%mm3,%%mm3\n"
  73. "lea (%0,%3,2), %0\n" /* pix1 += 2*line_size */
  74. "lea (%1,%3,2), %1\n" /* pix2 += 2*line_size */
  75. "paddd %%mm2,%%mm1\n"
  76. "paddd %%mm4,%%mm3\n"
  77. "paddd %%mm1,%%mm7\n"
  78. "paddd %%mm3,%%mm7\n"
  79. "decl %%ecx\n"
  80. "jnz 1b\n"
  81. "movq %%mm7,%%mm1\n"
  82. "psrlq $32, %%mm7\n" /* shift hi dword to lo */
  83. "paddd %%mm7,%%mm1\n"
  84. "movd %%mm1,%2\n"
  85. : "+r" (pix1), "+r" (pix2), "=r"(tmp)
  86. : "r" ((x86_reg)line_size) , "m" (h)
  87. : "%ecx");
  88. return tmp;
  89. }
  90. static int sse16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
  91. int tmp;
  92. __asm__ volatile (
  93. "movl %4,%%ecx\n"
  94. "pxor %%mm0,%%mm0\n" /* mm0 = 0 */
  95. "pxor %%mm7,%%mm7\n" /* mm7 holds the sum */
  96. "1:\n"
  97. "movq (%0),%%mm1\n" /* mm1 = pix1[0-7] */
  98. "movq (%1),%%mm2\n" /* mm2 = pix2[0-7] */
  99. "movq 8(%0),%%mm3\n" /* mm3 = pix1[8-15] */
  100. "movq 8(%1),%%mm4\n" /* mm4 = pix2[8-15] */
  101. /* todo: mm1-mm2, mm3-mm4 */
  102. /* algo: subtract mm1 from mm2 with saturation and vice versa */
  103. /* OR the results to get absolute difference */
  104. "movq %%mm1,%%mm5\n"
  105. "movq %%mm3,%%mm6\n"
  106. "psubusb %%mm2,%%mm1\n"
  107. "psubusb %%mm4,%%mm3\n"
  108. "psubusb %%mm5,%%mm2\n"
  109. "psubusb %%mm6,%%mm4\n"
  110. "por %%mm1,%%mm2\n"
  111. "por %%mm3,%%mm4\n"
  112. /* now convert to 16-bit vectors so we can square them */
  113. "movq %%mm2,%%mm1\n"
  114. "movq %%mm4,%%mm3\n"
  115. "punpckhbw %%mm0,%%mm2\n"
  116. "punpckhbw %%mm0,%%mm4\n"
  117. "punpcklbw %%mm0,%%mm1\n" /* mm1 now spread over (mm1,mm2) */
  118. "punpcklbw %%mm0,%%mm3\n" /* mm4 now spread over (mm3,mm4) */
  119. "pmaddwd %%mm2,%%mm2\n"
  120. "pmaddwd %%mm4,%%mm4\n"
  121. "pmaddwd %%mm1,%%mm1\n"
  122. "pmaddwd %%mm3,%%mm3\n"
  123. "add %3,%0\n"
  124. "add %3,%1\n"
  125. "paddd %%mm2,%%mm1\n"
  126. "paddd %%mm4,%%mm3\n"
  127. "paddd %%mm1,%%mm7\n"
  128. "paddd %%mm3,%%mm7\n"
  129. "decl %%ecx\n"
  130. "jnz 1b\n"
  131. "movq %%mm7,%%mm1\n"
  132. "psrlq $32, %%mm7\n" /* shift hi dword to lo */
  133. "paddd %%mm7,%%mm1\n"
  134. "movd %%mm1,%2\n"
  135. : "+r" (pix1), "+r" (pix2), "=r"(tmp)
  136. : "r" ((x86_reg)line_size) , "m" (h)
  137. : "%ecx");
  138. return tmp;
  139. }
  140. static int hf_noise8_mmx(uint8_t * pix1, int line_size, int h) {
  141. int tmp;
  142. __asm__ volatile (
  143. "movl %3,%%ecx\n"
  144. "pxor %%mm7,%%mm7\n"
  145. "pxor %%mm6,%%mm6\n"
  146. "movq (%0),%%mm0\n"
  147. "movq %%mm0, %%mm1\n"
  148. "psllq $8, %%mm0\n"
  149. "psrlq $8, %%mm1\n"
  150. "psrlq $8, %%mm0\n"
  151. "movq %%mm0, %%mm2\n"
  152. "movq %%mm1, %%mm3\n"
  153. "punpcklbw %%mm7,%%mm0\n"
  154. "punpcklbw %%mm7,%%mm1\n"
  155. "punpckhbw %%mm7,%%mm2\n"
  156. "punpckhbw %%mm7,%%mm3\n"
  157. "psubw %%mm1, %%mm0\n"
  158. "psubw %%mm3, %%mm2\n"
  159. "add %2,%0\n"
  160. "movq (%0),%%mm4\n"
  161. "movq %%mm4, %%mm1\n"
  162. "psllq $8, %%mm4\n"
  163. "psrlq $8, %%mm1\n"
  164. "psrlq $8, %%mm4\n"
  165. "movq %%mm4, %%mm5\n"
  166. "movq %%mm1, %%mm3\n"
  167. "punpcklbw %%mm7,%%mm4\n"
  168. "punpcklbw %%mm7,%%mm1\n"
  169. "punpckhbw %%mm7,%%mm5\n"
  170. "punpckhbw %%mm7,%%mm3\n"
  171. "psubw %%mm1, %%mm4\n"
  172. "psubw %%mm3, %%mm5\n"
  173. "psubw %%mm4, %%mm0\n"
  174. "psubw %%mm5, %%mm2\n"
  175. "pxor %%mm3, %%mm3\n"
  176. "pxor %%mm1, %%mm1\n"
  177. "pcmpgtw %%mm0, %%mm3\n\t"
  178. "pcmpgtw %%mm2, %%mm1\n\t"
  179. "pxor %%mm3, %%mm0\n"
  180. "pxor %%mm1, %%mm2\n"
  181. "psubw %%mm3, %%mm0\n"
  182. "psubw %%mm1, %%mm2\n"
  183. "paddw %%mm0, %%mm2\n"
  184. "paddw %%mm2, %%mm6\n"
  185. "add %2,%0\n"
  186. "1:\n"
  187. "movq (%0),%%mm0\n"
  188. "movq %%mm0, %%mm1\n"
  189. "psllq $8, %%mm0\n"
  190. "psrlq $8, %%mm1\n"
  191. "psrlq $8, %%mm0\n"
  192. "movq %%mm0, %%mm2\n"
  193. "movq %%mm1, %%mm3\n"
  194. "punpcklbw %%mm7,%%mm0\n"
  195. "punpcklbw %%mm7,%%mm1\n"
  196. "punpckhbw %%mm7,%%mm2\n"
  197. "punpckhbw %%mm7,%%mm3\n"
  198. "psubw %%mm1, %%mm0\n"
  199. "psubw %%mm3, %%mm2\n"
  200. "psubw %%mm0, %%mm4\n"
  201. "psubw %%mm2, %%mm5\n"
  202. "pxor %%mm3, %%mm3\n"
  203. "pxor %%mm1, %%mm1\n"
  204. "pcmpgtw %%mm4, %%mm3\n\t"
  205. "pcmpgtw %%mm5, %%mm1\n\t"
  206. "pxor %%mm3, %%mm4\n"
  207. "pxor %%mm1, %%mm5\n"
  208. "psubw %%mm3, %%mm4\n"
  209. "psubw %%mm1, %%mm5\n"
  210. "paddw %%mm4, %%mm5\n"
  211. "paddw %%mm5, %%mm6\n"
  212. "add %2,%0\n"
  213. "movq (%0),%%mm4\n"
  214. "movq %%mm4, %%mm1\n"
  215. "psllq $8, %%mm4\n"
  216. "psrlq $8, %%mm1\n"
  217. "psrlq $8, %%mm4\n"
  218. "movq %%mm4, %%mm5\n"
  219. "movq %%mm1, %%mm3\n"
  220. "punpcklbw %%mm7,%%mm4\n"
  221. "punpcklbw %%mm7,%%mm1\n"
  222. "punpckhbw %%mm7,%%mm5\n"
  223. "punpckhbw %%mm7,%%mm3\n"
  224. "psubw %%mm1, %%mm4\n"
  225. "psubw %%mm3, %%mm5\n"
  226. "psubw %%mm4, %%mm0\n"
  227. "psubw %%mm5, %%mm2\n"
  228. "pxor %%mm3, %%mm3\n"
  229. "pxor %%mm1, %%mm1\n"
  230. "pcmpgtw %%mm0, %%mm3\n\t"
  231. "pcmpgtw %%mm2, %%mm1\n\t"
  232. "pxor %%mm3, %%mm0\n"
  233. "pxor %%mm1, %%mm2\n"
  234. "psubw %%mm3, %%mm0\n"
  235. "psubw %%mm1, %%mm2\n"
  236. "paddw %%mm0, %%mm2\n"
  237. "paddw %%mm2, %%mm6\n"
  238. "add %2,%0\n"
  239. "subl $2, %%ecx\n"
  240. " jnz 1b\n"
  241. "movq %%mm6, %%mm0\n"
  242. "punpcklwd %%mm7,%%mm0\n"
  243. "punpckhwd %%mm7,%%mm6\n"
  244. "paddd %%mm0, %%mm6\n"
  245. "movq %%mm6,%%mm0\n"
  246. "psrlq $32, %%mm6\n"
  247. "paddd %%mm6,%%mm0\n"
  248. "movd %%mm0,%1\n"
  249. : "+r" (pix1), "=r"(tmp)
  250. : "r" ((x86_reg)line_size) , "g" (h-2)
  251. : "%ecx");
  252. return tmp;
  253. }
  254. static int hf_noise16_mmx(uint8_t * pix1, int line_size, int h) {
  255. int tmp;
  256. uint8_t * pix= pix1;
  257. __asm__ volatile (
  258. "movl %3,%%ecx\n"
  259. "pxor %%mm7,%%mm7\n"
  260. "pxor %%mm6,%%mm6\n"
  261. "movq (%0),%%mm0\n"
  262. "movq 1(%0),%%mm1\n"
  263. "movq %%mm0, %%mm2\n"
  264. "movq %%mm1, %%mm3\n"
  265. "punpcklbw %%mm7,%%mm0\n"
  266. "punpcklbw %%mm7,%%mm1\n"
  267. "punpckhbw %%mm7,%%mm2\n"
  268. "punpckhbw %%mm7,%%mm3\n"
  269. "psubw %%mm1, %%mm0\n"
  270. "psubw %%mm3, %%mm2\n"
  271. "add %2,%0\n"
  272. "movq (%0),%%mm4\n"
  273. "movq 1(%0),%%mm1\n"
  274. "movq %%mm4, %%mm5\n"
  275. "movq %%mm1, %%mm3\n"
  276. "punpcklbw %%mm7,%%mm4\n"
  277. "punpcklbw %%mm7,%%mm1\n"
  278. "punpckhbw %%mm7,%%mm5\n"
  279. "punpckhbw %%mm7,%%mm3\n"
  280. "psubw %%mm1, %%mm4\n"
  281. "psubw %%mm3, %%mm5\n"
  282. "psubw %%mm4, %%mm0\n"
  283. "psubw %%mm5, %%mm2\n"
  284. "pxor %%mm3, %%mm3\n"
  285. "pxor %%mm1, %%mm1\n"
  286. "pcmpgtw %%mm0, %%mm3\n\t"
  287. "pcmpgtw %%mm2, %%mm1\n\t"
  288. "pxor %%mm3, %%mm0\n"
  289. "pxor %%mm1, %%mm2\n"
  290. "psubw %%mm3, %%mm0\n"
  291. "psubw %%mm1, %%mm2\n"
  292. "paddw %%mm0, %%mm2\n"
  293. "paddw %%mm2, %%mm6\n"
  294. "add %2,%0\n"
  295. "1:\n"
  296. "movq (%0),%%mm0\n"
  297. "movq 1(%0),%%mm1\n"
  298. "movq %%mm0, %%mm2\n"
  299. "movq %%mm1, %%mm3\n"
  300. "punpcklbw %%mm7,%%mm0\n"
  301. "punpcklbw %%mm7,%%mm1\n"
  302. "punpckhbw %%mm7,%%mm2\n"
  303. "punpckhbw %%mm7,%%mm3\n"
  304. "psubw %%mm1, %%mm0\n"
  305. "psubw %%mm3, %%mm2\n"
  306. "psubw %%mm0, %%mm4\n"
  307. "psubw %%mm2, %%mm5\n"
  308. "pxor %%mm3, %%mm3\n"
  309. "pxor %%mm1, %%mm1\n"
  310. "pcmpgtw %%mm4, %%mm3\n\t"
  311. "pcmpgtw %%mm5, %%mm1\n\t"
  312. "pxor %%mm3, %%mm4\n"
  313. "pxor %%mm1, %%mm5\n"
  314. "psubw %%mm3, %%mm4\n"
  315. "psubw %%mm1, %%mm5\n"
  316. "paddw %%mm4, %%mm5\n"
  317. "paddw %%mm5, %%mm6\n"
  318. "add %2,%0\n"
  319. "movq (%0),%%mm4\n"
  320. "movq 1(%0),%%mm1\n"
  321. "movq %%mm4, %%mm5\n"
  322. "movq %%mm1, %%mm3\n"
  323. "punpcklbw %%mm7,%%mm4\n"
  324. "punpcklbw %%mm7,%%mm1\n"
  325. "punpckhbw %%mm7,%%mm5\n"
  326. "punpckhbw %%mm7,%%mm3\n"
  327. "psubw %%mm1, %%mm4\n"
  328. "psubw %%mm3, %%mm5\n"
  329. "psubw %%mm4, %%mm0\n"
  330. "psubw %%mm5, %%mm2\n"
  331. "pxor %%mm3, %%mm3\n"
  332. "pxor %%mm1, %%mm1\n"
  333. "pcmpgtw %%mm0, %%mm3\n\t"
  334. "pcmpgtw %%mm2, %%mm1\n\t"
  335. "pxor %%mm3, %%mm0\n"
  336. "pxor %%mm1, %%mm2\n"
  337. "psubw %%mm3, %%mm0\n"
  338. "psubw %%mm1, %%mm2\n"
  339. "paddw %%mm0, %%mm2\n"
  340. "paddw %%mm2, %%mm6\n"
  341. "add %2,%0\n"
  342. "subl $2, %%ecx\n"
  343. " jnz 1b\n"
  344. "movq %%mm6, %%mm0\n"
  345. "punpcklwd %%mm7,%%mm0\n"
  346. "punpckhwd %%mm7,%%mm6\n"
  347. "paddd %%mm0, %%mm6\n"
  348. "movq %%mm6,%%mm0\n"
  349. "psrlq $32, %%mm6\n"
  350. "paddd %%mm6,%%mm0\n"
  351. "movd %%mm0,%1\n"
  352. : "+r" (pix1), "=r"(tmp)
  353. : "r" ((x86_reg)line_size) , "g" (h-2)
  354. : "%ecx");
  355. return tmp + hf_noise8_mmx(pix+8, line_size, h);
  356. }
  357. static int nsse16_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
  358. MpegEncContext *c = p;
  359. int score1, score2;
  360. if(c) score1 = c->dsp.sse[0](c, pix1, pix2, line_size, h);
  361. else score1 = sse16_mmx(c, pix1, pix2, line_size, h);
  362. score2= hf_noise16_mmx(pix1, line_size, h) - hf_noise16_mmx(pix2, line_size, h);
  363. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  364. else return score1 + FFABS(score2)*8;
  365. }
  366. static int nsse8_mmx(void *p, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
  367. MpegEncContext *c = p;
  368. int score1= sse8_mmx(c, pix1, pix2, line_size, h);
  369. int score2= hf_noise8_mmx(pix1, line_size, h) - hf_noise8_mmx(pix2, line_size, h);
  370. if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight;
  371. else return score1 + FFABS(score2)*8;
  372. }
  373. static int vsad_intra16_mmx(void *v, uint8_t * pix, uint8_t * dummy, int line_size, int h) {
  374. int tmp;
  375. av_assert2( (((int)pix) & 7) == 0);
  376. av_assert2((line_size &7) ==0);
  377. #define SUM(in0, in1, out0, out1) \
  378. "movq (%0), %%mm2\n"\
  379. "movq 8(%0), %%mm3\n"\
  380. "add %2,%0\n"\
  381. "movq %%mm2, " #out0 "\n"\
  382. "movq %%mm3, " #out1 "\n"\
  383. "psubusb " #in0 ", %%mm2\n"\
  384. "psubusb " #in1 ", %%mm3\n"\
  385. "psubusb " #out0 ", " #in0 "\n"\
  386. "psubusb " #out1 ", " #in1 "\n"\
  387. "por %%mm2, " #in0 "\n"\
  388. "por %%mm3, " #in1 "\n"\
  389. "movq " #in0 ", %%mm2\n"\
  390. "movq " #in1 ", %%mm3\n"\
  391. "punpcklbw %%mm7, " #in0 "\n"\
  392. "punpcklbw %%mm7, " #in1 "\n"\
  393. "punpckhbw %%mm7, %%mm2\n"\
  394. "punpckhbw %%mm7, %%mm3\n"\
  395. "paddw " #in1 ", " #in0 "\n"\
  396. "paddw %%mm3, %%mm2\n"\
  397. "paddw %%mm2, " #in0 "\n"\
  398. "paddw " #in0 ", %%mm6\n"
  399. __asm__ volatile (
  400. "movl %3,%%ecx\n"
  401. "pxor %%mm6,%%mm6\n"
  402. "pxor %%mm7,%%mm7\n"
  403. "movq (%0),%%mm0\n"
  404. "movq 8(%0),%%mm1\n"
  405. "add %2,%0\n"
  406. "jmp 2f\n"
  407. "1:\n"
  408. SUM(%%mm4, %%mm5, %%mm0, %%mm1)
  409. "2:\n"
  410. SUM(%%mm0, %%mm1, %%mm4, %%mm5)
  411. "subl $2, %%ecx\n"
  412. "jnz 1b\n"
  413. "movq %%mm6,%%mm0\n"
  414. "psrlq $32, %%mm6\n"
  415. "paddw %%mm6,%%mm0\n"
  416. "movq %%mm0,%%mm6\n"
  417. "psrlq $16, %%mm0\n"
  418. "paddw %%mm6,%%mm0\n"
  419. "movd %%mm0,%1\n"
  420. : "+r" (pix), "=r"(tmp)
  421. : "r" ((x86_reg)line_size) , "m" (h)
  422. : "%ecx");
  423. return tmp & 0xFFFF;
  424. }
  425. #undef SUM
  426. static int vsad_intra16_mmxext(void *v, uint8_t *pix, uint8_t *dummy,
  427. int line_size, int h)
  428. {
  429. int tmp;
  430. av_assert2( (((int)pix) & 7) == 0);
  431. av_assert2((line_size &7) ==0);
  432. #define SUM(in0, in1, out0, out1) \
  433. "movq (%0), " #out0 "\n"\
  434. "movq 8(%0), " #out1 "\n"\
  435. "add %2,%0\n"\
  436. "psadbw " #out0 ", " #in0 "\n"\
  437. "psadbw " #out1 ", " #in1 "\n"\
  438. "paddw " #in1 ", " #in0 "\n"\
  439. "paddw " #in0 ", %%mm6\n"
  440. __asm__ volatile (
  441. "movl %3,%%ecx\n"
  442. "pxor %%mm6,%%mm6\n"
  443. "pxor %%mm7,%%mm7\n"
  444. "movq (%0),%%mm0\n"
  445. "movq 8(%0),%%mm1\n"
  446. "add %2,%0\n"
  447. "jmp 2f\n"
  448. "1:\n"
  449. SUM(%%mm4, %%mm5, %%mm0, %%mm1)
  450. "2:\n"
  451. SUM(%%mm0, %%mm1, %%mm4, %%mm5)
  452. "subl $2, %%ecx\n"
  453. "jnz 1b\n"
  454. "movd %%mm6,%1\n"
  455. : "+r" (pix), "=r"(tmp)
  456. : "r" ((x86_reg)line_size) , "m" (h)
  457. : "%ecx");
  458. return tmp;
  459. }
  460. #undef SUM
  461. static int vsad16_mmx(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) {
  462. int tmp;
  463. av_assert2( (((int)pix1) & 7) == 0);
  464. av_assert2( (((int)pix2) & 7) == 0);
  465. av_assert2((line_size &7) ==0);
  466. #define SUM(in0, in1, out0, out1) \
  467. "movq (%0),%%mm2\n"\
  468. "movq (%1)," #out0 "\n"\
  469. "movq 8(%0),%%mm3\n"\
  470. "movq 8(%1)," #out1 "\n"\
  471. "add %3,%0\n"\
  472. "add %3,%1\n"\
  473. "psubb " #out0 ", %%mm2\n"\
  474. "psubb " #out1 ", %%mm3\n"\
  475. "pxor %%mm7, %%mm2\n"\
  476. "pxor %%mm7, %%mm3\n"\
  477. "movq %%mm2, " #out0 "\n"\
  478. "movq %%mm3, " #out1 "\n"\
  479. "psubusb " #in0 ", %%mm2\n"\
  480. "psubusb " #in1 ", %%mm3\n"\
  481. "psubusb " #out0 ", " #in0 "\n"\
  482. "psubusb " #out1 ", " #in1 "\n"\
  483. "por %%mm2, " #in0 "\n"\
  484. "por %%mm3, " #in1 "\n"\
  485. "movq " #in0 ", %%mm2\n"\
  486. "movq " #in1 ", %%mm3\n"\
  487. "punpcklbw %%mm7, " #in0 "\n"\
  488. "punpcklbw %%mm7, " #in1 "\n"\
  489. "punpckhbw %%mm7, %%mm2\n"\
  490. "punpckhbw %%mm7, %%mm3\n"\
  491. "paddw " #in1 ", " #in0 "\n"\
  492. "paddw %%mm3, %%mm2\n"\
  493. "paddw %%mm2, " #in0 "\n"\
  494. "paddw " #in0 ", %%mm6\n"
  495. __asm__ volatile (
  496. "movl %4,%%ecx\n"
  497. "pxor %%mm6,%%mm6\n"
  498. "pcmpeqw %%mm7,%%mm7\n"
  499. "psllw $15, %%mm7\n"
  500. "packsswb %%mm7, %%mm7\n"
  501. "movq (%0),%%mm0\n"
  502. "movq (%1),%%mm2\n"
  503. "movq 8(%0),%%mm1\n"
  504. "movq 8(%1),%%mm3\n"
  505. "add %3,%0\n"
  506. "add %3,%1\n"
  507. "psubb %%mm2, %%mm0\n"
  508. "psubb %%mm3, %%mm1\n"
  509. "pxor %%mm7, %%mm0\n"
  510. "pxor %%mm7, %%mm1\n"
  511. "jmp 2f\n"
  512. "1:\n"
  513. SUM(%%mm4, %%mm5, %%mm0, %%mm1)
  514. "2:\n"
  515. SUM(%%mm0, %%mm1, %%mm4, %%mm5)
  516. "subl $2, %%ecx\n"
  517. "jnz 1b\n"
  518. "movq %%mm6,%%mm0\n"
  519. "psrlq $32, %%mm6\n"
  520. "paddw %%mm6,%%mm0\n"
  521. "movq %%mm0,%%mm6\n"
  522. "psrlq $16, %%mm0\n"
  523. "paddw %%mm6,%%mm0\n"
  524. "movd %%mm0,%2\n"
  525. : "+r" (pix1), "+r" (pix2), "=r"(tmp)
  526. : "r" ((x86_reg)line_size) , "m" (h)
  527. : "%ecx");
  528. return tmp & 0x7FFF;
  529. }
  530. #undef SUM
  531. static int vsad16_mmxext(void *v, uint8_t *pix1, uint8_t *pix2,
  532. int line_size, int h)
  533. {
  534. int tmp;
  535. av_assert2( (((int)pix1) & 7) == 0);
  536. av_assert2( (((int)pix2) & 7) == 0);
  537. av_assert2((line_size &7) ==0);
  538. #define SUM(in0, in1, out0, out1) \
  539. "movq (%0)," #out0 "\n"\
  540. "movq (%1),%%mm2\n"\
  541. "movq 8(%0)," #out1 "\n"\
  542. "movq 8(%1),%%mm3\n"\
  543. "add %3,%0\n"\
  544. "add %3,%1\n"\
  545. "psubb %%mm2, " #out0 "\n"\
  546. "psubb %%mm3, " #out1 "\n"\
  547. "pxor %%mm7, " #out0 "\n"\
  548. "pxor %%mm7, " #out1 "\n"\
  549. "psadbw " #out0 ", " #in0 "\n"\
  550. "psadbw " #out1 ", " #in1 "\n"\
  551. "paddw " #in1 ", " #in0 "\n"\
  552. "paddw " #in0 ", %%mm6\n"
  553. __asm__ volatile (
  554. "movl %4,%%ecx\n"
  555. "pxor %%mm6,%%mm6\n"
  556. "pcmpeqw %%mm7,%%mm7\n"
  557. "psllw $15, %%mm7\n"
  558. "packsswb %%mm7, %%mm7\n"
  559. "movq (%0),%%mm0\n"
  560. "movq (%1),%%mm2\n"
  561. "movq 8(%0),%%mm1\n"
  562. "movq 8(%1),%%mm3\n"
  563. "add %3,%0\n"
  564. "add %3,%1\n"
  565. "psubb %%mm2, %%mm0\n"
  566. "psubb %%mm3, %%mm1\n"
  567. "pxor %%mm7, %%mm0\n"
  568. "pxor %%mm7, %%mm1\n"
  569. "jmp 2f\n"
  570. "1:\n"
  571. SUM(%%mm4, %%mm5, %%mm0, %%mm1)
  572. "2:\n"
  573. SUM(%%mm0, %%mm1, %%mm4, %%mm5)
  574. "subl $2, %%ecx\n"
  575. "jnz 1b\n"
  576. "movd %%mm6,%2\n"
  577. : "+r" (pix1), "+r" (pix2), "=r"(tmp)
  578. : "r" ((x86_reg)line_size) , "m" (h)
  579. : "%ecx");
  580. return tmp;
  581. }
  582. #undef SUM
  583. static void diff_bytes_mmx(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int w){
  584. x86_reg i=0;
  585. if(w>=16)
  586. __asm__ volatile(
  587. "1: \n\t"
  588. "movq (%2, %0), %%mm0 \n\t"
  589. "movq (%1, %0), %%mm1 \n\t"
  590. "psubb %%mm0, %%mm1 \n\t"
  591. "movq %%mm1, (%3, %0) \n\t"
  592. "movq 8(%2, %0), %%mm0 \n\t"
  593. "movq 8(%1, %0), %%mm1 \n\t"
  594. "psubb %%mm0, %%mm1 \n\t"
  595. "movq %%mm1, 8(%3, %0) \n\t"
  596. "add $16, %0 \n\t"
  597. "cmp %4, %0 \n\t"
  598. " jb 1b \n\t"
  599. : "+r" (i)
  600. : "r"(src1), "r"(src2), "r"(dst), "r"((x86_reg)w-15)
  601. );
  602. for(; i<w; i++)
  603. dst[i+0] = src1[i+0]-src2[i+0];
  604. }
  605. static void sub_hfyu_median_prediction_mmxext(uint8_t *dst, const uint8_t *src1,
  606. const uint8_t *src2, int w,
  607. int *left, int *left_top)
  608. {
  609. x86_reg i=0;
  610. uint8_t l, lt;
  611. __asm__ volatile(
  612. "movq (%1, %0), %%mm0 \n\t" // LT
  613. "psllq $8, %%mm0 \n\t"
  614. "1: \n\t"
  615. "movq (%1, %0), %%mm1 \n\t" // T
  616. "movq -1(%2, %0), %%mm2 \n\t" // L
  617. "movq (%2, %0), %%mm3 \n\t" // X
  618. "movq %%mm2, %%mm4 \n\t" // L
  619. "psubb %%mm0, %%mm2 \n\t"
  620. "paddb %%mm1, %%mm2 \n\t" // L + T - LT
  621. "movq %%mm4, %%mm5 \n\t" // L
  622. "pmaxub %%mm1, %%mm4 \n\t" // max(T, L)
  623. "pminub %%mm5, %%mm1 \n\t" // min(T, L)
  624. "pminub %%mm2, %%mm4 \n\t"
  625. "pmaxub %%mm1, %%mm4 \n\t"
  626. "psubb %%mm4, %%mm3 \n\t" // dst - pred
  627. "movq %%mm3, (%3, %0) \n\t"
  628. "add $8, %0 \n\t"
  629. "movq -1(%1, %0), %%mm0 \n\t" // LT
  630. "cmp %4, %0 \n\t"
  631. " jb 1b \n\t"
  632. : "+r" (i)
  633. : "r"(src1), "r"(src2), "r"(dst), "r"((x86_reg)w)
  634. );
  635. l= *left;
  636. lt= *left_top;
  637. dst[0]= src2[0] - mid_pred(l, src1[0], (l + src1[0] - lt)&0xFF);
  638. *left_top= src1[w-1];
  639. *left = src2[w-1];
  640. }
  641. #define MMABS_MMX(a,z)\
  642. "pxor " #z ", " #z " \n\t"\
  643. "pcmpgtw " #a ", " #z " \n\t"\
  644. "pxor " #z ", " #a " \n\t"\
  645. "psubw " #z ", " #a " \n\t"
  646. #define MMABS_MMXEXT(a, z) \
  647. "pxor " #z ", " #z " \n\t"\
  648. "psubw " #a ", " #z " \n\t"\
  649. "pmaxsw " #z ", " #a " \n\t"
  650. #define MMABS_SSSE3(a,z)\
  651. "pabsw " #a ", " #a " \n\t"
  652. #define MMABS_SUM(a,z, sum)\
  653. MMABS(a,z)\
  654. "paddusw " #a ", " #sum " \n\t"
  655. /* FIXME: HSUM_* saturates at 64k, while an 8x8 hadamard or dct block can get up to
  656. * about 100k on extreme inputs. But that's very unlikely to occur in natural video,
  657. * and it's even more unlikely to not have any alternative mvs/modes with lower cost. */
  658. #define HSUM_MMX(a, t, dst)\
  659. "movq "#a", "#t" \n\t"\
  660. "psrlq $32, "#a" \n\t"\
  661. "paddusw "#t", "#a" \n\t"\
  662. "movq "#a", "#t" \n\t"\
  663. "psrlq $16, "#a" \n\t"\
  664. "paddusw "#t", "#a" \n\t"\
  665. "movd "#a", "#dst" \n\t"\
  666. #define HSUM_MMXEXT(a, t, dst) \
  667. "pshufw $0x0E, "#a", "#t" \n\t"\
  668. "paddusw "#t", "#a" \n\t"\
  669. "pshufw $0x01, "#a", "#t" \n\t"\
  670. "paddusw "#t", "#a" \n\t"\
  671. "movd "#a", "#dst" \n\t"\
  672. #define HSUM_SSE2(a, t, dst)\
  673. "movhlps "#a", "#t" \n\t"\
  674. "paddusw "#t", "#a" \n\t"\
  675. "pshuflw $0x0E, "#a", "#t" \n\t"\
  676. "paddusw "#t", "#a" \n\t"\
  677. "pshuflw $0x01, "#a", "#t" \n\t"\
  678. "paddusw "#t", "#a" \n\t"\
  679. "movd "#a", "#dst" \n\t"\
  680. #define DCT_SAD4(m,mm,o)\
  681. "mov"#m" "#o"+ 0(%1), "#mm"2 \n\t"\
  682. "mov"#m" "#o"+16(%1), "#mm"3 \n\t"\
  683. "mov"#m" "#o"+32(%1), "#mm"4 \n\t"\
  684. "mov"#m" "#o"+48(%1), "#mm"5 \n\t"\
  685. MMABS_SUM(mm##2, mm##6, mm##0)\
  686. MMABS_SUM(mm##3, mm##7, mm##1)\
  687. MMABS_SUM(mm##4, mm##6, mm##0)\
  688. MMABS_SUM(mm##5, mm##7, mm##1)\
  689. #define DCT_SAD_MMX\
  690. "pxor %%mm0, %%mm0 \n\t"\
  691. "pxor %%mm1, %%mm1 \n\t"\
  692. DCT_SAD4(q, %%mm, 0)\
  693. DCT_SAD4(q, %%mm, 8)\
  694. DCT_SAD4(q, %%mm, 64)\
  695. DCT_SAD4(q, %%mm, 72)\
  696. "paddusw %%mm1, %%mm0 \n\t"\
  697. HSUM(%%mm0, %%mm1, %0)
  698. #define DCT_SAD_SSE2\
  699. "pxor %%xmm0, %%xmm0 \n\t"\
  700. "pxor %%xmm1, %%xmm1 \n\t"\
  701. DCT_SAD4(dqa, %%xmm, 0)\
  702. DCT_SAD4(dqa, %%xmm, 64)\
  703. "paddusw %%xmm1, %%xmm0 \n\t"\
  704. HSUM(%%xmm0, %%xmm1, %0)
  705. #define DCT_SAD_FUNC(cpu) \
  706. static int sum_abs_dctelem_##cpu(int16_t *block){\
  707. int sum;\
  708. __asm__ volatile(\
  709. DCT_SAD\
  710. :"=r"(sum)\
  711. :"r"(block)\
  712. );\
  713. return sum&0xFFFF;\
  714. }
  715. #define DCT_SAD DCT_SAD_MMX
  716. #define HSUM(a,t,dst) HSUM_MMX(a,t,dst)
  717. #define MMABS(a,z) MMABS_MMX(a,z)
  718. DCT_SAD_FUNC(mmx)
  719. #undef MMABS
  720. #undef HSUM
  721. #define HSUM(a,t,dst) HSUM_MMXEXT(a,t,dst)
  722. #define MMABS(a,z) MMABS_MMXEXT(a,z)
  723. DCT_SAD_FUNC(mmxext)
  724. #undef HSUM
  725. #undef DCT_SAD
  726. #define DCT_SAD DCT_SAD_SSE2
  727. #define HSUM(a,t,dst) HSUM_SSE2(a,t,dst)
  728. DCT_SAD_FUNC(sse2)
  729. #undef MMABS
  730. #if HAVE_SSSE3_INLINE
  731. #define MMABS(a,z) MMABS_SSSE3(a,z)
  732. DCT_SAD_FUNC(ssse3)
  733. #undef MMABS
  734. #endif
  735. #undef HSUM
  736. #undef DCT_SAD
  737. static int ssd_int8_vs_int16_mmx(const int8_t *pix1, const int16_t *pix2, int size){
  738. int sum;
  739. x86_reg i=size;
  740. __asm__ volatile(
  741. "pxor %%mm4, %%mm4 \n"
  742. "1: \n"
  743. "sub $8, %0 \n"
  744. "movq (%2,%0), %%mm2 \n"
  745. "movq (%3,%0,2), %%mm0 \n"
  746. "movq 8(%3,%0,2), %%mm1 \n"
  747. "punpckhbw %%mm2, %%mm3 \n"
  748. "punpcklbw %%mm2, %%mm2 \n"
  749. "psraw $8, %%mm3 \n"
  750. "psraw $8, %%mm2 \n"
  751. "psubw %%mm3, %%mm1 \n"
  752. "psubw %%mm2, %%mm0 \n"
  753. "pmaddwd %%mm1, %%mm1 \n"
  754. "pmaddwd %%mm0, %%mm0 \n"
  755. "paddd %%mm1, %%mm4 \n"
  756. "paddd %%mm0, %%mm4 \n"
  757. "jg 1b \n"
  758. "movq %%mm4, %%mm3 \n"
  759. "psrlq $32, %%mm3 \n"
  760. "paddd %%mm3, %%mm4 \n"
  761. "movd %%mm4, %1 \n"
  762. :"+r"(i), "=r"(sum)
  763. :"r"(pix1), "r"(pix2)
  764. );
  765. return sum;
  766. }
  767. #define PHADDD(a, t)\
  768. "movq "#a", "#t" \n\t"\
  769. "psrlq $32, "#a" \n\t"\
  770. "paddd "#t", "#a" \n\t"
  771. /*
  772. pmulhw: dst[0-15]=(src[0-15]*dst[0-15])[16-31]
  773. pmulhrw: dst[0-15]=(src[0-15]*dst[0-15] + 0x8000)[16-31]
  774. pmulhrsw: dst[0-15]=(src[0-15]*dst[0-15] + 0x4000)[15-30]
  775. */
  776. #define PMULHRW(x, y, s, o)\
  777. "pmulhw " #s ", "#x " \n\t"\
  778. "pmulhw " #s ", "#y " \n\t"\
  779. "paddw " #o ", "#x " \n\t"\
  780. "paddw " #o ", "#y " \n\t"\
  781. "psraw $1, "#x " \n\t"\
  782. "psraw $1, "#y " \n\t"
  783. #define DEF(x) x ## _mmx
  784. #define SET_RND MOVQ_WONE
  785. #define SCALE_OFFSET 1
  786. #include "dsputil_qns_template.c"
  787. #undef DEF
  788. #undef SET_RND
  789. #undef SCALE_OFFSET
  790. #undef PMULHRW
  791. #define DEF(x) x ## _3dnow
  792. #define SET_RND(x)
  793. #define SCALE_OFFSET 0
  794. #define PMULHRW(x, y, s, o)\
  795. "pmulhrw " #s ", "#x " \n\t"\
  796. "pmulhrw " #s ", "#y " \n\t"
  797. #include "dsputil_qns_template.c"
  798. #undef DEF
  799. #undef SET_RND
  800. #undef SCALE_OFFSET
  801. #undef PMULHRW
  802. #if HAVE_SSSE3_INLINE
  803. #undef PHADDD
  804. #define DEF(x) x ## _ssse3
  805. #define SET_RND(x)
  806. #define SCALE_OFFSET -1
  807. #define PHADDD(a, t)\
  808. "pshufw $0x0E, "#a", "#t" \n\t"\
  809. "paddd "#t", "#a" \n\t" /* faster than phaddd on core2 */
  810. #define PMULHRW(x, y, s, o)\
  811. "pmulhrsw " #s ", "#x " \n\t"\
  812. "pmulhrsw " #s ", "#y " \n\t"
  813. #include "dsputil_qns_template.c"
  814. #undef DEF
  815. #undef SET_RND
  816. #undef SCALE_OFFSET
  817. #undef PMULHRW
  818. #undef PHADDD
  819. #endif /* HAVE_SSSE3_INLINE */
  820. #endif /* HAVE_INLINE_ASM */
  821. int ff_sse16_sse2(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h);
  822. #define hadamard_func(cpu) \
  823. int ff_hadamard8_diff_##cpu (void *s, uint8_t *src1, uint8_t *src2, \
  824. int stride, int h); \
  825. int ff_hadamard8_diff16_##cpu(void *s, uint8_t *src1, uint8_t *src2, \
  826. int stride, int h);
  827. hadamard_func(mmx)
  828. hadamard_func(mmxext)
  829. hadamard_func(sse2)
  830. hadamard_func(ssse3)
  831. av_cold void ff_dsputilenc_init_mmx(DSPContext *c, AVCodecContext *avctx)
  832. {
  833. int mm_flags = av_get_cpu_flags();
  834. #if HAVE_YASM
  835. int bit_depth = avctx->bits_per_raw_sample;
  836. if (EXTERNAL_MMX(mm_flags)) {
  837. if (bit_depth <= 8)
  838. c->get_pixels = ff_get_pixels_mmx;
  839. c->diff_pixels = ff_diff_pixels_mmx;
  840. c->pix_sum = ff_pix_sum16_mmx;
  841. c->pix_norm1 = ff_pix_norm1_mmx;
  842. }
  843. if (EXTERNAL_SSE2(mm_flags))
  844. if (bit_depth <= 8)
  845. c->get_pixels = ff_get_pixels_sse2;
  846. #endif /* HAVE_YASM */
  847. #if HAVE_INLINE_ASM
  848. if (mm_flags & AV_CPU_FLAG_MMX) {
  849. const int dct_algo = avctx->dct_algo;
  850. if (avctx->bits_per_raw_sample <= 8 &&
  851. (dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX)) {
  852. if(mm_flags & AV_CPU_FLAG_SSE2){
  853. c->fdct = ff_fdct_sse2;
  854. } else if (mm_flags & AV_CPU_FLAG_MMXEXT) {
  855. c->fdct = ff_fdct_mmxext;
  856. }else{
  857. c->fdct = ff_fdct_mmx;
  858. }
  859. }
  860. c->diff_bytes= diff_bytes_mmx;
  861. c->sum_abs_dctelem= sum_abs_dctelem_mmx;
  862. c->sse[0] = sse16_mmx;
  863. c->sse[1] = sse8_mmx;
  864. c->vsad[4]= vsad_intra16_mmx;
  865. c->nsse[0] = nsse16_mmx;
  866. c->nsse[1] = nsse8_mmx;
  867. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  868. c->vsad[0] = vsad16_mmx;
  869. }
  870. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  871. c->try_8x8basis= try_8x8basis_mmx;
  872. }
  873. c->add_8x8basis= add_8x8basis_mmx;
  874. c->ssd_int8_vs_int16 = ssd_int8_vs_int16_mmx;
  875. if (mm_flags & AV_CPU_FLAG_MMXEXT) {
  876. c->sum_abs_dctelem = sum_abs_dctelem_mmxext;
  877. c->vsad[4] = vsad_intra16_mmxext;
  878. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  879. c->vsad[0] = vsad16_mmxext;
  880. }
  881. c->sub_hfyu_median_prediction = sub_hfyu_median_prediction_mmxext;
  882. }
  883. if(mm_flags & AV_CPU_FLAG_SSE2){
  884. c->sum_abs_dctelem= sum_abs_dctelem_sse2;
  885. }
  886. #if HAVE_SSSE3_INLINE
  887. if(mm_flags & AV_CPU_FLAG_SSSE3){
  888. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  889. c->try_8x8basis= try_8x8basis_ssse3;
  890. }
  891. c->add_8x8basis= add_8x8basis_ssse3;
  892. c->sum_abs_dctelem= sum_abs_dctelem_ssse3;
  893. }
  894. #endif
  895. if(mm_flags & AV_CPU_FLAG_3DNOW){
  896. if(!(avctx->flags & CODEC_FLAG_BITEXACT)){
  897. c->try_8x8basis= try_8x8basis_3dnow;
  898. }
  899. c->add_8x8basis= add_8x8basis_3dnow;
  900. }
  901. }
  902. #endif /* HAVE_INLINE_ASM */
  903. if (EXTERNAL_MMX(mm_flags)) {
  904. c->hadamard8_diff[0] = ff_hadamard8_diff16_mmx;
  905. c->hadamard8_diff[1] = ff_hadamard8_diff_mmx;
  906. if (EXTERNAL_MMXEXT(mm_flags)) {
  907. c->hadamard8_diff[0] = ff_hadamard8_diff16_mmxext;
  908. c->hadamard8_diff[1] = ff_hadamard8_diff_mmxext;
  909. }
  910. if (EXTERNAL_SSE2(mm_flags)) {
  911. c->sse[0] = ff_sse16_sse2;
  912. #if HAVE_ALIGNED_STACK
  913. c->hadamard8_diff[0] = ff_hadamard8_diff16_sse2;
  914. c->hadamard8_diff[1] = ff_hadamard8_diff_sse2;
  915. #endif
  916. }
  917. if (EXTERNAL_SSSE3(mm_flags) && HAVE_ALIGNED_STACK) {
  918. c->hadamard8_diff[0] = ff_hadamard8_diff16_ssse3;
  919. c->hadamard8_diff[1] = ff_hadamard8_diff_ssse3;
  920. }
  921. }
  922. ff_dsputil_init_pix_mmx(c, avctx);
  923. }