jidctred-sse2.asm 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. ;
  2. ; jidctred.asm - reduced-size IDCT (SSE2)
  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_sse2)
  68. EXTN(jconst_idct_red_sse2):
  69. PW_F184_MF076 times 4 dw F_1_847,-F_0_765
  70. PW_F256_F089 times 4 dw F_2_562, F_0_899
  71. PW_F106_MF217 times 4 dw F_1_061,-F_2_172
  72. PW_MF060_MF050 times 4 dw -F_0_601,-F_0_509
  73. PW_F145_MF021 times 4 dw F_1_451,-F_0_211
  74. PW_F362_MF127 times 4 dw F_3_624,-F_1_272
  75. PW_F085_MF072 times 4 dw F_0_850,-F_0_720
  76. PD_DESCALE_P1_4 times 4 dd 1 << (DESCALE_P1_4-1)
  77. PD_DESCALE_P2_4 times 4 dd 1 << (DESCALE_P2_4-1)
  78. PD_DESCALE_P1_2 times 4 dd 1 << (DESCALE_P1_2-1)
  79. PD_DESCALE_P2_2 times 4 dd 1 << (DESCALE_P2_2-1)
  80. PB_CENTERJSAMP times 16 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_sse2 (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_XMMWORD ; xmmword wk[WK_NUM]
  99. %define WK_NUM 2
  100. align 16
  101. global EXTN(jsimd_idct_4x4_sse2)
  102. EXTN(jsimd_idct_4x4_sse2):
  103. push ebp
  104. mov eax,esp ; eax = original ebp
  105. sub esp, byte 4
  106. and esp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
  107. mov [esp],eax
  108. mov ebp,esp ; ebp = aligned ebp
  109. lea esp, [wk(0)]
  110. pushpic ebx
  111. ; push ecx ; unused
  112. ; push edx ; need not be preserved
  113. push esi
  114. push edi
  115. get_GOT ebx ; get GOT address
  116. ; ---- Pass 1: process columns from input.
  117. ; mov eax, [original_ebp]
  118. mov edx, POINTER [dct_table(eax)] ; quantptr
  119. mov esi, JCOEFPTR [coef_block(eax)] ; inptr
  120. %ifndef NO_ZERO_COLUMN_TEST_4X4_SSE2
  121. mov eax, DWORD [DWBLOCK(1,0,esi,SIZEOF_JCOEF)]
  122. or eax, DWORD [DWBLOCK(2,0,esi,SIZEOF_JCOEF)]
  123. jnz short .columnDCT
  124. movdqa xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  125. movdqa xmm1, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)]
  126. por xmm0, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  127. por xmm1, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  128. por xmm0, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)]
  129. por xmm1, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  130. por xmm0,xmm1
  131. packsswb xmm0,xmm0
  132. packsswb xmm0,xmm0
  133. movd eax,xmm0
  134. test eax,eax
  135. jnz short .columnDCT
  136. ; -- AC terms all zero
  137. movdqa xmm0, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  138. pmullw xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  139. psllw xmm0,PASS1_BITS
  140. movdqa xmm3,xmm0 ; xmm0=in0=(00 01 02 03 04 05 06 07)
  141. punpcklwd xmm0,xmm0 ; xmm0=(00 00 01 01 02 02 03 03)
  142. punpckhwd xmm3,xmm3 ; xmm3=(04 04 05 05 06 06 07 07)
  143. pshufd xmm1,xmm0,0x50 ; xmm1=[col0 col1]=(00 00 00 00 01 01 01 01)
  144. pshufd xmm0,xmm0,0xFA ; xmm0=[col2 col3]=(02 02 02 02 03 03 03 03)
  145. pshufd xmm6,xmm3,0x50 ; xmm6=[col4 col5]=(04 04 04 04 05 05 05 05)
  146. pshufd xmm3,xmm3,0xFA ; xmm3=[col6 col7]=(06 06 06 06 07 07 07 07)
  147. jmp near .column_end
  148. alignx 16,7
  149. %endif
  150. .columnDCT:
  151. ; -- Odd part
  152. movdqa xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  153. movdqa xmm1, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  154. pmullw xmm0, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  155. pmullw xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  156. movdqa xmm2, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  157. movdqa xmm3, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  158. pmullw xmm2, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  159. pmullw xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  160. movdqa xmm4,xmm0
  161. movdqa xmm5,xmm0
  162. punpcklwd xmm4,xmm1
  163. punpckhwd xmm5,xmm1
  164. movdqa xmm0,xmm4
  165. movdqa xmm1,xmm5
  166. pmaddwd xmm4,[GOTOFF(ebx,PW_F256_F089)] ; xmm4=(tmp2L)
  167. pmaddwd xmm5,[GOTOFF(ebx,PW_F256_F089)] ; xmm5=(tmp2H)
  168. pmaddwd xmm0,[GOTOFF(ebx,PW_F106_MF217)] ; xmm0=(tmp0L)
  169. pmaddwd xmm1,[GOTOFF(ebx,PW_F106_MF217)] ; xmm1=(tmp0H)
  170. movdqa xmm6,xmm2
  171. movdqa xmm7,xmm2
  172. punpcklwd xmm6,xmm3
  173. punpckhwd xmm7,xmm3
  174. movdqa xmm2,xmm6
  175. movdqa xmm3,xmm7
  176. pmaddwd xmm6,[GOTOFF(ebx,PW_MF060_MF050)] ; xmm6=(tmp2L)
  177. pmaddwd xmm7,[GOTOFF(ebx,PW_MF060_MF050)] ; xmm7=(tmp2H)
  178. pmaddwd xmm2,[GOTOFF(ebx,PW_F145_MF021)] ; xmm2=(tmp0L)
  179. pmaddwd xmm3,[GOTOFF(ebx,PW_F145_MF021)] ; xmm3=(tmp0H)
  180. paddd xmm6,xmm4 ; xmm6=tmp2L
  181. paddd xmm7,xmm5 ; xmm7=tmp2H
  182. paddd xmm2,xmm0 ; xmm2=tmp0L
  183. paddd xmm3,xmm1 ; xmm3=tmp0H
  184. movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=tmp0L
  185. movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=tmp0H
  186. ; -- Even part
  187. movdqa xmm4, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  188. movdqa xmm5, XMMWORD [XMMBLOCK(2,0,esi,SIZEOF_JCOEF)]
  189. movdqa xmm0, XMMWORD [XMMBLOCK(6,0,esi,SIZEOF_JCOEF)]
  190. pmullw xmm4, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  191. pmullw xmm5, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  192. pmullw xmm0, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  193. pxor xmm1,xmm1
  194. pxor xmm2,xmm2
  195. punpcklwd xmm1,xmm4 ; xmm1=tmp0L
  196. punpckhwd xmm2,xmm4 ; xmm2=tmp0H
  197. psrad xmm1,(16-CONST_BITS-1) ; psrad xmm1,16 & pslld xmm1,CONST_BITS+1
  198. psrad xmm2,(16-CONST_BITS-1) ; psrad xmm2,16 & pslld xmm2,CONST_BITS+1
  199. movdqa xmm3,xmm5 ; xmm5=in2=z2
  200. punpcklwd xmm5,xmm0 ; xmm0=in6=z3
  201. punpckhwd xmm3,xmm0
  202. pmaddwd xmm5,[GOTOFF(ebx,PW_F184_MF076)] ; xmm5=tmp2L
  203. pmaddwd xmm3,[GOTOFF(ebx,PW_F184_MF076)] ; xmm3=tmp2H
  204. movdqa xmm4,xmm1
  205. movdqa xmm0,xmm2
  206. paddd xmm1,xmm5 ; xmm1=tmp10L
  207. paddd xmm2,xmm3 ; xmm2=tmp10H
  208. psubd xmm4,xmm5 ; xmm4=tmp12L
  209. psubd xmm0,xmm3 ; xmm0=tmp12H
  210. ; -- Final output stage
  211. movdqa xmm5,xmm1
  212. movdqa xmm3,xmm2
  213. paddd xmm1,xmm6 ; xmm1=data0L
  214. paddd xmm2,xmm7 ; xmm2=data0H
  215. psubd xmm5,xmm6 ; xmm5=data3L
  216. psubd xmm3,xmm7 ; xmm3=data3H
  217. movdqa xmm6,[GOTOFF(ebx,PD_DESCALE_P1_4)] ; xmm6=[PD_DESCALE_P1_4]
  218. paddd xmm1,xmm6
  219. paddd xmm2,xmm6
  220. psrad xmm1,DESCALE_P1_4
  221. psrad xmm2,DESCALE_P1_4
  222. paddd xmm5,xmm6
  223. paddd xmm3,xmm6
  224. psrad xmm5,DESCALE_P1_4
  225. psrad xmm3,DESCALE_P1_4
  226. packssdw xmm1,xmm2 ; xmm1=data0=(00 01 02 03 04 05 06 07)
  227. packssdw xmm5,xmm3 ; xmm5=data3=(30 31 32 33 34 35 36 37)
  228. movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp0L
  229. movdqa xmm6, XMMWORD [wk(1)] ; xmm6=tmp0H
  230. movdqa xmm2,xmm4
  231. movdqa xmm3,xmm0
  232. paddd xmm4,xmm7 ; xmm4=data1L
  233. paddd xmm0,xmm6 ; xmm0=data1H
  234. psubd xmm2,xmm7 ; xmm2=data2L
  235. psubd xmm3,xmm6 ; xmm3=data2H
  236. movdqa xmm7,[GOTOFF(ebx,PD_DESCALE_P1_4)] ; xmm7=[PD_DESCALE_P1_4]
  237. paddd xmm4,xmm7
  238. paddd xmm0,xmm7
  239. psrad xmm4,DESCALE_P1_4
  240. psrad xmm0,DESCALE_P1_4
  241. paddd xmm2,xmm7
  242. paddd xmm3,xmm7
  243. psrad xmm2,DESCALE_P1_4
  244. psrad xmm3,DESCALE_P1_4
  245. packssdw xmm4,xmm0 ; xmm4=data1=(10 11 12 13 14 15 16 17)
  246. packssdw xmm2,xmm3 ; xmm2=data2=(20 21 22 23 24 25 26 27)
  247. movdqa xmm6,xmm1 ; transpose coefficients(phase 1)
  248. punpcklwd xmm1,xmm4 ; xmm1=(00 10 01 11 02 12 03 13)
  249. punpckhwd xmm6,xmm4 ; xmm6=(04 14 05 15 06 16 07 17)
  250. movdqa xmm7,xmm2 ; transpose coefficients(phase 1)
  251. punpcklwd xmm2,xmm5 ; xmm2=(20 30 21 31 22 32 23 33)
  252. punpckhwd xmm7,xmm5 ; xmm7=(24 34 25 35 26 36 27 37)
  253. movdqa xmm0,xmm1 ; transpose coefficients(phase 2)
  254. punpckldq xmm1,xmm2 ; xmm1=[col0 col1]=(00 10 20 30 01 11 21 31)
  255. punpckhdq xmm0,xmm2 ; xmm0=[col2 col3]=(02 12 22 32 03 13 23 33)
  256. movdqa xmm3,xmm6 ; transpose coefficients(phase 2)
  257. punpckldq xmm6,xmm7 ; xmm6=[col4 col5]=(04 14 24 34 05 15 25 35)
  258. punpckhdq xmm3,xmm7 ; xmm3=[col6 col7]=(06 16 26 36 07 17 27 37)
  259. .column_end:
  260. ; -- Prefetch the next coefficient block
  261. prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
  262. prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
  263. prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
  264. prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
  265. ; ---- Pass 2: process rows, store into output array.
  266. mov eax, [original_ebp]
  267. mov edi, JSAMPARRAY [output_buf(eax)] ; (JSAMPROW *)
  268. mov eax, JDIMENSION [output_col(eax)]
  269. ; -- Even part
  270. pxor xmm4,xmm4
  271. punpcklwd xmm4,xmm1 ; xmm4=tmp0
  272. psrad xmm4,(16-CONST_BITS-1) ; psrad xmm4,16 & pslld xmm4,CONST_BITS+1
  273. ; -- Odd part
  274. punpckhwd xmm1,xmm0
  275. punpckhwd xmm6,xmm3
  276. movdqa xmm5,xmm1
  277. movdqa xmm2,xmm6
  278. pmaddwd xmm1,[GOTOFF(ebx,PW_F256_F089)] ; xmm1=(tmp2)
  279. pmaddwd xmm6,[GOTOFF(ebx,PW_MF060_MF050)] ; xmm6=(tmp2)
  280. pmaddwd xmm5,[GOTOFF(ebx,PW_F106_MF217)] ; xmm5=(tmp0)
  281. pmaddwd xmm2,[GOTOFF(ebx,PW_F145_MF021)] ; xmm2=(tmp0)
  282. paddd xmm6,xmm1 ; xmm6=tmp2
  283. paddd xmm2,xmm5 ; xmm2=tmp0
  284. ; -- Even part
  285. punpcklwd xmm0,xmm3
  286. pmaddwd xmm0,[GOTOFF(ebx,PW_F184_MF076)] ; xmm0=tmp2
  287. movdqa xmm7,xmm4
  288. paddd xmm4,xmm0 ; xmm4=tmp10
  289. psubd xmm7,xmm0 ; xmm7=tmp12
  290. ; -- Final output stage
  291. movdqa xmm1,[GOTOFF(ebx,PD_DESCALE_P2_4)] ; xmm1=[PD_DESCALE_P2_4]
  292. movdqa xmm5,xmm4
  293. movdqa xmm3,xmm7
  294. paddd xmm4,xmm6 ; xmm4=data0=(00 10 20 30)
  295. paddd xmm7,xmm2 ; xmm7=data1=(01 11 21 31)
  296. psubd xmm5,xmm6 ; xmm5=data3=(03 13 23 33)
  297. psubd xmm3,xmm2 ; xmm3=data2=(02 12 22 32)
  298. paddd xmm4,xmm1
  299. paddd xmm7,xmm1
  300. psrad xmm4,DESCALE_P2_4
  301. psrad xmm7,DESCALE_P2_4
  302. paddd xmm5,xmm1
  303. paddd xmm3,xmm1
  304. psrad xmm5,DESCALE_P2_4
  305. psrad xmm3,DESCALE_P2_4
  306. packssdw xmm4,xmm3 ; xmm4=(00 10 20 30 02 12 22 32)
  307. packssdw xmm7,xmm5 ; xmm7=(01 11 21 31 03 13 23 33)
  308. movdqa xmm0,xmm4 ; transpose coefficients(phase 1)
  309. punpcklwd xmm4,xmm7 ; xmm4=(00 01 10 11 20 21 30 31)
  310. punpckhwd xmm0,xmm7 ; xmm0=(02 03 12 13 22 23 32 33)
  311. movdqa xmm6,xmm4 ; transpose coefficients(phase 2)
  312. punpckldq xmm4,xmm0 ; xmm4=(00 01 02 03 10 11 12 13)
  313. punpckhdq xmm6,xmm0 ; xmm6=(20 21 22 23 30 31 32 33)
  314. packsswb xmm4,xmm6 ; xmm4=(00 01 02 03 10 11 12 13 20 ..)
  315. paddb xmm4,[GOTOFF(ebx,PB_CENTERJSAMP)]
  316. pshufd xmm2,xmm4,0x39 ; xmm2=(10 11 12 13 20 21 22 23 30 ..)
  317. pshufd xmm1,xmm4,0x4E ; xmm1=(20 21 22 23 30 31 32 33 00 ..)
  318. pshufd xmm3,xmm4,0x93 ; xmm3=(30 31 32 33 00 01 02 03 10 ..)
  319. mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
  320. mov esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
  321. movd XMM_DWORD [edx+eax*SIZEOF_JSAMPLE], xmm4
  322. movd XMM_DWORD [esi+eax*SIZEOF_JSAMPLE], xmm2
  323. mov edx, JSAMPROW [edi+2*SIZEOF_JSAMPROW]
  324. mov esi, JSAMPROW [edi+3*SIZEOF_JSAMPROW]
  325. movd XMM_DWORD [edx+eax*SIZEOF_JSAMPLE], xmm1
  326. movd XMM_DWORD [esi+eax*SIZEOF_JSAMPLE], xmm3
  327. pop edi
  328. pop esi
  329. ; pop edx ; need not be preserved
  330. ; pop ecx ; unused
  331. poppic ebx
  332. mov esp,ebp ; esp <- aligned ebp
  333. pop esp ; esp <- original ebp
  334. pop ebp
  335. ret
  336. ; --------------------------------------------------------------------------
  337. ;
  338. ; Perform dequantization and inverse DCT on one block of coefficients,
  339. ; producing a reduced-size 2x2 output block.
  340. ;
  341. ; GLOBAL(void)
  342. ; jsimd_idct_2x2_sse2 (void *dct_table, JCOEFPTR coef_block,
  343. ; JSAMPARRAY output_buf, JDIMENSION output_col)
  344. ;
  345. %define dct_table(b) (b)+8 ; void *dct_table
  346. %define coef_block(b) (b)+12 ; JCOEFPTR coef_block
  347. %define output_buf(b) (b)+16 ; JSAMPARRAY output_buf
  348. %define output_col(b) (b)+20 ; JDIMENSION output_col
  349. align 16
  350. global EXTN(jsimd_idct_2x2_sse2)
  351. EXTN(jsimd_idct_2x2_sse2):
  352. push ebp
  353. mov ebp,esp
  354. push ebx
  355. ; push ecx ; need not be preserved
  356. ; push edx ; need not be preserved
  357. push esi
  358. push edi
  359. get_GOT ebx ; get GOT address
  360. ; ---- Pass 1: process columns from input.
  361. mov edx, POINTER [dct_table(ebp)] ; quantptr
  362. mov esi, JCOEFPTR [coef_block(ebp)] ; inptr
  363. ; | input: | result: |
  364. ; | 00 01 ** 03 ** 05 ** 07 | |
  365. ; | 10 11 ** 13 ** 15 ** 17 | |
  366. ; | ** ** ** ** ** ** ** ** | |
  367. ; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 |
  368. ; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 |
  369. ; | 50 51 ** 53 ** 55 ** 57 | |
  370. ; | ** ** ** ** ** ** ** ** | |
  371. ; | 70 71 ** 73 ** 75 ** 77 | |
  372. ; -- Odd part
  373. movdqa xmm0, XMMWORD [XMMBLOCK(1,0,esi,SIZEOF_JCOEF)]
  374. movdqa xmm1, XMMWORD [XMMBLOCK(3,0,esi,SIZEOF_JCOEF)]
  375. pmullw xmm0, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  376. pmullw xmm1, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  377. movdqa xmm2, XMMWORD [XMMBLOCK(5,0,esi,SIZEOF_JCOEF)]
  378. movdqa xmm3, XMMWORD [XMMBLOCK(7,0,esi,SIZEOF_JCOEF)]
  379. pmullw xmm2, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  380. pmullw xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  381. ; xmm0=(10 11 ** 13 ** 15 ** 17), xmm1=(30 31 ** 33 ** 35 ** 37)
  382. ; xmm2=(50 51 ** 53 ** 55 ** 57), xmm3=(70 71 ** 73 ** 75 ** 77)
  383. pcmpeqd xmm7,xmm7
  384. pslld xmm7,WORD_BIT ; xmm7={0x0000 0xFFFF 0x0000 0xFFFF ..}
  385. movdqa xmm4,xmm0 ; xmm4=(10 11 ** 13 ** 15 ** 17)
  386. movdqa xmm5,xmm2 ; xmm5=(50 51 ** 53 ** 55 ** 57)
  387. punpcklwd xmm4,xmm1 ; xmm4=(10 30 11 31 ** ** 13 33)
  388. punpcklwd xmm5,xmm3 ; xmm5=(50 70 51 71 ** ** 53 73)
  389. pmaddwd xmm4,[GOTOFF(ebx,PW_F362_MF127)]
  390. pmaddwd xmm5,[GOTOFF(ebx,PW_F085_MF072)]
  391. psrld xmm0,WORD_BIT ; xmm0=(11 -- 13 -- 15 -- 17 --)
  392. pand xmm1,xmm7 ; xmm1=(-- 31 -- 33 -- 35 -- 37)
  393. psrld xmm2,WORD_BIT ; xmm2=(51 -- 53 -- 55 -- 57 --)
  394. pand xmm3,xmm7 ; xmm3=(-- 71 -- 73 -- 75 -- 77)
  395. por xmm0,xmm1 ; xmm0=(11 31 13 33 15 35 17 37)
  396. por xmm2,xmm3 ; xmm2=(51 71 53 73 55 75 57 77)
  397. pmaddwd xmm0,[GOTOFF(ebx,PW_F362_MF127)]
  398. pmaddwd xmm2,[GOTOFF(ebx,PW_F085_MF072)]
  399. paddd xmm4,xmm5 ; xmm4=tmp0[col0 col1 **** col3]
  400. paddd xmm0,xmm2 ; xmm0=tmp0[col1 col3 col5 col7]
  401. ; -- Even part
  402. movdqa xmm6, XMMWORD [XMMBLOCK(0,0,esi,SIZEOF_JCOEF)]
  403. pmullw xmm6, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_ISLOW_MULT_TYPE)]
  404. ; xmm6=(00 01 ** 03 ** 05 ** 07)
  405. movdqa xmm1,xmm6 ; xmm1=(00 01 ** 03 ** 05 ** 07)
  406. pslld xmm6,WORD_BIT ; xmm6=(-- 00 -- ** -- ** -- **)
  407. pand xmm1,xmm7 ; xmm1=(-- 01 -- 03 -- 05 -- 07)
  408. psrad xmm6,(WORD_BIT-CONST_BITS-2) ; xmm6=tmp10[col0 **** **** ****]
  409. psrad xmm1,(WORD_BIT-CONST_BITS-2) ; xmm1=tmp10[col1 col3 col5 col7]
  410. ; -- Final output stage
  411. movdqa xmm3,xmm6
  412. movdqa xmm5,xmm1
  413. paddd xmm6,xmm4 ; xmm6=data0[col0 **** **** ****]=(A0 ** ** **)
  414. paddd xmm1,xmm0 ; xmm1=data0[col1 col3 col5 col7]=(A1 A3 A5 A7)
  415. psubd xmm3,xmm4 ; xmm3=data1[col0 **** **** ****]=(B0 ** ** **)
  416. psubd xmm5,xmm0 ; xmm5=data1[col1 col3 col5 col7]=(B1 B3 B5 B7)
  417. movdqa xmm2,[GOTOFF(ebx,PD_DESCALE_P1_2)] ; xmm2=[PD_DESCALE_P1_2]
  418. punpckldq xmm6,xmm3 ; xmm6=(A0 B0 ** **)
  419. movdqa xmm7,xmm1
  420. punpcklqdq xmm1,xmm5 ; xmm1=(A1 A3 B1 B3)
  421. punpckhqdq xmm7,xmm5 ; xmm7=(A5 A7 B5 B7)
  422. paddd xmm6,xmm2
  423. psrad xmm6,DESCALE_P1_2
  424. paddd xmm1,xmm2
  425. paddd xmm7,xmm2
  426. psrad xmm1,DESCALE_P1_2
  427. psrad xmm7,DESCALE_P1_2
  428. ; -- Prefetch the next coefficient block
  429. prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
  430. prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
  431. prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
  432. prefetchnta [esi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
  433. ; ---- Pass 2: process rows, store into output array.
  434. mov edi, JSAMPARRAY [output_buf(ebp)] ; (JSAMPROW *)
  435. mov eax, JDIMENSION [output_col(ebp)]
  436. ; | input:| result:|
  437. ; | A0 B0 | |
  438. ; | A1 B1 | C0 C1 |
  439. ; | A3 B3 | D0 D1 |
  440. ; | A5 B5 | |
  441. ; | A7 B7 | |
  442. ; -- Odd part
  443. packssdw xmm1,xmm1 ; xmm1=(A1 A3 B1 B3 A1 A3 B1 B3)
  444. packssdw xmm7,xmm7 ; xmm7=(A5 A7 B5 B7 A5 A7 B5 B7)
  445. pmaddwd xmm1,[GOTOFF(ebx,PW_F362_MF127)]
  446. pmaddwd xmm7,[GOTOFF(ebx,PW_F085_MF072)]
  447. paddd xmm1,xmm7 ; xmm1=tmp0[row0 row1 row0 row1]
  448. ; -- Even part
  449. pslld xmm6,(CONST_BITS+2) ; xmm6=tmp10[row0 row1 **** ****]
  450. ; -- Final output stage
  451. movdqa xmm4,xmm6
  452. paddd xmm6,xmm1 ; xmm6=data0[row0 row1 **** ****]=(C0 C1 ** **)
  453. psubd xmm4,xmm1 ; xmm4=data1[row0 row1 **** ****]=(D0 D1 ** **)
  454. punpckldq xmm6,xmm4 ; xmm6=(C0 D0 C1 D1)
  455. paddd xmm6,[GOTOFF(ebx,PD_DESCALE_P2_2)]
  456. psrad xmm6,DESCALE_P2_2
  457. packssdw xmm6,xmm6 ; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1)
  458. packsswb xmm6,xmm6 ; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1 ..)
  459. paddb xmm6,[GOTOFF(ebx,PB_CENTERJSAMP)]
  460. pextrw ebx,xmm6,0x00 ; ebx=(C0 D0 -- --)
  461. pextrw ecx,xmm6,0x01 ; ecx=(C1 D1 -- --)
  462. mov edx, JSAMPROW [edi+0*SIZEOF_JSAMPROW]
  463. mov esi, JSAMPROW [edi+1*SIZEOF_JSAMPROW]
  464. mov WORD [edx+eax*SIZEOF_JSAMPLE], bx
  465. mov WORD [esi+eax*SIZEOF_JSAMPLE], cx
  466. pop edi
  467. pop esi
  468. ; pop edx ; need not be preserved
  469. ; pop ecx ; need not be preserved
  470. pop ebx
  471. pop ebp
  472. ret
  473. ; For some reason, the OS X linker does not honor the request to align the
  474. ; segment unless we do this.
  475. align 16