2
0

fdct.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. /*
  2. * SIMD-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 "libavutil/x86/asm.h"
  34. #include "fdct.h"
  35. #if HAVE_MMX_INLINE
  36. //////////////////////////////////////////////////////////////////////
  37. //
  38. // constants for the forward DCT
  39. // -----------------------------
  40. //
  41. // Be sure to check that your compiler is aligning all constants to QWORD
  42. // (8-byte) memory boundaries! Otherwise the unaligned memory access will
  43. // severely stall MMX execution.
  44. //
  45. //////////////////////////////////////////////////////////////////////
  46. #define BITS_FRW_ACC 3 //; 2 or 3 for accuracy
  47. #define SHIFT_FRW_COL BITS_FRW_ACC
  48. #define SHIFT_FRW_ROW (BITS_FRW_ACC + 17 - 3)
  49. #define RND_FRW_ROW (1 << (SHIFT_FRW_ROW-1))
  50. //#define RND_FRW_COL (1 << (SHIFT_FRW_COL-1))
  51. #define X8(x) x,x,x,x,x,x,x,x
  52. //concatenated table, for forward DCT transformation
  53. DECLARE_ALIGNED(16, static const int16_t, fdct_tg_all_16)[24] = {
  54. X8(13036), // tg * (2<<16) + 0.5
  55. X8(27146), // tg * (2<<16) + 0.5
  56. X8(-21746) // tg * (2<<16) + 0.5
  57. };
  58. DECLARE_ALIGNED(16, static const int16_t, ocos_4_16)[8] = {
  59. X8(23170) //cos * (2<<15) + 0.5
  60. };
  61. DECLARE_ALIGNED(16, static const int16_t, fdct_one_corr)[8] = { X8(1) };
  62. DECLARE_ALIGNED(8, static const int32_t, fdct_r_row)[2] = {RND_FRW_ROW, RND_FRW_ROW };
  63. static const struct
  64. {
  65. DECLARE_ALIGNED(16, const int32_t, fdct_r_row_sse2)[4];
  66. } fdct_r_row_sse2 =
  67. {{
  68. RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW
  69. }};
  70. //DECLARE_ALIGNED(16, static const long, fdct_r_row_sse2)[4] = {RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW};
  71. DECLARE_ALIGNED(8, static const int16_t, tab_frw_01234567)[] = { // forward_dct coeff table
  72. 16384, 16384, 22725, 19266,
  73. 16384, 16384, 12873, 4520,
  74. 21407, 8867, 19266, -4520,
  75. -8867, -21407, -22725, -12873,
  76. 16384, -16384, 12873, -22725,
  77. -16384, 16384, 4520, 19266,
  78. 8867, -21407, 4520, -12873,
  79. 21407, -8867, 19266, -22725,
  80. 22725, 22725, 31521, 26722,
  81. 22725, 22725, 17855, 6270,
  82. 29692, 12299, 26722, -6270,
  83. -12299, -29692, -31521, -17855,
  84. 22725, -22725, 17855, -31521,
  85. -22725, 22725, 6270, 26722,
  86. 12299, -29692, 6270, -17855,
  87. 29692, -12299, 26722, -31521,
  88. 21407, 21407, 29692, 25172,
  89. 21407, 21407, 16819, 5906,
  90. 27969, 11585, 25172, -5906,
  91. -11585, -27969, -29692, -16819,
  92. 21407, -21407, 16819, -29692,
  93. -21407, 21407, 5906, 25172,
  94. 11585, -27969, 5906, -16819,
  95. 27969, -11585, 25172, -29692,
  96. 19266, 19266, 26722, 22654,
  97. 19266, 19266, 15137, 5315,
  98. 25172, 10426, 22654, -5315,
  99. -10426, -25172, -26722, -15137,
  100. 19266, -19266, 15137, -26722,
  101. -19266, 19266, 5315, 22654,
  102. 10426, -25172, 5315, -15137,
  103. 25172, -10426, 22654, -26722,
  104. 16384, 16384, 22725, 19266,
  105. 16384, 16384, 12873, 4520,
  106. 21407, 8867, 19266, -4520,
  107. -8867, -21407, -22725, -12873,
  108. 16384, -16384, 12873, -22725,
  109. -16384, 16384, 4520, 19266,
  110. 8867, -21407, 4520, -12873,
  111. 21407, -8867, 19266, -22725,
  112. 19266, 19266, 26722, 22654,
  113. 19266, 19266, 15137, 5315,
  114. 25172, 10426, 22654, -5315,
  115. -10426, -25172, -26722, -15137,
  116. 19266, -19266, 15137, -26722,
  117. -19266, 19266, 5315, 22654,
  118. 10426, -25172, 5315, -15137,
  119. 25172, -10426, 22654, -26722,
  120. 21407, 21407, 29692, 25172,
  121. 21407, 21407, 16819, 5906,
  122. 27969, 11585, 25172, -5906,
  123. -11585, -27969, -29692, -16819,
  124. 21407, -21407, 16819, -29692,
  125. -21407, 21407, 5906, 25172,
  126. 11585, -27969, 5906, -16819,
  127. 27969, -11585, 25172, -29692,
  128. 22725, 22725, 31521, 26722,
  129. 22725, 22725, 17855, 6270,
  130. 29692, 12299, 26722, -6270,
  131. -12299, -29692, -31521, -17855,
  132. 22725, -22725, 17855, -31521,
  133. -22725, 22725, 6270, 26722,
  134. 12299, -29692, 6270, -17855,
  135. 29692, -12299, 26722, -31521,
  136. };
  137. static const struct
  138. {
  139. DECLARE_ALIGNED(16, const int16_t, tab_frw_01234567_sse2)[256];
  140. } tab_frw_01234567_sse2 =
  141. {{
  142. //DECLARE_ALIGNED(16, static const int16_t, tab_frw_01234567_sse2)[] = { // forward_dct coeff table
  143. #define TABLE_SSE2 C4, C4, C1, C3, -C6, -C2, -C1, -C5, \
  144. C4, C4, C5, C7, C2, C6, C3, -C7, \
  145. -C4, C4, C7, C3, C6, -C2, C7, -C5, \
  146. C4, -C4, C5, -C1, C2, -C6, C3, -C1,
  147. // c1..c7 * cos(pi/4) * 2^15
  148. #define C1 22725
  149. #define C2 21407
  150. #define C3 19266
  151. #define C4 16384
  152. #define C5 12873
  153. #define C6 8867
  154. #define C7 4520
  155. TABLE_SSE2
  156. #undef C1
  157. #undef C2
  158. #undef C3
  159. #undef C4
  160. #undef C5
  161. #undef C6
  162. #undef C7
  163. #define C1 31521
  164. #define C2 29692
  165. #define C3 26722
  166. #define C4 22725
  167. #define C5 17855
  168. #define C6 12299
  169. #define C7 6270
  170. TABLE_SSE2
  171. #undef C1
  172. #undef C2
  173. #undef C3
  174. #undef C4
  175. #undef C5
  176. #undef C6
  177. #undef C7
  178. #define C1 29692
  179. #define C2 27969
  180. #define C3 25172
  181. #define C4 21407
  182. #define C5 16819
  183. #define C6 11585
  184. #define C7 5906
  185. TABLE_SSE2
  186. #undef C1
  187. #undef C2
  188. #undef C3
  189. #undef C4
  190. #undef C5
  191. #undef C6
  192. #undef C7
  193. #define C1 26722
  194. #define C2 25172
  195. #define C3 22654
  196. #define C4 19266
  197. #define C5 15137
  198. #define C6 10426
  199. #define C7 5315
  200. TABLE_SSE2
  201. #undef C1
  202. #undef C2
  203. #undef C3
  204. #undef C4
  205. #undef C5
  206. #undef C6
  207. #undef C7
  208. #define C1 22725
  209. #define C2 21407
  210. #define C3 19266
  211. #define C4 16384
  212. #define C5 12873
  213. #define C6 8867
  214. #define C7 4520
  215. TABLE_SSE2
  216. #undef C1
  217. #undef C2
  218. #undef C3
  219. #undef C4
  220. #undef C5
  221. #undef C6
  222. #undef C7
  223. #define C1 26722
  224. #define C2 25172
  225. #define C3 22654
  226. #define C4 19266
  227. #define C5 15137
  228. #define C6 10426
  229. #define C7 5315
  230. TABLE_SSE2
  231. #undef C1
  232. #undef C2
  233. #undef C3
  234. #undef C4
  235. #undef C5
  236. #undef C6
  237. #undef C7
  238. #define C1 29692
  239. #define C2 27969
  240. #define C3 25172
  241. #define C4 21407
  242. #define C5 16819
  243. #define C6 11585
  244. #define C7 5906
  245. TABLE_SSE2
  246. #undef C1
  247. #undef C2
  248. #undef C3
  249. #undef C4
  250. #undef C5
  251. #undef C6
  252. #undef C7
  253. #define C1 31521
  254. #define C2 29692
  255. #define C3 26722
  256. #define C4 22725
  257. #define C5 17855
  258. #define C6 12299
  259. #define C7 6270
  260. TABLE_SSE2
  261. }};
  262. #define S(s) AV_TOSTRING(s) //AV_STRINGIFY is too long
  263. #define FDCT_COL(cpu, mm, mov)\
  264. static av_always_inline void fdct_col_##cpu(const int16_t *in, int16_t *out, int offset)\
  265. {\
  266. __asm__ volatile (\
  267. #mov" 16(%0), %%"#mm"0 \n\t" \
  268. #mov" 96(%0), %%"#mm"1 \n\t" \
  269. #mov" %%"#mm"0, %%"#mm"2 \n\t" \
  270. #mov" 32(%0), %%"#mm"3 \n\t" \
  271. "paddsw %%"#mm"1, %%"#mm"0 \n\t" \
  272. #mov" 80(%0), %%"#mm"4 \n\t" \
  273. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"0 \n\t" \
  274. #mov" (%0), %%"#mm"5 \n\t" \
  275. "paddsw %%"#mm"3, %%"#mm"4 \n\t" \
  276. "paddsw 112(%0), %%"#mm"5 \n\t" \
  277. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"4 \n\t" \
  278. #mov" %%"#mm"0, %%"#mm"6 \n\t" \
  279. "psubsw %%"#mm"1, %%"#mm"2 \n\t" \
  280. #mov" 16(%1), %%"#mm"1 \n\t" \
  281. "psubsw %%"#mm"4, %%"#mm"0 \n\t" \
  282. #mov" 48(%0), %%"#mm"7 \n\t" \
  283. "pmulhw %%"#mm"0, %%"#mm"1 \n\t" \
  284. "paddsw 64(%0), %%"#mm"7 \n\t" \
  285. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"5 \n\t" \
  286. "paddsw %%"#mm"4, %%"#mm"6 \n\t" \
  287. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"7 \n\t" \
  288. #mov" %%"#mm"5, %%"#mm"4 \n\t" \
  289. "psubsw %%"#mm"7, %%"#mm"5 \n\t" \
  290. "paddsw %%"#mm"5, %%"#mm"1 \n\t" \
  291. "paddsw %%"#mm"7, %%"#mm"4 \n\t" \
  292. "por (%2), %%"#mm"1 \n\t" \
  293. "psllw $"S(SHIFT_FRW_COL)"+1, %%"#mm"2 \n\t" \
  294. "pmulhw 16(%1), %%"#mm"5 \n\t" \
  295. #mov" %%"#mm"4, %%"#mm"7 \n\t" \
  296. "psubsw 80(%0), %%"#mm"3 \n\t" \
  297. "psubsw %%"#mm"6, %%"#mm"4 \n\t" \
  298. #mov" %%"#mm"1, 32(%3) \n\t" \
  299. "paddsw %%"#mm"6, %%"#mm"7 \n\t" \
  300. #mov" 48(%0), %%"#mm"1 \n\t" \
  301. "psllw $"S(SHIFT_FRW_COL)"+1, %%"#mm"3 \n\t" \
  302. "psubsw 64(%0), %%"#mm"1 \n\t" \
  303. #mov" %%"#mm"2, %%"#mm"6 \n\t" \
  304. #mov" %%"#mm"4, 64(%3) \n\t" \
  305. "paddsw %%"#mm"3, %%"#mm"2 \n\t" \
  306. "pmulhw (%4), %%"#mm"2 \n\t" \
  307. "psubsw %%"#mm"3, %%"#mm"6 \n\t" \
  308. "pmulhw (%4), %%"#mm"6 \n\t" \
  309. "psubsw %%"#mm"0, %%"#mm"5 \n\t" \
  310. "por (%2), %%"#mm"5 \n\t" \
  311. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"1 \n\t" \
  312. "por (%2), %%"#mm"2 \n\t" \
  313. #mov" %%"#mm"1, %%"#mm"4 \n\t" \
  314. #mov" (%0), %%"#mm"3 \n\t" \
  315. "paddsw %%"#mm"6, %%"#mm"1 \n\t" \
  316. "psubsw 112(%0), %%"#mm"3 \n\t" \
  317. "psubsw %%"#mm"6, %%"#mm"4 \n\t" \
  318. #mov" (%1), %%"#mm"0 \n\t" \
  319. "psllw $"S(SHIFT_FRW_COL)", %%"#mm"3 \n\t" \
  320. #mov" 32(%1), %%"#mm"6 \n\t" \
  321. "pmulhw %%"#mm"1, %%"#mm"0 \n\t" \
  322. #mov" %%"#mm"7, (%3) \n\t" \
  323. "pmulhw %%"#mm"4, %%"#mm"6 \n\t" \
  324. #mov" %%"#mm"5, 96(%3) \n\t" \
  325. #mov" %%"#mm"3, %%"#mm"7 \n\t" \
  326. #mov" 32(%1), %%"#mm"5 \n\t" \
  327. "psubsw %%"#mm"2, %%"#mm"7 \n\t" \
  328. "paddsw %%"#mm"2, %%"#mm"3 \n\t" \
  329. "pmulhw %%"#mm"7, %%"#mm"5 \n\t" \
  330. "paddsw %%"#mm"3, %%"#mm"0 \n\t" \
  331. "paddsw %%"#mm"4, %%"#mm"6 \n\t" \
  332. "pmulhw (%1), %%"#mm"3 \n\t" \
  333. "por (%2), %%"#mm"0 \n\t" \
  334. "paddsw %%"#mm"7, %%"#mm"5 \n\t" \
  335. "psubsw %%"#mm"6, %%"#mm"7 \n\t" \
  336. #mov" %%"#mm"0, 16(%3) \n\t" \
  337. "paddsw %%"#mm"4, %%"#mm"5 \n\t" \
  338. #mov" %%"#mm"7, 48(%3) \n\t" \
  339. "psubsw %%"#mm"1, %%"#mm"3 \n\t" \
  340. #mov" %%"#mm"5, 80(%3) \n\t" \
  341. #mov" %%"#mm"3, 112(%3) \n\t" \
  342. : \
  343. : "r" (in + offset), "r" (fdct_tg_all_16), "r" (fdct_one_corr), \
  344. "r" (out + offset), "r" (ocos_4_16)); \
  345. }
  346. FDCT_COL(mmx, mm, movq)
  347. FDCT_COL(sse2, xmm, movdqa)
  348. static av_always_inline void fdct_row_sse2(const int16_t *in, int16_t *out)
  349. {
  350. __asm__ volatile(
  351. #define FDCT_ROW_SSE2_H1(i,t) \
  352. "movq " #i "(%0), %%xmm2 \n\t" \
  353. "movq " #i "+8(%0), %%xmm0 \n\t" \
  354. "movdqa " #t "+32(%1), %%xmm3 \n\t" \
  355. "movdqa " #t "+48(%1), %%xmm7 \n\t" \
  356. "movdqa " #t "(%1), %%xmm4 \n\t" \
  357. "movdqa " #t "+16(%1), %%xmm5 \n\t"
  358. #define FDCT_ROW_SSE2_H2(i,t) \
  359. "movq " #i "(%0), %%xmm2 \n\t" \
  360. "movq " #i "+8(%0), %%xmm0 \n\t" \
  361. "movdqa " #t "+32(%1), %%xmm3 \n\t" \
  362. "movdqa " #t "+48(%1), %%xmm7 \n\t"
  363. #define FDCT_ROW_SSE2(i) \
  364. "movq %%xmm2, %%xmm1 \n\t" \
  365. "pshuflw $27, %%xmm0, %%xmm0 \n\t" \
  366. "paddsw %%xmm0, %%xmm1 \n\t" \
  367. "psubsw %%xmm0, %%xmm2 \n\t" \
  368. "punpckldq %%xmm2, %%xmm1 \n\t" \
  369. "pshufd $78, %%xmm1, %%xmm2 \n\t" \
  370. "pmaddwd %%xmm2, %%xmm3 \n\t" \
  371. "pmaddwd %%xmm1, %%xmm7 \n\t" \
  372. "pmaddwd %%xmm5, %%xmm2 \n\t" \
  373. "pmaddwd %%xmm4, %%xmm1 \n\t" \
  374. "paddd %%xmm7, %%xmm3 \n\t" \
  375. "paddd %%xmm2, %%xmm1 \n\t" \
  376. "paddd %%xmm6, %%xmm3 \n\t" \
  377. "paddd %%xmm6, %%xmm1 \n\t" \
  378. "psrad %3, %%xmm3 \n\t" \
  379. "psrad %3, %%xmm1 \n\t" \
  380. "packssdw %%xmm3, %%xmm1 \n\t" \
  381. "movdqa %%xmm1, " #i "(%4) \n\t"
  382. "movdqa (%2), %%xmm6 \n\t"
  383. FDCT_ROW_SSE2_H1(0,0)
  384. FDCT_ROW_SSE2(0)
  385. FDCT_ROW_SSE2_H2(64,0)
  386. FDCT_ROW_SSE2(64)
  387. FDCT_ROW_SSE2_H1(16,64)
  388. FDCT_ROW_SSE2(16)
  389. FDCT_ROW_SSE2_H2(112,64)
  390. FDCT_ROW_SSE2(112)
  391. FDCT_ROW_SSE2_H1(32,128)
  392. FDCT_ROW_SSE2(32)
  393. FDCT_ROW_SSE2_H2(96,128)
  394. FDCT_ROW_SSE2(96)
  395. FDCT_ROW_SSE2_H1(48,192)
  396. FDCT_ROW_SSE2(48)
  397. FDCT_ROW_SSE2_H2(80,192)
  398. FDCT_ROW_SSE2(80)
  399. :
  400. : "r" (in), "r" (tab_frw_01234567_sse2.tab_frw_01234567_sse2),
  401. "r" (fdct_r_row_sse2.fdct_r_row_sse2), "i" (SHIFT_FRW_ROW), "r" (out)
  402. XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
  403. "%xmm4", "%xmm5", "%xmm6", "%xmm7")
  404. );
  405. }
  406. static av_always_inline void fdct_row_mmxext(const int16_t *in, int16_t *out,
  407. const int16_t *table)
  408. {
  409. __asm__ volatile (
  410. "pshufw $0x1B, 8(%0), %%mm5 \n\t"
  411. "movq (%0), %%mm0 \n\t"
  412. "movq %%mm0, %%mm1 \n\t"
  413. "paddsw %%mm5, %%mm0 \n\t"
  414. "psubsw %%mm5, %%mm1 \n\t"
  415. "movq %%mm0, %%mm2 \n\t"
  416. "punpckldq %%mm1, %%mm0 \n\t"
  417. "punpckhdq %%mm1, %%mm2 \n\t"
  418. "movq (%1), %%mm1 \n\t"
  419. "movq 8(%1), %%mm3 \n\t"
  420. "movq 16(%1), %%mm4 \n\t"
  421. "movq 24(%1), %%mm5 \n\t"
  422. "movq 32(%1), %%mm6 \n\t"
  423. "movq 40(%1), %%mm7 \n\t"
  424. "pmaddwd %%mm0, %%mm1 \n\t"
  425. "pmaddwd %%mm2, %%mm3 \n\t"
  426. "pmaddwd %%mm0, %%mm4 \n\t"
  427. "pmaddwd %%mm2, %%mm5 \n\t"
  428. "pmaddwd %%mm0, %%mm6 \n\t"
  429. "pmaddwd %%mm2, %%mm7 \n\t"
  430. "pmaddwd 48(%1), %%mm0 \n\t"
  431. "pmaddwd 56(%1), %%mm2 \n\t"
  432. "paddd %%mm1, %%mm3 \n\t"
  433. "paddd %%mm4, %%mm5 \n\t"
  434. "paddd %%mm6, %%mm7 \n\t"
  435. "paddd %%mm0, %%mm2 \n\t"
  436. "movq (%2), %%mm0 \n\t"
  437. "paddd %%mm0, %%mm3 \n\t"
  438. "paddd %%mm0, %%mm5 \n\t"
  439. "paddd %%mm0, %%mm7 \n\t"
  440. "paddd %%mm0, %%mm2 \n\t"
  441. "psrad $"S(SHIFT_FRW_ROW)", %%mm3 \n\t"
  442. "psrad $"S(SHIFT_FRW_ROW)", %%mm5 \n\t"
  443. "psrad $"S(SHIFT_FRW_ROW)", %%mm7 \n\t"
  444. "psrad $"S(SHIFT_FRW_ROW)", %%mm2 \n\t"
  445. "packssdw %%mm5, %%mm3 \n\t"
  446. "packssdw %%mm2, %%mm7 \n\t"
  447. "movq %%mm3, (%3) \n\t"
  448. "movq %%mm7, 8(%3) \n\t"
  449. :
  450. : "r" (in), "r" (table), "r" (fdct_r_row), "r" (out));
  451. }
  452. static av_always_inline void fdct_row_mmx(const int16_t *in, int16_t *out, const int16_t *table)
  453. {
  454. //FIXME reorder (I do not have an old MMX-only CPU here to benchmark ...)
  455. __asm__ volatile(
  456. "movd 12(%0), %%mm1 \n\t"
  457. "punpcklwd 8(%0), %%mm1 \n\t"
  458. "movq %%mm1, %%mm2 \n\t"
  459. "psrlq $0x20, %%mm1 \n\t"
  460. "movq 0(%0), %%mm0 \n\t"
  461. "punpcklwd %%mm2, %%mm1 \n\t"
  462. "movq %%mm0, %%mm5 \n\t"
  463. "paddsw %%mm1, %%mm0 \n\t"
  464. "psubsw %%mm1, %%mm5 \n\t"
  465. "movq %%mm0, %%mm2 \n\t"
  466. "punpckldq %%mm5, %%mm0 \n\t"
  467. "punpckhdq %%mm5, %%mm2 \n\t"
  468. "movq 0(%1), %%mm1 \n\t"
  469. "movq 8(%1), %%mm3 \n\t"
  470. "movq 16(%1), %%mm4 \n\t"
  471. "movq 24(%1), %%mm5 \n\t"
  472. "movq 32(%1), %%mm6 \n\t"
  473. "movq 40(%1), %%mm7 \n\t"
  474. "pmaddwd %%mm0, %%mm1 \n\t"
  475. "pmaddwd %%mm2, %%mm3 \n\t"
  476. "pmaddwd %%mm0, %%mm4 \n\t"
  477. "pmaddwd %%mm2, %%mm5 \n\t"
  478. "pmaddwd %%mm0, %%mm6 \n\t"
  479. "pmaddwd %%mm2, %%mm7 \n\t"
  480. "pmaddwd 48(%1), %%mm0 \n\t"
  481. "pmaddwd 56(%1), %%mm2 \n\t"
  482. "paddd %%mm1, %%mm3 \n\t"
  483. "paddd %%mm4, %%mm5 \n\t"
  484. "paddd %%mm6, %%mm7 \n\t"
  485. "paddd %%mm0, %%mm2 \n\t"
  486. "movq (%2), %%mm0 \n\t"
  487. "paddd %%mm0, %%mm3 \n\t"
  488. "paddd %%mm0, %%mm5 \n\t"
  489. "paddd %%mm0, %%mm7 \n\t"
  490. "paddd %%mm0, %%mm2 \n\t"
  491. "psrad $"S(SHIFT_FRW_ROW)", %%mm3 \n\t"
  492. "psrad $"S(SHIFT_FRW_ROW)", %%mm5 \n\t"
  493. "psrad $"S(SHIFT_FRW_ROW)", %%mm7 \n\t"
  494. "psrad $"S(SHIFT_FRW_ROW)", %%mm2 \n\t"
  495. "packssdw %%mm5, %%mm3 \n\t"
  496. "packssdw %%mm2, %%mm7 \n\t"
  497. "movq %%mm3, 0(%3) \n\t"
  498. "movq %%mm7, 8(%3) \n\t"
  499. :
  500. : "r" (in), "r" (table), "r" (fdct_r_row), "r" (out));
  501. }
  502. void ff_fdct_mmx(int16_t *block)
  503. {
  504. DECLARE_ALIGNED(8, int64_t, align_tmp)[16];
  505. int16_t * block1= (int16_t*)align_tmp;
  506. const int16_t *table= tab_frw_01234567;
  507. int i;
  508. fdct_col_mmx(block, block1, 0);
  509. fdct_col_mmx(block, block1, 4);
  510. for(i=8;i>0;i--) {
  511. fdct_row_mmx(block1, block, table);
  512. block1 += 8;
  513. table += 32;
  514. block += 8;
  515. }
  516. }
  517. #endif /* HAVE_MMX_INLINE */
  518. #if HAVE_MMXEXT_INLINE
  519. void ff_fdct_mmxext(int16_t *block)
  520. {
  521. DECLARE_ALIGNED(8, int64_t, align_tmp)[16];
  522. int16_t *block1= (int16_t*)align_tmp;
  523. const int16_t *table= tab_frw_01234567;
  524. int i;
  525. fdct_col_mmx(block, block1, 0);
  526. fdct_col_mmx(block, block1, 4);
  527. for(i=8;i>0;i--) {
  528. fdct_row_mmxext(block1, block, table);
  529. block1 += 8;
  530. table += 32;
  531. block += 8;
  532. }
  533. }
  534. #endif /* HAVE_MMXEXT_INLINE */
  535. #if HAVE_SSE2_INLINE
  536. void ff_fdct_sse2(int16_t *block)
  537. {
  538. DECLARE_ALIGNED(16, int64_t, align_tmp)[16];
  539. int16_t * const block1= (int16_t*)align_tmp;
  540. fdct_col_sse2(block, block1, 0);
  541. fdct_row_sse2(block1, block);
  542. }
  543. #endif /* HAVE_SSE2_INLINE */