fdct_mmx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  1. /*
  2. * MMX optimized forward DCT
  3. * The gcc porting is Copyright (c) 2001 Fabrice Bellard.
  4. * cleanup/optimizations are Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  5. * SSE2 optimization is Copyright (c) 2004 Denes Balatoni.
  6. *
  7. * from fdctam32.c - AP922 MMX(3D-Now) forward-DCT
  8. *
  9. * Intel Application Note AP-922 - fast, precise implementation of DCT
  10. * http://developer.intel.com/vtune/cbts/appnotes.htm
  11. *
  12. * Also of inspiration:
  13. * a page about fdct at http://www.geocities.com/ssavekar/dct.htm
  14. * Skal's fdct at http://skal.planet-d.net/coding/dct.html
  15. *
  16. * This file is part of FFmpeg.
  17. *
  18. * FFmpeg is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU Lesser General Public
  20. * License as published by the Free Software Foundation; either
  21. * version 2.1 of the License, or (at your option) any later version.
  22. *
  23. * FFmpeg is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  26. * Lesser General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU Lesser General Public
  29. * License along with FFmpeg; if not, write to the Free Software
  30. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  31. */
  32. #include "libavutil/common.h"
  33. #include "libavcodec/dsputil.h"
  34. #define ATTR_ALIGN(align) __attribute__ ((__aligned__ (align)))
  35. //////////////////////////////////////////////////////////////////////
  36. //
  37. // constants for the forward DCT
  38. // -----------------------------
  39. //
  40. // Be sure to check that your compiler is aligning all constants to QWORD
  41. // (8-byte) memory boundaries! Otherwise the unaligned memory access will
  42. // severely stall MMX execution.
  43. //
  44. //////////////////////////////////////////////////////////////////////
  45. #define BITS_FRW_ACC 3 //; 2 or 3 for accuracy
  46. #define SHIFT_FRW_COL BITS_FRW_ACC
  47. #define SHIFT_FRW_ROW (BITS_FRW_ACC + 17 - 3)
  48. #define RND_FRW_ROW (1 << (SHIFT_FRW_ROW-1))
  49. //#define RND_FRW_COL (1 << (SHIFT_FRW_COL-1))
  50. #define X8(x) x,x,x,x,x,x,x,x
  51. //concatenated table, for forward DCT transformation
  52. static const int16_t fdct_tg_all_16[24] ATTR_ALIGN(16) = {
  53. X8(13036), // tg * (2<<16) + 0.5
  54. X8(27146), // tg * (2<<16) + 0.5
  55. X8(-21746) // tg * (2<<16) + 0.5
  56. };
  57. static const int16_t ocos_4_16[8] ATTR_ALIGN(16) = {
  58. X8(23170) //cos * (2<<15) + 0.5
  59. };
  60. static const int16_t fdct_one_corr[8] ATTR_ALIGN(16) = { X8(1) };
  61. static const int32_t fdct_r_row[2] ATTR_ALIGN(8) = {RND_FRW_ROW, RND_FRW_ROW };
  62. static struct
  63. {
  64. const int32_t fdct_r_row_sse2[4] ATTR_ALIGN(16);
  65. } fdct_r_row_sse2 ATTR_ALIGN(16)=
  66. {{
  67. RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW
  68. }};
  69. //static const long fdct_r_row_sse2[4] ATTR_ALIGN(16) = {RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW};
  70. static const int16_t tab_frw_01234567[] ATTR_ALIGN(8) = { // forward_dct coeff table
  71. 16384, 16384, 22725, 19266,
  72. 16384, 16384, 12873, 4520,
  73. 21407, 8867, 19266, -4520,
  74. -8867, -21407, -22725, -12873,
  75. 16384, -16384, 12873, -22725,
  76. -16384, 16384, 4520, 19266,
  77. 8867, -21407, 4520, -12873,
  78. 21407, -8867, 19266, -22725,
  79. 22725, 22725, 31521, 26722,
  80. 22725, 22725, 17855, 6270,
  81. 29692, 12299, 26722, -6270,
  82. -12299, -29692, -31521, -17855,
  83. 22725, -22725, 17855, -31521,
  84. -22725, 22725, 6270, 26722,
  85. 12299, -29692, 6270, -17855,
  86. 29692, -12299, 26722, -31521,
  87. 21407, 21407, 29692, 25172,
  88. 21407, 21407, 16819, 5906,
  89. 27969, 11585, 25172, -5906,
  90. -11585, -27969, -29692, -16819,
  91. 21407, -21407, 16819, -29692,
  92. -21407, 21407, 5906, 25172,
  93. 11585, -27969, 5906, -16819,
  94. 27969, -11585, 25172, -29692,
  95. 19266, 19266, 26722, 22654,
  96. 19266, 19266, 15137, 5315,
  97. 25172, 10426, 22654, -5315,
  98. -10426, -25172, -26722, -15137,
  99. 19266, -19266, 15137, -26722,
  100. -19266, 19266, 5315, 22654,
  101. 10426, -25172, 5315, -15137,
  102. 25172, -10426, 22654, -26722,
  103. 16384, 16384, 22725, 19266,
  104. 16384, 16384, 12873, 4520,
  105. 21407, 8867, 19266, -4520,
  106. -8867, -21407, -22725, -12873,
  107. 16384, -16384, 12873, -22725,
  108. -16384, 16384, 4520, 19266,
  109. 8867, -21407, 4520, -12873,
  110. 21407, -8867, 19266, -22725,
  111. 19266, 19266, 26722, 22654,
  112. 19266, 19266, 15137, 5315,
  113. 25172, 10426, 22654, -5315,
  114. -10426, -25172, -26722, -15137,
  115. 19266, -19266, 15137, -26722,
  116. -19266, 19266, 5315, 22654,
  117. 10426, -25172, 5315, -15137,
  118. 25172, -10426, 22654, -26722,
  119. 21407, 21407, 29692, 25172,
  120. 21407, 21407, 16819, 5906,
  121. 27969, 11585, 25172, -5906,
  122. -11585, -27969, -29692, -16819,
  123. 21407, -21407, 16819, -29692,
  124. -21407, 21407, 5906, 25172,
  125. 11585, -27969, 5906, -16819,
  126. 27969, -11585, 25172, -29692,
  127. 22725, 22725, 31521, 26722,
  128. 22725, 22725, 17855, 6270,
  129. 29692, 12299, 26722, -6270,
  130. -12299, -29692, -31521, -17855,
  131. 22725, -22725, 17855, -31521,
  132. -22725, 22725, 6270, 26722,
  133. 12299, -29692, 6270, -17855,
  134. 29692, -12299, 26722, -31521,
  135. };
  136. static struct
  137. {
  138. const int16_t tab_frw_01234567_sse2[256] ATTR_ALIGN(16);
  139. } tab_frw_01234567_sse2 ATTR_ALIGN(16) =
  140. {{
  141. //static const int16_t tab_frw_01234567_sse2[] ATTR_ALIGN(16) = { // forward_dct coeff table
  142. #define TABLE_SSE2 C4, C4, C1, C3, -C6, -C2, -C1, -C5, \
  143. C4, C4, C5, C7, C2, C6, C3, -C7, \
  144. -C4, C4, C7, C3, C6, -C2, C7, -C5, \
  145. C4, -C4, C5, -C1, C2, -C6, C3, -C1,
  146. // c1..c7 * cos(pi/4) * 2^15
  147. #define C1 22725
  148. #define C2 21407
  149. #define C3 19266
  150. #define C4 16384
  151. #define C5 12873
  152. #define C6 8867
  153. #define C7 4520
  154. TABLE_SSE2
  155. #undef C1
  156. #undef C2
  157. #undef C3
  158. #undef C4
  159. #undef C5
  160. #undef C6
  161. #undef C7
  162. #define C1 31521
  163. #define C2 29692
  164. #define C3 26722
  165. #define C4 22725
  166. #define C5 17855
  167. #define C6 12299
  168. #define C7 6270
  169. TABLE_SSE2
  170. #undef C1
  171. #undef C2
  172. #undef C3
  173. #undef C4
  174. #undef C5
  175. #undef C6
  176. #undef C7
  177. #define C1 29692
  178. #define C2 27969
  179. #define C3 25172
  180. #define C4 21407
  181. #define C5 16819
  182. #define C6 11585
  183. #define C7 5906
  184. TABLE_SSE2
  185. #undef C1
  186. #undef C2
  187. #undef C3
  188. #undef C4
  189. #undef C5
  190. #undef C6
  191. #undef C7
  192. #define C1 26722
  193. #define C2 25172
  194. #define C3 22654
  195. #define C4 19266
  196. #define C5 15137
  197. #define C6 10426
  198. #define C7 5315
  199. TABLE_SSE2
  200. #undef C1
  201. #undef C2
  202. #undef C3
  203. #undef C4
  204. #undef C5
  205. #undef C6
  206. #undef C7
  207. #define C1 22725
  208. #define C2 21407
  209. #define C3 19266
  210. #define C4 16384
  211. #define C5 12873
  212. #define C6 8867
  213. #define C7 4520
  214. TABLE_SSE2
  215. #undef C1
  216. #undef C2
  217. #undef C3
  218. #undef C4
  219. #undef C5
  220. #undef C6
  221. #undef C7
  222. #define C1 26722
  223. #define C2 25172
  224. #define C3 22654
  225. #define C4 19266
  226. #define C5 15137
  227. #define C6 10426
  228. #define C7 5315
  229. TABLE_SSE2
  230. #undef C1
  231. #undef C2
  232. #undef C3
  233. #undef C4
  234. #undef C5
  235. #undef C6
  236. #undef C7
  237. #define C1 29692
  238. #define C2 27969
  239. #define C3 25172
  240. #define C4 21407
  241. #define C5 16819
  242. #define C6 11585
  243. #define C7 5906
  244. TABLE_SSE2
  245. #undef C1
  246. #undef C2
  247. #undef C3
  248. #undef C4
  249. #undef C5
  250. #undef C6
  251. #undef C7
  252. #define C1 31521
  253. #define C2 29692
  254. #define C3 26722
  255. #define C4 22725
  256. #define C5 17855
  257. #define C6 12299
  258. #define C7 6270
  259. TABLE_SSE2
  260. }};
  261. #define S(s) AV_TOSTRING(s) //AV_STRINGIFY is too long
  262. #define FDCT_COL(cpu, mm, mov)\
  263. static av_always_inline void fdct_col_##cpu(const int16_t *in, int16_t *out, int offset)\
  264. {\
  265. __asm__ volatile (\
  266. #mov" 16(%0), %%"#mm"0 \n\t" \
  267. #mov" 96(%0), %%"#mm"1 \n\t" \
  268. #mov" %%"#mm"0, %%"#mm"2 \n\t" \
  269. #mov" 32(%0), %%"#mm"3 \n\t" \
  270. "paddsw %%"#mm"1, %%"#mm"0 \n\t" \
  271. #mov" 80(%0), %%"#mm"4 \n\t" \
  272. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"0 \n\t" \
  273. #mov" (%0), %%"#mm"5 \n\t" \
  274. "paddsw %%"#mm"3, %%"#mm"4 \n\t" \
  275. "paddsw 112(%0), %%"#mm"5 \n\t" \
  276. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"4 \n\t" \
  277. #mov" %%"#mm"0, %%"#mm"6 \n\t" \
  278. "psubsw %%"#mm"1, %%"#mm"2 \n\t" \
  279. #mov" 16(%1), %%"#mm"1 \n\t" \
  280. "psubsw %%"#mm"4, %%"#mm"0 \n\t" \
  281. #mov" 48(%0), %%"#mm"7 \n\t" \
  282. "pmulhw %%"#mm"0, %%"#mm"1 \n\t" \
  283. "paddsw 64(%0), %%"#mm"7 \n\t" \
  284. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"5 \n\t" \
  285. "paddsw %%"#mm"4, %%"#mm"6 \n\t" \
  286. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"7 \n\t" \
  287. #mov" %%"#mm"5, %%"#mm"4 \n\t" \
  288. "psubsw %%"#mm"7, %%"#mm"5 \n\t" \
  289. "paddsw %%"#mm"5, %%"#mm"1 \n\t" \
  290. "paddsw %%"#mm"7, %%"#mm"4 \n\t" \
  291. "por (%2), %%"#mm"1 \n\t" \
  292. "psllw $"S(SHIFT_FRW_COL)"+1, %%"#mm"2 \n\t" \
  293. "pmulhw 16(%1), %%"#mm"5 \n\t" \
  294. #mov" %%"#mm"4, %%"#mm"7 \n\t" \
  295. "psubsw 80(%0), %%"#mm"3 \n\t" \
  296. "psubsw %%"#mm"6, %%"#mm"4 \n\t" \
  297. #mov" %%"#mm"1, 32(%3) \n\t" \
  298. "paddsw %%"#mm"6, %%"#mm"7 \n\t" \
  299. #mov" 48(%0), %%"#mm"1 \n\t" \
  300. "psllw $"S(SHIFT_FRW_COL)"+1, %%"#mm"3 \n\t" \
  301. "psubsw 64(%0), %%"#mm"1 \n\t" \
  302. #mov" %%"#mm"2, %%"#mm"6 \n\t" \
  303. #mov" %%"#mm"4, 64(%3) \n\t" \
  304. "paddsw %%"#mm"3, %%"#mm"2 \n\t" \
  305. "pmulhw (%4), %%"#mm"2 \n\t" \
  306. "psubsw %%"#mm"3, %%"#mm"6 \n\t" \
  307. "pmulhw (%4), %%"#mm"6 \n\t" \
  308. "psubsw %%"#mm"0, %%"#mm"5 \n\t" \
  309. "por (%2), %%"#mm"5 \n\t" \
  310. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"1 \n\t" \
  311. "por (%2), %%"#mm"2 \n\t" \
  312. #mov" %%"#mm"1, %%"#mm"4 \n\t" \
  313. #mov" (%0), %%"#mm"3 \n\t" \
  314. "paddsw %%"#mm"6, %%"#mm"1 \n\t" \
  315. "psubsw 112(%0), %%"#mm"3 \n\t" \
  316. "psubsw %%"#mm"6, %%"#mm"4 \n\t" \
  317. #mov" (%1), %%"#mm"0 \n\t" \
  318. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"3 \n\t" \
  319. #mov" 32(%1), %%"#mm"6 \n\t" \
  320. "pmulhw %%"#mm"1, %%"#mm"0 \n\t" \
  321. #mov" %%"#mm"7, (%3) \n\t" \
  322. "pmulhw %%"#mm"4, %%"#mm"6 \n\t" \
  323. #mov" %%"#mm"5, 96(%3) \n\t" \
  324. #mov" %%"#mm"3, %%"#mm"7 \n\t" \
  325. #mov" 32(%1), %%"#mm"5 \n\t" \
  326. "psubsw %%"#mm"2, %%"#mm"7 \n\t" \
  327. "paddsw %%"#mm"2, %%"#mm"3 \n\t" \
  328. "pmulhw %%"#mm"7, %%"#mm"5 \n\t" \
  329. "paddsw %%"#mm"3, %%"#mm"0 \n\t" \
  330. "paddsw %%"#mm"4, %%"#mm"6 \n\t" \
  331. "pmulhw (%1), %%"#mm"3 \n\t" \
  332. "por (%2), %%"#mm"0 \n\t" \
  333. "paddsw %%"#mm"7, %%"#mm"5 \n\t" \
  334. "psubsw %%"#mm"6, %%"#mm"7 \n\t" \
  335. #mov" %%"#mm"0, 16(%3) \n\t" \
  336. "paddsw %%"#mm"4, %%"#mm"5 \n\t" \
  337. #mov" %%"#mm"7, 48(%3) \n\t" \
  338. "psubsw %%"#mm"1, %%"#mm"3 \n\t" \
  339. #mov" %%"#mm"5, 80(%3) \n\t" \
  340. #mov" %%"#mm"3, 112(%3) \n\t" \
  341. : \
  342. : "r" (in + offset), "r" (fdct_tg_all_16), "r" (fdct_one_corr), \
  343. "r" (out + offset), "r" (ocos_4_16)); \
  344. }
  345. FDCT_COL(mmx, mm, movq)
  346. FDCT_COL(sse2, xmm, movdqa)
  347. static av_always_inline void fdct_row_sse2(const int16_t *in, int16_t *out)
  348. {
  349. __asm__ volatile(
  350. #define FDCT_ROW_SSE2_H1(i,t) \
  351. "movq " #i "(%0), %%xmm2 \n\t" \
  352. "movq " #i "+8(%0), %%xmm0 \n\t" \
  353. "movdqa " #t "+32(%1), %%xmm3 \n\t" \
  354. "movdqa " #t "+48(%1), %%xmm7 \n\t" \
  355. "movdqa " #t "(%1), %%xmm4 \n\t" \
  356. "movdqa " #t "+16(%1), %%xmm5 \n\t"
  357. #define FDCT_ROW_SSE2_H2(i,t) \
  358. "movq " #i "(%0), %%xmm2 \n\t" \
  359. "movq " #i "+8(%0), %%xmm0 \n\t" \
  360. "movdqa " #t "+32(%1), %%xmm3 \n\t" \
  361. "movdqa " #t "+48(%1), %%xmm7 \n\t"
  362. #define FDCT_ROW_SSE2(i) \
  363. "movq %%xmm2, %%xmm1 \n\t" \
  364. "pshuflw $27, %%xmm0, %%xmm0 \n\t" \
  365. "paddsw %%xmm0, %%xmm1 \n\t" \
  366. "psubsw %%xmm0, %%xmm2 \n\t" \
  367. "punpckldq %%xmm2, %%xmm1 \n\t" \
  368. "pshufd $78, %%xmm1, %%xmm2 \n\t" \
  369. "pmaddwd %%xmm2, %%xmm3 \n\t" \
  370. "pmaddwd %%xmm1, %%xmm7 \n\t" \
  371. "pmaddwd %%xmm5, %%xmm2 \n\t" \
  372. "pmaddwd %%xmm4, %%xmm1 \n\t" \
  373. "paddd %%xmm7, %%xmm3 \n\t" \
  374. "paddd %%xmm2, %%xmm1 \n\t" \
  375. "paddd %%xmm6, %%xmm3 \n\t" \
  376. "paddd %%xmm6, %%xmm1 \n\t" \
  377. "psrad %3, %%xmm3 \n\t" \
  378. "psrad %3, %%xmm1 \n\t" \
  379. "packssdw %%xmm3, %%xmm1 \n\t" \
  380. "movdqa %%xmm1, " #i "(%4) \n\t"
  381. "movdqa (%2), %%xmm6 \n\t"
  382. FDCT_ROW_SSE2_H1(0,0)
  383. FDCT_ROW_SSE2(0)
  384. FDCT_ROW_SSE2_H2(64,0)
  385. FDCT_ROW_SSE2(64)
  386. FDCT_ROW_SSE2_H1(16,64)
  387. FDCT_ROW_SSE2(16)
  388. FDCT_ROW_SSE2_H2(112,64)
  389. FDCT_ROW_SSE2(112)
  390. FDCT_ROW_SSE2_H1(32,128)
  391. FDCT_ROW_SSE2(32)
  392. FDCT_ROW_SSE2_H2(96,128)
  393. FDCT_ROW_SSE2(96)
  394. FDCT_ROW_SSE2_H1(48,192)
  395. FDCT_ROW_SSE2(48)
  396. FDCT_ROW_SSE2_H2(80,192)
  397. FDCT_ROW_SSE2(80)
  398. :
  399. : "r" (in), "r" (tab_frw_01234567_sse2.tab_frw_01234567_sse2), "r" (fdct_r_row_sse2.fdct_r_row_sse2), "i" (SHIFT_FRW_ROW), "r" (out)
  400. );
  401. }
  402. static av_always_inline void fdct_row_mmx2(const int16_t *in, int16_t *out, const int16_t *table)
  403. {
  404. __asm__ volatile (
  405. "pshufw $0x1B, 8(%0), %%mm5 \n\t"
  406. "movq (%0), %%mm0 \n\t"
  407. "movq %%mm0, %%mm1 \n\t"
  408. "paddsw %%mm5, %%mm0 \n\t"
  409. "psubsw %%mm5, %%mm1 \n\t"
  410. "movq %%mm0, %%mm2 \n\t"
  411. "punpckldq %%mm1, %%mm0 \n\t"
  412. "punpckhdq %%mm1, %%mm2 \n\t"
  413. "movq (%1), %%mm1 \n\t"
  414. "movq 8(%1), %%mm3 \n\t"
  415. "movq 16(%1), %%mm4 \n\t"
  416. "movq 24(%1), %%mm5 \n\t"
  417. "movq 32(%1), %%mm6 \n\t"
  418. "movq 40(%1), %%mm7 \n\t"
  419. "pmaddwd %%mm0, %%mm1 \n\t"
  420. "pmaddwd %%mm2, %%mm3 \n\t"
  421. "pmaddwd %%mm0, %%mm4 \n\t"
  422. "pmaddwd %%mm2, %%mm5 \n\t"
  423. "pmaddwd %%mm0, %%mm6 \n\t"
  424. "pmaddwd %%mm2, %%mm7 \n\t"
  425. "pmaddwd 48(%1), %%mm0 \n\t"
  426. "pmaddwd 56(%1), %%mm2 \n\t"
  427. "paddd %%mm1, %%mm3 \n\t"
  428. "paddd %%mm4, %%mm5 \n\t"
  429. "paddd %%mm6, %%mm7 \n\t"
  430. "paddd %%mm0, %%mm2 \n\t"
  431. "movq (%2), %%mm0 \n\t"
  432. "paddd %%mm0, %%mm3 \n\t"
  433. "paddd %%mm0, %%mm5 \n\t"
  434. "paddd %%mm0, %%mm7 \n\t"
  435. "paddd %%mm0, %%mm2 \n\t"
  436. "psrad $"S(SHIFT_FRW_ROW)", %%mm3 \n\t"
  437. "psrad $"S(SHIFT_FRW_ROW)", %%mm5 \n\t"
  438. "psrad $"S(SHIFT_FRW_ROW)", %%mm7 \n\t"
  439. "psrad $"S(SHIFT_FRW_ROW)", %%mm2 \n\t"
  440. "packssdw %%mm5, %%mm3 \n\t"
  441. "packssdw %%mm2, %%mm7 \n\t"
  442. "movq %%mm3, (%3) \n\t"
  443. "movq %%mm7, 8(%3) \n\t"
  444. :
  445. : "r" (in), "r" (table), "r" (fdct_r_row), "r" (out));
  446. }
  447. static av_always_inline void fdct_row_mmx(const int16_t *in, int16_t *out, const int16_t *table)
  448. {
  449. //FIXME reorder (I do not have an old MMX-only CPU here to benchmark ...)
  450. __asm__ volatile(
  451. "movd 12(%0), %%mm1 \n\t"
  452. "punpcklwd 8(%0), %%mm1 \n\t"
  453. "movq %%mm1, %%mm2 \n\t"
  454. "psrlq $0x20, %%mm1 \n\t"
  455. "movq 0(%0), %%mm0 \n\t"
  456. "punpcklwd %%mm2, %%mm1 \n\t"
  457. "movq %%mm0, %%mm5 \n\t"
  458. "paddsw %%mm1, %%mm0 \n\t"
  459. "psubsw %%mm1, %%mm5 \n\t"
  460. "movq %%mm0, %%mm2 \n\t"
  461. "punpckldq %%mm5, %%mm0 \n\t"
  462. "punpckhdq %%mm5, %%mm2 \n\t"
  463. "movq 0(%1), %%mm1 \n\t"
  464. "movq 8(%1), %%mm3 \n\t"
  465. "movq 16(%1), %%mm4 \n\t"
  466. "movq 24(%1), %%mm5 \n\t"
  467. "movq 32(%1), %%mm6 \n\t"
  468. "movq 40(%1), %%mm7 \n\t"
  469. "pmaddwd %%mm0, %%mm1 \n\t"
  470. "pmaddwd %%mm2, %%mm3 \n\t"
  471. "pmaddwd %%mm0, %%mm4 \n\t"
  472. "pmaddwd %%mm2, %%mm5 \n\t"
  473. "pmaddwd %%mm0, %%mm6 \n\t"
  474. "pmaddwd %%mm2, %%mm7 \n\t"
  475. "pmaddwd 48(%1), %%mm0 \n\t"
  476. "pmaddwd 56(%1), %%mm2 \n\t"
  477. "paddd %%mm1, %%mm3 \n\t"
  478. "paddd %%mm4, %%mm5 \n\t"
  479. "paddd %%mm6, %%mm7 \n\t"
  480. "paddd %%mm0, %%mm2 \n\t"
  481. "movq (%2), %%mm0 \n\t"
  482. "paddd %%mm0, %%mm3 \n\t"
  483. "paddd %%mm0, %%mm5 \n\t"
  484. "paddd %%mm0, %%mm7 \n\t"
  485. "paddd %%mm0, %%mm2 \n\t"
  486. "psrad $"S(SHIFT_FRW_ROW)", %%mm3 \n\t"
  487. "psrad $"S(SHIFT_FRW_ROW)", %%mm5 \n\t"
  488. "psrad $"S(SHIFT_FRW_ROW)", %%mm7 \n\t"
  489. "psrad $"S(SHIFT_FRW_ROW)", %%mm2 \n\t"
  490. "packssdw %%mm5, %%mm3 \n\t"
  491. "packssdw %%mm2, %%mm7 \n\t"
  492. "movq %%mm3, 0(%3) \n\t"
  493. "movq %%mm7, 8(%3) \n\t"
  494. :
  495. : "r" (in), "r" (table), "r" (fdct_r_row), "r" (out));
  496. }
  497. void ff_fdct_mmx(int16_t *block)
  498. {
  499. int64_t align_tmp[16] ATTR_ALIGN(8);
  500. int16_t * block1= (int16_t*)align_tmp;
  501. const int16_t *table= tab_frw_01234567;
  502. int i;
  503. fdct_col_mmx(block, block1, 0);
  504. fdct_col_mmx(block, block1, 4);
  505. for(i=8;i>0;i--) {
  506. fdct_row_mmx(block1, block, table);
  507. block1 += 8;
  508. table += 32;
  509. block += 8;
  510. }
  511. }
  512. void ff_fdct_mmx2(int16_t *block)
  513. {
  514. int64_t align_tmp[16] ATTR_ALIGN(8);
  515. int16_t *block1= (int16_t*)align_tmp;
  516. const int16_t *table= tab_frw_01234567;
  517. int i;
  518. fdct_col_mmx(block, block1, 0);
  519. fdct_col_mmx(block, block1, 4);
  520. for(i=8;i>0;i--) {
  521. fdct_row_mmx2(block1, block, table);
  522. block1 += 8;
  523. table += 32;
  524. block += 8;
  525. }
  526. }
  527. void ff_fdct_sse2(int16_t *block)
  528. {
  529. int64_t align_tmp[16] ATTR_ALIGN(16);
  530. int16_t * const block1= (int16_t*)align_tmp;
  531. fdct_col_sse2(block, block1, 0);
  532. fdct_row_sse2(block1, block);
  533. }