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.

582 lines
18KB

  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 Libav.
  17. *
  18. * Libav 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. * Libav 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 Libav; 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_cpu.h"
  34. #include "libavcodec/dsputil.h"
  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. DECLARE_ALIGNED(16, static const int16_t, fdct_tg_all_16)[24] = {
  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. DECLARE_ALIGNED(16, static const int16_t, ocos_4_16)[8] = {
  58. X8(23170) //cos * (2<<15) + 0.5
  59. };
  60. DECLARE_ALIGNED(16, static const int16_t, fdct_one_corr)[8] = { X8(1) };
  61. DECLARE_ALIGNED(8, static const int32_t, fdct_r_row)[2] = {RND_FRW_ROW, RND_FRW_ROW };
  62. static struct
  63. {
  64. DECLARE_ALIGNED(16, const int32_t, fdct_r_row_sse2)[4];
  65. } fdct_r_row_sse2 =
  66. {{
  67. RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW
  68. }};
  69. //DECLARE_ALIGNED(16, static const long, fdct_r_row_sse2)[4] = {RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW, RND_FRW_ROW};
  70. DECLARE_ALIGNED(8, static const int16_t, tab_frw_01234567)[] = { // 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. DECLARE_ALIGNED(16, const int16_t, tab_frw_01234567_sse2)[256];
  139. } tab_frw_01234567_sse2 =
  140. {{
  141. //DECLARE_ALIGNED(16, static const int16_t, tab_frw_01234567_sse2)[] = { // 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),
  400. "r" (fdct_r_row_sse2.fdct_r_row_sse2), "i" (SHIFT_FRW_ROW), "r" (out)
  401. XMM_CLOBBERS_ONLY("%xmm0", "%xmm1", "%xmm2", "%xmm3",
  402. "%xmm4", "%xmm5", "%xmm6", "%xmm7")
  403. );
  404. }
  405. static av_always_inline void fdct_row_mmx2(const int16_t *in, int16_t *out, const int16_t *table)
  406. {
  407. __asm__ volatile (
  408. "pshufw $0x1B, 8(%0), %%mm5 \n\t"
  409. "movq (%0), %%mm0 \n\t"
  410. "movq %%mm0, %%mm1 \n\t"
  411. "paddsw %%mm5, %%mm0 \n\t"
  412. "psubsw %%mm5, %%mm1 \n\t"
  413. "movq %%mm0, %%mm2 \n\t"
  414. "punpckldq %%mm1, %%mm0 \n\t"
  415. "punpckhdq %%mm1, %%mm2 \n\t"
  416. "movq (%1), %%mm1 \n\t"
  417. "movq 8(%1), %%mm3 \n\t"
  418. "movq 16(%1), %%mm4 \n\t"
  419. "movq 24(%1), %%mm5 \n\t"
  420. "movq 32(%1), %%mm6 \n\t"
  421. "movq 40(%1), %%mm7 \n\t"
  422. "pmaddwd %%mm0, %%mm1 \n\t"
  423. "pmaddwd %%mm2, %%mm3 \n\t"
  424. "pmaddwd %%mm0, %%mm4 \n\t"
  425. "pmaddwd %%mm2, %%mm5 \n\t"
  426. "pmaddwd %%mm0, %%mm6 \n\t"
  427. "pmaddwd %%mm2, %%mm7 \n\t"
  428. "pmaddwd 48(%1), %%mm0 \n\t"
  429. "pmaddwd 56(%1), %%mm2 \n\t"
  430. "paddd %%mm1, %%mm3 \n\t"
  431. "paddd %%mm4, %%mm5 \n\t"
  432. "paddd %%mm6, %%mm7 \n\t"
  433. "paddd %%mm0, %%mm2 \n\t"
  434. "movq (%2), %%mm0 \n\t"
  435. "paddd %%mm0, %%mm3 \n\t"
  436. "paddd %%mm0, %%mm5 \n\t"
  437. "paddd %%mm0, %%mm7 \n\t"
  438. "paddd %%mm0, %%mm2 \n\t"
  439. "psrad $"S(SHIFT_FRW_ROW)", %%mm3 \n\t"
  440. "psrad $"S(SHIFT_FRW_ROW)", %%mm5 \n\t"
  441. "psrad $"S(SHIFT_FRW_ROW)", %%mm7 \n\t"
  442. "psrad $"S(SHIFT_FRW_ROW)", %%mm2 \n\t"
  443. "packssdw %%mm5, %%mm3 \n\t"
  444. "packssdw %%mm2, %%mm7 \n\t"
  445. "movq %%mm3, (%3) \n\t"
  446. "movq %%mm7, 8(%3) \n\t"
  447. :
  448. : "r" (in), "r" (table), "r" (fdct_r_row), "r" (out));
  449. }
  450. static av_always_inline void fdct_row_mmx(const int16_t *in, int16_t *out, const int16_t *table)
  451. {
  452. //FIXME reorder (I do not have an old MMX-only CPU here to benchmark ...)
  453. __asm__ volatile(
  454. "movd 12(%0), %%mm1 \n\t"
  455. "punpcklwd 8(%0), %%mm1 \n\t"
  456. "movq %%mm1, %%mm2 \n\t"
  457. "psrlq $0x20, %%mm1 \n\t"
  458. "movq 0(%0), %%mm0 \n\t"
  459. "punpcklwd %%mm2, %%mm1 \n\t"
  460. "movq %%mm0, %%mm5 \n\t"
  461. "paddsw %%mm1, %%mm0 \n\t"
  462. "psubsw %%mm1, %%mm5 \n\t"
  463. "movq %%mm0, %%mm2 \n\t"
  464. "punpckldq %%mm5, %%mm0 \n\t"
  465. "punpckhdq %%mm5, %%mm2 \n\t"
  466. "movq 0(%1), %%mm1 \n\t"
  467. "movq 8(%1), %%mm3 \n\t"
  468. "movq 16(%1), %%mm4 \n\t"
  469. "movq 24(%1), %%mm5 \n\t"
  470. "movq 32(%1), %%mm6 \n\t"
  471. "movq 40(%1), %%mm7 \n\t"
  472. "pmaddwd %%mm0, %%mm1 \n\t"
  473. "pmaddwd %%mm2, %%mm3 \n\t"
  474. "pmaddwd %%mm0, %%mm4 \n\t"
  475. "pmaddwd %%mm2, %%mm5 \n\t"
  476. "pmaddwd %%mm0, %%mm6 \n\t"
  477. "pmaddwd %%mm2, %%mm7 \n\t"
  478. "pmaddwd 48(%1), %%mm0 \n\t"
  479. "pmaddwd 56(%1), %%mm2 \n\t"
  480. "paddd %%mm1, %%mm3 \n\t"
  481. "paddd %%mm4, %%mm5 \n\t"
  482. "paddd %%mm6, %%mm7 \n\t"
  483. "paddd %%mm0, %%mm2 \n\t"
  484. "movq (%2), %%mm0 \n\t"
  485. "paddd %%mm0, %%mm3 \n\t"
  486. "paddd %%mm0, %%mm5 \n\t"
  487. "paddd %%mm0, %%mm7 \n\t"
  488. "paddd %%mm0, %%mm2 \n\t"
  489. "psrad $"S(SHIFT_FRW_ROW)", %%mm3 \n\t"
  490. "psrad $"S(SHIFT_FRW_ROW)", %%mm5 \n\t"
  491. "psrad $"S(SHIFT_FRW_ROW)", %%mm7 \n\t"
  492. "psrad $"S(SHIFT_FRW_ROW)", %%mm2 \n\t"
  493. "packssdw %%mm5, %%mm3 \n\t"
  494. "packssdw %%mm2, %%mm7 \n\t"
  495. "movq %%mm3, 0(%3) \n\t"
  496. "movq %%mm7, 8(%3) \n\t"
  497. :
  498. : "r" (in), "r" (table), "r" (fdct_r_row), "r" (out));
  499. }
  500. void ff_fdct_mmx(int16_t *block)
  501. {
  502. DECLARE_ALIGNED(8, int64_t, align_tmp)[16];
  503. int16_t * block1= (int16_t*)align_tmp;
  504. const int16_t *table= tab_frw_01234567;
  505. int i;
  506. fdct_col_mmx(block, block1, 0);
  507. fdct_col_mmx(block, block1, 4);
  508. for(i=8;i>0;i--) {
  509. fdct_row_mmx(block1, block, table);
  510. block1 += 8;
  511. table += 32;
  512. block += 8;
  513. }
  514. }
  515. void ff_fdct_mmx2(int16_t *block)
  516. {
  517. DECLARE_ALIGNED(8, int64_t, align_tmp)[16];
  518. int16_t *block1= (int16_t*)align_tmp;
  519. const int16_t *table= tab_frw_01234567;
  520. int i;
  521. fdct_col_mmx(block, block1, 0);
  522. fdct_col_mmx(block, block1, 4);
  523. for(i=8;i>0;i--) {
  524. fdct_row_mmx2(block1, block, table);
  525. block1 += 8;
  526. table += 32;
  527. block += 8;
  528. }
  529. }
  530. void ff_fdct_sse2(int16_t *block)
  531. {
  532. DECLARE_ALIGNED(16, int64_t, align_tmp)[16];
  533. int16_t * const block1= (int16_t*)align_tmp;
  534. fdct_col_sse2(block, block1, 0);
  535. fdct_row_sse2(block1, block);
  536. }