mmxfdct.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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) 1999-2006 *
  9. * by the Xiph.Org Foundation http://www.xiph.org/ *
  10. * *
  11. ********************************************************************/
  12. /*MMX fDCT implementation for x86_32*/
  13. /*$Id: fdct_ses2.c 14579 2008-03-12 06:42:40Z xiphmont $*/
  14. #include "x86enc.h"
  15. #if defined(OC_X86_ASM)
  16. #define OC_FDCT_STAGE1_8x4 __asm{ \
  17. /*Stage 1:*/ \
  18. /*mm0=t7'=t0-t7*/ \
  19. __asm psubw mm0,mm7 \
  20. __asm paddw mm7,mm7 \
  21. /*mm1=t6'=t1-t6*/ \
  22. __asm psubw mm1, mm6 \
  23. __asm paddw mm6,mm6 \
  24. /*mm2=t5'=t2-t5*/ \
  25. __asm psubw mm2,mm5 \
  26. __asm paddw mm5,mm5 \
  27. /*mm3=t4'=t3-t4*/ \
  28. __asm psubw mm3,mm4 \
  29. __asm paddw mm4,mm4 \
  30. /*mm7=t0'=t0+t7*/ \
  31. __asm paddw mm7,mm0 \
  32. /*mm6=t1'=t1+t6*/ \
  33. __asm paddw mm6,mm1 \
  34. /*mm5=t2'=t2+t5*/ \
  35. __asm paddw mm5,mm2 \
  36. /*mm4=t3'=t3+t4*/ \
  37. __asm paddw mm4,mm3\
  38. }
  39. #define OC_FDCT8x4(_r0,_r1,_r2,_r3,_r4,_r5,_r6,_r7) __asm{ \
  40. /*Stage 2:*/ \
  41. /*mm7=t3''=t0'-t3'*/ \
  42. __asm psubw mm7,mm4 \
  43. __asm paddw mm4,mm4 \
  44. /*mm6=t2''=t1'-t2'*/ \
  45. __asm psubw mm6,mm5 \
  46. __asm movq [Y+_r6],mm7 \
  47. __asm paddw mm5,mm5 \
  48. /*mm1=t5''=t6'-t5'*/ \
  49. __asm psubw mm1,mm2 \
  50. __asm movq [Y+_r2],mm6 \
  51. /*mm4=t0''=t0'+t3'*/ \
  52. __asm paddw mm4,mm7 \
  53. __asm paddw mm2,mm2 \
  54. /*mm5=t1''=t1'+t2'*/ \
  55. __asm movq [Y+_r0],mm4 \
  56. __asm paddw mm5,mm6 \
  57. /*mm2=t6''=t6'+t5'*/ \
  58. __asm paddw mm2,mm1 \
  59. __asm movq [Y+_r4],mm5 \
  60. /*mm0=t7', mm1=t5'', mm2=t6'', mm3=t4'.*/ \
  61. /*mm4, mm5, mm6, mm7 are free.*/ \
  62. /*Stage 3:*/ \
  63. /*mm6={2}x4, mm7={27146,0xB500>>1}x2*/ \
  64. __asm mov A,0x5A806A0A \
  65. __asm pcmpeqb mm6,mm6 \
  66. __asm movd mm7,A \
  67. __asm psrlw mm6,15 \
  68. __asm punpckldq mm7,mm7 \
  69. __asm paddw mm6,mm6 \
  70. /*mm0=0, m2={-1}x4 \
  71. mm5:mm4=t5''*27146+0xB500*/ \
  72. __asm movq mm4,mm1 \
  73. __asm movq mm5,mm1 \
  74. __asm punpcklwd mm4,mm6 \
  75. __asm movq [Y+_r3],mm2 \
  76. __asm pmaddwd mm4,mm7 \
  77. __asm movq [Y+_r7],mm0 \
  78. __asm punpckhwd mm5,mm6 \
  79. __asm pxor mm0,mm0 \
  80. __asm pmaddwd mm5,mm7 \
  81. __asm pcmpeqb mm2,mm2 \
  82. /*mm2=t6'', mm1=t5''+(t5''!=0) \
  83. mm4=(t5''*27146+0xB500>>16)*/ \
  84. __asm pcmpeqw mm0,mm1 \
  85. __asm psrad mm4,16 \
  86. __asm psubw mm0,mm2 \
  87. __asm movq mm2, [Y+_r3] \
  88. __asm psrad mm5,16 \
  89. __asm paddw mm1,mm0 \
  90. __asm packssdw mm4,mm5 \
  91. /*mm4=s=(t5''*27146+0xB500>>16)+t5''+(t5''!=0)>>1*/ \
  92. __asm paddw mm4,mm1 \
  93. __asm movq mm0, [Y+_r7] \
  94. __asm psraw mm4,1 \
  95. __asm movq mm1,mm3 \
  96. /*mm3=t4''=t4'+s*/ \
  97. __asm paddw mm3,mm4 \
  98. /*mm1=t5'''=t4'-s*/ \
  99. __asm psubw mm1,mm4 \
  100. /*mm1=0, mm3={-1}x4 \
  101. mm5:mm4=t6''*27146+0xB500*/ \
  102. __asm movq mm4,mm2 \
  103. __asm movq mm5,mm2 \
  104. __asm punpcklwd mm4,mm6 \
  105. __asm movq [Y+_r5],mm1 \
  106. __asm pmaddwd mm4,mm7 \
  107. __asm movq [Y+_r1],mm3 \
  108. __asm punpckhwd mm5,mm6 \
  109. __asm pxor mm1,mm1 \
  110. __asm pmaddwd mm5,mm7 \
  111. __asm pcmpeqb mm3,mm3 \
  112. /*mm2=t6''+(t6''!=0), mm4=(t6''*27146+0xB500>>16)*/ \
  113. __asm psrad mm4,16 \
  114. __asm pcmpeqw mm1,mm2 \
  115. __asm psrad mm5,16 \
  116. __asm psubw mm1,mm3 \
  117. __asm packssdw mm4,mm5 \
  118. __asm paddw mm2,mm1 \
  119. /*mm1=t1'' \
  120. mm4=s=(t6''*27146+0xB500>>16)+t6''+(t6''!=0)>>1*/ \
  121. __asm paddw mm4,mm2 \
  122. __asm movq mm1,[Y+_r4] \
  123. __asm psraw mm4,1 \
  124. __asm movq mm2,mm0 \
  125. /*mm7={54491-0x7FFF,0x7FFF}x2 \
  126. mm0=t7''=t7'+s*/ \
  127. __asm paddw mm0,mm4 \
  128. /*mm2=t6'''=t7'-s*/ \
  129. __asm psubw mm2,mm4 \
  130. /*Stage 4:*/ \
  131. /*mm0=0, mm2=t0'' \
  132. mm5:mm4=t1''*27146+0xB500*/ \
  133. __asm movq mm4,mm1 \
  134. __asm movq mm5,mm1 \
  135. __asm punpcklwd mm4,mm6 \
  136. __asm movq [Y+_r3],mm2 \
  137. __asm pmaddwd mm4,mm7 \
  138. __asm movq mm2,[Y+_r0] \
  139. __asm punpckhwd mm5,mm6 \
  140. __asm movq [Y+_r7],mm0 \
  141. __asm pmaddwd mm5,mm7 \
  142. __asm pxor mm0,mm0 \
  143. /*mm7={27146,0x4000>>1}x2 \
  144. mm0=s=(t1''*27146+0xB500>>16)+t1''+(t1''!=0)*/ \
  145. __asm psrad mm4,16 \
  146. __asm mov A,0x20006A0A \
  147. __asm pcmpeqw mm0,mm1 \
  148. __asm movd mm7,A \
  149. __asm psrad mm5,16 \
  150. __asm psubw mm0,mm3 \
  151. __asm packssdw mm4,mm5 \
  152. __asm paddw mm0,mm1 \
  153. __asm punpckldq mm7,mm7 \
  154. __asm paddw mm0,mm4 \
  155. /*mm6={0x00000E3D}x2 \
  156. mm1=-(t0''==0), mm5:mm4=t0''*27146+0x4000*/ \
  157. __asm movq mm4,mm2 \
  158. __asm movq mm5,mm2 \
  159. __asm punpcklwd mm4,mm6 \
  160. __asm mov A,0x0E3D \
  161. __asm pmaddwd mm4,mm7 \
  162. __asm punpckhwd mm5,mm6 \
  163. __asm movd mm6,A \
  164. __asm pmaddwd mm5,mm7 \
  165. __asm pxor mm1,mm1 \
  166. __asm punpckldq mm6,mm6 \
  167. __asm pcmpeqw mm1,mm2 \
  168. /*mm4=r=(t0''*27146+0x4000>>16)+t0''+(t0''!=0)*/ \
  169. __asm psrad mm4,16 \
  170. __asm psubw mm1,mm3 \
  171. __asm psrad mm5,16 \
  172. __asm paddw mm2,mm1 \
  173. __asm packssdw mm4,mm5 \
  174. __asm movq mm1,[Y+_r5] \
  175. __asm paddw mm4,mm2 \
  176. /*mm2=t6'', mm0=_y[0]=u=r+s>>1 \
  177. The naive implementation could cause overflow, so we use \
  178. u=(r&s)+((r^s)>>1).*/ \
  179. __asm movq mm2,[Y+_r3] \
  180. __asm movq mm7,mm0 \
  181. __asm pxor mm0,mm4 \
  182. __asm pand mm7,mm4 \
  183. __asm psraw mm0,1 \
  184. __asm mov A,0x7FFF54DC \
  185. __asm paddw mm0,mm7 \
  186. __asm movd mm7,A \
  187. /*mm7={54491-0x7FFF,0x7FFF}x2 \
  188. mm4=_y[4]=v=r-u*/ \
  189. __asm psubw mm4,mm0 \
  190. __asm punpckldq mm7,mm7 \
  191. __asm movq [Y+_r4],mm4 \
  192. /*mm0=0, mm7={36410}x4 \
  193. mm1=(t5'''!=0), mm5:mm4=54491*t5'''+0x0E3D*/ \
  194. __asm movq mm4,mm1 \
  195. __asm movq mm5,mm1 \
  196. __asm punpcklwd mm4,mm1 \
  197. __asm mov A,0x8E3A8E3A \
  198. __asm pmaddwd mm4,mm7 \
  199. __asm movq [Y+_r0],mm0 \
  200. __asm punpckhwd mm5,mm1 \
  201. __asm pxor mm0,mm0 \
  202. __asm pmaddwd mm5,mm7 \
  203. __asm pcmpeqw mm1,mm0 \
  204. __asm movd mm7,A \
  205. __asm psubw mm1,mm3 \
  206. __asm punpckldq mm7,mm7 \
  207. __asm paddd mm4,mm6 \
  208. __asm paddd mm5,mm6 \
  209. /*mm0=0 \
  210. mm3:mm1=36410*t6'''+((t5'''!=0)<<16)*/ \
  211. __asm movq mm6,mm2 \
  212. __asm movq mm3,mm2 \
  213. __asm pmulhw mm6,mm7 \
  214. __asm paddw mm1,mm2 \
  215. __asm pmullw mm3,mm7 \
  216. __asm pxor mm0,mm0 \
  217. __asm paddw mm6,mm1 \
  218. __asm movq mm1,mm3 \
  219. __asm punpckhwd mm3,mm6 \
  220. __asm punpcklwd mm1,mm6 \
  221. /*mm3={-1}x4, mm6={1}x4 \
  222. mm4=_y[5]=u=(54491*t5'''+36410*t6'''+0x0E3D>>16)+(t5'''!=0)*/ \
  223. __asm paddd mm5,mm3 \
  224. __asm paddd mm4,mm1 \
  225. __asm psrad mm5,16 \
  226. __asm pxor mm6,mm6 \
  227. __asm psrad mm4,16 \
  228. __asm pcmpeqb mm3,mm3 \
  229. __asm packssdw mm4,mm5 \
  230. __asm psubw mm6,mm3 \
  231. /*mm1=t7'', mm7={26568,0x3400}x2 \
  232. mm2=s=t6'''-(36410*u>>16)*/ \
  233. __asm movq mm1,mm4 \
  234. __asm mov A,0x340067C8 \
  235. __asm pmulhw mm4,mm7 \
  236. __asm movd mm7,A \
  237. __asm movq [Y+_r5],mm1 \
  238. __asm punpckldq mm7,mm7 \
  239. __asm paddw mm4,mm1 \
  240. __asm movq mm1,[Y+_r7] \
  241. __asm psubw mm2,mm4 \
  242. /*mm6={0x00007B1B}x2 \
  243. mm0=(s!=0), mm5:mm4=s*26568+0x3400*/ \
  244. __asm movq mm4,mm2 \
  245. __asm movq mm5,mm2 \
  246. __asm punpcklwd mm4,mm6 \
  247. __asm pcmpeqw mm0,mm2 \
  248. __asm pmaddwd mm4,mm7 \
  249. __asm mov A,0x7B1B \
  250. __asm punpckhwd mm5,mm6 \
  251. __asm movd mm6,A \
  252. __asm pmaddwd mm5,mm7 \
  253. __asm psubw mm0,mm3 \
  254. __asm punpckldq mm6,mm6 \
  255. /*mm7={64277-0x7FFF,0x7FFF}x2 \
  256. mm2=_y[3]=v=(s*26568+0x3400>>17)+s+(s!=0)*/ \
  257. __asm psrad mm4,17 \
  258. __asm paddw mm2,mm0 \
  259. __asm psrad mm5,17 \
  260. __asm mov A,0x7FFF7B16 \
  261. __asm packssdw mm4,mm5 \
  262. __asm movd mm7,A \
  263. __asm paddw mm2,mm4 \
  264. __asm punpckldq mm7,mm7 \
  265. /*mm0=0, mm7={12785}x4 \
  266. mm1=(t7''!=0), mm2=t4'', mm5:mm4=64277*t7''+0x7B1B*/ \
  267. __asm movq mm4,mm1 \
  268. __asm movq mm5,mm1 \
  269. __asm movq [Y+_r3],mm2 \
  270. __asm punpcklwd mm4,mm1 \
  271. __asm movq mm2,[Y+_r1] \
  272. __asm pmaddwd mm4,mm7 \
  273. __asm mov A,0x31F131F1 \
  274. __asm punpckhwd mm5,mm1 \
  275. __asm pxor mm0,mm0 \
  276. __asm pmaddwd mm5,mm7 \
  277. __asm pcmpeqw mm1,mm0 \
  278. __asm movd mm7,A \
  279. __asm psubw mm1,mm3 \
  280. __asm punpckldq mm7,mm7 \
  281. __asm paddd mm4,mm6 \
  282. __asm paddd mm5,mm6 \
  283. /*mm3:mm1=12785*t4'''+((t7''!=0)<<16)*/ \
  284. __asm movq mm6,mm2 \
  285. __asm movq mm3,mm2 \
  286. __asm pmulhw mm6,mm7 \
  287. __asm pmullw mm3,mm7 \
  288. __asm paddw mm6,mm1 \
  289. __asm movq mm1,mm3 \
  290. __asm punpckhwd mm3,mm6 \
  291. __asm punpcklwd mm1,mm6 \
  292. /*mm3={-1}x4, mm6={1}x4 \
  293. mm4=_y[1]=u=(12785*t4'''+64277*t7''+0x7B1B>>16)+(t7''!=0)*/ \
  294. __asm paddd mm5,mm3 \
  295. __asm paddd mm4,mm1 \
  296. __asm psrad mm5,16 \
  297. __asm pxor mm6,mm6 \
  298. __asm psrad mm4,16 \
  299. __asm pcmpeqb mm3,mm3 \
  300. __asm packssdw mm4,mm5 \
  301. __asm psubw mm6,mm3 \
  302. /*mm1=t3'', mm7={20539,0x3000}x2 \
  303. mm4=s=(12785*u>>16)-t4''*/ \
  304. __asm movq [Y+_r1],mm4 \
  305. __asm pmulhw mm4,mm7 \
  306. __asm mov A,0x3000503B \
  307. __asm movq mm1,[Y+_r6] \
  308. __asm movd mm7,A \
  309. __asm psubw mm4,mm2 \
  310. __asm punpckldq mm7,mm7 \
  311. /*mm6={0x00006CB7}x2 \
  312. mm0=(s!=0), mm5:mm4=s*20539+0x3000*/ \
  313. __asm movq mm5,mm4 \
  314. __asm movq mm2,mm4 \
  315. __asm punpcklwd mm4,mm6 \
  316. __asm pcmpeqw mm0,mm2 \
  317. __asm pmaddwd mm4,mm7 \
  318. __asm mov A,0x6CB7 \
  319. __asm punpckhwd mm5,mm6 \
  320. __asm movd mm6,A \
  321. __asm pmaddwd mm5,mm7 \
  322. __asm psubw mm0,mm3 \
  323. __asm punpckldq mm6,mm6 \
  324. /*mm7={60547-0x7FFF,0x7FFF}x2 \
  325. mm2=_y[7]=v=(s*20539+0x3000>>20)+s+(s!=0)*/ \
  326. __asm psrad mm4,20 \
  327. __asm paddw mm2,mm0 \
  328. __asm psrad mm5,20 \
  329. __asm mov A,0x7FFF6C84 \
  330. __asm packssdw mm4,mm5 \
  331. __asm movd mm7,A \
  332. __asm paddw mm2,mm4 \
  333. __asm punpckldq mm7,mm7 \
  334. /*mm0=0, mm7={25080}x4 \
  335. mm2=t2'', mm5:mm4=60547*t3''+0x6CB7*/ \
  336. __asm movq mm4,mm1 \
  337. __asm movq mm5,mm1 \
  338. __asm movq [Y+_r7],mm2 \
  339. __asm punpcklwd mm4,mm1 \
  340. __asm movq mm2,[Y+_r2] \
  341. __asm pmaddwd mm4,mm7 \
  342. __asm mov A,0x61F861F8 \
  343. __asm punpckhwd mm5,mm1 \
  344. __asm pxor mm0,mm0 \
  345. __asm pmaddwd mm5,mm7 \
  346. __asm movd mm7,A \
  347. __asm pcmpeqw mm1,mm0 \
  348. __asm psubw mm1,mm3 \
  349. __asm punpckldq mm7,mm7 \
  350. __asm paddd mm4,mm6 \
  351. __asm paddd mm5,mm6 \
  352. /*mm3:mm1=25080*t2''+((t3''!=0)<<16)*/ \
  353. __asm movq mm6,mm2 \
  354. __asm movq mm3,mm2 \
  355. __asm pmulhw mm6,mm7 \
  356. __asm pmullw mm3,mm7 \
  357. __asm paddw mm6,mm1 \
  358. __asm movq mm1,mm3 \
  359. __asm punpckhwd mm3,mm6 \
  360. __asm punpcklwd mm1,mm6 \
  361. /*mm1={-1}x4 \
  362. mm4=u=(25080*t2''+60547*t3''+0x6CB7>>16)+(t3''!=0)*/ \
  363. __asm paddd mm5,mm3 \
  364. __asm paddd mm4,mm1 \
  365. __asm psrad mm5,16 \
  366. __asm mov A,0x28005460 \
  367. __asm psrad mm4,16 \
  368. __asm pcmpeqb mm1,mm1 \
  369. __asm packssdw mm4,mm5 \
  370. /*mm5={1}x4, mm6=_y[2]=u, mm7={21600,0x2800}x2 \
  371. mm4=s=(25080*u>>16)-t2''*/ \
  372. __asm movq mm6,mm4 \
  373. __asm pmulhw mm4,mm7 \
  374. __asm pxor mm5,mm5 \
  375. __asm movd mm7,A \
  376. __asm psubw mm5,mm1 \
  377. __asm punpckldq mm7,mm7 \
  378. __asm psubw mm4,mm2 \
  379. /*mm2=s+(s!=0) \
  380. mm4:mm3=s*21600+0x2800*/ \
  381. __asm movq mm3,mm4 \
  382. __asm movq mm2,mm4 \
  383. __asm punpckhwd mm4,mm5 \
  384. __asm pcmpeqw mm0,mm2 \
  385. __asm pmaddwd mm4,mm7 \
  386. __asm psubw mm0,mm1 \
  387. __asm punpcklwd mm3,mm5 \
  388. __asm paddw mm2,mm0 \
  389. __asm pmaddwd mm3,mm7 \
  390. /*mm0=_y[4], mm1=_y[7], mm4=_y[0], mm5=_y[5] \
  391. mm3=_y[6]=v=(s*21600+0x2800>>18)+s+(s!=0)*/ \
  392. __asm movq mm0,[Y+_r4] \
  393. __asm psrad mm4,18 \
  394. __asm movq mm5,[Y+_r5] \
  395. __asm psrad mm3,18 \
  396. __asm movq mm1,[Y+_r7] \
  397. __asm packssdw mm3,mm4 \
  398. __asm movq mm4,[Y+_r0] \
  399. __asm paddw mm3,mm2 \
  400. }
  401. /*On input, mm4=_y[0], mm6=_y[2], mm0=_y[4], mm5=_y[5], mm3=_y[6], mm1=_y[7].
  402. On output, {_y[4],mm1,mm2,mm3} contains the transpose of _y[4...7] and
  403. {mm4,mm5,mm6,mm7} contains the transpose of _y[0...3].*/
  404. #define OC_TRANSPOSE8x4(_r0,_r1,_r2,_r3,_r4,_r5,_r6,_r7) __asm{ \
  405. /*First 4x4 transpose:*/ \
  406. /*mm0 = e3 e2 e1 e0 \
  407. mm5 = f3 f2 f1 f0 \
  408. mm3 = g3 g2 g1 g0 \
  409. mm1 = h3 h2 h1 h0*/ \
  410. __asm movq mm2,mm0 \
  411. __asm punpcklwd mm0,mm5 \
  412. __asm punpckhwd mm2,mm5 \
  413. __asm movq mm5,mm3 \
  414. __asm punpcklwd mm3,mm1 \
  415. __asm punpckhwd mm5,mm1 \
  416. /*mm0 = f1 e1 f0 e0 \
  417. mm2 = f3 e3 f2 e2 \
  418. mm3 = h1 g1 h0 g0 \
  419. mm5 = h3 g3 h2 g2*/ \
  420. __asm movq mm1,mm0 \
  421. __asm punpckldq mm0,mm3 \
  422. __asm movq [Y+_r4],mm0 \
  423. __asm punpckhdq mm1,mm3 \
  424. __asm movq mm0,[Y+_r1] \
  425. __asm movq mm3,mm2 \
  426. __asm punpckldq mm2,mm5 \
  427. __asm punpckhdq mm3,mm5 \
  428. __asm movq mm5,[Y+_r3] \
  429. /*_y[4] = h0 g0 f0 e0 \
  430. mm1 = h1 g1 f1 e1 \
  431. mm2 = h2 g2 f2 e2 \
  432. mm3 = h3 g3 f3 e3*/ \
  433. /*Second 4x4 transpose:*/ \
  434. /*mm4 = a3 a2 a1 a0 \
  435. mm0 = b3 b2 b1 b0 \
  436. mm6 = c3 c2 c1 c0 \
  437. mm5 = d3 d2 d1 d0*/ \
  438. __asm movq mm7,mm4 \
  439. __asm punpcklwd mm4,mm0 \
  440. __asm punpckhwd mm7,mm0 \
  441. __asm movq mm0,mm6 \
  442. __asm punpcklwd mm6,mm5 \
  443. __asm punpckhwd mm0,mm5 \
  444. /*mm4 = b1 a1 b0 a0 \
  445. mm7 = b3 a3 b2 a2 \
  446. mm6 = d1 c1 d0 c0 \
  447. mm0 = d3 c3 d2 c2*/ \
  448. __asm movq mm5,mm4 \
  449. __asm punpckldq mm4,mm6 \
  450. __asm punpckhdq mm5,mm6 \
  451. __asm movq mm6,mm7 \
  452. __asm punpckhdq mm7,mm0 \
  453. __asm punpckldq mm6,mm0 \
  454. /*mm4 = d0 c0 b0 a0 \
  455. mm5 = d1 c1 b1 a1 \
  456. mm6 = d2 c2 b2 a2 \
  457. mm7 = d3 c3 b3 a3*/ \
  458. }
  459. /*MMX implementation of the fDCT.*/
  460. void oc_enc_fdct8x8_mmx(ogg_int16_t _y[64],const ogg_int16_t _x[64]){
  461. ptrdiff_t a;
  462. __asm{
  463. #define Y eax
  464. #define A ecx
  465. #define X edx
  466. /*Add two extra bits of working precision to improve accuracy; any more and
  467. we could overflow.*/
  468. /*We also add biases to correct for some systematic error that remains in
  469. the full fDCT->iDCT round trip.*/
  470. mov X, _x
  471. mov Y, _y
  472. movq mm0,[0x00+X]
  473. movq mm1,[0x10+X]
  474. movq mm2,[0x20+X]
  475. movq mm3,[0x30+X]
  476. pcmpeqb mm4,mm4
  477. pxor mm7,mm7
  478. movq mm5,mm0
  479. psllw mm0,2
  480. pcmpeqw mm5,mm7
  481. movq mm7,[0x70+X]
  482. psllw mm1,2
  483. psubw mm5,mm4
  484. psllw mm2,2
  485. mov A,1
  486. pslld mm5,16
  487. movd mm6,A
  488. psllq mm5,16
  489. mov A,0x10001
  490. psllw mm3,2
  491. movd mm4,A
  492. punpckhwd mm5,mm6
  493. psubw mm1,mm6
  494. movq mm6,[0x60+X]
  495. paddw mm0,mm5
  496. movq mm5,[0x50+X]
  497. paddw mm0,mm4
  498. movq mm4,[0x40+X]
  499. /*We inline stage1 of the transform here so we can get better instruction
  500. scheduling with the shifts.*/
  501. /*mm0=t7'=t0-t7*/
  502. psllw mm7,2
  503. psubw mm0,mm7
  504. psllw mm6,2
  505. paddw mm7,mm7
  506. /*mm1=t6'=t1-t6*/
  507. psllw mm5,2
  508. psubw mm1,mm6
  509. psllw mm4,2
  510. paddw mm6,mm6
  511. /*mm2=t5'=t2-t5*/
  512. psubw mm2,mm5
  513. paddw mm5,mm5
  514. /*mm3=t4'=t3-t4*/
  515. psubw mm3,mm4
  516. paddw mm4,mm4
  517. /*mm7=t0'=t0+t7*/
  518. paddw mm7,mm0
  519. /*mm6=t1'=t1+t6*/
  520. paddw mm6,mm1
  521. /*mm5=t2'=t2+t5*/
  522. paddw mm5,mm2
  523. /*mm4=t3'=t3+t4*/
  524. paddw mm4,mm3
  525. OC_FDCT8x4(0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70)
  526. OC_TRANSPOSE8x4(0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70)
  527. /*Swap out this 8x4 block for the next one.*/
  528. movq mm0,[0x08+X]
  529. movq [0x30+Y],mm7
  530. movq mm7,[0x78+X]
  531. movq [0x50+Y],mm1
  532. movq mm1,[0x18+X]
  533. movq [0x20+Y],mm6
  534. movq mm6,[0x68+X]
  535. movq [0x60+Y],mm2
  536. movq mm2,[0x28+X]
  537. movq [0x10+Y],mm5
  538. movq mm5,[0x58+X]
  539. movq [0x70+Y],mm3
  540. movq mm3,[0x38+X]
  541. /*And increase its working precision, too.*/
  542. psllw mm0,2
  543. movq [0x00+Y],mm4
  544. psllw mm7,2
  545. movq mm4,[0x48+X]
  546. /*We inline stage1 of the transform here so we can get better instruction
  547. scheduling with the shifts.*/
  548. /*mm0=t7'=t0-t7*/
  549. psubw mm0,mm7
  550. psllw mm1,2
  551. paddw mm7,mm7
  552. psllw mm6,2
  553. /*mm1=t6'=t1-t6*/
  554. psubw mm1,mm6
  555. psllw mm2,2
  556. paddw mm6,mm6
  557. psllw mm5,2
  558. /*mm2=t5'=t2-t5*/
  559. psubw mm2,mm5
  560. psllw mm3,2
  561. paddw mm5,mm5
  562. psllw mm4,2
  563. /*mm3=t4'=t3-t4*/
  564. psubw mm3,mm4
  565. paddw mm4,mm4
  566. /*mm7=t0'=t0+t7*/
  567. paddw mm7,mm0
  568. /*mm6=t1'=t1+t6*/
  569. paddw mm6,mm1
  570. /*mm5=t2'=t2+t5*/
  571. paddw mm5,mm2
  572. /*mm4=t3'=t3+t4*/
  573. paddw mm4,mm3
  574. OC_FDCT8x4(0x08,0x18,0x28,0x38,0x48,0x58,0x68,0x78)
  575. OC_TRANSPOSE8x4(0x08,0x18,0x28,0x38,0x48,0x58,0x68,0x78)
  576. /*Here the first 4x4 block of output from the last transpose is the second
  577. 4x4 block of input for the next transform.
  578. We have cleverly arranged that it already be in the appropriate place,
  579. so we only have to do half the stores and loads.*/
  580. movq mm0,[0x00+Y]
  581. movq [0x58+Y],mm1
  582. movq mm1,[0x10+Y]
  583. movq [0x68+Y],mm2
  584. movq mm2,[0x20+Y]
  585. movq [0x78+Y],mm3
  586. movq mm3,[0x30+Y]
  587. OC_FDCT_STAGE1_8x4
  588. OC_FDCT8x4(0x00,0x10,0x20,0x30,0x08,0x18,0x28,0x38)
  589. OC_TRANSPOSE8x4(0x00,0x10,0x20,0x30,0x08,0x18,0x28,0x38)
  590. /*mm0={-2}x4*/
  591. pcmpeqw mm0,mm0
  592. paddw mm0,mm0
  593. /*Round the results.*/
  594. psubw mm1,mm0
  595. psubw mm2,mm0
  596. psraw mm1,2
  597. psubw mm3,mm0
  598. movq [0x18+Y],mm1
  599. psraw mm2,2
  600. psubw mm4,mm0
  601. movq mm1,[0x08+Y]
  602. psraw mm3,2
  603. psubw mm5,mm0
  604. psraw mm4,2
  605. psubw mm6,mm0
  606. psraw mm5,2
  607. psubw mm7,mm0
  608. psraw mm6,2
  609. psubw mm1,mm0
  610. psraw mm7,2
  611. movq mm0,[0x40+Y]
  612. psraw mm1,2
  613. movq [0x30+Y],mm7
  614. movq mm7,[0x78+Y]
  615. movq [0x08+Y],mm1
  616. movq mm1,[0x50+Y]
  617. movq [0x20+Y],mm6
  618. movq mm6,[0x68+Y]
  619. movq [0x28+Y],mm2
  620. movq mm2,[0x60+Y]
  621. movq [0x10+Y],mm5
  622. movq mm5,[0x58+Y]
  623. movq [0x38+Y],mm3
  624. movq mm3,[0x70+Y]
  625. movq [0x00+Y],mm4
  626. movq mm4,[0x48+Y]
  627. OC_FDCT_STAGE1_8x4
  628. OC_FDCT8x4(0x40,0x50,0x60,0x70,0x48,0x58,0x68,0x78)
  629. OC_TRANSPOSE8x4(0x40,0x50,0x60,0x70,0x48,0x58,0x68,0x78)
  630. /*mm0={-2}x4*/
  631. pcmpeqw mm0,mm0
  632. paddw mm0,mm0
  633. /*Round the results.*/
  634. psubw mm1,mm0
  635. psubw mm2,mm0
  636. psraw mm1,2
  637. psubw mm3,mm0
  638. movq [0x58+Y],mm1
  639. psraw mm2,2
  640. psubw mm4,mm0
  641. movq mm1,[0x48+Y]
  642. psraw mm3,2
  643. psubw mm5,mm0
  644. movq [0x68+Y],mm2
  645. psraw mm4,2
  646. psubw mm6,mm0
  647. movq [0x78+Y],mm3
  648. psraw mm5,2
  649. psubw mm7,mm0
  650. movq [0x40+Y],mm4
  651. psraw mm6,2
  652. psubw mm1,mm0
  653. movq [0x50+Y],mm5
  654. psraw mm7,2
  655. movq [0x60+Y],mm6
  656. psraw mm1,2
  657. movq [0x70+Y],mm7
  658. movq [0x48+Y],mm1
  659. #undef Y
  660. #undef A
  661. #undef X
  662. }
  663. }
  664. #endif