mmxidct.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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: mmxidct.c 17446 2010-09-23 20:06:20Z tterribe $
  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. /*This routine accepts an 8x8 matrix, but in partially transposed form.
  271. Every 4x4 block is transposed.*/
  272. __asm__ __volatile__(
  273. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16,_y)
  274. #define OC_J(_k,_y) OC_MEM_OFFS(((_k)-4)*16+8,_y)
  275. OC_ROW_IDCT(y,x)
  276. OC_TRANSPOSE(y)
  277. #undef OC_I
  278. #undef OC_J
  279. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16+64,_y)
  280. #define OC_J(_k,_y) OC_MEM_OFFS(((_k)-4)*16+72,_y)
  281. OC_ROW_IDCT(y,x)
  282. OC_TRANSPOSE(y)
  283. #undef OC_I
  284. #undef OC_J
  285. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16,_y)
  286. #define OC_J(_k,_y) OC_I(_k,_y)
  287. OC_COLUMN_IDCT(y)
  288. #undef OC_I
  289. #undef OC_J
  290. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16+8,_y)
  291. #define OC_J(_k,_y) OC_I(_k,_y)
  292. OC_COLUMN_IDCT(y)
  293. #undef OC_I
  294. #undef OC_J
  295. :[y]"=m"OC_ARRAY_OPERAND(ogg_int16_t,_y,64)
  296. :[x]"m"OC_CONST_ARRAY_OPERAND(ogg_int16_t,_x,64),
  297. [c]"m"OC_CONST_ARRAY_OPERAND(ogg_int16_t,OC_IDCT_CONSTS,128)
  298. );
  299. if(_x!=_y){
  300. int i;
  301. __asm__ __volatile__("pxor %%mm0,%%mm0\n\t"::);
  302. for(i=0;i<4;i++){
  303. __asm__ __volatile__(
  304. "movq %%mm0,"OC_MEM_OFFS(0x00,x)"\n\t"
  305. "movq %%mm0,"OC_MEM_OFFS(0x08,x)"\n\t"
  306. "movq %%mm0,"OC_MEM_OFFS(0x10,x)"\n\t"
  307. "movq %%mm0,"OC_MEM_OFFS(0x18,x)"\n\t"
  308. :[x]"=m"OC_ARRAY_OPERAND(ogg_int16_t,_x+16*i,16)
  309. );
  310. }
  311. }
  312. }
  313. /*25 cycles.*/
  314. #define OC_IDCT_BEGIN_10(_y,_x) \
  315. "#OC_IDCT_BEGIN_10\n\t" \
  316. "movq "OC_I(3,_x)",%%mm2\n\t" \
  317. "nop\n\t" \
  318. "movq "OC_MEM_OFFS(0x30,c)",%%mm6\n\t" \
  319. "movq %%mm2,%%mm4\n\t" \
  320. "movq "OC_MEM_OFFS(0x50,c)",%%mm1\n\t" \
  321. "pmulhw %%mm6,%%mm4\n\t" \
  322. "movq "OC_I(1,_x)",%%mm3\n\t" \
  323. "pmulhw %%mm2,%%mm1\n\t" \
  324. "movq "OC_MEM_OFFS(0x10,c)",%%mm0\n\t" \
  325. "paddw %%mm2,%%mm4\n\t" \
  326. "pxor %%mm6,%%mm6\n\t" \
  327. "paddw %%mm1,%%mm2\n\t" \
  328. "movq "OC_I(2,_x)",%%mm5\n\t" \
  329. "pmulhw %%mm3,%%mm0\n\t" \
  330. "movq %%mm5,%%mm1\n\t" \
  331. "paddw %%mm3,%%mm0\n\t" \
  332. "pmulhw "OC_MEM_OFFS(0x70,c)",%%mm3\n\t" \
  333. "psubw %%mm2,%%mm6\n\t" \
  334. "pmulhw "OC_MEM_OFFS(0x20,c)",%%mm5\n\t" \
  335. "psubw %%mm4,%%mm0\n\t" \
  336. "movq "OC_I(2,_x)",%%mm7\n\t" \
  337. "paddw %%mm4,%%mm4\n\t" \
  338. "paddw %%mm5,%%mm7\n\t" \
  339. "paddw %%mm0,%%mm4\n\t" \
  340. "pmulhw "OC_MEM_OFFS(0x60,c)",%%mm1\n\t" \
  341. "psubw %%mm6,%%mm3\n\t" \
  342. "movq %%mm4,"OC_I(1,_y)"\n\t" \
  343. "paddw %%mm6,%%mm6\n\t" \
  344. "movq "OC_MEM_OFFS(0x40,c)",%%mm4\n\t" \
  345. "paddw %%mm3,%%mm6\n\t" \
  346. "movq %%mm3,%%mm5\n\t" \
  347. "pmulhw %%mm4,%%mm3\n\t" \
  348. "movq %%mm6,"OC_I(2,_y)"\n\t" \
  349. "movq %%mm0,%%mm2\n\t" \
  350. "movq "OC_I(0,_x)",%%mm6\n\t" \
  351. "pmulhw %%mm4,%%mm0\n\t" \
  352. "paddw %%mm3,%%mm5\n\t" \
  353. "paddw %%mm0,%%mm2\n\t" \
  354. "psubw %%mm1,%%mm5\n\t" \
  355. "pmulhw %%mm4,%%mm6\n\t" \
  356. "paddw "OC_I(0,_x)",%%mm6\n\t" \
  357. "paddw %%mm1,%%mm1\n\t" \
  358. "movq %%mm6,%%mm4\n\t" \
  359. "paddw %%mm5,%%mm1\n\t" \
  360. "psubw %%mm2,%%mm6\n\t" \
  361. "paddw %%mm2,%%mm2\n\t" \
  362. "movq "OC_I(1,_y)",%%mm0\n\t" \
  363. "paddw %%mm6,%%mm2\n\t" \
  364. "psubw %%mm1,%%mm2\n\t" \
  365. "nop\n\t" \
  366. "#end OC_IDCT_BEGIN_10\n\t" \
  367. /*25+8=33 cycles.*/
  368. #define OC_ROW_IDCT_10(_y,_x) \
  369. "#OC_ROW_IDCT_10\n\t" \
  370. OC_IDCT_BEGIN_10(_y,_x) \
  371. /*r3=D'*/ \
  372. "movq "OC_I(2,_y)",%%mm3\n\t" \
  373. /*r4=E'=E-G*/ \
  374. "psubw %%mm7,%%mm4\n\t" \
  375. /*r1=H'+H'*/ \
  376. "paddw %%mm1,%%mm1\n\t" \
  377. /*r7=G+G*/ \
  378. "paddw %%mm7,%%mm7\n\t" \
  379. /*r1=R1=A''+H'*/ \
  380. "paddw %%mm2,%%mm1\n\t" \
  381. /*r7=G'=E+G*/ \
  382. "paddw %%mm4,%%mm7\n\t" \
  383. /*r4=R4=E'-D'*/ \
  384. "psubw %%mm3,%%mm4\n\t" \
  385. "paddw %%mm3,%%mm3\n\t" \
  386. /*r6=R6=F'-B''*/ \
  387. "psubw %%mm5,%%mm6\n\t" \
  388. "paddw %%mm5,%%mm5\n\t" \
  389. /*r3=R3=E'+D'*/ \
  390. "paddw %%mm4,%%mm3\n\t" \
  391. /*r5=R5=F'+B''*/ \
  392. "paddw %%mm6,%%mm5\n\t" \
  393. /*r7=R7=G'-C'*/ \
  394. "psubw %%mm0,%%mm7\n\t" \
  395. "paddw %%mm0,%%mm0\n\t" \
  396. /*Save R1.*/ \
  397. "movq %%mm1,"OC_I(1,_y)"\n\t" \
  398. /*r0=R0=G'+C'*/ \
  399. "paddw %%mm7,%%mm0\n\t" \
  400. "#end OC_ROW_IDCT_10\n\t" \
  401. /*25+19=44 cycles'*/
  402. #define OC_COLUMN_IDCT_10(_y) \
  403. "#OC_COLUMN_IDCT_10\n\t" \
  404. OC_IDCT_BEGIN_10(_y,_y) \
  405. "paddw "OC_MEM_OFFS(0x00,c)",%%mm2\n\t" \
  406. /*r1=H'+H'*/ \
  407. "paddw %%mm1,%%mm1\n\t" \
  408. /*r1=R1=A''+H'*/ \
  409. "paddw %%mm2,%%mm1\n\t" \
  410. /*r2=NR2*/ \
  411. "psraw $4,%%mm2\n\t" \
  412. /*r4=E'=E-G*/ \
  413. "psubw %%mm7,%%mm4\n\t" \
  414. /*r1=NR1*/ \
  415. "psraw $4,%%mm1\n\t" \
  416. /*r3=D'*/ \
  417. "movq "OC_I(2,_y)",%%mm3\n\t" \
  418. /*r7=G+G*/ \
  419. "paddw %%mm7,%%mm7\n\t" \
  420. /*Store NR2 at I(2).*/ \
  421. "movq %%mm2,"OC_I(2,_y)"\n\t" \
  422. /*r7=G'=E+G*/ \
  423. "paddw %%mm4,%%mm7\n\t" \
  424. /*Store NR1 at I(1).*/ \
  425. "movq %%mm1,"OC_I(1,_y)"\n\t" \
  426. /*r4=R4=E'-D'*/ \
  427. "psubw %%mm3,%%mm4\n\t" \
  428. "paddw "OC_MEM_OFFS(0x00,c)",%%mm4\n\t" \
  429. /*r3=D'+D'*/ \
  430. "paddw %%mm3,%%mm3\n\t" \
  431. /*r3=R3=E'+D'*/ \
  432. "paddw %%mm4,%%mm3\n\t" \
  433. /*r4=NR4*/ \
  434. "psraw $4,%%mm4\n\t" \
  435. /*r6=R6=F'-B''*/ \
  436. "psubw %%mm5,%%mm6\n\t" \
  437. /*r3=NR3*/ \
  438. "psraw $4,%%mm3\n\t" \
  439. "paddw "OC_MEM_OFFS(0x00,c)",%%mm6\n\t" \
  440. /*r5=B''+B''*/ \
  441. "paddw %%mm5,%%mm5\n\t" \
  442. /*r5=R5=F'+B''*/ \
  443. "paddw %%mm6,%%mm5\n\t" \
  444. /*r6=NR6*/ \
  445. "psraw $4,%%mm6\n\t" \
  446. /*Store NR4 at J(4).*/ \
  447. "movq %%mm4,"OC_J(4,_y)"\n\t" \
  448. /*r5=NR5*/ \
  449. "psraw $4,%%mm5\n\t" \
  450. /*Store NR3 at I(3).*/ \
  451. "movq %%mm3,"OC_I(3,_y)"\n\t" \
  452. /*r7=R7=G'-C'*/ \
  453. "psubw %%mm0,%%mm7\n\t" \
  454. "paddw "OC_MEM_OFFS(0x00,c)",%%mm7\n\t" \
  455. /*r0=C'+C'*/ \
  456. "paddw %%mm0,%%mm0\n\t" \
  457. /*r0=R0=G'+C'*/ \
  458. "paddw %%mm7,%%mm0\n\t" \
  459. /*r7=NR7*/ \
  460. "psraw $4,%%mm7\n\t" \
  461. /*Store NR6 at J(6).*/ \
  462. "movq %%mm6,"OC_J(6,_y)"\n\t" \
  463. /*r0=NR0*/ \
  464. "psraw $4,%%mm0\n\t" \
  465. /*Store NR5 at J(5).*/ \
  466. "movq %%mm5,"OC_J(5,_y)"\n\t" \
  467. /*Store NR7 at J(7).*/ \
  468. "movq %%mm7,"OC_J(7,_y)"\n\t" \
  469. /*Store NR0 at I(0).*/ \
  470. "movq %%mm0,"OC_I(0,_y)"\n\t" \
  471. "#end OC_COLUMN_IDCT_10\n\t" \
  472. static void oc_idct8x8_10_mmx(ogg_int16_t _y[64],ogg_int16_t _x[64]){
  473. __asm__ __volatile__(
  474. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16,_y)
  475. #define OC_J(_k,_y) OC_MEM_OFFS(((_k)-4)*16+8,_y)
  476. /*Done with dequant, descramble, and partial transpose.
  477. Now do the iDCT itself.*/
  478. OC_ROW_IDCT_10(y,x)
  479. OC_TRANSPOSE(y)
  480. #undef OC_I
  481. #undef OC_J
  482. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16,_y)
  483. #define OC_J(_k,_y) OC_I(_k,_y)
  484. OC_COLUMN_IDCT_10(y)
  485. #undef OC_I
  486. #undef OC_J
  487. #define OC_I(_k,_y) OC_MEM_OFFS((_k)*16+8,_y)
  488. #define OC_J(_k,_y) OC_I(_k,_y)
  489. OC_COLUMN_IDCT_10(y)
  490. #undef OC_I
  491. #undef OC_J
  492. :[y]"=m"OC_ARRAY_OPERAND(ogg_int16_t,_y,64)
  493. :[x]"m"OC_CONST_ARRAY_OPERAND(ogg_int16_t,_x,64),
  494. [c]"m"OC_CONST_ARRAY_OPERAND(ogg_int16_t,OC_IDCT_CONSTS,128)
  495. );
  496. if(_x!=_y){
  497. __asm__ __volatile__(
  498. "pxor %%mm0,%%mm0\n\t"
  499. "movq %%mm0,"OC_MEM_OFFS(0x00,x)"\n\t"
  500. "movq %%mm0,"OC_MEM_OFFS(0x10,x)"\n\t"
  501. "movq %%mm0,"OC_MEM_OFFS(0x20,x)"\n\t"
  502. "movq %%mm0,"OC_MEM_OFFS(0x30,x)"\n\t"
  503. :[x]"+m"OC_ARRAY_OPERAND(ogg_int16_t,_x,28)
  504. );
  505. }
  506. }
  507. /*Performs an inverse 8x8 Type-II DCT transform.
  508. The input is assumed to be scaled by a factor of 4 relative to orthonormal
  509. version of the transform.*/
  510. void oc_idct8x8_mmx(ogg_int16_t _y[64],ogg_int16_t _x[64],int _last_zzi){
  511. /*_last_zzi is subtly different from an actual count of the number of
  512. coefficients we decoded for this block.
  513. It contains the value of zzi BEFORE the final token in the block was
  514. decoded.
  515. In most cases this is an EOB token (the continuation of an EOB run from a
  516. previous block counts), and so this is the same as the coefficient count.
  517. However, in the case that the last token was NOT an EOB token, but filled
  518. the block up with exactly 64 coefficients, _last_zzi will be less than 64.
  519. Provided the last token was not a pure zero run, the minimum value it can
  520. be is 46, and so that doesn't affect any of the cases in this routine.
  521. However, if the last token WAS a pure zero run of length 63, then _last_zzi
  522. will be 1 while the number of coefficients decoded is 64.
  523. Thus, we will trigger the following special case, where the real
  524. coefficient count would not.
  525. Note also that a zero run of length 64 will give _last_zzi a value of 0,
  526. but we still process the DC coefficient, which might have a non-zero value
  527. due to DC prediction.
  528. Although convoluted, this is arguably the correct behavior: it allows us to
  529. use a smaller transform when the block ends with a long zero run instead
  530. of a normal EOB token.
  531. It could be smarter... multiple separate zero runs at the end of a block
  532. will fool it, but an encoder that generates these really deserves what it
  533. gets.
  534. Needless to say we inherited this approach from VP3.*/
  535. /*Then perform the iDCT.*/
  536. if(_last_zzi<=10)oc_idct8x8_10_mmx(_y,_x);
  537. else oc_idct8x8_slow_mmx(_y,_x);
  538. }
  539. #endif