sse2idct.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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 16503 2009-08-22 18:14:02Z giles $
  14. ********************************************************************/
  15. /*SSE2 acceleration of Theora's iDCT.*/
  16. #include "x86int.h"
  17. #include "sse2trans.h"
  18. #include "../dct.h"
  19. #if defined(OC_X86_ASM)
  20. /*A table of constants used by the MMX routines.*/
  21. const unsigned short __attribute__((aligned(16),used)) OC_IDCT_CONSTS[64]={
  22. 8, 8, 8, 8, 8, 8, 8, 8,
  23. OC_C1S7,OC_C1S7,OC_C1S7,OC_C1S7,OC_C1S7,OC_C1S7,OC_C1S7,OC_C1S7,
  24. OC_C2S6,OC_C2S6,OC_C2S6,OC_C2S6,OC_C2S6,OC_C2S6,OC_C2S6,OC_C2S6,
  25. OC_C3S5,OC_C3S5,OC_C3S5,OC_C3S5,OC_C3S5,OC_C3S5,OC_C3S5,OC_C3S5,
  26. OC_C4S4,OC_C4S4,OC_C4S4,OC_C4S4,OC_C4S4,OC_C4S4,OC_C4S4,OC_C4S4,
  27. OC_C5S3,OC_C5S3,OC_C5S3,OC_C5S3,OC_C5S3,OC_C5S3,OC_C5S3,OC_C5S3,
  28. OC_C6S2,OC_C6S2,OC_C6S2,OC_C6S2,OC_C6S2,OC_C6S2,OC_C6S2,OC_C6S2,
  29. OC_C7S1,OC_C7S1,OC_C7S1,OC_C7S1,OC_C7S1,OC_C7S1,OC_C7S1,OC_C7S1
  30. };
  31. /*Performs the first three stages of the iDCT.
  32. xmm2, xmm6, xmm3, and xmm5 must contain the corresponding rows of the input
  33. (accessed in that order).
  34. The remaining rows must be in _x at their corresponding locations.
  35. On output, xmm7 down to xmm4 contain rows 0 through 3, and xmm0 up to xmm3
  36. contain rows 4 through 7.*/
  37. #define OC_IDCT_8x8_ABC(_x) \
  38. "#OC_IDCT_8x8_ABC\n\t" \
  39. /*Stage 1:*/ \
  40. /*2-3 rotation by 6pi/16. \
  41. xmm4=xmm7=C6, xmm0=xmm1=C2, xmm2=X2, xmm6=X6.*/ \
  42. "movdqa "OC_MEM_OFFS(0x20,c)",%%xmm1\n\t" \
  43. "movdqa "OC_MEM_OFFS(0x60,c)",%%xmm4\n\t" \
  44. "movdqa %%xmm1,%%xmm0\n\t" \
  45. "pmulhw %%xmm2,%%xmm1\n\t" \
  46. "movdqa %%xmm4,%%xmm7\n\t" \
  47. "pmulhw %%xmm6,%%xmm0\n\t" \
  48. "pmulhw %%xmm2,%%xmm7\n\t" \
  49. "pmulhw %%xmm6,%%xmm4\n\t" \
  50. "paddw %%xmm6,%%xmm0\n\t" \
  51. "movdqa "OC_MEM_OFFS(0x30,c)",%%xmm6\n\t" \
  52. "paddw %%xmm1,%%xmm2\n\t" \
  53. "psubw %%xmm0,%%xmm7\n\t" \
  54. "movdqa %%xmm7,"OC_MEM_OFFS(0x00,buf)"\n\t" \
  55. "paddw %%xmm4,%%xmm2\n\t" \
  56. "movdqa "OC_MEM_OFFS(0x50,c)",%%xmm4\n\t" \
  57. "movdqa %%xmm2,"OC_MEM_OFFS(0x10,buf)"\n\t" \
  58. /*5-6 rotation by 3pi/16. \
  59. xmm4=xmm2=C5, xmm1=xmm6=C3, xmm3=X3, xmm5=X5.*/ \
  60. "movdqa %%xmm4,%%xmm2\n\t" \
  61. "movdqa %%xmm6,%%xmm1\n\t" \
  62. "pmulhw %%xmm3,%%xmm4\n\t" \
  63. "pmulhw %%xmm5,%%xmm1\n\t" \
  64. "pmulhw %%xmm3,%%xmm6\n\t" \
  65. "pmulhw %%xmm5,%%xmm2\n\t" \
  66. "paddw %%xmm3,%%xmm4\n\t" \
  67. "paddw %%xmm5,%%xmm3\n\t" \
  68. "paddw %%xmm6,%%xmm3\n\t" \
  69. "movdqa "OC_MEM_OFFS(0x70,_x)",%%xmm6\n\t" \
  70. "paddw %%xmm5,%%xmm1\n\t" \
  71. "movdqa "OC_MEM_OFFS(0x10,_x)",%%xmm5\n\t" \
  72. "paddw %%xmm3,%%xmm2\n\t" \
  73. "movdqa "OC_MEM_OFFS(0x70,c)",%%xmm3\n\t" \
  74. "psubw %%xmm4,%%xmm1\n\t" \
  75. "movdqa "OC_MEM_OFFS(0x10,c)",%%xmm4\n\t" \
  76. /*4-7 rotation by 7pi/16. \
  77. xmm4=xmm7=C1, xmm3=xmm0=C7, xmm5=X1, xmm6=X7.*/ \
  78. "movdqa %%xmm3,%%xmm0\n\t" \
  79. "movdqa %%xmm4,%%xmm7\n\t" \
  80. "pmulhw %%xmm5,%%xmm3\n\t" \
  81. "pmulhw %%xmm5,%%xmm7\n\t" \
  82. "pmulhw %%xmm6,%%xmm4\n\t" \
  83. "pmulhw %%xmm6,%%xmm0\n\t" \
  84. "paddw %%xmm6,%%xmm4\n\t" \
  85. "movdqa "OC_MEM_OFFS(0x40,_x)",%%xmm6\n\t" \
  86. "paddw %%xmm5,%%xmm7\n\t" \
  87. "psubw %%xmm4,%%xmm3\n\t" \
  88. "movdqa "OC_MEM_OFFS(0x40,c)",%%xmm4\n\t" \
  89. "paddw %%xmm7,%%xmm0\n\t" \
  90. "movdqa "OC_MEM_OFFS(0x00,_x)",%%xmm7\n\t" \
  91. /*0-1 butterfly. \
  92. xmm4=xmm5=C4, xmm7=X0, xmm6=X4.*/ \
  93. "paddw %%xmm7,%%xmm6\n\t" \
  94. "movdqa %%xmm4,%%xmm5\n\t" \
  95. "pmulhw %%xmm6,%%xmm4\n\t" \
  96. "paddw %%xmm7,%%xmm7\n\t" \
  97. "psubw %%xmm6,%%xmm7\n\t" \
  98. "paddw %%xmm6,%%xmm4\n\t" \
  99. /*Stage 2:*/ \
  100. /*4-5 butterfly: xmm3=t[4], xmm1=t[5] \
  101. 7-6 butterfly: xmm2=t[6], xmm0=t[7]*/ \
  102. "movdqa %%xmm3,%%xmm6\n\t" \
  103. "paddw %%xmm1,%%xmm3\n\t" \
  104. "psubw %%xmm1,%%xmm6\n\t" \
  105. "movdqa %%xmm5,%%xmm1\n\t" \
  106. "pmulhw %%xmm7,%%xmm5\n\t" \
  107. "paddw %%xmm7,%%xmm5\n\t" \
  108. "movdqa %%xmm0,%%xmm7\n\t" \
  109. "paddw %%xmm2,%%xmm0\n\t" \
  110. "psubw %%xmm2,%%xmm7\n\t" \
  111. "movdqa %%xmm1,%%xmm2\n\t" \
  112. "pmulhw %%xmm6,%%xmm1\n\t" \
  113. "pmulhw %%xmm7,%%xmm2\n\t" \
  114. "paddw %%xmm6,%%xmm1\n\t" \
  115. "movdqa "OC_MEM_OFFS(0x00,buf)",%%xmm6\n\t" \
  116. "paddw %%xmm7,%%xmm2\n\t" \
  117. "movdqa "OC_MEM_OFFS(0x10,buf)",%%xmm7\n\t" \
  118. /*Stage 3: \
  119. 6-5 butterfly: xmm1=t[5], xmm2=t[6] -> xmm1=t[6]+t[5], xmm2=t[6]-t[5] \
  120. 0-3 butterfly: xmm4=t[0], xmm7=t[3] -> xmm7=t[0]+t[3], xmm4=t[0]-t[3] \
  121. 1-2 butterfly: xmm5=t[1], xmm6=t[2] -> xmm6=t[1]+t[2], xmm5=t[1]-t[2]*/ \
  122. "paddw %%xmm2,%%xmm1\n\t" \
  123. "paddw %%xmm5,%%xmm6\n\t" \
  124. "paddw %%xmm4,%%xmm7\n\t" \
  125. "paddw %%xmm2,%%xmm2\n\t" \
  126. "paddw %%xmm4,%%xmm4\n\t" \
  127. "paddw %%xmm5,%%xmm5\n\t" \
  128. "psubw %%xmm1,%%xmm2\n\t" \
  129. "psubw %%xmm7,%%xmm4\n\t" \
  130. "psubw %%xmm6,%%xmm5\n\t" \
  131. /*Performs the last stage of the iDCT.
  132. On input, xmm7 down to xmm4 contain rows 0 through 3, and xmm0 up to xmm3
  133. contain rows 4 through 7.
  134. On output, xmm0 through xmm7 contain the corresponding rows.*/
  135. #define OC_IDCT_8x8_D \
  136. "#OC_IDCT_8x8_D\n\t" \
  137. /*Stage 4: \
  138. 0-7 butterfly: xmm7=t[0], xmm0=t[7] -> xmm0=t[0]+t[7], xmm7=t[0]-t[7] \
  139. 1-6 butterfly: xmm6=t[1], xmm1=t[6] -> xmm1=t[1]+t[6], xmm6=t[1]-t[6] \
  140. 2-5 butterfly: xmm5=t[2], xmm2=t[5] -> xmm2=t[2]+t[5], xmm5=t[2]-t[5] \
  141. 3-4 butterfly: xmm4=t[3], xmm3=t[4] -> xmm3=t[3]+t[4], xmm4=t[3]-t[4]*/ \
  142. "psubw %%xmm0,%%xmm7\n\t" \
  143. "psubw %%xmm1,%%xmm6\n\t" \
  144. "psubw %%xmm2,%%xmm5\n\t" \
  145. "psubw %%xmm3,%%xmm4\n\t" \
  146. "paddw %%xmm0,%%xmm0\n\t" \
  147. "paddw %%xmm1,%%xmm1\n\t" \
  148. "paddw %%xmm2,%%xmm2\n\t" \
  149. "paddw %%xmm3,%%xmm3\n\t" \
  150. "paddw %%xmm7,%%xmm0\n\t" \
  151. "paddw %%xmm6,%%xmm1\n\t" \
  152. "paddw %%xmm5,%%xmm2\n\t" \
  153. "paddw %%xmm4,%%xmm3\n\t" \
  154. /*Performs the last stage of the iDCT.
  155. On input, xmm7 down to xmm4 contain rows 0 through 3, and xmm0 up to xmm3
  156. contain rows 4 through 7.
  157. On output, xmm0 through xmm7 contain the corresponding rows.*/
  158. #define OC_IDCT_8x8_D_STORE \
  159. "#OC_IDCT_8x8_D_STORE\n\t" \
  160. /*Stage 4: \
  161. 0-7 butterfly: xmm7=t[0], xmm0=t[7] -> xmm0=t[0]+t[7], xmm7=t[0]-t[7] \
  162. 1-6 butterfly: xmm6=t[1], xmm1=t[6] -> xmm1=t[1]+t[6], xmm6=t[1]-t[6] \
  163. 2-5 butterfly: xmm5=t[2], xmm2=t[5] -> xmm2=t[2]+t[5], xmm5=t[2]-t[5] \
  164. 3-4 butterfly: xmm4=t[3], xmm3=t[4] -> xmm3=t[3]+t[4], xmm4=t[3]-t[4]*/ \
  165. "psubw %%xmm3,%%xmm4\n\t" \
  166. "movdqa %%xmm4,"OC_MEM_OFFS(0x40,y)"\n\t" \
  167. "movdqa "OC_MEM_OFFS(0x00,c)",%%xmm4\n\t" \
  168. "psubw %%xmm0,%%xmm7\n\t" \
  169. "psubw %%xmm1,%%xmm6\n\t" \
  170. "psubw %%xmm2,%%xmm5\n\t" \
  171. "paddw %%xmm4,%%xmm7\n\t" \
  172. "paddw %%xmm4,%%xmm6\n\t" \
  173. "paddw %%xmm4,%%xmm5\n\t" \
  174. "paddw "OC_MEM_OFFS(0x40,y)",%%xmm4\n\t" \
  175. "paddw %%xmm0,%%xmm0\n\t" \
  176. "paddw %%xmm1,%%xmm1\n\t" \
  177. "paddw %%xmm2,%%xmm2\n\t" \
  178. "paddw %%xmm3,%%xmm3\n\t" \
  179. "paddw %%xmm7,%%xmm0\n\t" \
  180. "paddw %%xmm6,%%xmm1\n\t" \
  181. "psraw $4,%%xmm0\n\t" \
  182. "paddw %%xmm5,%%xmm2\n\t" \
  183. "movdqa %%xmm0,"OC_MEM_OFFS(0x00,y)"\n\t" \
  184. "psraw $4,%%xmm1\n\t" \
  185. "paddw %%xmm4,%%xmm3\n\t" \
  186. "movdqa %%xmm1,"OC_MEM_OFFS(0x10,y)"\n\t" \
  187. "psraw $4,%%xmm2\n\t" \
  188. "movdqa %%xmm2,"OC_MEM_OFFS(0x20,y)"\n\t" \
  189. "psraw $4,%%xmm3\n\t" \
  190. "movdqa %%xmm3,"OC_MEM_OFFS(0x30,y)"\n\t" \
  191. "psraw $4,%%xmm4\n\t" \
  192. "movdqa %%xmm4,"OC_MEM_OFFS(0x40,y)"\n\t" \
  193. "psraw $4,%%xmm5\n\t" \
  194. "movdqa %%xmm5,"OC_MEM_OFFS(0x50,y)"\n\t" \
  195. "psraw $4,%%xmm6\n\t" \
  196. "movdqa %%xmm6,"OC_MEM_OFFS(0x60,y)"\n\t" \
  197. "psraw $4,%%xmm7\n\t" \
  198. "movdqa %%xmm7,"OC_MEM_OFFS(0x70,y)"\n\t" \
  199. static void oc_idct8x8_slow_sse2(ogg_int16_t _y[64],ogg_int16_t _x[64]){
  200. OC_ALIGN16(ogg_int16_t buf[16]);
  201. /*This routine accepts an 8x8 matrix pre-transposed.*/
  202. __asm__ __volatile__(
  203. /*Load rows 2, 3, 5, and 6 for the first stage of the iDCT.*/
  204. "movdqa "OC_MEM_OFFS(0x20,x)",%%xmm2\n\t"
  205. "movdqa "OC_MEM_OFFS(0x60,x)",%%xmm6\n\t"
  206. "movdqa "OC_MEM_OFFS(0x30,x)",%%xmm3\n\t"
  207. "movdqa "OC_MEM_OFFS(0x50,x)",%%xmm5\n\t"
  208. OC_IDCT_8x8_ABC(x)
  209. OC_IDCT_8x8_D
  210. OC_TRANSPOSE_8x8
  211. /*Clear out rows 0, 1, 4, and 7 for the first stage of the iDCT.*/
  212. "movdqa %%xmm7,"OC_MEM_OFFS(0x70,y)"\n\t"
  213. "movdqa %%xmm4,"OC_MEM_OFFS(0x40,y)"\n\t"
  214. "movdqa %%xmm1,"OC_MEM_OFFS(0x10,y)"\n\t"
  215. "movdqa %%xmm0,"OC_MEM_OFFS(0x00,y)"\n\t"
  216. OC_IDCT_8x8_ABC(y)
  217. OC_IDCT_8x8_D_STORE
  218. :[buf]"=m"(OC_ARRAY_OPERAND(ogg_int16_t,buf,16)),
  219. [y]"=m"(OC_ARRAY_OPERAND(ogg_int16_t,_y,64))
  220. :[x]"m"(OC_CONST_ARRAY_OPERAND(ogg_int16_t,_x,64)),
  221. [c]"m"(OC_CONST_ARRAY_OPERAND(ogg_int16_t,OC_IDCT_CONSTS,128))
  222. );
  223. if(_x!=_y){
  224. int i;
  225. __asm__ __volatile__("pxor %%xmm0,%%xmm0\n\t"::);
  226. /*Clear input data for next block (decoder only).*/
  227. for(i=0;i<2;i++){
  228. __asm__ __volatile__(
  229. "movdqa %%xmm0,"OC_MEM_OFFS(0x00,x)"\n\t"
  230. "movdqa %%xmm0,"OC_MEM_OFFS(0x10,x)"\n\t"
  231. "movdqa %%xmm0,"OC_MEM_OFFS(0x20,x)"\n\t"
  232. "movdqa %%xmm0,"OC_MEM_OFFS(0x30,x)"\n\t"
  233. :[x]"=m"(OC_ARRAY_OPERAND(ogg_int16_t,_x+i*32,32))
  234. );
  235. }
  236. }
  237. }
  238. /*For the first step of the 10-coefficient version of the 8x8 iDCT, we only
  239. need to work with four columns at a time.
  240. Doing this in MMX is faster on processors with a 64-bit data path.*/
  241. #define OC_IDCT_8x8_10_MMX \
  242. "#OC_IDCT_8x8_10_MMX\n\t" \
  243. /*Stage 1:*/ \
  244. /*2-3 rotation by 6pi/16. \
  245. mm7=C6, mm6=C2, mm2=X2, X6=0.*/ \
  246. "movq "OC_MEM_OFFS(0x60,c)",%%mm7\n\t" \
  247. "movq "OC_MEM_OFFS(0x20,c)",%%mm6\n\t" \
  248. "pmulhw %%mm2,%%mm6\n\t" \
  249. "pmulhw %%mm2,%%mm7\n\t" \
  250. "movq "OC_MEM_OFFS(0x50,c)",%%mm5\n\t" \
  251. "paddw %%mm6,%%mm2\n\t" \
  252. "movq %%mm2,"OC_MEM_OFFS(0x10,buf)"\n\t" \
  253. "movq "OC_MEM_OFFS(0x30,c)",%%mm2\n\t" \
  254. "movq %%mm7,"OC_MEM_OFFS(0x00,buf)"\n\t" \
  255. /*5-6 rotation by 3pi/16. \
  256. mm5=C5, mm2=C3, mm3=X3, X5=0.*/ \
  257. "pmulhw %%mm3,%%mm5\n\t" \
  258. "pmulhw %%mm3,%%mm2\n\t" \
  259. "movq "OC_MEM_OFFS(0x10,c)",%%mm7\n\t" \
  260. "paddw %%mm3,%%mm5\n\t" \
  261. "paddw %%mm3,%%mm2\n\t" \
  262. "movq "OC_MEM_OFFS(0x70,c)",%%mm3\n\t" \
  263. /*4-7 rotation by 7pi/16. \
  264. mm7=C1, mm3=C7, mm1=X1, X7=0.*/ \
  265. "pmulhw %%mm1,%%mm3\n\t" \
  266. "pmulhw %%mm1,%%mm7\n\t" \
  267. "movq "OC_MEM_OFFS(0x40,c)",%%mm4\n\t" \
  268. "movq %%mm3,%%mm6\n\t" \
  269. "paddw %%mm1,%%mm7\n\t" \
  270. /*0-1 butterfly. \
  271. mm4=C4, mm0=X0, X4=0.*/ \
  272. /*Stage 2:*/ \
  273. /*4-5 butterfly: mm3=t[4], mm5=t[5] \
  274. 7-6 butterfly: mm2=t[6], mm7=t[7]*/ \
  275. "psubw %%mm5,%%mm3\n\t" \
  276. "paddw %%mm5,%%mm6\n\t" \
  277. "movq %%mm4,%%mm1\n\t" \
  278. "pmulhw %%mm0,%%mm4\n\t" \
  279. "paddw %%mm0,%%mm4\n\t" \
  280. "movq %%mm7,%%mm0\n\t" \
  281. "movq %%mm4,%%mm5\n\t" \
  282. "paddw %%mm2,%%mm0\n\t" \
  283. "psubw %%mm2,%%mm7\n\t" \
  284. "movq %%mm1,%%mm2\n\t" \
  285. "pmulhw %%mm6,%%mm1\n\t" \
  286. "pmulhw %%mm7,%%mm2\n\t" \
  287. "paddw %%mm6,%%mm1\n\t" \
  288. "movq "OC_MEM_OFFS(0x00,buf)",%%mm6\n\t" \
  289. "paddw %%mm7,%%mm2\n\t" \
  290. "movq "OC_MEM_OFFS(0x10,buf)",%%mm7\n\t" \
  291. /*Stage 3: \
  292. 6-5 butterfly: mm1=t[5], mm2=t[6] -> mm1=t[6]+t[5], mm2=t[6]-t[5] \
  293. 0-3 butterfly: mm4=t[0], mm7=t[3] -> mm7=t[0]+t[3], mm4=t[0]-t[3] \
  294. 1-2 butterfly: mm5=t[1], mm6=t[2] -> mm6=t[1]+t[2], mm5=t[1]-t[2]*/ \
  295. "paddw %%mm2,%%mm1\n\t" \
  296. "paddw %%mm5,%%mm6\n\t" \
  297. "paddw %%mm4,%%mm7\n\t" \
  298. "paddw %%mm2,%%mm2\n\t" \
  299. "paddw %%mm4,%%mm4\n\t" \
  300. "paddw %%mm5,%%mm5\n\t" \
  301. "psubw %%mm1,%%mm2\n\t" \
  302. "psubw %%mm7,%%mm4\n\t" \
  303. "psubw %%mm6,%%mm5\n\t" \
  304. /*Stage 4: \
  305. 0-7 butterfly: mm7=t[0], mm0=t[7] -> mm0=t[0]+t[7], mm7=t[0]-t[7] \
  306. 1-6 butterfly: mm6=t[1], mm1=t[6] -> mm1=t[1]+t[6], mm6=t[1]-t[6] \
  307. 2-5 butterfly: mm5=t[2], mm2=t[5] -> mm2=t[2]+t[5], mm5=t[2]-t[5] \
  308. 3-4 butterfly: mm4=t[3], mm3=t[4] -> mm3=t[3]+t[4], mm4=t[3]-t[4]*/ \
  309. "psubw %%mm0,%%mm7\n\t" \
  310. "psubw %%mm1,%%mm6\n\t" \
  311. "psubw %%mm2,%%mm5\n\t" \
  312. "psubw %%mm3,%%mm4\n\t" \
  313. "paddw %%mm0,%%mm0\n\t" \
  314. "paddw %%mm1,%%mm1\n\t" \
  315. "paddw %%mm2,%%mm2\n\t" \
  316. "paddw %%mm3,%%mm3\n\t" \
  317. "paddw %%mm7,%%mm0\n\t" \
  318. "paddw %%mm6,%%mm1\n\t" \
  319. "paddw %%mm5,%%mm2\n\t" \
  320. "paddw %%mm4,%%mm3\n\t" \
  321. #define OC_IDCT_8x8_10_ABC \
  322. "#OC_IDCT_8x8_10_ABC\n\t" \
  323. /*Stage 1:*/ \
  324. /*2-3 rotation by 6pi/16. \
  325. xmm7=C6, xmm6=C2, xmm2=X2, X6=0.*/ \
  326. "movdqa "OC_MEM_OFFS(0x60,c)",%%xmm7\n\t" \
  327. "movdqa "OC_MEM_OFFS(0x20,c)",%%xmm6\n\t" \
  328. "pmulhw %%xmm2,%%xmm6\n\t" \
  329. "pmulhw %%xmm2,%%xmm7\n\t" \
  330. "movdqa "OC_MEM_OFFS(0x50,c)",%%xmm5\n\t" \
  331. "paddw %%xmm6,%%xmm2\n\t" \
  332. "movdqa %%xmm2,"OC_MEM_OFFS(0x10,buf)"\n\t" \
  333. "movdqa "OC_MEM_OFFS(0x30,c)",%%xmm2\n\t" \
  334. "movdqa %%xmm7,"OC_MEM_OFFS(0x00,buf)"\n\t" \
  335. /*5-6 rotation by 3pi/16. \
  336. xmm5=C5, xmm2=C3, xmm3=X3, X5=0.*/ \
  337. "pmulhw %%xmm3,%%xmm5\n\t" \
  338. "pmulhw %%xmm3,%%xmm2\n\t" \
  339. "movdqa "OC_MEM_OFFS(0x10,c)",%%xmm7\n\t" \
  340. "paddw %%xmm3,%%xmm5\n\t" \
  341. "paddw %%xmm3,%%xmm2\n\t" \
  342. "movdqa "OC_MEM_OFFS(0x70,c)",%%xmm3\n\t" \
  343. /*4-7 rotation by 7pi/16. \
  344. xmm7=C1, xmm3=C7, xmm1=X1, X7=0.*/ \
  345. "pmulhw %%xmm1,%%xmm3\n\t" \
  346. "pmulhw %%xmm1,%%xmm7\n\t" \
  347. "movdqa "OC_MEM_OFFS(0x40,c)",%%xmm4\n\t" \
  348. "movdqa %%xmm3,%%xmm6\n\t" \
  349. "paddw %%xmm1,%%xmm7\n\t" \
  350. /*0-1 butterfly. \
  351. xmm4=C4, xmm0=X0, X4=0.*/ \
  352. /*Stage 2:*/ \
  353. /*4-5 butterfly: xmm3=t[4], xmm5=t[5] \
  354. 7-6 butterfly: xmm2=t[6], xmm7=t[7]*/ \
  355. "psubw %%xmm5,%%xmm3\n\t" \
  356. "paddw %%xmm5,%%xmm6\n\t" \
  357. "movdqa %%xmm4,%%xmm1\n\t" \
  358. "pmulhw %%xmm0,%%xmm4\n\t" \
  359. "paddw %%xmm0,%%xmm4\n\t" \
  360. "movdqa %%xmm7,%%xmm0\n\t" \
  361. "movdqa %%xmm4,%%xmm5\n\t" \
  362. "paddw %%xmm2,%%xmm0\n\t" \
  363. "psubw %%xmm2,%%xmm7\n\t" \
  364. "movdqa %%xmm1,%%xmm2\n\t" \
  365. "pmulhw %%xmm6,%%xmm1\n\t" \
  366. "pmulhw %%xmm7,%%xmm2\n\t" \
  367. "paddw %%xmm6,%%xmm1\n\t" \
  368. "movdqa "OC_MEM_OFFS(0x00,buf)",%%xmm6\n\t" \
  369. "paddw %%xmm7,%%xmm2\n\t" \
  370. "movdqa "OC_MEM_OFFS(0x10,buf)",%%xmm7\n\t" \
  371. /*Stage 3: \
  372. 6-5 butterfly: xmm1=t[5], xmm2=t[6] -> xmm1=t[6]+t[5], xmm2=t[6]-t[5] \
  373. 0-3 butterfly: xmm4=t[0], xmm7=t[3] -> xmm7=t[0]+t[3], xmm4=t[0]-t[3] \
  374. 1-2 butterfly: xmm5=t[1], xmm6=t[2] -> xmm6=t[1]+t[2], xmm5=t[1]-t[2]*/ \
  375. "paddw %%xmm2,%%xmm1\n\t" \
  376. "paddw %%xmm5,%%xmm6\n\t" \
  377. "paddw %%xmm4,%%xmm7\n\t" \
  378. "paddw %%xmm2,%%xmm2\n\t" \
  379. "paddw %%xmm4,%%xmm4\n\t" \
  380. "paddw %%xmm5,%%xmm5\n\t" \
  381. "psubw %%xmm1,%%xmm2\n\t" \
  382. "psubw %%xmm7,%%xmm4\n\t" \
  383. "psubw %%xmm6,%%xmm5\n\t" \
  384. static void oc_idct8x8_10_sse2(ogg_int16_t _y[64],ogg_int16_t _x[64]){
  385. OC_ALIGN16(ogg_int16_t buf[16]);
  386. /*This routine accepts an 8x8 matrix pre-transposed.*/
  387. __asm__ __volatile__(
  388. "movq "OC_MEM_OFFS(0x20,x)",%%mm2\n\t"
  389. "movq "OC_MEM_OFFS(0x30,x)",%%mm3\n\t"
  390. "movq "OC_MEM_OFFS(0x10,x)",%%mm1\n\t"
  391. "movq "OC_MEM_OFFS(0x00,x)",%%mm0\n\t"
  392. OC_IDCT_8x8_10_MMX
  393. OC_TRANSPOSE_8x4_MMX2SSE
  394. OC_IDCT_8x8_10_ABC
  395. OC_IDCT_8x8_D_STORE
  396. :[buf]"=m"(OC_ARRAY_OPERAND(short,buf,16)),
  397. [y]"=m"(OC_ARRAY_OPERAND(ogg_int16_t,_y,64))
  398. :[x]"m"OC_CONST_ARRAY_OPERAND(ogg_int16_t,_x,64),
  399. [c]"m"(OC_CONST_ARRAY_OPERAND(ogg_int16_t,OC_IDCT_CONSTS,128))
  400. );
  401. if(_x!=_y){
  402. /*Clear input data for next block (decoder only).*/
  403. __asm__ __volatile__(
  404. "pxor %%mm0,%%mm0\n\t"
  405. "movq %%mm0,"OC_MEM_OFFS(0x00,x)"\n\t"
  406. "movq %%mm0,"OC_MEM_OFFS(0x10,x)"\n\t"
  407. "movq %%mm0,"OC_MEM_OFFS(0x20,x)"\n\t"
  408. "movq %%mm0,"OC_MEM_OFFS(0x30,x)"\n\t"
  409. :[x]"+m"(OC_ARRAY_OPERAND(ogg_int16_t,_x,28))
  410. );
  411. }
  412. }
  413. /*Performs an inverse 8x8 Type-II DCT transform.
  414. The input is assumed to be scaled by a factor of 4 relative to orthonormal
  415. version of the transform.*/
  416. void oc_idct8x8_sse2(ogg_int16_t _y[64],ogg_int16_t _x[64],int _last_zzi){
  417. /*_last_zzi is subtly different from an actual count of the number of
  418. coefficients we decoded for this block.
  419. It contains the value of zzi BEFORE the final token in the block was
  420. decoded.
  421. In most cases this is an EOB token (the continuation of an EOB run from a
  422. previous block counts), and so this is the same as the coefficient count.
  423. However, in the case that the last token was NOT an EOB token, but filled
  424. the block up with exactly 64 coefficients, _last_zzi will be less than 64.
  425. Provided the last token was not a pure zero run, the minimum value it can
  426. be is 46, and so that doesn't affect any of the cases in this routine.
  427. However, if the last token WAS a pure zero run of length 63, then _last_zzi
  428. will be 1 while the number of coefficients decoded is 64.
  429. Thus, we will trigger the following special case, where the real
  430. coefficient count would not.
  431. Note also that a zero run of length 64 will give _last_zzi a value of 0,
  432. but we still process the DC coefficient, which might have a non-zero value
  433. due to DC prediction.
  434. Although convoluted, this is arguably the correct behavior: it allows us to
  435. use a smaller transform when the block ends with a long zero run instead
  436. of a normal EOB token.
  437. It could be smarter... multiple separate zero runs at the end of a block
  438. will fool it, but an encoder that generates these really deserves what it
  439. gets.
  440. Needless to say we inherited this approach from VP3.*/
  441. /*Then perform the iDCT.*/
  442. if(_last_zzi<=10)oc_idct8x8_10_sse2(_y,_x);
  443. else oc_idct8x8_slow_sse2(_y,_x);
  444. }
  445. #endif