mmxidct.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
  5. * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6. * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
  7. * *
  8. * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
  9. * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
  10. * *
  11. ********************************************************************
  12. function:
  13. last mod: $Id$
  14. ********************************************************************/
  15. /*MMX acceleration of Theora's iDCT.
  16. Originally written by Rudolf Marek, based on code from On2's VP3.*/
  17. #include "x86int.h"
  18. #include "../dct.h"
  19. #if defined(OC_X86_ASM)
  20. /*These are offsets into the table of constants below.*/
  21. /*7 rows of cosines, in order: pi/16 * (1 ... 7).*/
  22. #define OC_COSINE_OFFSET (0)
  23. /*A row of 8's.*/
  24. #define OC_EIGHT_OFFSET (56)
  25. /*38 cycles*/
  26. #define OC_IDCT_BEGIN(_y,_x) \
  27. "#OC_IDCT_BEGIN\n\t" \
  28. "movq "OC_I(3,_x)",%%mm2\n\t" \
  29. "movq "OC_MEM_OFFS(0x30,c)",%%mm6\n\t" \
  30. "movq %%mm2,%%mm4\n\t" \
  31. "movq "OC_J(5,_x)",%%mm7\n\t" \
  32. "pmulhw %%mm6,%%mm4\n\t" \
  33. "movq "OC_MEM_OFFS(0x50,c)",%%mm1\n\t" \
  34. "pmulhw %%mm7,%%mm6\n\t" \
  35. "movq %%mm1,%%mm5\n\t" \
  36. "pmulhw %%mm2,%%mm1\n\t" \
  37. "movq "OC_I(1,_x)",%%mm3\n\t" \
  38. "pmulhw %%mm7,%%mm5\n\t" \
  39. "movq "OC_MEM_OFFS(0x10,c)",%%mm0\n\t" \
  40. "paddw %%mm2,%%mm4\n\t" \
  41. "paddw %%mm7,%%mm6\n\t" \
  42. "paddw %%mm1,%%mm2\n\t" \
  43. "movq "OC_J(7,_x)",%%mm1\n\t" \
  44. "paddw %%mm5,%%mm7\n\t" \
  45. "movq %%mm0,%%mm5\n\t" \
  46. "pmulhw %%mm3,%%mm0\n\t" \
  47. "paddw %%mm7,%%mm4\n\t" \
  48. "pmulhw %%mm1,%%mm5\n\t" \
  49. "movq "OC_MEM_OFFS(0x70,c)",%%mm7\n\t" \
  50. "psubw %%mm2,%%mm6\n\t" \
  51. "paddw %%mm3,%%mm0\n\t" \
  52. "pmulhw %%mm7,%%mm3\n\t" \
  53. "movq "OC_I(2,_x)",%%mm2\n\t" \
  54. "pmulhw %%mm1,%%mm7\n\t" \
  55. "paddw %%mm1,%%mm5\n\t" \
  56. "movq %%mm2,%%mm1\n\t" \
  57. "pmulhw "OC_MEM_OFFS(0x20,c)",%%mm2\n\t" \
  58. "psubw %%mm5,%%mm3\n\t" \
  59. "movq "OC_J(6,_x)",%%mm5\n\t" \
  60. "paddw %%mm7,%%mm0\n\t" \
  61. "movq %%mm5,%%mm7\n\t" \
  62. "psubw %%mm4,%%mm0\n\t" \
  63. "pmulhw "OC_MEM_OFFS(0x20,c)",%%mm5\n\t" \
  64. "paddw %%mm1,%%mm2\n\t" \
  65. "pmulhw "OC_MEM_OFFS(0x60,c)",%%mm1\n\t" \
  66. "paddw %%mm4,%%mm4\n\t" \
  67. "paddw %%mm0,%%mm4\n\t" \
  68. "psubw %%mm6,%%mm3\n\t" \
  69. "paddw %%mm7,%%mm5\n\t" \
  70. "paddw %%mm6,%%mm6\n\t" \
  71. "pmulhw "OC_MEM_OFFS(0x60,c)",%%mm7\n\t" \
  72. "paddw %%mm3,%%mm6\n\t" \
  73. "movq %%mm4,"OC_I(1,_y)"\n\t" \
  74. "psubw %%mm5,%%mm1\n\t" \
  75. "movq "OC_MEM_OFFS(0x40,c)",%%mm4\n\t" \
  76. "movq %%mm3,%%mm5\n\t" \
  77. "pmulhw %%mm4,%%mm3\n\t" \
  78. "paddw %%mm2,%%mm7\n\t" \
  79. "movq %%mm6,"OC_I(2,_y)"\n\t" \
  80. "movq %%mm0,%%mm2\n\t" \
  81. "movq "OC_I(0,_x)",%%mm6\n\t" \
  82. "pmulhw %%mm4,%%mm0\n\t" \
  83. "paddw %%mm3,%%mm5\n\t" \
  84. "movq "OC_J(4,_x)",%%mm3\n\t" \
  85. "psubw %%mm1,%%mm5\n\t" \
  86. "paddw %%mm0,%%mm2\n\t" \
  87. "psubw %%mm3,%%mm6\n\t" \
  88. "movq %%mm6,%%mm0\n\t" \
  89. "pmulhw %%mm4,%%mm6\n\t" \
  90. "paddw %%mm3,%%mm3\n\t" \
  91. "paddw %%mm1,%%mm1\n\t" \
  92. "paddw %%mm0,%%mm3\n\t" \
  93. "paddw %%mm5,%%mm1\n\t" \
  94. "pmulhw %%mm3,%%mm4\n\t" \
  95. "paddw %%mm0,%%mm6\n\t" \
  96. "psubw %%mm2,%%mm6\n\t" \
  97. "paddw %%mm2,%%mm2\n\t" \
  98. "movq "OC_I(1,_y)",%%mm0\n\t" \
  99. "paddw %%mm6,%%mm2\n\t" \
  100. "paddw %%mm3,%%mm4\n\t" \
  101. "psubw %%mm1,%%mm2\n\t" \
  102. "#end OC_IDCT_BEGIN\n\t" \
  103. /*38+8=46 cycles.*/
  104. #define OC_ROW_IDCT(_y,_x) \
  105. "#OC_ROW_IDCT\n" \
  106. OC_IDCT_BEGIN(_y,_x) \
  107. /*r3=D'*/ \
  108. "movq "OC_I(2,_y)",%%mm3\n\t" \
  109. /*r4=E'=E-G*/ \
  110. "psubw %%mm7,%%mm4\n\t" \
  111. /*r1=H'+H'*/ \
  112. "paddw %%mm1,%%mm1\n\t" \
  113. /*r7=G+G*/ \
  114. "paddw %%mm7,%%mm7\n\t" \
  115. /*r1=R1=A''+H'*/ \
  116. "paddw %%mm2,%%mm1\n\t" \
  117. /*r7=G'=E+G*/ \
  118. "paddw %%mm4,%%mm7\n\t" \
  119. /*r4=R4=E'-D'*/ \
  120. "psubw %%mm3,%%mm4\n\t" \
  121. "paddw %%mm3,%%mm3\n\t" \
  122. /*r6=R6=F'-B''*/ \
  123. "psubw %%mm5,%%mm6\n\t" \
  124. "paddw %%mm5,%%mm5\n\t" \
  125. /*r3=R3=E'+D'*/ \
  126. "paddw %%mm4,%%mm3\n\t" \
  127. /*r5=R5=F'+B''*/ \
  128. "paddw %%mm6,%%mm5\n\t" \
  129. /*r7=R7=G'-C'*/ \
  130. "psubw %%mm0,%%mm7\n\t" \
  131. "paddw %%mm0,%%mm0\n\t" \
  132. /*Save R1.*/ \
  133. "movq %%mm1,"OC_I(1,_y)"\n\t" \
  134. /*r0=R0=G.+C.*/ \
  135. "paddw %%mm7,%%mm0\n\t" \
  136. "#end OC_ROW_IDCT\n\t" \
  137. /*The following macro does two 4x4 transposes in place.
  138. At entry, we assume:
  139. r0 = a3 a2 a1 a0
  140. I(1) = b3 b2 b1 b0
  141. r2 = c3 c2 c1 c0
  142. r3 = d3 d2 d1 d0
  143. r4 = e3 e2 e1 e0
  144. r5 = f3 f2 f1 f0
  145. r6 = g3 g2 g1 g0
  146. r7 = h3 h2 h1 h0
  147. At exit, we have:
  148. I(0) = d0 c0 b0 a0
  149. I(1) = d1 c1 b1 a1
  150. I(2) = d2 c2 b2 a2
  151. I(3) = d3 c3 b3 a3
  152. J(4) = h0 g0 f0 e0
  153. J(5) = h1 g1 f1 e1
  154. J(6) = h2 g2 f2 e2
  155. J(7) = h3 g3 f3 e3
  156. I(0) I(1) I(2) I(3) is the transpose of r0 I(1) r2 r3.
  157. J(4) J(5) J(6) J(7) is the transpose of r4 r5 r6 r7.
  158. Since r1 is free at entry, we calculate the Js first.*/
  159. /*19 cycles.*/
  160. #define OC_TRANSPOSE(_y) \
  161. "#OC_TRANSPOSE\n\t" \
  162. "movq %%mm4,%%mm1\n\t" \
  163. "punpcklwd %%mm5,%%mm4\n\t" \
  164. "movq %%mm0,"OC_I(0,_y)"\n\t" \
  165. "punpckhwd %%mm5,%%mm1\n\t" \
  166. "movq %%mm6,%%mm0\n\t" \
  167. "punpcklwd %%mm7,%%mm6\n\t" \
  168. "movq %%mm4,%%mm5\n\t" \
  169. "punpckldq %%mm6,%%mm4\n\t" \
  170. "punpckhdq %%mm6,%%mm5\n\t" \
  171. "movq %%mm1,%%mm6\n\t" \
  172. "movq %%mm4,"OC_J(4,_y)"\n\t" \
  173. "punpckhwd %%mm7,%%mm0\n\t" \
  174. "movq %%mm5,"OC_J(5,_y)"\n\t" \
  175. "punpckhdq %%mm0,%%mm6\n\t" \
  176. "movq "OC_I(0,_y)",%%mm4\n\t" \
  177. "punpckldq %%mm0,%%mm1\n\t" \
  178. "movq "OC_I(1,_y)",%%mm5\n\t" \
  179. "movq %%mm4,%%mm0\n\t" \
  180. "movq %%mm6,"OC_J(7,_y)"\n\t" \
  181. "punpcklwd %%mm5,%%mm0\n\t" \
  182. "movq %%mm1,"OC_J(6,_y)"\n\t" \
  183. "punpckhwd %%mm5,%%mm4\n\t" \
  184. "movq %%mm2,%%mm5\n\t" \
  185. "punpcklwd %%mm3,%%mm2\n\t" \
  186. "movq %%mm0,%%mm1\n\t" \
  187. "punpckldq %%mm2,%%mm0\n\t" \
  188. "punpckhdq %%mm2,%%mm1\n\t" \
  189. "movq %%mm4,%%mm2\n\t" \
  190. "movq %%mm0,"OC_I(0,_y)"\n\t" \
  191. "punpckhwd %%mm3,%%mm5\n\t" \
  192. "movq %%mm1,"OC_I(1,_y)"\n\t" \
  193. "punpckhdq %%mm5,%%mm4\n\t" \
  194. "punpckldq %%mm5,%%mm2\n\t" \
  195. "movq %%mm4,"OC_I(3,_y)"\n\t" \
  196. "movq %%mm2,"OC_I(2,_y)"\n\t" \
  197. "#end OC_TRANSPOSE\n\t" \
  198. /*38+19=57 cycles.*/
  199. #define OC_COLUMN_IDCT(_y) \
  200. "#OC_COLUMN_IDCT\n" \
  201. OC_IDCT_BEGIN(_y,_y) \
  202. "paddw "OC_MEM_OFFS(0x00,c)",%%mm2\n\t" \
  203. /*r1=H'+H'*/ \
  204. "paddw %%mm1,%%mm1\n\t" \
  205. /*r1=R1=A''+H'*/ \
  206. "paddw %%mm2,%%mm1\n\t" \
  207. /*r2=NR2*/ \
  208. "psraw $4,%%mm2\n\t" \
  209. /*r4=E'=E-G*/ \
  210. "psubw %%mm7,%%mm4\n\t" \
  211. /*r1=NR1*/ \
  212. "psraw $4,%%mm1\n\t" \
  213. /*r3=D'*/ \
  214. "movq "OC_I(2,_y)",%%mm3\n\t" \
  215. /*r7=G+G*/ \
  216. "paddw %%mm7,%%mm7\n\t" \
  217. /*Store NR2 at I(2).*/ \
  218. "movq %%mm2,"OC_I(2,_y)"\n\t" \
  219. /*r7=G'=E+G*/ \
  220. "paddw %%mm4,%%mm7\n\t" \
  221. /*Store NR1 at I(1).*/ \
  222. "movq %%mm1,"OC_I(1,_y)"\n\t" \
  223. /*r4=R4=E'-D'*/ \
  224. "psubw %%mm3,%%mm4\n\t" \
  225. "paddw "OC_MEM_OFFS(0x00,c)",%%mm4\n\t" \
  226. /*r3=D'+D'*/ \
  227. "paddw %%mm3,%%mm3\n\t" \
  228. /*r3=R3=E'+D'*/ \
  229. "paddw %%mm4,%%mm3\n\t" \
  230. /*r4=NR4*/ \
  231. "psraw $4,%%mm4\n\t" \
  232. /*r6=R6=F'-B''*/ \
  233. "psubw %%mm5,%%mm6\n\t" \
  234. /*r3=NR3*/ \
  235. "psraw $4,%%mm3\n\t" \
  236. "paddw "OC_MEM_OFFS(0x00,c)",%%mm6\n\t" \
  237. /*r5=B''+B''*/ \
  238. "paddw %%mm5,%%mm5\n\t" \
  239. /*r5=R5=F'+B''*/ \
  240. "paddw %%mm6,%%mm5\n\t" \
  241. /*r6=NR6*/ \
  242. "psraw $4,%%mm6\n\t" \
  243. /*Store NR4 at J(4).*/ \
  244. "movq %%mm4,"OC_J(4,_y)"\n\t" \
  245. /*r5=NR5*/ \
  246. "psraw $4,%%mm5\n\t" \
  247. /*Store NR3 at I(3).*/ \
  248. "movq %%mm3,"OC_I(3,_y)"\n\t" \
  249. /*r7=R7=G'-C'*/ \
  250. "psubw %%mm0,%%mm7\n\t" \
  251. "paddw "OC_MEM_OFFS(0x00,c)",%%mm7\n\t" \
  252. /*r0=C'+C'*/ \
  253. "paddw %%mm0,%%mm0\n\t" \
  254. /*r0=R0=G'+C'*/ \
  255. "paddw %%mm7,%%mm0\n\t" \
  256. /*r7=NR7*/ \
  257. "psraw $4,%%mm7\n\t" \
  258. /*Store NR6 at J(6).*/ \
  259. "movq %%mm6,"OC_J(6,_y)"\n\t" \
  260. /*r0=NR0*/ \
  261. "psraw $4,%%mm0\n\t" \
  262. /*Store NR5 at J(5).*/ \
  263. "movq %%mm5,"OC_J(5,_y)"\n\t" \
  264. /*Store NR7 at J(7).*/ \
  265. "movq %%mm7,"OC_J(7,_y)"\n\t" \
  266. /*Store NR0 at I(0).*/ \
  267. "movq %%mm0,"OC_I(0,_y)"\n\t" \
  268. "#end OC_COLUMN_IDCT\n\t" \
  269. static void oc_idct8x8_slow_mmx(ogg_int16_t _y[64],ogg_int16_t _x[64]){
  270. int i;
  271. /*This routine accepts an 8x8 matrix, but in partially transposed form.
  272. Every 4x4 block is transposed.*/
  273. __asm__ __volatile__(
  274. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16,_y)
  275. #define OC_J(_k,_y) OC_MEM_OFFS(((_k)-4)*16+8,_y)
  276. OC_ROW_IDCT(y,x)
  277. OC_TRANSPOSE(y)
  278. #undef OC_I
  279. #undef OC_J
  280. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16+64,_y)
  281. #define OC_J(_k,_y) OC_MEM_OFFS(((_k)-4)*16+72,_y)
  282. OC_ROW_IDCT(y,x)
  283. OC_TRANSPOSE(y)
  284. #undef OC_I
  285. #undef OC_J
  286. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16,_y)
  287. #define OC_J(_k,_y) OC_I(_k,_y)
  288. OC_COLUMN_IDCT(y)
  289. #undef OC_I
  290. #undef OC_J
  291. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16+8,_y)
  292. #define OC_J(_k,_y) OC_I(_k,_y)
  293. OC_COLUMN_IDCT(y)
  294. #undef OC_I
  295. #undef OC_J
  296. :[y]"=m"OC_ARRAY_OPERAND(ogg_int16_t,_y,64)
  297. :[x]"m"OC_CONST_ARRAY_OPERAND(ogg_int16_t,_x,64),
  298. [c]"m"OC_CONST_ARRAY_OPERAND(ogg_int16_t,OC_IDCT_CONSTS,128)
  299. );
  300. __asm__ __volatile__("pxor %%mm0,%%mm0\n\t"::);
  301. for(i=0;i<4;i++){
  302. __asm__ __volatile__(
  303. "movq %%mm0,"OC_MEM_OFFS(0x00,x)"\n\t"
  304. "movq %%mm0,"OC_MEM_OFFS(0x08,x)"\n\t"
  305. "movq %%mm0,"OC_MEM_OFFS(0x10,x)"\n\t"
  306. "movq %%mm0,"OC_MEM_OFFS(0x18,x)"\n\t"
  307. :[x]"=m"OC_ARRAY_OPERAND(ogg_int16_t,_x+16*i,16)
  308. );
  309. }
  310. }
  311. /*25 cycles.*/
  312. #define OC_IDCT_BEGIN_10(_y,_x) \
  313. "#OC_IDCT_BEGIN_10\n\t" \
  314. "movq "OC_I(3,_x)",%%mm2\n\t" \
  315. "nop\n\t" \
  316. "movq "OC_MEM_OFFS(0x30,c)",%%mm6\n\t" \
  317. "movq %%mm2,%%mm4\n\t" \
  318. "movq "OC_MEM_OFFS(0x50,c)",%%mm1\n\t" \
  319. "pmulhw %%mm6,%%mm4\n\t" \
  320. "movq "OC_I(1,_x)",%%mm3\n\t" \
  321. "pmulhw %%mm2,%%mm1\n\t" \
  322. "movq "OC_MEM_OFFS(0x10,c)",%%mm0\n\t" \
  323. "paddw %%mm2,%%mm4\n\t" \
  324. "pxor %%mm6,%%mm6\n\t" \
  325. "paddw %%mm1,%%mm2\n\t" \
  326. "movq "OC_I(2,_x)",%%mm5\n\t" \
  327. "pmulhw %%mm3,%%mm0\n\t" \
  328. "movq %%mm5,%%mm1\n\t" \
  329. "paddw %%mm3,%%mm0\n\t" \
  330. "pmulhw "OC_MEM_OFFS(0x70,c)",%%mm3\n\t" \
  331. "psubw %%mm2,%%mm6\n\t" \
  332. "pmulhw "OC_MEM_OFFS(0x20,c)",%%mm5\n\t" \
  333. "psubw %%mm4,%%mm0\n\t" \
  334. "movq "OC_I(2,_x)",%%mm7\n\t" \
  335. "paddw %%mm4,%%mm4\n\t" \
  336. "paddw %%mm5,%%mm7\n\t" \
  337. "paddw %%mm0,%%mm4\n\t" \
  338. "pmulhw "OC_MEM_OFFS(0x60,c)",%%mm1\n\t" \
  339. "psubw %%mm6,%%mm3\n\t" \
  340. "movq %%mm4,"OC_I(1,_y)"\n\t" \
  341. "paddw %%mm6,%%mm6\n\t" \
  342. "movq "OC_MEM_OFFS(0x40,c)",%%mm4\n\t" \
  343. "paddw %%mm3,%%mm6\n\t" \
  344. "movq %%mm3,%%mm5\n\t" \
  345. "pmulhw %%mm4,%%mm3\n\t" \
  346. "movq %%mm6,"OC_I(2,_y)"\n\t" \
  347. "movq %%mm0,%%mm2\n\t" \
  348. "movq "OC_I(0,_x)",%%mm6\n\t" \
  349. "pmulhw %%mm4,%%mm0\n\t" \
  350. "paddw %%mm3,%%mm5\n\t" \
  351. "paddw %%mm0,%%mm2\n\t" \
  352. "psubw %%mm1,%%mm5\n\t" \
  353. "pmulhw %%mm4,%%mm6\n\t" \
  354. "paddw "OC_I(0,_x)",%%mm6\n\t" \
  355. "paddw %%mm1,%%mm1\n\t" \
  356. "movq %%mm6,%%mm4\n\t" \
  357. "paddw %%mm5,%%mm1\n\t" \
  358. "psubw %%mm2,%%mm6\n\t" \
  359. "paddw %%mm2,%%mm2\n\t" \
  360. "movq "OC_I(1,_y)",%%mm0\n\t" \
  361. "paddw %%mm6,%%mm2\n\t" \
  362. "psubw %%mm1,%%mm2\n\t" \
  363. "nop\n\t" \
  364. "#end OC_IDCT_BEGIN_10\n\t" \
  365. /*25+8=33 cycles.*/
  366. #define OC_ROW_IDCT_10(_y,_x) \
  367. "#OC_ROW_IDCT_10\n\t" \
  368. OC_IDCT_BEGIN_10(_y,_x) \
  369. /*r3=D'*/ \
  370. "movq "OC_I(2,_y)",%%mm3\n\t" \
  371. /*r4=E'=E-G*/ \
  372. "psubw %%mm7,%%mm4\n\t" \
  373. /*r1=H'+H'*/ \
  374. "paddw %%mm1,%%mm1\n\t" \
  375. /*r7=G+G*/ \
  376. "paddw %%mm7,%%mm7\n\t" \
  377. /*r1=R1=A''+H'*/ \
  378. "paddw %%mm2,%%mm1\n\t" \
  379. /*r7=G'=E+G*/ \
  380. "paddw %%mm4,%%mm7\n\t" \
  381. /*r4=R4=E'-D'*/ \
  382. "psubw %%mm3,%%mm4\n\t" \
  383. "paddw %%mm3,%%mm3\n\t" \
  384. /*r6=R6=F'-B''*/ \
  385. "psubw %%mm5,%%mm6\n\t" \
  386. "paddw %%mm5,%%mm5\n\t" \
  387. /*r3=R3=E'+D'*/ \
  388. "paddw %%mm4,%%mm3\n\t" \
  389. /*r5=R5=F'+B''*/ \
  390. "paddw %%mm6,%%mm5\n\t" \
  391. /*r7=R7=G'-C'*/ \
  392. "psubw %%mm0,%%mm7\n\t" \
  393. "paddw %%mm0,%%mm0\n\t" \
  394. /*Save R1.*/ \
  395. "movq %%mm1,"OC_I(1,_y)"\n\t" \
  396. /*r0=R0=G'+C'*/ \
  397. "paddw %%mm7,%%mm0\n\t" \
  398. "#end OC_ROW_IDCT_10\n\t" \
  399. /*25+19=44 cycles'*/
  400. #define OC_COLUMN_IDCT_10(_y) \
  401. "#OC_COLUMN_IDCT_10\n\t" \
  402. OC_IDCT_BEGIN_10(_y,_y) \
  403. "paddw "OC_MEM_OFFS(0x00,c)",%%mm2\n\t" \
  404. /*r1=H'+H'*/ \
  405. "paddw %%mm1,%%mm1\n\t" \
  406. /*r1=R1=A''+H'*/ \
  407. "paddw %%mm2,%%mm1\n\t" \
  408. /*r2=NR2*/ \
  409. "psraw $4,%%mm2\n\t" \
  410. /*r4=E'=E-G*/ \
  411. "psubw %%mm7,%%mm4\n\t" \
  412. /*r1=NR1*/ \
  413. "psraw $4,%%mm1\n\t" \
  414. /*r3=D'*/ \
  415. "movq "OC_I(2,_y)",%%mm3\n\t" \
  416. /*r7=G+G*/ \
  417. "paddw %%mm7,%%mm7\n\t" \
  418. /*Store NR2 at I(2).*/ \
  419. "movq %%mm2,"OC_I(2,_y)"\n\t" \
  420. /*r7=G'=E+G*/ \
  421. "paddw %%mm4,%%mm7\n\t" \
  422. /*Store NR1 at I(1).*/ \
  423. "movq %%mm1,"OC_I(1,_y)"\n\t" \
  424. /*r4=R4=E'-D'*/ \
  425. "psubw %%mm3,%%mm4\n\t" \
  426. "paddw "OC_MEM_OFFS(0x00,c)",%%mm4\n\t" \
  427. /*r3=D'+D'*/ \
  428. "paddw %%mm3,%%mm3\n\t" \
  429. /*r3=R3=E'+D'*/ \
  430. "paddw %%mm4,%%mm3\n\t" \
  431. /*r4=NR4*/ \
  432. "psraw $4,%%mm4\n\t" \
  433. /*r6=R6=F'-B''*/ \
  434. "psubw %%mm5,%%mm6\n\t" \
  435. /*r3=NR3*/ \
  436. "psraw $4,%%mm3\n\t" \
  437. "paddw "OC_MEM_OFFS(0x00,c)",%%mm6\n\t" \
  438. /*r5=B''+B''*/ \
  439. "paddw %%mm5,%%mm5\n\t" \
  440. /*r5=R5=F'+B''*/ \
  441. "paddw %%mm6,%%mm5\n\t" \
  442. /*r6=NR6*/ \
  443. "psraw $4,%%mm6\n\t" \
  444. /*Store NR4 at J(4).*/ \
  445. "movq %%mm4,"OC_J(4,_y)"\n\t" \
  446. /*r5=NR5*/ \
  447. "psraw $4,%%mm5\n\t" \
  448. /*Store NR3 at I(3).*/ \
  449. "movq %%mm3,"OC_I(3,_y)"\n\t" \
  450. /*r7=R7=G'-C'*/ \
  451. "psubw %%mm0,%%mm7\n\t" \
  452. "paddw "OC_MEM_OFFS(0x00,c)",%%mm7\n\t" \
  453. /*r0=C'+C'*/ \
  454. "paddw %%mm0,%%mm0\n\t" \
  455. /*r0=R0=G'+C'*/ \
  456. "paddw %%mm7,%%mm0\n\t" \
  457. /*r7=NR7*/ \
  458. "psraw $4,%%mm7\n\t" \
  459. /*Store NR6 at J(6).*/ \
  460. "movq %%mm6,"OC_J(6,_y)"\n\t" \
  461. /*r0=NR0*/ \
  462. "psraw $4,%%mm0\n\t" \
  463. /*Store NR5 at J(5).*/ \
  464. "movq %%mm5,"OC_J(5,_y)"\n\t" \
  465. /*Store NR7 at J(7).*/ \
  466. "movq %%mm7,"OC_J(7,_y)"\n\t" \
  467. /*Store NR0 at I(0).*/ \
  468. "movq %%mm0,"OC_I(0,_y)"\n\t" \
  469. "#end OC_COLUMN_IDCT_10\n\t" \
  470. static void oc_idct8x8_10_mmx(ogg_int16_t _y[64],ogg_int16_t _x[64]){
  471. __asm__ __volatile__(
  472. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16,_y)
  473. #define OC_J(_k,_y) OC_MEM_OFFS(((_k)-4)*16+8,_y)
  474. /*Done with dequant, descramble, and partial transpose.
  475. Now do the iDCT itself.*/
  476. OC_ROW_IDCT_10(y,x)
  477. OC_TRANSPOSE(y)
  478. #undef OC_I
  479. #undef OC_J
  480. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16,_y)
  481. #define OC_J(_k,_y) OC_I(_k,_y)
  482. OC_COLUMN_IDCT_10(y)
  483. #undef OC_I
  484. #undef OC_J
  485. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16+8,_y)
  486. #define OC_J(_k,_y) OC_I(_k,_y)
  487. OC_COLUMN_IDCT_10(y)
  488. #undef OC_I
  489. #undef OC_J
  490. :[y]"=m"OC_ARRAY_OPERAND(ogg_int16_t,_y,64)
  491. :[x]"m"OC_CONST_ARRAY_OPERAND(ogg_int16_t,_x,64),
  492. [c]"m"OC_CONST_ARRAY_OPERAND(ogg_int16_t,OC_IDCT_CONSTS,128)
  493. );
  494. __asm__ __volatile__(
  495. "pxor %%mm0,%%mm0\n\t"
  496. "movq %%mm0,"OC_MEM_OFFS(0x00,x)"\n\t"
  497. "movq %%mm0,"OC_MEM_OFFS(0x10,x)"\n\t"
  498. "movq %%mm0,"OC_MEM_OFFS(0x20,x)"\n\t"
  499. "movq %%mm0,"OC_MEM_OFFS(0x30,x)"\n\t"
  500. :[x]"+m"OC_ARRAY_OPERAND(ogg_int16_t,_x,28)
  501. );
  502. }
  503. /*Performs an inverse 8x8 Type-II DCT transform.
  504. The input is assumed to be scaled by a factor of 4 relative to orthonormal
  505. version of the transform.*/
  506. void oc_idct8x8_mmx(ogg_int16_t _y[64],ogg_int16_t _x[64],int _last_zzi){
  507. /*_last_zzi is subtly different from an actual count of the number of
  508. coefficients we decoded for this block.
  509. It contains the value of zzi BEFORE the final token in the block was
  510. decoded.
  511. In most cases this is an EOB token (the continuation of an EOB run from a
  512. previous block counts), and so this is the same as the coefficient count.
  513. However, in the case that the last token was NOT an EOB token, but filled
  514. the block up with exactly 64 coefficients, _last_zzi will be less than 64.
  515. Provided the last token was not a pure zero run, the minimum value it can
  516. be is 46, and so that doesn't affect any of the cases in this routine.
  517. However, if the last token WAS a pure zero run of length 63, then _last_zzi
  518. will be 1 while the number of coefficients decoded is 64.
  519. Thus, we will trigger the following special case, where the real
  520. coefficient count would not.
  521. Note also that a zero run of length 64 will give _last_zzi a value of 0,
  522. but we still process the DC coefficient, which might have a non-zero value
  523. due to DC prediction.
  524. Although convoluted, this is arguably the correct behavior: it allows us to
  525. use a smaller transform when the block ends with a long zero run instead
  526. of a normal EOB token.
  527. It could be smarter... multiple separate zero runs at the end of a block
  528. will fool it, but an encoder that generates these really deserves what it
  529. gets.
  530. Needless to say we inherited this approach from VP3.*/
  531. /*Then perform the iDCT.*/
  532. if(_last_zzi<=10)oc_idct8x8_10_mmx(_y,_x);
  533. else oc_idct8x8_slow_mmx(_y,_x);
  534. }
  535. #endif