jidctred-mmx.asm 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. ;
  2. ; jidctred.asm - reduced-size IDCT (MMX)
  3. ;
  4. ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ;
  6. ; Based on the x86 SIMD extension for IJG JPEG library
  7. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
  8. ; For conditions of distribution and use, see copyright notice in jsimdext.inc
  9. ;
  10. ; This file should be assembled with NASM (Netwide Assembler),
  11. ; can *not* be assembled with Microsoft's MASM or any compatible
  12. ; assembler (including Borland's Turbo Assembler).
  13. ; NASM is available from http://nasm.sourceforge.net/ or
  14. ; http://sourceforge.net/project/showfiles.php?group_id=6208
  15. ;
  16. ; This file contains inverse-DCT routines that produce reduced-size
  17. ; output: either 4x4 or 2x2 pixels from an 8x8 DCT block.
  18. ; The following code is based directly on the IJG's original jidctred.c;
  19. ; see the jidctred.c for more details.
  20. ;
  21. ; [TAB8]
  22. %include "jsimdext.inc"
  23. %include "jdct.inc"
  24. ; --------------------------------------------------------------------------
  25. %define CONST_BITS 13
  26. %define PASS1_BITS 2
  27. %define DESCALE_P1_4 (CONST_BITS-PASS1_BITS+1)
  28. %define DESCALE_P2_4 (CONST_BITS+PASS1_BITS+3+1)
  29. %define DESCALE_P1_2 (CONST_BITS-PASS1_BITS+2)
  30. %define DESCALE_P2_2 (CONST_BITS+PASS1_BITS+3+2)
  31. %if CONST_BITS == 13
  32. F_0_211 equ 1730 ; FIX(0.211164243)
  33. F_0_509 equ 4176 ; FIX(0.509795579)
  34. F_0_601 equ 4926 ; FIX(0.601344887)
  35. F_0_720 equ 5906 ; FIX(0.720959822)
  36. F_0_765 equ 6270 ; FIX(0.765366865)
  37. F_0_850 equ 6967 ; FIX(0.850430095)
  38. F_0_899 equ 7373 ; FIX(0.899976223)
  39. F_1_061 equ 8697 ; FIX(1.061594337)
  40. F_1_272 equ 10426 ; FIX(1.272758580)
  41. F_1_451 equ 11893 ; FIX(1.451774981)
  42. F_1_847 equ 15137 ; FIX(1.847759065)
  43. F_2_172 equ 17799 ; FIX(2.172734803)
  44. F_2_562 equ 20995 ; FIX(2.562915447)
  45. F_3_624 equ 29692 ; FIX(3.624509785)
  46. %else
  47. ; NASM cannot do compile-time arithmetic on floating-point constants.
  48. %define DESCALE(x,n) (((x)+(1<<((n)-1)))>>(n))
  49. F_0_211 equ DESCALE( 226735879,30-CONST_BITS) ; FIX(0.211164243)
  50. F_0_509 equ DESCALE( 547388834,30-CONST_BITS) ; FIX(0.509795579)
  51. F_0_601 equ DESCALE( 645689155,30-CONST_BITS) ; FIX(0.601344887)
  52. F_0_720 equ DESCALE( 774124714,30-CONST_BITS) ; FIX(0.720959822)
  53. F_0_765 equ DESCALE( 821806413,30-CONST_BITS) ; FIX(0.765366865)
  54. F_0_850 equ DESCALE( 913142361,30-CONST_BITS) ; FIX(0.850430095)
  55. F_0_899 equ DESCALE( 966342111,30-CONST_BITS) ; FIX(0.899976223)
  56. F_1_061 equ DESCALE(1139878239,30-CONST_BITS) ; FIX(1.061594337)
  57. F_1_272 equ DESCALE(1366614119,30-CONST_BITS) ; FIX(1.272758580)
  58. F_1_451 equ DESCALE(1558831516,30-CONST_BITS) ; FIX(1.451774981)
  59. F_1_847 equ DESCALE(1984016188,30-CONST_BITS) ; FIX(1.847759065)
  60. F_2_172 equ DESCALE(2332956230,30-CONST_BITS) ; FIX(2.172734803)
  61. F_2_562 equ DESCALE(2751909506,30-CONST_BITS) ; FIX(2.562915447)
  62. F_3_624 equ DESCALE(3891787747,30-CONST_BITS) ; FIX(3.624509785)
  63. %endif
  64. ; --------------------------------------------------------------------------
  65. SECTION SEG_CONST
  66. alignz 16
  67. global EXTN(jconst_idct_red_mmx)
  68. EXTN(jconst_idct_red_mmx):
  69. PW_F184_MF076 times 2 dw F_1_847,-F_0_765
  70. PW_F256_F089 times 2 dw F_2_562, F_0_899
  71. PW_F106_MF217 times 2 dw F_1_061,-F_2_172
  72. PW_MF060_MF050 times 2 dw -F_0_601,-F_0_509
  73. PW_F145_MF021 times 2 dw F_1_451,-F_0_211
  74. PW_F362_MF127 times 2 dw F_3_624,-F_1_272
  75. PW_F085_MF072 times 2 dw F_0_850,-F_0_720
  76. PD_DESCALE_P1_4 times 2 dd 1 << (DESCALE_P1_4-1)
  77. PD_DESCALE_P2_4 times 2 dd 1 << (DESCALE_P2_4-1)
  78. PD_DESCALE_P1_2 times 2 dd 1 << (DESCALE_P1_2-1)
  79. PD_DESCALE_P2_2 times 2 dd 1 << (DESCALE_P2_2-1)
  80. PB_CENTERJSAMP times 8 db CENTERJSAMPLE
  81. alignz 16
  82. ; --------------------------------------------------------------------------
  83. SECTION SEG_TEXT
  84. BITS 32
  85. ;
  86. ; Perform dequantization and inverse DCT on one block of coefficients,
  87. ; producing a reduced-size 4x4 output block.
  88. ;
  89. ; GLOBAL(void)
  90. ; jsimd_idct_4x4_mmx (void *dct_table, JCOEFPTR coef_block,
  91. ; JSAMPARRAY output_buf, JDIMENSION output_col)
  92. ;
  93. %define dct_table(b) (b)+8 ; void *dct_table
  94. %define coef_block(b) (b)+12 ; JCOEFPTR coef_block
  95. %define output_buf(b) (b)+16 ; JSAMPARRAY output_buf
  96. %define output_col(b) (b)+20 ; JDIMENSION output_col
  97. %define original_ebp ebp+0
  98. %define wk(i) ebp-(WK_NUM-(i))*SIZEOF_MMWORD ; mmword wk[WK_NUM]
  99. %define WK_NUM 2
  100. %define workspace wk(0)-DCTSIZE2*SIZEOF_JCOEF
  101. ; JCOEF workspace[DCTSIZE2]
  102. align 16
  103. global EXTN(jsimd_idct_4x4_mmx)
  104. EXTN(jsimd_idct_4x4_mmx):
  105. push ebp
  106. mov eax,esp ; eax = original ebp
  107. sub esp, byte 4
  108. and esp, byte (-SIZEOF_MMWORD) ; align to 64 bits
  109. mov [esp],eax
  110. mov ebp,esp ; ebp = aligned ebp
  111. lea esp, [workspace]
  112. pushpic ebx
  113. ; push ecx ; need not be preserved
  114. ; push edx ; need not be preserved
  115. push esi
  116. push edi
  117. get_GOT ebx ; get GOT address
  118. ; ---- Pass 1: process columns from input, store into work array.
  119. ; mov eax, [original_ebp]
  120. mov edx, POINTER [dct_table(eax)] ; quantptr
  121. mov esi, JCOEFPTR [coef_block(eax)] ; inptr
  122. lea edi, [workspace] ; JCOEF *wsptr
  123. mov ecx, DCTSIZE/4 ; ctr
  124. alignx 16,7
  125. .columnloop:
  126. %ifndef NO_ZERO_COLUMN_TEST_4X4_MMX
  127. mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
  128. or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
  129. jnz short .columnDCT
  130. movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  131. movq mm1, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
  132. por mm0, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  133. por mm1, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  134. por mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
  135. por mm1, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  136. por mm0,mm1
  137. packsswb mm0,mm0
  138. movd eax,mm0
  139. test eax,eax
  140. jnz short .columnDCT
  141. ; -- AC terms all zero
  142. movq mm0, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  143. pmullw mm0, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  144. psllw mm0,PASS1_BITS
  145. movq mm2,mm0 ; mm0=in0=(00 01 02 03)
  146. punpcklwd mm0,mm0 ; mm0=(00 00 01 01)
  147. punpckhwd mm2,mm2 ; mm2=(02 02 03 03)
  148. movq mm1,mm0
  149. punpckldq mm0,mm0 ; mm0=(00 00 00 00)
  150. punpckhdq mm1,mm1 ; mm1=(01 01 01 01)
  151. movq mm3,mm2
  152. punpckldq mm2,mm2 ; mm2=(02 02 02 02)
  153. punpckhdq mm3,mm3 ; mm3=(03 03 03 03)
  154. movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm0
  155. movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm1
  156. movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm2
  157. movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3
  158. jmp near .nextcolumn
  159. alignx 16,7
  160. %endif
  161. .columnDCT:
  162. ; -- Odd part
  163. movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  164. movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  165. pmullw mm0, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  166. pmullw mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  167. movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  168. movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  169. pmullw mm2, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  170. pmullw mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  171. movq mm4,mm0
  172. movq mm5,mm0
  173. punpcklwd mm4,mm1
  174. punpckhwd mm5,mm1
  175. movq mm0,mm4
  176. movq mm1,mm5
  177. pmaddwd mm4,[GOTOFF(ebx,PW_F256_F089)] ; mm4=(tmp2L)
  178. pmaddwd mm5,[GOTOFF(ebx,PW_F256_F089)] ; mm5=(tmp2H)
  179. pmaddwd mm0,[GOTOFF(ebx,PW_F106_MF217)] ; mm0=(tmp0L)
  180. pmaddwd mm1,[GOTOFF(ebx,PW_F106_MF217)] ; mm1=(tmp0H)
  181. movq mm6,mm2
  182. movq mm7,mm2
  183. punpcklwd mm6,mm3
  184. punpckhwd mm7,mm3
  185. movq mm2,mm6
  186. movq mm3,mm7
  187. pmaddwd mm6,[GOTOFF(ebx,PW_MF060_MF050)] ; mm6=(tmp2L)
  188. pmaddwd mm7,[GOTOFF(ebx,PW_MF060_MF050)] ; mm7=(tmp2H)
  189. pmaddwd mm2,[GOTOFF(ebx,PW_F145_MF021)] ; mm2=(tmp0L)
  190. pmaddwd mm3,[GOTOFF(ebx,PW_F145_MF021)] ; mm3=(tmp0H)
  191. paddd mm6,mm4 ; mm6=tmp2L
  192. paddd mm7,mm5 ; mm7=tmp2H
  193. paddd mm2,mm0 ; mm2=tmp0L
  194. paddd mm3,mm1 ; mm3=tmp0H
  195. movq MMWORD [wk(0)], mm2 ; wk(0)=tmp0L
  196. movq MMWORD [wk(1)], mm3 ; wk(1)=tmp0H
  197. ; -- Even part
  198. movq mm4, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  199. movq mm5, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
  200. movq mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
  201. pmullw mm4, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  202. pmullw mm5, MMWORD [MMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  203. pmullw mm0, MMWORD [MMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  204. pxor mm1,mm1
  205. pxor mm2,mm2
  206. punpcklwd mm1,mm4 ; mm1=tmp0L
  207. punpckhwd mm2,mm4 ; mm2=tmp0H
  208. psrad mm1,(16-CONST_BITS-1) ; psrad mm1,16 & pslld mm1,CONST_BITS+1
  209. psrad mm2,(16-CONST_BITS-1) ; psrad mm2,16 & pslld mm2,CONST_BITS+1
  210. movq mm3,mm5 ; mm5=in2=z2
  211. punpcklwd mm5,mm0 ; mm0=in6=z3
  212. punpckhwd mm3,mm0
  213. pmaddwd mm5,[GOTOFF(ebx,PW_F184_MF076)] ; mm5=tmp2L
  214. pmaddwd mm3,[GOTOFF(ebx,PW_F184_MF076)] ; mm3=tmp2H
  215. movq mm4,mm1
  216. movq mm0,mm2
  217. paddd mm1,mm5 ; mm1=tmp10L
  218. paddd mm2,mm3 ; mm2=tmp10H
  219. psubd mm4,mm5 ; mm4=tmp12L
  220. psubd mm0,mm3 ; mm0=tmp12H
  221. ; -- Final output stage
  222. movq mm5,mm1
  223. movq mm3,mm2
  224. paddd mm1,mm6 ; mm1=data0L
  225. paddd mm2,mm7 ; mm2=data0H
  226. psubd mm5,mm6 ; mm5=data3L
  227. psubd mm3,mm7 ; mm3=data3H
  228. movq mm6,[GOTOFF(ebx,PD_DESCALE_P1_4)] ; mm6=[PD_DESCALE_P1_4]
  229. paddd mm1,mm6
  230. paddd mm2,mm6
  231. psrad mm1,DESCALE_P1_4
  232. psrad mm2,DESCALE_P1_4
  233. paddd mm5,mm6
  234. paddd mm3,mm6
  235. psrad mm5,DESCALE_P1_4
  236. psrad mm3,DESCALE_P1_4
  237. packssdw mm1,mm2 ; mm1=data0=(00 01 02 03)
  238. packssdw mm5,mm3 ; mm5=data3=(30 31 32 33)
  239. movq mm7, MMWORD [wk(0)] ; mm7=tmp0L
  240. movq mm6, MMWORD [wk(1)] ; mm6=tmp0H
  241. movq mm2,mm4
  242. movq mm3,mm0
  243. paddd mm4,mm7 ; mm4=data1L
  244. paddd mm0,mm6 ; mm0=data1H
  245. psubd mm2,mm7 ; mm2=data2L
  246. psubd mm3,mm6 ; mm3=data2H
  247. movq mm7,[GOTOFF(ebx,PD_DESCALE_P1_4)] ; mm7=[PD_DESCALE_P1_4]
  248. paddd mm4,mm7
  249. paddd mm0,mm7
  250. psrad mm4,DESCALE_P1_4
  251. psrad mm0,DESCALE_P1_4
  252. paddd mm2,mm7
  253. paddd mm3,mm7
  254. psrad mm2,DESCALE_P1_4
  255. psrad mm3,DESCALE_P1_4
  256. packssdw mm4,mm0 ; mm4=data1=(10 11 12 13)
  257. packssdw mm2,mm3 ; mm2=data2=(20 21 22 23)
  258. movq mm6,mm1 ; transpose coefficients(phase 1)
  259. punpcklwd mm1,mm4 ; mm1=(00 10 01 11)
  260. punpckhwd mm6,mm4 ; mm6=(02 12 03 13)
  261. movq mm7,mm2 ; transpose coefficients(phase 1)
  262. punpcklwd mm2,mm5 ; mm2=(20 30 21 31)
  263. punpckhwd mm7,mm5 ; mm7=(22 32 23 33)
  264. movq mm0,mm1 ; transpose coefficients(phase 2)
  265. punpckldq mm1,mm2 ; mm1=(00 10 20 30)
  266. punpckhdq mm0,mm2 ; mm0=(01 11 21 31)
  267. movq mm3,mm6 ; transpose coefficients(phase 2)
  268. punpckldq mm6,mm7 ; mm6=(02 12 22 32)
  269. punpckhdq mm3,mm7 ; mm3=(03 13 23 33)
  270. movq MMWORD [MMBLOCK(0,0,edi,SIZEOF_JCOEF)], mm1
  271. movq MMWORD [MMBLOCK(1,0,edi,SIZEOF_JCOEF)], mm0
  272. movq MMWORD [MMBLOCK(2,0,edi,SIZEOF_JCOEF)], mm6
  273. movq MMWORD [MMBLOCK(3,0,edi,SIZEOF_JCOEF)], mm3
  274. .nextcolumn:
  275. add esi, byte 4*SIZEOF_JCOEF ; coef_block
  276. add edx, byte 4*SIZEOF_ISLOW_MULT_TYPE ; quantptr
  277. add edi, byte 4*DCTSIZE*SIZEOF_JCOEF ; wsptr
  278. dec ecx ; ctr
  279. jnz near .columnloop
  280. ; ---- Pass 2: process rows from work array, store into output array.
  281. mov eax, [original_ebp]
  282. lea esi, [workspace] ; JCOEF *wsptr
  283. mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *)
  284. mov eax, JDIMENSION [output_col(eax)]
  285. ; -- Odd part
  286. movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  287. movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  288. movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  289. movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  290. movq mm4,mm0
  291. movq mm5,mm0
  292. punpcklwd mm4,mm1
  293. punpckhwd mm5,mm1
  294. movq mm0,mm4
  295. movq mm1,mm5
  296. pmaddwd mm4,[GOTOFF(ebx,PW_F256_F089)] ; mm4=(tmp2L)
  297. pmaddwd mm5,[GOTOFF(ebx,PW_F256_F089)] ; mm5=(tmp2H)
  298. pmaddwd mm0,[GOTOFF(ebx,PW_F106_MF217)] ; mm0=(tmp0L)
  299. pmaddwd mm1,[GOTOFF(ebx,PW_F106_MF217)] ; mm1=(tmp0H)
  300. movq mm6,mm2
  301. movq mm7,mm2
  302. punpcklwd mm6,mm3
  303. punpckhwd mm7,mm3
  304. movq mm2,mm6
  305. movq mm3,mm7
  306. pmaddwd mm6,[GOTOFF(ebx,PW_MF060_MF050)] ; mm6=(tmp2L)
  307. pmaddwd mm7,[GOTOFF(ebx,PW_MF060_MF050)] ; mm7=(tmp2H)
  308. pmaddwd mm2,[GOTOFF(ebx,PW_F145_MF021)] ; mm2=(tmp0L)
  309. pmaddwd mm3,[GOTOFF(ebx,PW_F145_MF021)] ; mm3=(tmp0H)
  310. paddd mm6,mm4 ; mm6=tmp2L
  311. paddd mm7,mm5 ; mm7=tmp2H
  312. paddd mm2,mm0 ; mm2=tmp0L
  313. paddd mm3,mm1 ; mm3=tmp0H
  314. movq MMWORD [wk(0)], mm2 ; wk(0)=tmp0L
  315. movq MMWORD [wk(1)], mm3 ; wk(1)=tmp0H
  316. ; -- Even part
  317. movq mm4, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  318. movq mm5, MMWORD [MMBLOCK(2,0,esi,SIZEOF_JCOEF)]
  319. movq mm0, MMWORD [MMBLOCK(6,0,esi,SIZEOF_JCOEF)]
  320. pxor mm1,mm1
  321. pxor mm2,mm2
  322. punpcklwd mm1,mm4 ; mm1=tmp0L
  323. punpckhwd mm2,mm4 ; mm2=tmp0H
  324. psrad mm1,(16-CONST_BITS-1) ; psrad mm1,16 & pslld mm1,CONST_BITS+1
  325. psrad mm2,(16-CONST_BITS-1) ; psrad mm2,16 & pslld mm2,CONST_BITS+1
  326. movq mm3,mm5 ; mm5=in2=z2
  327. punpcklwd mm5,mm0 ; mm0=in6=z3
  328. punpckhwd mm3,mm0
  329. pmaddwd mm5,[GOTOFF(ebx,PW_F184_MF076)] ; mm5=tmp2L
  330. pmaddwd mm3,[GOTOFF(ebx,PW_F184_MF076)] ; mm3=tmp2H
  331. movq mm4,mm1
  332. movq mm0,mm2
  333. paddd mm1,mm5 ; mm1=tmp10L
  334. paddd mm2,mm3 ; mm2=tmp10H
  335. psubd mm4,mm5 ; mm4=tmp12L
  336. psubd mm0,mm3 ; mm0=tmp12H
  337. ; -- Final output stage
  338. movq mm5,mm1
  339. movq mm3,mm2
  340. paddd mm1,mm6 ; mm1=data0L
  341. paddd mm2,mm7 ; mm2=data0H
  342. psubd mm5,mm6 ; mm5=data3L
  343. psubd mm3,mm7 ; mm3=data3H
  344. movq mm6,[GOTOFF(ebx,PD_DESCALE_P2_4)] ; mm6=[PD_DESCALE_P2_4]
  345. paddd mm1,mm6
  346. paddd mm2,mm6
  347. psrad mm1,DESCALE_P2_4
  348. psrad mm2,DESCALE_P2_4
  349. paddd mm5,mm6
  350. paddd mm3,mm6
  351. psrad mm5,DESCALE_P2_4
  352. psrad mm3,DESCALE_P2_4
  353. packssdw mm1,mm2 ; mm1=data0=(00 10 20 30)
  354. packssdw mm5,mm3 ; mm5=data3=(03 13 23 33)
  355. movq mm7, MMWORD [wk(0)] ; mm7=tmp0L
  356. movq mm6, MMWORD [wk(1)] ; mm6=tmp0H
  357. movq mm2,mm4
  358. movq mm3,mm0
  359. paddd mm4,mm7 ; mm4=data1L
  360. paddd mm0,mm6 ; mm0=data1H
  361. psubd mm2,mm7 ; mm2=data2L
  362. psubd mm3,mm6 ; mm3=data2H
  363. movq mm7,[GOTOFF(ebx,PD_DESCALE_P2_4)] ; mm7=[PD_DESCALE_P2_4]
  364. paddd mm4,mm7
  365. paddd mm0,mm7
  366. psrad mm4,DESCALE_P2_4
  367. psrad mm0,DESCALE_P2_4
  368. paddd mm2,mm7
  369. paddd mm3,mm7
  370. psrad mm2,DESCALE_P2_4
  371. psrad mm3,DESCALE_P2_4
  372. packssdw mm4,mm0 ; mm4=data1=(01 11 21 31)
  373. packssdw mm2,mm3 ; mm2=data2=(02 12 22 32)
  374. movq mm6,[GOTOFF(ebx,PB_CENTERJSAMP)] ; mm6=[PB_CENTERJSAMP]
  375. packsswb mm1,mm2 ; mm1=(00 10 20 30 02 12 22 32)
  376. packsswb mm4,mm5 ; mm4=(01 11 21 31 03 13 23 33)
  377. paddb mm1,mm6
  378. paddb mm4,mm6
  379. movq mm7,mm1 ; transpose coefficients(phase 1)
  380. punpcklbw mm1,mm4 ; mm1=(00 01 10 11 20 21 30 31)
  381. punpckhbw mm7,mm4 ; mm7=(02 03 12 13 22 23 32 33)
  382. movq mm0,mm1 ; transpose coefficients(phase 2)
  383. punpcklwd mm1,mm7 ; mm1=(00 01 02 03 10 11 12 13)
  384. punpckhwd mm0,mm7 ; mm0=(20 21 22 23 30 31 32 33)
  385. mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
  386. mov esi, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
  387. movd DWORD [edx+eax*SIZEOF_JSAMPLE], mm1
  388. movd DWORD [esi+eax*SIZEOF_JSAMPLE], mm0
  389. psrlq mm1,4*BYTE_BIT
  390. psrlq mm0,4*BYTE_BIT
  391. mov edx, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
  392. mov esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
  393. movd DWORD [edx+eax*SIZEOF_JSAMPLE], mm1
  394. movd DWORD [esi+eax*SIZEOF_JSAMPLE], mm0
  395. emms ; empty MMX state
  396. pop edi
  397. pop esi
  398. ; pop edx ; need not be preserved
  399. ; pop ecx ; need not be preserved
  400. poppic ebx
  401. mov esp,ebp ; esp <- aligned ebp
  402. pop esp ; esp <- original ebp
  403. pop ebp
  404. ret
  405. ; --------------------------------------------------------------------------
  406. ;
  407. ; Perform dequantization and inverse DCT on one block of coefficients,
  408. ; producing a reduced-size 2x2 output block.
  409. ;
  410. ; GLOBAL(void)
  411. ; jsimd_idct_2x2_mmx (void *dct_table, JCOEFPTR coef_block,
  412. ; JSAMPARRAY output_buf, JDIMENSION output_col)
  413. ;
  414. %define dct_table(b) (b)+8 ; void *dct_table
  415. %define coef_block(b) (b)+12 ; JCOEFPTR coef_block
  416. %define output_buf(b) (b)+16 ; JSAMPARRAY output_buf
  417. %define output_col(b) (b)+20 ; JDIMENSION output_col
  418. align 16
  419. global EXTN(jsimd_idct_2x2_mmx)
  420. EXTN(jsimd_idct_2x2_mmx):
  421. push ebp
  422. mov ebp,esp
  423. push ebx
  424. ; push ecx ; need not be preserved
  425. ; push edx ; need not be preserved
  426. push esi
  427. push edi
  428. get_GOT ebx ; get GOT address
  429. ; ---- Pass 1: process columns from input.
  430. mov edx, POINTER [dct_table(ebp)] ; quantptr
  431. mov esi, JCOEFPTR [coef_block(ebp)] ; inptr
  432. ; | input: | result: |
  433. ; | 00 01 ** 03 ** 05 ** 07 | |
  434. ; | 10 11 ** 13 ** 15 ** 17 | |
  435. ; | ** ** ** ** ** ** ** ** | |
  436. ; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 |
  437. ; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 |
  438. ; | 50 51 ** 53 ** 55 ** 57 | |
  439. ; | ** ** ** ** ** ** ** ** | |
  440. ; | 70 71 ** 73 ** 75 ** 77 | |
  441. ; -- Odd part
  442. movq mm0, MMWORD [MMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  443. movq mm1, MMWORD [MMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  444. pmullw mm0, MMWORD [MMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  445. pmullw mm1, MMWORD [MMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  446. movq mm2, MMWORD [MMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  447. movq mm3, MMWORD [MMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  448. pmullw mm2, MMWORD [MMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  449. pmullw mm3, MMWORD [MMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  450. ; mm0=(10 11 ** 13), mm1=(30 31 ** 33)
  451. ; mm2=(50 51 ** 53), mm3=(70 71 ** 73)
  452. pcmpeqd mm7,mm7
  453. pslld mm7,WORD_BIT ; mm7={0x0000 0xFFFF 0x0000 0xFFFF}
  454. movq mm4,mm0 ; mm4=(10 11 ** 13)
  455. movq mm5,mm2 ; mm5=(50 51 ** 53)
  456. punpcklwd mm4,mm1 ; mm4=(10 30 11 31)
  457. punpcklwd mm5,mm3 ; mm5=(50 70 51 71)
  458. pmaddwd mm4,[GOTOFF(ebx,PW_F362_MF127)]
  459. pmaddwd mm5,[GOTOFF(ebx,PW_F085_MF072)]
  460. psrld mm0,WORD_BIT ; mm0=(11 -- 13 --)
  461. pand mm1,mm7 ; mm1=(-- 31 -- 33)
  462. psrld mm2,WORD_BIT ; mm2=(51 -- 53 --)
  463. pand mm3,mm7 ; mm3=(-- 71 -- 73)
  464. por mm0,mm1 ; mm0=(11 31 13 33)
  465. por mm2,mm3 ; mm2=(51 71 53 73)
  466. pmaddwd mm0,[GOTOFF(ebx,PW_F362_MF127)]
  467. pmaddwd mm2,[GOTOFF(ebx,PW_F085_MF072)]
  468. paddd mm4,mm5 ; mm4=tmp0[col0 col1]
  469. movq mm6, MMWORD [MMBLOCK(1,1,esi,SIZEOF_JCOEF)]
  470. movq mm1, MMWORD [MMBLOCK(3,1,esi,SIZEOF_JCOEF)]
  471. pmullw mm6, MMWORD [MMBLOCK(1,1,edx,SIZEOF_ISLOW_MULT_TYPE)]
  472. pmullw mm1, MMWORD [MMBLOCK(3,1,edx,SIZEOF_ISLOW_MULT_TYPE)]
  473. movq mm3, MMWORD [MMBLOCK(5,1,esi,SIZEOF_JCOEF)]
  474. movq mm5, MMWORD [MMBLOCK(7,1,esi,SIZEOF_JCOEF)]
  475. pmullw mm3, MMWORD [MMBLOCK(5,1,edx,SIZEOF_ISLOW_MULT_TYPE)]
  476. pmullw mm5, MMWORD [MMBLOCK(7,1,edx,SIZEOF_ISLOW_MULT_TYPE)]
  477. ; mm6=(** 15 ** 17), mm1=(** 35 ** 37)
  478. ; mm3=(** 55 ** 57), mm5=(** 75 ** 77)
  479. psrld mm6,WORD_BIT ; mm6=(15 -- 17 --)
  480. pand mm1,mm7 ; mm1=(-- 35 -- 37)
  481. psrld mm3,WORD_BIT ; mm3=(55 -- 57 --)
  482. pand mm5,mm7 ; mm5=(-- 75 -- 77)
  483. por mm6,mm1 ; mm6=(15 35 17 37)
  484. por mm3,mm5 ; mm3=(55 75 57 77)
  485. pmaddwd mm6,[GOTOFF(ebx,PW_F362_MF127)]
  486. pmaddwd mm3,[GOTOFF(ebx,PW_F085_MF072)]
  487. paddd mm0,mm2 ; mm0=tmp0[col1 col3]
  488. paddd mm6,mm3 ; mm6=tmp0[col5 col7]
  489. ; -- Even part
  490. movq mm1, MMWORD [MMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  491. movq mm5, MMWORD [MMBLOCK(0,1,esi,SIZEOF_JCOEF)]
  492. pmullw mm1, MMWORD [MMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  493. pmullw mm5, MMWORD [MMBLOCK(0,1,edx,SIZEOF_ISLOW_MULT_TYPE)]
  494. ; mm1=(00 01 ** 03), mm5=(** 05 ** 07)
  495. movq mm2,mm1 ; mm2=(00 01 ** 03)
  496. pslld mm1,WORD_BIT ; mm1=(-- 00 -- **)
  497. psrad mm1,(WORD_BIT-CONST_BITS-2) ; mm1=tmp10[col0 ****]
  498. pand mm2,mm7 ; mm2=(-- 01 -- 03)
  499. pand mm5,mm7 ; mm5=(-- 05 -- 07)
  500. psrad mm2,(WORD_BIT-CONST_BITS-2) ; mm2=tmp10[col1 col3]
  501. psrad mm5,(WORD_BIT-CONST_BITS-2) ; mm5=tmp10[col5 col7]
  502. ; -- Final output stage
  503. movq mm3,mm1
  504. paddd mm1,mm4 ; mm1=data0[col0 ****]=(A0 **)
  505. psubd mm3,mm4 ; mm3=data1[col0 ****]=(B0 **)
  506. punpckldq mm1,mm3 ; mm1=(A0 B0)
  507. movq mm7,[GOTOFF(ebx,PD_DESCALE_P1_2)] ; mm7=[PD_DESCALE_P1_2]
  508. movq mm4,mm2
  509. movq mm3,mm5
  510. paddd mm2,mm0 ; mm2=data0[col1 col3]=(A1 A3)
  511. paddd mm5,mm6 ; mm5=data0[col5 col7]=(A5 A7)
  512. psubd mm4,mm0 ; mm4=data1[col1 col3]=(B1 B3)
  513. psubd mm3,mm6 ; mm3=data1[col5 col7]=(B5 B7)
  514. paddd mm1,mm7
  515. psrad mm1,DESCALE_P1_2
  516. paddd mm2,mm7
  517. paddd mm5,mm7
  518. psrad mm2,DESCALE_P1_2
  519. psrad mm5,DESCALE_P1_2
  520. paddd mm4,mm7
  521. paddd mm3,mm7
  522. psrad mm4,DESCALE_P1_2
  523. psrad mm3,DESCALE_P1_2
  524. ; ---- Pass 2: process rows, store into output array.
  525. mov edi, JSAMPARRAY [output_buf(ebp)] ; (JSAMPROW *)
  526. mov eax, JDIMENSION [output_col(ebp)]
  527. ; | input:| result:|
  528. ; | A0 B0 | |
  529. ; | A1 B1 | C0 C1 |
  530. ; | A3 B3 | D0 D1 |
  531. ; | A5 B5 | |
  532. ; | A7 B7 | |
  533. ; -- Odd part
  534. packssdw mm2,mm4 ; mm2=(A1 A3 B1 B3)
  535. packssdw mm5,mm3 ; mm5=(A5 A7 B5 B7)
  536. pmaddwd mm2,[GOTOFF(ebx,PW_F362_MF127)]
  537. pmaddwd mm5,[GOTOFF(ebx,PW_F085_MF072)]
  538. paddd mm2,mm5 ; mm2=tmp0[row0 row1]
  539. ; -- Even part
  540. pslld mm1,(CONST_BITS+2) ; mm1=tmp10[row0 row1]
  541. ; -- Final output stage
  542. movq mm0,[GOTOFF(ebx,PD_DESCALE_P2_2)] ; mm0=[PD_DESCALE_P2_2]
  543. movq mm6,mm1
  544. paddd mm1,mm2 ; mm1=data0[row0 row1]=(C0 C1)
  545. psubd mm6,mm2 ; mm6=data1[row0 row1]=(D0 D1)
  546. paddd mm1,mm0
  547. paddd mm6,mm0
  548. psrad mm1,DESCALE_P2_2
  549. psrad mm6,DESCALE_P2_2
  550. movq mm7,mm1 ; transpose coefficients
  551. punpckldq mm1,mm6 ; mm1=(C0 D0)
  552. punpckhdq mm7,mm6 ; mm7=(C1 D1)
  553. packssdw mm1,mm7 ; mm1=(C0 D0 C1 D1)
  554. packsswb mm1,mm1 ; mm1=(C0 D0 C1 D1 C0 D0 C1 D1)
  555. paddb mm1,[GOTOFF(ebx,PB_CENTERJSAMP)]
  556. movd ecx,mm1
  557. movd ebx,mm1 ; ebx=(C0 D0 C1 D1)
  558. shr ecx,2*BYTE_BIT ; ecx=(C1 D1 -- --)
  559. mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
  560. mov esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
  561. mov WORD [edx+eax*SIZEOF_JSAMPLE], bx
  562. mov WORD [esi+eax*SIZEOF_JSAMPLE], cx
  563. emms ; empty MMX state
  564. pop edi
  565. pop esi
  566. ; pop edx ; need not be preserved
  567. ; pop ecx ; need not be preserved
  568. pop ebx
  569. pop ebp
  570. ret
  571. ; For some reason, the OS X linker does not honor the request to align the
  572. ; segment unless we do this.
  573. align 16