jfdctint-mmx.asm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. ;
  2. ; jfdctint.asm - accurate integer FDCT (MMX)
  3. ;
  4. ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ; Copyright (C) 2016, D. R. Commander.
  6. ;
  7. ; Based on the x86 SIMD extension for IJG JPEG library
  8. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
  9. ; For conditions of distribution and use, see copyright notice in jsimdext.inc
  10. ;
  11. ; This file should be assembled with NASM (Netwide Assembler),
  12. ; can *not* be assembled with Microsoft's MASM or any compatible
  13. ; assembler (including Borland's Turbo Assembler).
  14. ; NASM is available from http://nasm.sourceforge.net/ or
  15. ; http://sourceforge.net/project/showfiles.php?group_id=6208
  16. ;
  17. ; This file contains a slow-but-accurate integer implementation of the
  18. ; forward DCT (Discrete Cosine Transform). The following code is based
  19. ; directly on the IJG's original jfdctint.c; see the jfdctint.c for
  20. ; more details.
  21. %include "jsimdext.inc"
  22. %include "jdct.inc"
  23. ; --------------------------------------------------------------------------
  24. %define CONST_BITS 13
  25. %define PASS1_BITS 2
  26. %define DESCALE_P1 (CONST_BITS - PASS1_BITS)
  27. %define DESCALE_P2 (CONST_BITS + PASS1_BITS)
  28. %if CONST_BITS == 13
  29. F_0_298 equ 2446 ; FIX(0.298631336)
  30. F_0_390 equ 3196 ; FIX(0.390180644)
  31. F_0_541 equ 4433 ; FIX(0.541196100)
  32. F_0_765 equ 6270 ; FIX(0.765366865)
  33. F_0_899 equ 7373 ; FIX(0.899976223)
  34. F_1_175 equ 9633 ; FIX(1.175875602)
  35. F_1_501 equ 12299 ; FIX(1.501321110)
  36. F_1_847 equ 15137 ; FIX(1.847759065)
  37. F_1_961 equ 16069 ; FIX(1.961570560)
  38. F_2_053 equ 16819 ; FIX(2.053119869)
  39. F_2_562 equ 20995 ; FIX(2.562915447)
  40. F_3_072 equ 25172 ; FIX(3.072711026)
  41. %else
  42. ; NASM cannot do compile-time arithmetic on floating-point constants.
  43. %define DESCALE(x, n) (((x) + (1 << ((n) - 1))) >> (n))
  44. F_0_298 equ DESCALE( 320652955, 30 - CONST_BITS) ; FIX(0.298631336)
  45. F_0_390 equ DESCALE( 418953276, 30 - CONST_BITS) ; FIX(0.390180644)
  46. F_0_541 equ DESCALE( 581104887, 30 - CONST_BITS) ; FIX(0.541196100)
  47. F_0_765 equ DESCALE( 821806413, 30 - CONST_BITS) ; FIX(0.765366865)
  48. F_0_899 equ DESCALE( 966342111, 30 - CONST_BITS) ; FIX(0.899976223)
  49. F_1_175 equ DESCALE(1262586813, 30 - CONST_BITS) ; FIX(1.175875602)
  50. F_1_501 equ DESCALE(1612031267, 30 - CONST_BITS) ; FIX(1.501321110)
  51. F_1_847 equ DESCALE(1984016188, 30 - CONST_BITS) ; FIX(1.847759065)
  52. F_1_961 equ DESCALE(2106220350, 30 - CONST_BITS) ; FIX(1.961570560)
  53. F_2_053 equ DESCALE(2204520673, 30 - CONST_BITS) ; FIX(2.053119869)
  54. F_2_562 equ DESCALE(2751909506, 30 - CONST_BITS) ; FIX(2.562915447)
  55. F_3_072 equ DESCALE(3299298341, 30 - CONST_BITS) ; FIX(3.072711026)
  56. %endif
  57. ; --------------------------------------------------------------------------
  58. SECTION SEG_CONST
  59. alignz 32
  60. GLOBAL_DATA(jconst_fdct_islow_mmx)
  61. EXTN(jconst_fdct_islow_mmx):
  62. PW_F130_F054 times 2 dw (F_0_541 + F_0_765), F_0_541
  63. PW_F054_MF130 times 2 dw F_0_541, (F_0_541 - F_1_847)
  64. PW_MF078_F117 times 2 dw (F_1_175 - F_1_961), F_1_175
  65. PW_F117_F078 times 2 dw F_1_175, (F_1_175 - F_0_390)
  66. PW_MF060_MF089 times 2 dw (F_0_298 - F_0_899), -F_0_899
  67. PW_MF089_F060 times 2 dw -F_0_899, (F_1_501 - F_0_899)
  68. PW_MF050_MF256 times 2 dw (F_2_053 - F_2_562), -F_2_562
  69. PW_MF256_F050 times 2 dw -F_2_562, (F_3_072 - F_2_562)
  70. PD_DESCALE_P1 times 2 dd 1 << (DESCALE_P1 - 1)
  71. PD_DESCALE_P2 times 2 dd 1 << (DESCALE_P2 - 1)
  72. PW_DESCALE_P2X times 4 dw 1 << (PASS1_BITS - 1)
  73. alignz 32
  74. ; --------------------------------------------------------------------------
  75. SECTION SEG_TEXT
  76. BITS 32
  77. ;
  78. ; Perform the forward DCT on one block of samples.
  79. ;
  80. ; GLOBAL(void)
  81. ; jsimd_fdct_islow_mmx(DCTELEM *data)
  82. ;
  83. %define data(b) (b) + 8 ; DCTELEM *data
  84. %define original_ebp ebp + 0
  85. %define wk(i) ebp - (WK_NUM - (i)) * SIZEOF_MMWORD ; mmword wk[WK_NUM]
  86. %define WK_NUM 2
  87. align 32
  88. GLOBAL_FUNCTION(jsimd_fdct_islow_mmx)
  89. EXTN(jsimd_fdct_islow_mmx):
  90. push ebp
  91. mov eax, esp ; eax = original ebp
  92. sub esp, byte 4
  93. and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
  94. mov [esp], eax
  95. mov ebp, esp ; ebp = aligned ebp
  96. lea esp, [wk(0)]
  97. pushpic ebx
  98. ; push ecx ; need not be preserved
  99. ; push edx ; need not be preserved
  100. ; push esi ; unused
  101. ; push edi ; unused
  102. get_GOT ebx ; get GOT address
  103. ; ---- Pass 1: process rows.
  104. mov edx, POINTER [data(eax)] ; (DCTELEM *)
  105. mov ecx, DCTSIZE/4
  106. alignx 16, 7
  107. .rowloop:
  108. movq mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
  109. movq mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
  110. movq mm2, MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)]
  111. movq mm3, MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)]
  112. ; mm0=(20 21 22 23), mm2=(24 25 26 27)
  113. ; mm1=(30 31 32 33), mm3=(34 35 36 37)
  114. movq mm4, mm0 ; transpose coefficients(phase 1)
  115. punpcklwd mm0, mm1 ; mm0=(20 30 21 31)
  116. punpckhwd mm4, mm1 ; mm4=(22 32 23 33)
  117. movq mm5, mm2 ; transpose coefficients(phase 1)
  118. punpcklwd mm2, mm3 ; mm2=(24 34 25 35)
  119. punpckhwd mm5, mm3 ; mm5=(26 36 27 37)
  120. movq mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
  121. movq mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
  122. movq mm1, MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)]
  123. movq mm3, MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)]
  124. ; mm6=(00 01 02 03), mm1=(04 05 06 07)
  125. ; mm7=(10 11 12 13), mm3=(14 15 16 17)
  126. movq MMWORD [wk(0)], mm4 ; wk(0)=(22 32 23 33)
  127. movq MMWORD [wk(1)], mm2 ; wk(1)=(24 34 25 35)
  128. movq mm4, mm6 ; transpose coefficients(phase 1)
  129. punpcklwd mm6, mm7 ; mm6=(00 10 01 11)
  130. punpckhwd mm4, mm7 ; mm4=(02 12 03 13)
  131. movq mm2, mm1 ; transpose coefficients(phase 1)
  132. punpcklwd mm1, mm3 ; mm1=(04 14 05 15)
  133. punpckhwd mm2, mm3 ; mm2=(06 16 07 17)
  134. movq mm7, mm6 ; transpose coefficients(phase 2)
  135. punpckldq mm6, mm0 ; mm6=(00 10 20 30)=data0
  136. punpckhdq mm7, mm0 ; mm7=(01 11 21 31)=data1
  137. movq mm3, mm2 ; transpose coefficients(phase 2)
  138. punpckldq mm2, mm5 ; mm2=(06 16 26 36)=data6
  139. punpckhdq mm3, mm5 ; mm3=(07 17 27 37)=data7
  140. movq mm0, mm7
  141. movq mm5, mm6
  142. psubw mm7, mm2 ; mm7=data1-data6=tmp6
  143. psubw mm6, mm3 ; mm6=data0-data7=tmp7
  144. paddw mm0, mm2 ; mm0=data1+data6=tmp1
  145. paddw mm5, mm3 ; mm5=data0+data7=tmp0
  146. movq mm2, MMWORD [wk(0)] ; mm2=(22 32 23 33)
  147. movq mm3, MMWORD [wk(1)] ; mm3=(24 34 25 35)
  148. movq MMWORD [wk(0)], mm7 ; wk(0)=tmp6
  149. movq MMWORD [wk(1)], mm6 ; wk(1)=tmp7
  150. movq mm7, mm4 ; transpose coefficients(phase 2)
  151. punpckldq mm4, mm2 ; mm4=(02 12 22 32)=data2
  152. punpckhdq mm7, mm2 ; mm7=(03 13 23 33)=data3
  153. movq mm6, mm1 ; transpose coefficients(phase 2)
  154. punpckldq mm1, mm3 ; mm1=(04 14 24 34)=data4
  155. punpckhdq mm6, mm3 ; mm6=(05 15 25 35)=data5
  156. movq mm2, mm7
  157. movq mm3, mm4
  158. paddw mm7, mm1 ; mm7=data3+data4=tmp3
  159. paddw mm4, mm6 ; mm4=data2+data5=tmp2
  160. psubw mm2, mm1 ; mm2=data3-data4=tmp4
  161. psubw mm3, mm6 ; mm3=data2-data5=tmp5
  162. ; -- Even part
  163. movq mm1, mm5
  164. movq mm6, mm0
  165. paddw mm5, mm7 ; mm5=tmp10
  166. paddw mm0, mm4 ; mm0=tmp11
  167. psubw mm1, mm7 ; mm1=tmp13
  168. psubw mm6, mm4 ; mm6=tmp12
  169. movq mm7, mm5
  170. paddw mm5, mm0 ; mm5=tmp10+tmp11
  171. psubw mm7, mm0 ; mm7=tmp10-tmp11
  172. psllw mm5, PASS1_BITS ; mm5=data0
  173. psllw mm7, PASS1_BITS ; mm7=data4
  174. movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm5
  175. movq MMWORD [MMBLOCK(0,1,edx,SIZEOF_DCTELEM)], mm7
  176. ; (Original)
  177. ; z1 = (tmp12 + tmp13) * 0.541196100;
  178. ; data2 = z1 + tmp13 * 0.765366865;
  179. ; data6 = z1 + tmp12 * -1.847759065;
  180. ;
  181. ; (This implementation)
  182. ; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
  183. ; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
  184. movq mm4, mm1 ; mm1=tmp13
  185. movq mm0, mm1
  186. punpcklwd mm4, mm6 ; mm6=tmp12
  187. punpckhwd mm0, mm6
  188. movq mm1, mm4
  189. movq mm6, mm0
  190. pmaddwd mm4, [GOTOFF(ebx,PW_F130_F054)] ; mm4=data2L
  191. pmaddwd mm0, [GOTOFF(ebx,PW_F130_F054)] ; mm0=data2H
  192. pmaddwd mm1, [GOTOFF(ebx,PW_F054_MF130)] ; mm1=data6L
  193. pmaddwd mm6, [GOTOFF(ebx,PW_F054_MF130)] ; mm6=data6H
  194. paddd mm4, [GOTOFF(ebx,PD_DESCALE_P1)]
  195. paddd mm0, [GOTOFF(ebx,PD_DESCALE_P1)]
  196. psrad mm4, DESCALE_P1
  197. psrad mm0, DESCALE_P1
  198. paddd mm1, [GOTOFF(ebx,PD_DESCALE_P1)]
  199. paddd mm6, [GOTOFF(ebx,PD_DESCALE_P1)]
  200. psrad mm1, DESCALE_P1
  201. psrad mm6, DESCALE_P1
  202. packssdw mm4, mm0 ; mm4=data2
  203. packssdw mm1, mm6 ; mm1=data6
  204. movq MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4
  205. movq MMWORD [MMBLOCK(2,1,edx,SIZEOF_DCTELEM)], mm1
  206. ; -- Odd part
  207. movq mm5, MMWORD [wk(0)] ; mm5=tmp6
  208. movq mm7, MMWORD [wk(1)] ; mm7=tmp7
  209. movq mm0, mm2 ; mm2=tmp4
  210. movq mm6, mm3 ; mm3=tmp5
  211. paddw mm0, mm5 ; mm0=z3
  212. paddw mm6, mm7 ; mm6=z4
  213. ; (Original)
  214. ; z5 = (z3 + z4) * 1.175875602;
  215. ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644;
  216. ; z3 += z5; z4 += z5;
  217. ;
  218. ; (This implementation)
  219. ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
  220. ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
  221. movq mm4, mm0
  222. movq mm1, mm0
  223. punpcklwd mm4, mm6
  224. punpckhwd mm1, mm6
  225. movq mm0, mm4
  226. movq mm6, mm1
  227. pmaddwd mm4, [GOTOFF(ebx,PW_MF078_F117)] ; mm4=z3L
  228. pmaddwd mm1, [GOTOFF(ebx,PW_MF078_F117)] ; mm1=z3H
  229. pmaddwd mm0, [GOTOFF(ebx,PW_F117_F078)] ; mm0=z4L
  230. pmaddwd mm6, [GOTOFF(ebx,PW_F117_F078)] ; mm6=z4H
  231. movq MMWORD [wk(0)], mm4 ; wk(0)=z3L
  232. movq MMWORD [wk(1)], mm1 ; wk(1)=z3H
  233. ; (Original)
  234. ; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6;
  235. ; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869;
  236. ; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110;
  237. ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447;
  238. ; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4;
  239. ; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4;
  240. ;
  241. ; (This implementation)
  242. ; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
  243. ; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
  244. ; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
  245. ; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
  246. ; data7 = tmp4 + z3; data5 = tmp5 + z4;
  247. ; data3 = tmp6 + z3; data1 = tmp7 + z4;
  248. movq mm4, mm2
  249. movq mm1, mm2
  250. punpcklwd mm4, mm7
  251. punpckhwd mm1, mm7
  252. movq mm2, mm4
  253. movq mm7, mm1
  254. pmaddwd mm4, [GOTOFF(ebx,PW_MF060_MF089)] ; mm4=tmp4L
  255. pmaddwd mm1, [GOTOFF(ebx,PW_MF060_MF089)] ; mm1=tmp4H
  256. pmaddwd mm2, [GOTOFF(ebx,PW_MF089_F060)] ; mm2=tmp7L
  257. pmaddwd mm7, [GOTOFF(ebx,PW_MF089_F060)] ; mm7=tmp7H
  258. paddd mm4, MMWORD [wk(0)] ; mm4=data7L
  259. paddd mm1, MMWORD [wk(1)] ; mm1=data7H
  260. paddd mm2, mm0 ; mm2=data1L
  261. paddd mm7, mm6 ; mm7=data1H
  262. paddd mm4, [GOTOFF(ebx,PD_DESCALE_P1)]
  263. paddd mm1, [GOTOFF(ebx,PD_DESCALE_P1)]
  264. psrad mm4, DESCALE_P1
  265. psrad mm1, DESCALE_P1
  266. paddd mm2, [GOTOFF(ebx,PD_DESCALE_P1)]
  267. paddd mm7, [GOTOFF(ebx,PD_DESCALE_P1)]
  268. psrad mm2, DESCALE_P1
  269. psrad mm7, DESCALE_P1
  270. packssdw mm4, mm1 ; mm4=data7
  271. packssdw mm2, mm7 ; mm2=data1
  272. movq MMWORD [MMBLOCK(3,1,edx,SIZEOF_DCTELEM)], mm4
  273. movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm2
  274. movq mm1, mm3
  275. movq mm7, mm3
  276. punpcklwd mm1, mm5
  277. punpckhwd mm7, mm5
  278. movq mm3, mm1
  279. movq mm5, mm7
  280. pmaddwd mm1, [GOTOFF(ebx,PW_MF050_MF256)] ; mm1=tmp5L
  281. pmaddwd mm7, [GOTOFF(ebx,PW_MF050_MF256)] ; mm7=tmp5H
  282. pmaddwd mm3, [GOTOFF(ebx,PW_MF256_F050)] ; mm3=tmp6L
  283. pmaddwd mm5, [GOTOFF(ebx,PW_MF256_F050)] ; mm5=tmp6H
  284. paddd mm1, mm0 ; mm1=data5L
  285. paddd mm7, mm6 ; mm7=data5H
  286. paddd mm3, MMWORD [wk(0)] ; mm3=data3L
  287. paddd mm5, MMWORD [wk(1)] ; mm5=data3H
  288. paddd mm1, [GOTOFF(ebx,PD_DESCALE_P1)]
  289. paddd mm7, [GOTOFF(ebx,PD_DESCALE_P1)]
  290. psrad mm1, DESCALE_P1
  291. psrad mm7, DESCALE_P1
  292. paddd mm3, [GOTOFF(ebx,PD_DESCALE_P1)]
  293. paddd mm5, [GOTOFF(ebx,PD_DESCALE_P1)]
  294. psrad mm3, DESCALE_P1
  295. psrad mm5, DESCALE_P1
  296. packssdw mm1, mm7 ; mm1=data5
  297. packssdw mm3, mm5 ; mm3=data3
  298. movq MMWORD [MMBLOCK(1,1,edx,SIZEOF_DCTELEM)], mm1
  299. movq MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm3
  300. add edx, byte 4*DCTSIZE*SIZEOF_DCTELEM
  301. dec ecx
  302. jnz near .rowloop
  303. ; ---- Pass 2: process columns.
  304. mov edx, POINTER [data(eax)] ; (DCTELEM *)
  305. mov ecx, DCTSIZE/4
  306. alignx 16, 7
  307. .columnloop:
  308. movq mm0, MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
  309. movq mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
  310. movq mm2, MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)]
  311. movq mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)]
  312. ; mm0=(02 12 22 32), mm2=(42 52 62 72)
  313. ; mm1=(03 13 23 33), mm3=(43 53 63 73)
  314. movq mm4, mm0 ; transpose coefficients(phase 1)
  315. punpcklwd mm0, mm1 ; mm0=(02 03 12 13)
  316. punpckhwd mm4, mm1 ; mm4=(22 23 32 33)
  317. movq mm5, mm2 ; transpose coefficients(phase 1)
  318. punpcklwd mm2, mm3 ; mm2=(42 43 52 53)
  319. punpckhwd mm5, mm3 ; mm5=(62 63 72 73)
  320. movq mm6, MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
  321. movq mm7, MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
  322. movq mm1, MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)]
  323. movq mm3, MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)]
  324. ; mm6=(00 10 20 30), mm1=(40 50 60 70)
  325. ; mm7=(01 11 21 31), mm3=(41 51 61 71)
  326. movq MMWORD [wk(0)], mm4 ; wk(0)=(22 23 32 33)
  327. movq MMWORD [wk(1)], mm2 ; wk(1)=(42 43 52 53)
  328. movq mm4, mm6 ; transpose coefficients(phase 1)
  329. punpcklwd mm6, mm7 ; mm6=(00 01 10 11)
  330. punpckhwd mm4, mm7 ; mm4=(20 21 30 31)
  331. movq mm2, mm1 ; transpose coefficients(phase 1)
  332. punpcklwd mm1, mm3 ; mm1=(40 41 50 51)
  333. punpckhwd mm2, mm3 ; mm2=(60 61 70 71)
  334. movq mm7, mm6 ; transpose coefficients(phase 2)
  335. punpckldq mm6, mm0 ; mm6=(00 01 02 03)=data0
  336. punpckhdq mm7, mm0 ; mm7=(10 11 12 13)=data1
  337. movq mm3, mm2 ; transpose coefficients(phase 2)
  338. punpckldq mm2, mm5 ; mm2=(60 61 62 63)=data6
  339. punpckhdq mm3, mm5 ; mm3=(70 71 72 73)=data7
  340. movq mm0, mm7
  341. movq mm5, mm6
  342. psubw mm7, mm2 ; mm7=data1-data6=tmp6
  343. psubw mm6, mm3 ; mm6=data0-data7=tmp7
  344. paddw mm0, mm2 ; mm0=data1+data6=tmp1
  345. paddw mm5, mm3 ; mm5=data0+data7=tmp0
  346. movq mm2, MMWORD [wk(0)] ; mm2=(22 23 32 33)
  347. movq mm3, MMWORD [wk(1)] ; mm3=(42 43 52 53)
  348. movq MMWORD [wk(0)], mm7 ; wk(0)=tmp6
  349. movq MMWORD [wk(1)], mm6 ; wk(1)=tmp7
  350. movq mm7, mm4 ; transpose coefficients(phase 2)
  351. punpckldq mm4, mm2 ; mm4=(20 21 22 23)=data2
  352. punpckhdq mm7, mm2 ; mm7=(30 31 32 33)=data3
  353. movq mm6, mm1 ; transpose coefficients(phase 2)
  354. punpckldq mm1, mm3 ; mm1=(40 41 42 43)=data4
  355. punpckhdq mm6, mm3 ; mm6=(50 51 52 53)=data5
  356. movq mm2, mm7
  357. movq mm3, mm4
  358. paddw mm7, mm1 ; mm7=data3+data4=tmp3
  359. paddw mm4, mm6 ; mm4=data2+data5=tmp2
  360. psubw mm2, mm1 ; mm2=data3-data4=tmp4
  361. psubw mm3, mm6 ; mm3=data2-data5=tmp5
  362. ; -- Even part
  363. movq mm1, mm5
  364. movq mm6, mm0
  365. paddw mm5, mm7 ; mm5=tmp10
  366. paddw mm0, mm4 ; mm0=tmp11
  367. psubw mm1, mm7 ; mm1=tmp13
  368. psubw mm6, mm4 ; mm6=tmp12
  369. movq mm7, mm5
  370. paddw mm5, mm0 ; mm5=tmp10+tmp11
  371. psubw mm7, mm0 ; mm7=tmp10-tmp11
  372. paddw mm5, [GOTOFF(ebx,PW_DESCALE_P2X)]
  373. paddw mm7, [GOTOFF(ebx,PW_DESCALE_P2X)]
  374. psraw mm5, PASS1_BITS ; mm5=data0
  375. psraw mm7, PASS1_BITS ; mm7=data4
  376. movq MMWORD [MMBLOCK(0,0,edx,SIZEOF_DCTELEM)], mm5
  377. movq MMWORD [MMBLOCK(4,0,edx,SIZEOF_DCTELEM)], mm7
  378. ; (Original)
  379. ; z1 = (tmp12 + tmp13) * 0.541196100;
  380. ; data2 = z1 + tmp13 * 0.765366865;
  381. ; data6 = z1 + tmp12 * -1.847759065;
  382. ;
  383. ; (This implementation)
  384. ; data2 = tmp13 * (0.541196100 + 0.765366865) + tmp12 * 0.541196100;
  385. ; data6 = tmp13 * 0.541196100 + tmp12 * (0.541196100 - 1.847759065);
  386. movq mm4, mm1 ; mm1=tmp13
  387. movq mm0, mm1
  388. punpcklwd mm4, mm6 ; mm6=tmp12
  389. punpckhwd mm0, mm6
  390. movq mm1, mm4
  391. movq mm6, mm0
  392. pmaddwd mm4, [GOTOFF(ebx,PW_F130_F054)] ; mm4=data2L
  393. pmaddwd mm0, [GOTOFF(ebx,PW_F130_F054)] ; mm0=data2H
  394. pmaddwd mm1, [GOTOFF(ebx,PW_F054_MF130)] ; mm1=data6L
  395. pmaddwd mm6, [GOTOFF(ebx,PW_F054_MF130)] ; mm6=data6H
  396. paddd mm4, [GOTOFF(ebx,PD_DESCALE_P2)]
  397. paddd mm0, [GOTOFF(ebx,PD_DESCALE_P2)]
  398. psrad mm4, DESCALE_P2
  399. psrad mm0, DESCALE_P2
  400. paddd mm1, [GOTOFF(ebx,PD_DESCALE_P2)]
  401. paddd mm6, [GOTOFF(ebx,PD_DESCALE_P2)]
  402. psrad mm1, DESCALE_P2
  403. psrad mm6, DESCALE_P2
  404. packssdw mm4, mm0 ; mm4=data2
  405. packssdw mm1, mm6 ; mm1=data6
  406. movq MMWORD [MMBLOCK(2,0,edx,SIZEOF_DCTELEM)], mm4
  407. movq MMWORD [MMBLOCK(6,0,edx,SIZEOF_DCTELEM)], mm1
  408. ; -- Odd part
  409. movq mm5, MMWORD [wk(0)] ; mm5=tmp6
  410. movq mm7, MMWORD [wk(1)] ; mm7=tmp7
  411. movq mm0, mm2 ; mm2=tmp4
  412. movq mm6, mm3 ; mm3=tmp5
  413. paddw mm0, mm5 ; mm0=z3
  414. paddw mm6, mm7 ; mm6=z4
  415. ; (Original)
  416. ; z5 = (z3 + z4) * 1.175875602;
  417. ; z3 = z3 * -1.961570560; z4 = z4 * -0.390180644;
  418. ; z3 += z5; z4 += z5;
  419. ;
  420. ; (This implementation)
  421. ; z3 = z3 * (1.175875602 - 1.961570560) + z4 * 1.175875602;
  422. ; z4 = z3 * 1.175875602 + z4 * (1.175875602 - 0.390180644);
  423. movq mm4, mm0
  424. movq mm1, mm0
  425. punpcklwd mm4, mm6
  426. punpckhwd mm1, mm6
  427. movq mm0, mm4
  428. movq mm6, mm1
  429. pmaddwd mm4, [GOTOFF(ebx,PW_MF078_F117)] ; mm4=z3L
  430. pmaddwd mm1, [GOTOFF(ebx,PW_MF078_F117)] ; mm1=z3H
  431. pmaddwd mm0, [GOTOFF(ebx,PW_F117_F078)] ; mm0=z4L
  432. pmaddwd mm6, [GOTOFF(ebx,PW_F117_F078)] ; mm6=z4H
  433. movq MMWORD [wk(0)], mm4 ; wk(0)=z3L
  434. movq MMWORD [wk(1)], mm1 ; wk(1)=z3H
  435. ; (Original)
  436. ; z1 = tmp4 + tmp7; z2 = tmp5 + tmp6;
  437. ; tmp4 = tmp4 * 0.298631336; tmp5 = tmp5 * 2.053119869;
  438. ; tmp6 = tmp6 * 3.072711026; tmp7 = tmp7 * 1.501321110;
  439. ; z1 = z1 * -0.899976223; z2 = z2 * -2.562915447;
  440. ; data7 = tmp4 + z1 + z3; data5 = tmp5 + z2 + z4;
  441. ; data3 = tmp6 + z2 + z3; data1 = tmp7 + z1 + z4;
  442. ;
  443. ; (This implementation)
  444. ; tmp4 = tmp4 * (0.298631336 - 0.899976223) + tmp7 * -0.899976223;
  445. ; tmp5 = tmp5 * (2.053119869 - 2.562915447) + tmp6 * -2.562915447;
  446. ; tmp6 = tmp5 * -2.562915447 + tmp6 * (3.072711026 - 2.562915447);
  447. ; tmp7 = tmp4 * -0.899976223 + tmp7 * (1.501321110 - 0.899976223);
  448. ; data7 = tmp4 + z3; data5 = tmp5 + z4;
  449. ; data3 = tmp6 + z3; data1 = tmp7 + z4;
  450. movq mm4, mm2
  451. movq mm1, mm2
  452. punpcklwd mm4, mm7
  453. punpckhwd mm1, mm7
  454. movq mm2, mm4
  455. movq mm7, mm1
  456. pmaddwd mm4, [GOTOFF(ebx,PW_MF060_MF089)] ; mm4=tmp4L
  457. pmaddwd mm1, [GOTOFF(ebx,PW_MF060_MF089)] ; mm1=tmp4H
  458. pmaddwd mm2, [GOTOFF(ebx,PW_MF089_F060)] ; mm2=tmp7L
  459. pmaddwd mm7, [GOTOFF(ebx,PW_MF089_F060)] ; mm7=tmp7H
  460. paddd mm4, MMWORD [wk(0)] ; mm4=data7L
  461. paddd mm1, MMWORD [wk(1)] ; mm1=data7H
  462. paddd mm2, mm0 ; mm2=data1L
  463. paddd mm7, mm6 ; mm7=data1H
  464. paddd mm4, [GOTOFF(ebx,PD_DESCALE_P2)]
  465. paddd mm1, [GOTOFF(ebx,PD_DESCALE_P2)]
  466. psrad mm4, DESCALE_P2
  467. psrad mm1, DESCALE_P2
  468. paddd mm2, [GOTOFF(ebx,PD_DESCALE_P2)]
  469. paddd mm7, [GOTOFF(ebx,PD_DESCALE_P2)]
  470. psrad mm2, DESCALE_P2
  471. psrad mm7, DESCALE_P2
  472. packssdw mm4, mm1 ; mm4=data7
  473. packssdw mm2, mm7 ; mm2=data1
  474. movq MMWORD [MMBLOCK(7,0,edx,SIZEOF_DCTELEM)], mm4
  475. movq MMWORD [MMBLOCK(1,0,edx,SIZEOF_DCTELEM)], mm2
  476. movq mm1, mm3
  477. movq mm7, mm3
  478. punpcklwd mm1, mm5
  479. punpckhwd mm7, mm5
  480. movq mm3, mm1
  481. movq mm5, mm7
  482. pmaddwd mm1, [GOTOFF(ebx,PW_MF050_MF256)] ; mm1=tmp5L
  483. pmaddwd mm7, [GOTOFF(ebx,PW_MF050_MF256)] ; mm7=tmp5H
  484. pmaddwd mm3, [GOTOFF(ebx,PW_MF256_F050)] ; mm3=tmp6L
  485. pmaddwd mm5, [GOTOFF(ebx,PW_MF256_F050)] ; mm5=tmp6H
  486. paddd mm1, mm0 ; mm1=data5L
  487. paddd mm7, mm6 ; mm7=data5H
  488. paddd mm3, MMWORD [wk(0)] ; mm3=data3L
  489. paddd mm5, MMWORD [wk(1)] ; mm5=data3H
  490. paddd mm1, [GOTOFF(ebx,PD_DESCALE_P2)]
  491. paddd mm7, [GOTOFF(ebx,PD_DESCALE_P2)]
  492. psrad mm1, DESCALE_P2
  493. psrad mm7, DESCALE_P2
  494. paddd mm3, [GOTOFF(ebx,PD_DESCALE_P2)]
  495. paddd mm5, [GOTOFF(ebx,PD_DESCALE_P2)]
  496. psrad mm3, DESCALE_P2
  497. psrad mm5, DESCALE_P2
  498. packssdw mm1, mm7 ; mm1=data5
  499. packssdw mm3, mm5 ; mm3=data3
  500. movq MMWORD [MMBLOCK(5,0,edx,SIZEOF_DCTELEM)], mm1
  501. movq MMWORD [MMBLOCK(3,0,edx,SIZEOF_DCTELEM)], mm3
  502. add edx, byte 4*SIZEOF_DCTELEM
  503. dec ecx
  504. jnz near .columnloop
  505. emms ; empty MMX state
  506. ; pop edi ; unused
  507. ; pop esi ; unused
  508. ; pop edx ; need not be preserved
  509. ; pop ecx ; need not be preserved
  510. poppic ebx
  511. mov esp, ebp ; esp <- aligned ebp
  512. pop esp ; esp <- original ebp
  513. pop ebp
  514. ret
  515. ; For some reason, the OS X linker does not honor the request to align the
  516. ; segment unless we do this.
  517. align 32