jidctred-sse2.asm 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. ;
  2. ; jidctred.asm - reduced-size IDCT (64-bit SSE2)
  3. ;
  4. ; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ; Copyright (C) 2009, 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 inverse-DCT routines that produce reduced-size
  18. ; output: either 4x4 or 2x2 pixels from an 8x8 DCT block.
  19. ; The following code is based directly on the IJG's original jidctred.c;
  20. ; see the jidctred.c for 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_4 (CONST_BITS - PASS1_BITS + 1)
  27. %define DESCALE_P2_4 (CONST_BITS + PASS1_BITS + 3 + 1)
  28. %define DESCALE_P1_2 (CONST_BITS - PASS1_BITS + 2)
  29. %define DESCALE_P2_2 (CONST_BITS + PASS1_BITS + 3 + 2)
  30. %if CONST_BITS == 13
  31. F_0_211 equ 1730 ; FIX(0.211164243)
  32. F_0_509 equ 4176 ; FIX(0.509795579)
  33. F_0_601 equ 4926 ; FIX(0.601344887)
  34. F_0_720 equ 5906 ; FIX(0.720959822)
  35. F_0_765 equ 6270 ; FIX(0.765366865)
  36. F_0_850 equ 6967 ; FIX(0.850430095)
  37. F_0_899 equ 7373 ; FIX(0.899976223)
  38. F_1_061 equ 8697 ; FIX(1.061594337)
  39. F_1_272 equ 10426 ; FIX(1.272758580)
  40. F_1_451 equ 11893 ; FIX(1.451774981)
  41. F_1_847 equ 15137 ; FIX(1.847759065)
  42. F_2_172 equ 17799 ; FIX(2.172734803)
  43. F_2_562 equ 20995 ; FIX(2.562915447)
  44. F_3_624 equ 29692 ; FIX(3.624509785)
  45. %else
  46. ; NASM cannot do compile-time arithmetic on floating-point constants.
  47. %define DESCALE(x, n) (((x) + (1 << ((n) - 1))) >> (n))
  48. F_0_211 equ DESCALE( 226735879, 30 - CONST_BITS) ; FIX(0.211164243)
  49. F_0_509 equ DESCALE( 547388834, 30 - CONST_BITS) ; FIX(0.509795579)
  50. F_0_601 equ DESCALE( 645689155, 30 - CONST_BITS) ; FIX(0.601344887)
  51. F_0_720 equ DESCALE( 774124714, 30 - CONST_BITS) ; FIX(0.720959822)
  52. F_0_765 equ DESCALE( 821806413, 30 - CONST_BITS) ; FIX(0.765366865)
  53. F_0_850 equ DESCALE( 913142361, 30 - CONST_BITS) ; FIX(0.850430095)
  54. F_0_899 equ DESCALE( 966342111, 30 - CONST_BITS) ; FIX(0.899976223)
  55. F_1_061 equ DESCALE(1139878239, 30 - CONST_BITS) ; FIX(1.061594337)
  56. F_1_272 equ DESCALE(1366614119, 30 - CONST_BITS) ; FIX(1.272758580)
  57. F_1_451 equ DESCALE(1558831516, 30 - CONST_BITS) ; FIX(1.451774981)
  58. F_1_847 equ DESCALE(1984016188, 30 - CONST_BITS) ; FIX(1.847759065)
  59. F_2_172 equ DESCALE(2332956230, 30 - CONST_BITS) ; FIX(2.172734803)
  60. F_2_562 equ DESCALE(2751909506, 30 - CONST_BITS) ; FIX(2.562915447)
  61. F_3_624 equ DESCALE(3891787747, 30 - CONST_BITS) ; FIX(3.624509785)
  62. %endif
  63. ; --------------------------------------------------------------------------
  64. SECTION SEG_CONST
  65. alignz 32
  66. GLOBAL_DATA(jconst_idct_red_sse2)
  67. EXTN(jconst_idct_red_sse2):
  68. PW_F184_MF076 times 4 dw F_1_847, -F_0_765
  69. PW_F256_F089 times 4 dw F_2_562, F_0_899
  70. PW_F106_MF217 times 4 dw F_1_061, -F_2_172
  71. PW_MF060_MF050 times 4 dw -F_0_601, -F_0_509
  72. PW_F145_MF021 times 4 dw F_1_451, -F_0_211
  73. PW_F362_MF127 times 4 dw F_3_624, -F_1_272
  74. PW_F085_MF072 times 4 dw F_0_850, -F_0_720
  75. PD_DESCALE_P1_4 times 4 dd 1 << (DESCALE_P1_4 - 1)
  76. PD_DESCALE_P2_4 times 4 dd 1 << (DESCALE_P2_4 - 1)
  77. PD_DESCALE_P1_2 times 4 dd 1 << (DESCALE_P1_2 - 1)
  78. PD_DESCALE_P2_2 times 4 dd 1 << (DESCALE_P2_2 - 1)
  79. PB_CENTERJSAMP times 16 db CENTERJSAMPLE
  80. alignz 32
  81. ; --------------------------------------------------------------------------
  82. SECTION SEG_TEXT
  83. BITS 64
  84. ;
  85. ; Perform dequantization and inverse DCT on one block of coefficients,
  86. ; producing a reduced-size 4x4 output block.
  87. ;
  88. ; GLOBAL(void)
  89. ; jsimd_idct_4x4_sse2(void *dct_table, JCOEFPTR coef_block,
  90. ; JSAMPARRAY output_buf, JDIMENSION output_col)
  91. ;
  92. ; r10 = void *dct_table
  93. ; r11 = JCOEFPTR coef_block
  94. ; r12 = JSAMPARRAY output_buf
  95. ; r13d = JDIMENSION output_col
  96. %define original_rbp rbp + 0
  97. %define wk(i) rbp - (WK_NUM - (i)) * SIZEOF_XMMWORD
  98. ; xmmword wk[WK_NUM]
  99. %define WK_NUM 2
  100. align 32
  101. GLOBAL_FUNCTION(jsimd_idct_4x4_sse2)
  102. EXTN(jsimd_idct_4x4_sse2):
  103. push rbp
  104. mov rax, rsp ; rax = original rbp
  105. sub rsp, byte 4
  106. and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
  107. mov [rsp], rax
  108. mov rbp, rsp ; rbp = aligned rbp
  109. lea rsp, [wk(0)]
  110. collect_args 4
  111. ; ---- Pass 1: process columns from input.
  112. mov rdx, r10 ; quantptr
  113. mov rsi, r11 ; inptr
  114. %ifndef NO_ZERO_COLUMN_TEST_4X4_SSE2
  115. mov eax, dword [DWBLOCK(1,0,rsi,SIZEOF_JCOEF)]
  116. or eax, dword [DWBLOCK(2,0,rsi,SIZEOF_JCOEF)]
  117. jnz short .columnDCT
  118. movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
  119. movdqa xmm1, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
  120. por xmm0, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
  121. por xmm1, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
  122. por xmm0, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
  123. por xmm1, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
  124. por xmm0, xmm1
  125. packsswb xmm0, xmm0
  126. packsswb xmm0, xmm0
  127. movd eax, xmm0
  128. test rax, rax
  129. jnz short .columnDCT
  130. ; -- AC terms all zero
  131. movdqa xmm0, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
  132. pmullw xmm0, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  133. psllw xmm0, PASS1_BITS
  134. movdqa xmm3, xmm0 ; xmm0=in0=(00 01 02 03 04 05 06 07)
  135. punpcklwd xmm0, xmm0 ; xmm0=(00 00 01 01 02 02 03 03)
  136. punpckhwd xmm3, xmm3 ; xmm3=(04 04 05 05 06 06 07 07)
  137. pshufd xmm1, xmm0, 0x50 ; xmm1=[col0 col1]=(00 00 00 00 01 01 01 01)
  138. pshufd xmm0, xmm0, 0xFA ; xmm0=[col2 col3]=(02 02 02 02 03 03 03 03)
  139. pshufd xmm6, xmm3, 0x50 ; xmm6=[col4 col5]=(04 04 04 04 05 05 05 05)
  140. pshufd xmm3, xmm3, 0xFA ; xmm3=[col6 col7]=(06 06 06 06 07 07 07 07)
  141. jmp near .column_end
  142. %endif
  143. .columnDCT:
  144. ; -- Odd part
  145. movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
  146. movdqa xmm1, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
  147. pmullw xmm0, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  148. pmullw xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  149. movdqa xmm2, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
  150. movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
  151. pmullw xmm2, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  152. pmullw xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  153. movdqa xmm4, xmm0
  154. movdqa xmm5, xmm0
  155. punpcklwd xmm4, xmm1
  156. punpckhwd xmm5, xmm1
  157. movdqa xmm0, xmm4
  158. movdqa xmm1, xmm5
  159. pmaddwd xmm4, [rel PW_F256_F089] ; xmm4=(tmp2L)
  160. pmaddwd xmm5, [rel PW_F256_F089] ; xmm5=(tmp2H)
  161. pmaddwd xmm0, [rel PW_F106_MF217] ; xmm0=(tmp0L)
  162. pmaddwd xmm1, [rel PW_F106_MF217] ; xmm1=(tmp0H)
  163. movdqa xmm6, xmm2
  164. movdqa xmm7, xmm2
  165. punpcklwd xmm6, xmm3
  166. punpckhwd xmm7, xmm3
  167. movdqa xmm2, xmm6
  168. movdqa xmm3, xmm7
  169. pmaddwd xmm6, [rel PW_MF060_MF050] ; xmm6=(tmp2L)
  170. pmaddwd xmm7, [rel PW_MF060_MF050] ; xmm7=(tmp2H)
  171. pmaddwd xmm2, [rel PW_F145_MF021] ; xmm2=(tmp0L)
  172. pmaddwd xmm3, [rel PW_F145_MF021] ; xmm3=(tmp0H)
  173. paddd xmm6, xmm4 ; xmm6=tmp2L
  174. paddd xmm7, xmm5 ; xmm7=tmp2H
  175. paddd xmm2, xmm0 ; xmm2=tmp0L
  176. paddd xmm3, xmm1 ; xmm3=tmp0H
  177. movdqa XMMWORD [wk(0)], xmm2 ; wk(0)=tmp0L
  178. movdqa XMMWORD [wk(1)], xmm3 ; wk(1)=tmp0H
  179. ; -- Even part
  180. movdqa xmm4, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
  181. movdqa xmm5, XMMWORD [XMMBLOCK(2,0,rsi,SIZEOF_JCOEF)]
  182. movdqa xmm0, XMMWORD [XMMBLOCK(6,0,rsi,SIZEOF_JCOEF)]
  183. pmullw xmm4, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  184. pmullw xmm5, XMMWORD [XMMBLOCK(2,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  185. pmullw xmm0, XMMWORD [XMMBLOCK(6,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  186. pxor xmm1, xmm1
  187. pxor xmm2, xmm2
  188. punpcklwd xmm1, xmm4 ; xmm1=tmp0L
  189. punpckhwd xmm2, xmm4 ; xmm2=tmp0H
  190. psrad xmm1, (16-CONST_BITS-1) ; psrad xmm1,16 & pslld xmm1,CONST_BITS+1
  191. psrad xmm2, (16-CONST_BITS-1) ; psrad xmm2,16 & pslld xmm2,CONST_BITS+1
  192. movdqa xmm3, xmm5 ; xmm5=in2=z2
  193. punpcklwd xmm5, xmm0 ; xmm0=in6=z3
  194. punpckhwd xmm3, xmm0
  195. pmaddwd xmm5, [rel PW_F184_MF076] ; xmm5=tmp2L
  196. pmaddwd xmm3, [rel PW_F184_MF076] ; xmm3=tmp2H
  197. movdqa xmm4, xmm1
  198. movdqa xmm0, xmm2
  199. paddd xmm1, xmm5 ; xmm1=tmp10L
  200. paddd xmm2, xmm3 ; xmm2=tmp10H
  201. psubd xmm4, xmm5 ; xmm4=tmp12L
  202. psubd xmm0, xmm3 ; xmm0=tmp12H
  203. ; -- Final output stage
  204. movdqa xmm5, xmm1
  205. movdqa xmm3, xmm2
  206. paddd xmm1, xmm6 ; xmm1=data0L
  207. paddd xmm2, xmm7 ; xmm2=data0H
  208. psubd xmm5, xmm6 ; xmm5=data3L
  209. psubd xmm3, xmm7 ; xmm3=data3H
  210. movdqa xmm6, [rel PD_DESCALE_P1_4] ; xmm6=[rel PD_DESCALE_P1_4]
  211. paddd xmm1, xmm6
  212. paddd xmm2, xmm6
  213. psrad xmm1, DESCALE_P1_4
  214. psrad xmm2, DESCALE_P1_4
  215. paddd xmm5, xmm6
  216. paddd xmm3, xmm6
  217. psrad xmm5, DESCALE_P1_4
  218. psrad xmm3, DESCALE_P1_4
  219. packssdw xmm1, xmm2 ; xmm1=data0=(00 01 02 03 04 05 06 07)
  220. packssdw xmm5, xmm3 ; xmm5=data3=(30 31 32 33 34 35 36 37)
  221. movdqa xmm7, XMMWORD [wk(0)] ; xmm7=tmp0L
  222. movdqa xmm6, XMMWORD [wk(1)] ; xmm6=tmp0H
  223. movdqa xmm2, xmm4
  224. movdqa xmm3, xmm0
  225. paddd xmm4, xmm7 ; xmm4=data1L
  226. paddd xmm0, xmm6 ; xmm0=data1H
  227. psubd xmm2, xmm7 ; xmm2=data2L
  228. psubd xmm3, xmm6 ; xmm3=data2H
  229. movdqa xmm7, [rel PD_DESCALE_P1_4] ; xmm7=[rel PD_DESCALE_P1_4]
  230. paddd xmm4, xmm7
  231. paddd xmm0, xmm7
  232. psrad xmm4, DESCALE_P1_4
  233. psrad xmm0, DESCALE_P1_4
  234. paddd xmm2, xmm7
  235. paddd xmm3, xmm7
  236. psrad xmm2, DESCALE_P1_4
  237. psrad xmm3, DESCALE_P1_4
  238. packssdw xmm4, xmm0 ; xmm4=data1=(10 11 12 13 14 15 16 17)
  239. packssdw xmm2, xmm3 ; xmm2=data2=(20 21 22 23 24 25 26 27)
  240. movdqa xmm6, xmm1 ; transpose coefficients(phase 1)
  241. punpcklwd xmm1, xmm4 ; xmm1=(00 10 01 11 02 12 03 13)
  242. punpckhwd xmm6, xmm4 ; xmm6=(04 14 05 15 06 16 07 17)
  243. movdqa xmm7, xmm2 ; transpose coefficients(phase 1)
  244. punpcklwd xmm2, xmm5 ; xmm2=(20 30 21 31 22 32 23 33)
  245. punpckhwd xmm7, xmm5 ; xmm7=(24 34 25 35 26 36 27 37)
  246. movdqa xmm0, xmm1 ; transpose coefficients(phase 2)
  247. punpckldq xmm1, xmm2 ; xmm1=[col0 col1]=(00 10 20 30 01 11 21 31)
  248. punpckhdq xmm0, xmm2 ; xmm0=[col2 col3]=(02 12 22 32 03 13 23 33)
  249. movdqa xmm3, xmm6 ; transpose coefficients(phase 2)
  250. punpckldq xmm6, xmm7 ; xmm6=[col4 col5]=(04 14 24 34 05 15 25 35)
  251. punpckhdq xmm3, xmm7 ; xmm3=[col6 col7]=(06 16 26 36 07 17 27 37)
  252. .column_end:
  253. ; -- Prefetch the next coefficient block
  254. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
  255. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
  256. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
  257. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
  258. ; ---- Pass 2: process rows, store into output array.
  259. mov rax, [original_rbp]
  260. mov rdi, r12 ; (JSAMPROW *)
  261. mov eax, r13d
  262. ; -- Even part
  263. pxor xmm4, xmm4
  264. punpcklwd xmm4, xmm1 ; xmm4=tmp0
  265. psrad xmm4, (16-CONST_BITS-1) ; psrad xmm4,16 & pslld xmm4,CONST_BITS+1
  266. ; -- Odd part
  267. punpckhwd xmm1, xmm0
  268. punpckhwd xmm6, xmm3
  269. movdqa xmm5, xmm1
  270. movdqa xmm2, xmm6
  271. pmaddwd xmm1, [rel PW_F256_F089] ; xmm1=(tmp2)
  272. pmaddwd xmm6, [rel PW_MF060_MF050] ; xmm6=(tmp2)
  273. pmaddwd xmm5, [rel PW_F106_MF217] ; xmm5=(tmp0)
  274. pmaddwd xmm2, [rel PW_F145_MF021] ; xmm2=(tmp0)
  275. paddd xmm6, xmm1 ; xmm6=tmp2
  276. paddd xmm2, xmm5 ; xmm2=tmp0
  277. ; -- Even part
  278. punpcklwd xmm0, xmm3
  279. pmaddwd xmm0, [rel PW_F184_MF076] ; xmm0=tmp2
  280. movdqa xmm7, xmm4
  281. paddd xmm4, xmm0 ; xmm4=tmp10
  282. psubd xmm7, xmm0 ; xmm7=tmp12
  283. ; -- Final output stage
  284. movdqa xmm1, [rel PD_DESCALE_P2_4] ; xmm1=[rel PD_DESCALE_P2_4]
  285. movdqa xmm5, xmm4
  286. movdqa xmm3, xmm7
  287. paddd xmm4, xmm6 ; xmm4=data0=(00 10 20 30)
  288. paddd xmm7, xmm2 ; xmm7=data1=(01 11 21 31)
  289. psubd xmm5, xmm6 ; xmm5=data3=(03 13 23 33)
  290. psubd xmm3, xmm2 ; xmm3=data2=(02 12 22 32)
  291. paddd xmm4, xmm1
  292. paddd xmm7, xmm1
  293. psrad xmm4, DESCALE_P2_4
  294. psrad xmm7, DESCALE_P2_4
  295. paddd xmm5, xmm1
  296. paddd xmm3, xmm1
  297. psrad xmm5, DESCALE_P2_4
  298. psrad xmm3, DESCALE_P2_4
  299. packssdw xmm4, xmm3 ; xmm4=(00 10 20 30 02 12 22 32)
  300. packssdw xmm7, xmm5 ; xmm7=(01 11 21 31 03 13 23 33)
  301. movdqa xmm0, xmm4 ; transpose coefficients(phase 1)
  302. punpcklwd xmm4, xmm7 ; xmm4=(00 01 10 11 20 21 30 31)
  303. punpckhwd xmm0, xmm7 ; xmm0=(02 03 12 13 22 23 32 33)
  304. movdqa xmm6, xmm4 ; transpose coefficients(phase 2)
  305. punpckldq xmm4, xmm0 ; xmm4=(00 01 02 03 10 11 12 13)
  306. punpckhdq xmm6, xmm0 ; xmm6=(20 21 22 23 30 31 32 33)
  307. packsswb xmm4, xmm6 ; xmm4=(00 01 02 03 10 11 12 13 20 ..)
  308. paddb xmm4, [rel PB_CENTERJSAMP]
  309. pshufd xmm2, xmm4, 0x39 ; xmm2=(10 11 12 13 20 21 22 23 30 ..)
  310. pshufd xmm1, xmm4, 0x4E ; xmm1=(20 21 22 23 30 31 32 33 00 ..)
  311. pshufd xmm3, xmm4, 0x93 ; xmm3=(30 31 32 33 00 01 02 03 10 ..)
  312. mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
  313. mov rsi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
  314. movd XMM_DWORD [rdx+rax*SIZEOF_JSAMPLE], xmm4
  315. movd XMM_DWORD [rsi+rax*SIZEOF_JSAMPLE], xmm2
  316. mov rdx, JSAMPROW [rdi+2*SIZEOF_JSAMPROW]
  317. mov rsi, JSAMPROW [rdi+3*SIZEOF_JSAMPROW]
  318. movd XMM_DWORD [rdx+rax*SIZEOF_JSAMPLE], xmm1
  319. movd XMM_DWORD [rsi+rax*SIZEOF_JSAMPLE], xmm3
  320. uncollect_args 4
  321. mov rsp, rbp ; rsp <- aligned rbp
  322. pop rsp ; rsp <- original rbp
  323. pop rbp
  324. ret
  325. ; --------------------------------------------------------------------------
  326. ;
  327. ; Perform dequantization and inverse DCT on one block of coefficients,
  328. ; producing a reduced-size 2x2 output block.
  329. ;
  330. ; GLOBAL(void)
  331. ; jsimd_idct_2x2_sse2(void *dct_table, JCOEFPTR coef_block,
  332. ; JSAMPARRAY output_buf, JDIMENSION output_col)
  333. ;
  334. ; r10 = void *dct_table
  335. ; r11 = JCOEFPTR coef_block
  336. ; r12 = JSAMPARRAY output_buf
  337. ; r13d = JDIMENSION output_col
  338. align 32
  339. GLOBAL_FUNCTION(jsimd_idct_2x2_sse2)
  340. EXTN(jsimd_idct_2x2_sse2):
  341. push rbp
  342. mov rax, rsp
  343. mov rbp, rsp
  344. collect_args 4
  345. push rbx
  346. ; ---- Pass 1: process columns from input.
  347. mov rdx, r10 ; quantptr
  348. mov rsi, r11 ; inptr
  349. ; | input: | result: |
  350. ; | 00 01 ** 03 ** 05 ** 07 | |
  351. ; | 10 11 ** 13 ** 15 ** 17 | |
  352. ; | ** ** ** ** ** ** ** ** | |
  353. ; | 30 31 ** 33 ** 35 ** 37 | A0 A1 A3 A5 A7 |
  354. ; | ** ** ** ** ** ** ** ** | B0 B1 B3 B5 B7 |
  355. ; | 50 51 ** 53 ** 55 ** 57 | |
  356. ; | ** ** ** ** ** ** ** ** | |
  357. ; | 70 71 ** 73 ** 75 ** 77 | |
  358. ; -- Odd part
  359. movdqa xmm0, XMMWORD [XMMBLOCK(1,0,rsi,SIZEOF_JCOEF)]
  360. movdqa xmm1, XMMWORD [XMMBLOCK(3,0,rsi,SIZEOF_JCOEF)]
  361. pmullw xmm0, XMMWORD [XMMBLOCK(1,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  362. pmullw xmm1, XMMWORD [XMMBLOCK(3,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  363. movdqa xmm2, XMMWORD [XMMBLOCK(5,0,rsi,SIZEOF_JCOEF)]
  364. movdqa xmm3, XMMWORD [XMMBLOCK(7,0,rsi,SIZEOF_JCOEF)]
  365. pmullw xmm2, XMMWORD [XMMBLOCK(5,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  366. pmullw xmm3, XMMWORD [XMMBLOCK(7,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  367. ; xmm0=(10 11 ** 13 ** 15 ** 17), xmm1=(30 31 ** 33 ** 35 ** 37)
  368. ; xmm2=(50 51 ** 53 ** 55 ** 57), xmm3=(70 71 ** 73 ** 75 ** 77)
  369. pcmpeqd xmm7, xmm7
  370. pslld xmm7, WORD_BIT ; xmm7={0x0000 0xFFFF 0x0000 0xFFFF ..}
  371. movdqa xmm4, xmm0 ; xmm4=(10 11 ** 13 ** 15 ** 17)
  372. movdqa xmm5, xmm2 ; xmm5=(50 51 ** 53 ** 55 ** 57)
  373. punpcklwd xmm4, xmm1 ; xmm4=(10 30 11 31 ** ** 13 33)
  374. punpcklwd xmm5, xmm3 ; xmm5=(50 70 51 71 ** ** 53 73)
  375. pmaddwd xmm4, [rel PW_F362_MF127]
  376. pmaddwd xmm5, [rel PW_F085_MF072]
  377. psrld xmm0, WORD_BIT ; xmm0=(11 -- 13 -- 15 -- 17 --)
  378. pand xmm1, xmm7 ; xmm1=(-- 31 -- 33 -- 35 -- 37)
  379. psrld xmm2, WORD_BIT ; xmm2=(51 -- 53 -- 55 -- 57 --)
  380. pand xmm3, xmm7 ; xmm3=(-- 71 -- 73 -- 75 -- 77)
  381. por xmm0, xmm1 ; xmm0=(11 31 13 33 15 35 17 37)
  382. por xmm2, xmm3 ; xmm2=(51 71 53 73 55 75 57 77)
  383. pmaddwd xmm0, [rel PW_F362_MF127]
  384. pmaddwd xmm2, [rel PW_F085_MF072]
  385. paddd xmm4, xmm5 ; xmm4=tmp0[col0 col1 **** col3]
  386. paddd xmm0, xmm2 ; xmm0=tmp0[col1 col3 col5 col7]
  387. ; -- Even part
  388. movdqa xmm6, XMMWORD [XMMBLOCK(0,0,rsi,SIZEOF_JCOEF)]
  389. pmullw xmm6, XMMWORD [XMMBLOCK(0,0,rdx,SIZEOF_ISLOW_MULT_TYPE)]
  390. ; xmm6=(00 01 ** 03 ** 05 ** 07)
  391. movdqa xmm1, xmm6 ; xmm1=(00 01 ** 03 ** 05 ** 07)
  392. pslld xmm6, WORD_BIT ; xmm6=(-- 00 -- ** -- ** -- **)
  393. pand xmm1, xmm7 ; xmm1=(-- 01 -- 03 -- 05 -- 07)
  394. psrad xmm6, (WORD_BIT-CONST_BITS-2) ; xmm6=tmp10[col0 **** **** ****]
  395. psrad xmm1, (WORD_BIT-CONST_BITS-2) ; xmm1=tmp10[col1 col3 col5 col7]
  396. ; -- Final output stage
  397. movdqa xmm3, xmm6
  398. movdqa xmm5, xmm1
  399. paddd xmm6, xmm4 ; xmm6=data0[col0 **** **** ****]=(A0 ** ** **)
  400. paddd xmm1, xmm0 ; xmm1=data0[col1 col3 col5 col7]=(A1 A3 A5 A7)
  401. psubd xmm3, xmm4 ; xmm3=data1[col0 **** **** ****]=(B0 ** ** **)
  402. psubd xmm5, xmm0 ; xmm5=data1[col1 col3 col5 col7]=(B1 B3 B5 B7)
  403. movdqa xmm2, [rel PD_DESCALE_P1_2] ; xmm2=[rel PD_DESCALE_P1_2]
  404. punpckldq xmm6, xmm3 ; xmm6=(A0 B0 ** **)
  405. movdqa xmm7, xmm1
  406. punpcklqdq xmm1, xmm5 ; xmm1=(A1 A3 B1 B3)
  407. punpckhqdq xmm7, xmm5 ; xmm7=(A5 A7 B5 B7)
  408. paddd xmm6, xmm2
  409. psrad xmm6, DESCALE_P1_2
  410. paddd xmm1, xmm2
  411. paddd xmm7, xmm2
  412. psrad xmm1, DESCALE_P1_2
  413. psrad xmm7, DESCALE_P1_2
  414. ; -- Prefetch the next coefficient block
  415. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 0*32]
  416. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 1*32]
  417. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 2*32]
  418. prefetchnta [rsi + DCTSIZE2*SIZEOF_JCOEF + 3*32]
  419. ; ---- Pass 2: process rows, store into output array.
  420. mov rdi, r12 ; (JSAMPROW *)
  421. mov eax, r13d
  422. ; | input:| result:|
  423. ; | A0 B0 | |
  424. ; | A1 B1 | C0 C1 |
  425. ; | A3 B3 | D0 D1 |
  426. ; | A5 B5 | |
  427. ; | A7 B7 | |
  428. ; -- Odd part
  429. packssdw xmm1, xmm1 ; xmm1=(A1 A3 B1 B3 A1 A3 B1 B3)
  430. packssdw xmm7, xmm7 ; xmm7=(A5 A7 B5 B7 A5 A7 B5 B7)
  431. pmaddwd xmm1, [rel PW_F362_MF127]
  432. pmaddwd xmm7, [rel PW_F085_MF072]
  433. paddd xmm1, xmm7 ; xmm1=tmp0[row0 row1 row0 row1]
  434. ; -- Even part
  435. pslld xmm6, (CONST_BITS+2) ; xmm6=tmp10[row0 row1 **** ****]
  436. ; -- Final output stage
  437. movdqa xmm4, xmm6
  438. paddd xmm6, xmm1 ; xmm6=data0[row0 row1 **** ****]=(C0 C1 ** **)
  439. psubd xmm4, xmm1 ; xmm4=data1[row0 row1 **** ****]=(D0 D1 ** **)
  440. punpckldq xmm6, xmm4 ; xmm6=(C0 D0 C1 D1)
  441. paddd xmm6, [rel PD_DESCALE_P2_2]
  442. psrad xmm6, DESCALE_P2_2
  443. packssdw xmm6, xmm6 ; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1)
  444. packsswb xmm6, xmm6 ; xmm6=(C0 D0 C1 D1 C0 D0 C1 D1 ..)
  445. paddb xmm6, [rel PB_CENTERJSAMP]
  446. pextrw ebx, xmm6, 0x00 ; ebx=(C0 D0 -- --)
  447. pextrw ecx, xmm6, 0x01 ; ecx=(C1 D1 -- --)
  448. mov rdx, JSAMPROW [rdi+0*SIZEOF_JSAMPROW]
  449. mov rsi, JSAMPROW [rdi+1*SIZEOF_JSAMPROW]
  450. mov word [rdx+rax*SIZEOF_JSAMPLE], bx
  451. mov word [rsi+rax*SIZEOF_JSAMPLE], cx
  452. pop rbx
  453. uncollect_args 4
  454. pop rbp
  455. ret
  456. ; For some reason, the OS X linker does not honor the request to align the
  457. ; segment unless we do this.
  458. align 32