jdmrgext-sse2.asm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. ;
  2. ; jdmrgext.asm - merged upsampling/color conversion (64-bit SSE2)
  3. ;
  4. ; Copyright 2009, 2012 Pierre Ossman <ossman@cendio.se> for Cendio AB
  5. ; Copyright (C) 2009, 2012, 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. %include "jcolsamp.inc"
  17. ; --------------------------------------------------------------------------
  18. ;
  19. ; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
  20. ;
  21. ; GLOBAL(void)
  22. ; jsimd_h2v1_merged_upsample_sse2(JDIMENSION output_width,
  23. ; JSAMPIMAGE input_buf,
  24. ; JDIMENSION in_row_group_ctr,
  25. ; JSAMPARRAY output_buf);
  26. ;
  27. ; r10d = JDIMENSION output_width
  28. ; r11 = JSAMPIMAGE input_buf
  29. ; r12d = JDIMENSION in_row_group_ctr
  30. ; r13 = JSAMPARRAY output_buf
  31. %define wk(i) rbp - (WK_NUM - (i)) * SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
  32. %define WK_NUM 3
  33. align 32
  34. GLOBAL_FUNCTION(jsimd_h2v1_merged_upsample_sse2)
  35. EXTN(jsimd_h2v1_merged_upsample_sse2):
  36. push rbp
  37. mov rax, rsp ; rax = original rbp
  38. sub rsp, byte 4
  39. and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
  40. mov [rsp], rax
  41. mov rbp, rsp ; rbp = aligned rbp
  42. lea rsp, [wk(0)]
  43. collect_args 4
  44. push rbx
  45. mov ecx, r10d ; col
  46. test rcx, rcx
  47. jz near .return
  48. push rcx
  49. mov rdi, r11
  50. mov ecx, r12d
  51. mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
  52. mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
  53. mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
  54. mov rdi, r13
  55. mov rsi, JSAMPROW [rsi+rcx*SIZEOF_JSAMPROW] ; inptr0
  56. mov rbx, JSAMPROW [rbx+rcx*SIZEOF_JSAMPROW] ; inptr1
  57. mov rdx, JSAMPROW [rdx+rcx*SIZEOF_JSAMPROW] ; inptr2
  58. mov rdi, JSAMPROW [rdi] ; outptr
  59. pop rcx ; col
  60. .columnloop:
  61. movdqa xmm6, XMMWORD [rbx] ; xmm6=Cb(0123456789ABCDEF)
  62. movdqa xmm7, XMMWORD [rdx] ; xmm7=Cr(0123456789ABCDEF)
  63. pxor xmm1, xmm1 ; xmm1=(all 0's)
  64. pcmpeqw xmm3, xmm3
  65. psllw xmm3, 7 ; xmm3={0xFF80 0xFF80 0xFF80 0xFF80 ..}
  66. movdqa xmm4, xmm6
  67. punpckhbw xmm6, xmm1 ; xmm6=Cb(89ABCDEF)=CbH
  68. punpcklbw xmm4, xmm1 ; xmm4=Cb(01234567)=CbL
  69. movdqa xmm0, xmm7
  70. punpckhbw xmm7, xmm1 ; xmm7=Cr(89ABCDEF)=CrH
  71. punpcklbw xmm0, xmm1 ; xmm0=Cr(01234567)=CrL
  72. paddw xmm6, xmm3
  73. paddw xmm4, xmm3
  74. paddw xmm7, xmm3
  75. paddw xmm0, xmm3
  76. ; (Original)
  77. ; R = Y + 1.40200 * Cr
  78. ; G = Y - 0.34414 * Cb - 0.71414 * Cr
  79. ; B = Y + 1.77200 * Cb
  80. ;
  81. ; (This implementation)
  82. ; R = Y + 0.40200 * Cr + Cr
  83. ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
  84. ; B = Y - 0.22800 * Cb + Cb + Cb
  85. movdqa xmm5, xmm6 ; xmm5=CbH
  86. movdqa xmm2, xmm4 ; xmm2=CbL
  87. paddw xmm6, xmm6 ; xmm6=2*CbH
  88. paddw xmm4, xmm4 ; xmm4=2*CbL
  89. movdqa xmm1, xmm7 ; xmm1=CrH
  90. movdqa xmm3, xmm0 ; xmm3=CrL
  91. paddw xmm7, xmm7 ; xmm7=2*CrH
  92. paddw xmm0, xmm0 ; xmm0=2*CrL
  93. pmulhw xmm6, [rel PW_MF0228] ; xmm6=(2*CbH * -FIX(0.22800))
  94. pmulhw xmm4, [rel PW_MF0228] ; xmm4=(2*CbL * -FIX(0.22800))
  95. pmulhw xmm7, [rel PW_F0402] ; xmm7=(2*CrH * FIX(0.40200))
  96. pmulhw xmm0, [rel PW_F0402] ; xmm0=(2*CrL * FIX(0.40200))
  97. paddw xmm6, [rel PW_ONE]
  98. paddw xmm4, [rel PW_ONE]
  99. psraw xmm6, 1 ; xmm6=(CbH * -FIX(0.22800))
  100. psraw xmm4, 1 ; xmm4=(CbL * -FIX(0.22800))
  101. paddw xmm7, [rel PW_ONE]
  102. paddw xmm0, [rel PW_ONE]
  103. psraw xmm7, 1 ; xmm7=(CrH * FIX(0.40200))
  104. psraw xmm0, 1 ; xmm0=(CrL * FIX(0.40200))
  105. paddw xmm6, xmm5
  106. paddw xmm4, xmm2
  107. paddw xmm6, xmm5 ; xmm6=(CbH * FIX(1.77200))=(B-Y)H
  108. paddw xmm4, xmm2 ; xmm4=(CbL * FIX(1.77200))=(B-Y)L
  109. paddw xmm7, xmm1 ; xmm7=(CrH * FIX(1.40200))=(R-Y)H
  110. paddw xmm0, xmm3 ; xmm0=(CrL * FIX(1.40200))=(R-Y)L
  111. movdqa XMMWORD [wk(0)], xmm6 ; wk(0)=(B-Y)H
  112. movdqa XMMWORD [wk(1)], xmm7 ; wk(1)=(R-Y)H
  113. movdqa xmm6, xmm5
  114. movdqa xmm7, xmm2
  115. punpcklwd xmm5, xmm1
  116. punpckhwd xmm6, xmm1
  117. pmaddwd xmm5, [rel PW_MF0344_F0285]
  118. pmaddwd xmm6, [rel PW_MF0344_F0285]
  119. punpcklwd xmm2, xmm3
  120. punpckhwd xmm7, xmm3
  121. pmaddwd xmm2, [rel PW_MF0344_F0285]
  122. pmaddwd xmm7, [rel PW_MF0344_F0285]
  123. paddd xmm5, [rel PD_ONEHALF]
  124. paddd xmm6, [rel PD_ONEHALF]
  125. psrad xmm5, SCALEBITS
  126. psrad xmm6, SCALEBITS
  127. paddd xmm2, [rel PD_ONEHALF]
  128. paddd xmm7, [rel PD_ONEHALF]
  129. psrad xmm2, SCALEBITS
  130. psrad xmm7, SCALEBITS
  131. packssdw xmm5, xmm6 ; xmm5=CbH*-FIX(0.344)+CrH*FIX(0.285)
  132. packssdw xmm2, xmm7 ; xmm2=CbL*-FIX(0.344)+CrL*FIX(0.285)
  133. psubw xmm5, xmm1 ; xmm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H
  134. psubw xmm2, xmm3 ; xmm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L
  135. movdqa XMMWORD [wk(2)], xmm5 ; wk(2)=(G-Y)H
  136. mov al, 2 ; Yctr
  137. jmp short .Yloop_1st
  138. .Yloop_2nd:
  139. movdqa xmm0, XMMWORD [wk(1)] ; xmm0=(R-Y)H
  140. movdqa xmm2, XMMWORD [wk(2)] ; xmm2=(G-Y)H
  141. movdqa xmm4, XMMWORD [wk(0)] ; xmm4=(B-Y)H
  142. .Yloop_1st:
  143. movdqa xmm7, XMMWORD [rsi] ; xmm7=Y(0123456789ABCDEF)
  144. pcmpeqw xmm6, xmm6
  145. psrlw xmm6, BYTE_BIT ; xmm6={0xFF 0x00 0xFF 0x00 ..}
  146. pand xmm6, xmm7 ; xmm6=Y(02468ACE)=YE
  147. psrlw xmm7, BYTE_BIT ; xmm7=Y(13579BDF)=YO
  148. movdqa xmm1, xmm0 ; xmm1=xmm0=(R-Y)(L/H)
  149. movdqa xmm3, xmm2 ; xmm3=xmm2=(G-Y)(L/H)
  150. movdqa xmm5, xmm4 ; xmm5=xmm4=(B-Y)(L/H)
  151. paddw xmm0, xmm6 ; xmm0=((R-Y)+YE)=RE=R(02468ACE)
  152. paddw xmm1, xmm7 ; xmm1=((R-Y)+YO)=RO=R(13579BDF)
  153. packuswb xmm0, xmm0 ; xmm0=R(02468ACE********)
  154. packuswb xmm1, xmm1 ; xmm1=R(13579BDF********)
  155. paddw xmm2, xmm6 ; xmm2=((G-Y)+YE)=GE=G(02468ACE)
  156. paddw xmm3, xmm7 ; xmm3=((G-Y)+YO)=GO=G(13579BDF)
  157. packuswb xmm2, xmm2 ; xmm2=G(02468ACE********)
  158. packuswb xmm3, xmm3 ; xmm3=G(13579BDF********)
  159. paddw xmm4, xmm6 ; xmm4=((B-Y)+YE)=BE=B(02468ACE)
  160. paddw xmm5, xmm7 ; xmm5=((B-Y)+YO)=BO=B(13579BDF)
  161. packuswb xmm4, xmm4 ; xmm4=B(02468ACE********)
  162. packuswb xmm5, xmm5 ; xmm5=B(13579BDF********)
  163. %if RGB_PIXELSIZE == 3 ; ---------------
  164. ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
  165. ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
  166. ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
  167. ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
  168. punpcklbw xmmA, xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
  169. punpcklbw xmmE, xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
  170. punpcklbw xmmD, xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
  171. movdqa xmmG, xmmA
  172. movdqa xmmH, xmmA
  173. punpcklwd xmmA, xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
  174. punpckhwd xmmG, xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
  175. psrldq xmmH, 2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
  176. psrldq xmmE, 2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
  177. movdqa xmmC, xmmD
  178. movdqa xmmB, xmmD
  179. punpcklwd xmmD, xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
  180. punpckhwd xmmC, xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
  181. psrldq xmmB, 2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
  182. movdqa xmmF, xmmE
  183. punpcklwd xmmE, xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
  184. punpckhwd xmmF, xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
  185. pshufd xmmH, xmmA, 0x4E ; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
  186. movdqa xmmB, xmmE
  187. punpckldq xmmA, xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
  188. punpckldq xmmE, xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
  189. punpckhdq xmmD, xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
  190. pshufd xmmH, xmmG, 0x4E ; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
  191. movdqa xmmB, xmmF
  192. punpckldq xmmG, xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
  193. punpckldq xmmF, xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
  194. punpckhdq xmmC, xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
  195. punpcklqdq xmmA, xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
  196. punpcklqdq xmmD, xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
  197. punpcklqdq xmmF, xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
  198. cmp rcx, byte SIZEOF_XMMWORD
  199. jb short .column_st32
  200. test rdi, SIZEOF_XMMWORD-1
  201. jnz short .out1
  202. ; --(aligned)-------------------
  203. movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  204. movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  205. movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
  206. jmp short .out0
  207. .out1: ; --(unaligned)-----------------
  208. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  209. movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  210. movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
  211. .out0:
  212. add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
  213. sub rcx, byte SIZEOF_XMMWORD
  214. jz near .endcolumn
  215. add rsi, byte SIZEOF_XMMWORD ; inptr0
  216. dec al ; Yctr
  217. jnz near .Yloop_2nd
  218. add rbx, byte SIZEOF_XMMWORD ; inptr1
  219. add rdx, byte SIZEOF_XMMWORD ; inptr2
  220. jmp near .columnloop
  221. .column_st32:
  222. lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE
  223. cmp rcx, byte 2*SIZEOF_XMMWORD
  224. jb short .column_st16
  225. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  226. movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  227. add rdi, byte 2*SIZEOF_XMMWORD ; outptr
  228. movdqa xmmA, xmmF
  229. sub rcx, byte 2*SIZEOF_XMMWORD
  230. jmp short .column_st15
  231. .column_st16:
  232. cmp rcx, byte SIZEOF_XMMWORD
  233. jb short .column_st15
  234. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  235. add rdi, byte SIZEOF_XMMWORD ; outptr
  236. movdqa xmmA, xmmD
  237. sub rcx, byte SIZEOF_XMMWORD
  238. .column_st15:
  239. ; Store the lower 8 bytes of xmmA to the output when it has enough
  240. ; space.
  241. cmp rcx, byte SIZEOF_MMWORD
  242. jb short .column_st7
  243. movq XMM_MMWORD [rdi], xmmA
  244. add rdi, byte SIZEOF_MMWORD
  245. sub rcx, byte SIZEOF_MMWORD
  246. psrldq xmmA, SIZEOF_MMWORD
  247. .column_st7:
  248. ; Store the lower 4 bytes of xmmA to the output when it has enough
  249. ; space.
  250. cmp rcx, byte SIZEOF_DWORD
  251. jb short .column_st3
  252. movd XMM_DWORD [rdi], xmmA
  253. add rdi, byte SIZEOF_DWORD
  254. sub rcx, byte SIZEOF_DWORD
  255. psrldq xmmA, SIZEOF_DWORD
  256. .column_st3:
  257. ; Store the lower 2 bytes of rax to the output when it has enough
  258. ; space.
  259. movd eax, xmmA
  260. cmp rcx, byte SIZEOF_WORD
  261. jb short .column_st1
  262. mov word [rdi], ax
  263. add rdi, byte SIZEOF_WORD
  264. sub rcx, byte SIZEOF_WORD
  265. shr rax, 16
  266. .column_st1:
  267. ; Store the lower 1 byte of rax to the output when it has enough
  268. ; space.
  269. test rcx, rcx
  270. jz short .endcolumn
  271. mov byte [rdi], al
  272. %else ; RGB_PIXELSIZE == 4 ; -----------
  273. %ifdef RGBX_FILLER_0XFF
  274. pcmpeqb xmm6, xmm6 ; xmm6=XE=X(02468ACE********)
  275. pcmpeqb xmm7, xmm7 ; xmm7=XO=X(13579BDF********)
  276. %else
  277. pxor xmm6, xmm6 ; xmm6=XE=X(02468ACE********)
  278. pxor xmm7, xmm7 ; xmm7=XO=X(13579BDF********)
  279. %endif
  280. ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
  281. ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
  282. ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
  283. ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
  284. punpcklbw xmmA, xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
  285. punpcklbw xmmE, xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
  286. punpcklbw xmmB, xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
  287. punpcklbw xmmF, xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
  288. movdqa xmmC, xmmA
  289. punpcklwd xmmA, xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
  290. punpckhwd xmmC, xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
  291. movdqa xmmG, xmmB
  292. punpcklwd xmmB, xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
  293. punpckhwd xmmG, xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
  294. movdqa xmmD, xmmA
  295. punpckldq xmmA, xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
  296. punpckhdq xmmD, xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
  297. movdqa xmmH, xmmC
  298. punpckldq xmmC, xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
  299. punpckhdq xmmH, xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
  300. cmp rcx, byte SIZEOF_XMMWORD
  301. jb short .column_st32
  302. test rdi, SIZEOF_XMMWORD-1
  303. jnz short .out1
  304. ; --(aligned)-------------------
  305. movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  306. movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  307. movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
  308. movntdq XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
  309. jmp short .out0
  310. .out1: ; --(unaligned)-----------------
  311. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  312. movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  313. movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
  314. movdqu XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
  315. .out0:
  316. add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
  317. sub rcx, byte SIZEOF_XMMWORD
  318. jz near .endcolumn
  319. add rsi, byte SIZEOF_XMMWORD ; inptr0
  320. dec al ; Yctr
  321. jnz near .Yloop_2nd
  322. add rbx, byte SIZEOF_XMMWORD ; inptr1
  323. add rdx, byte SIZEOF_XMMWORD ; inptr2
  324. jmp near .columnloop
  325. .column_st32:
  326. cmp rcx, byte SIZEOF_XMMWORD/2
  327. jb short .column_st16
  328. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  329. movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  330. add rdi, byte 2*SIZEOF_XMMWORD ; outptr
  331. movdqa xmmA, xmmC
  332. movdqa xmmD, xmmH
  333. sub rcx, byte SIZEOF_XMMWORD/2
  334. .column_st16:
  335. cmp rcx, byte SIZEOF_XMMWORD/4
  336. jb short .column_st15
  337. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  338. add rdi, byte SIZEOF_XMMWORD ; outptr
  339. movdqa xmmA, xmmD
  340. sub rcx, byte SIZEOF_XMMWORD/4
  341. .column_st15:
  342. ; Store two pixels (8 bytes) of xmmA to the output when it has enough
  343. ; space.
  344. cmp rcx, byte SIZEOF_XMMWORD/8
  345. jb short .column_st7
  346. movq XMM_MMWORD [rdi], xmmA
  347. add rdi, byte SIZEOF_XMMWORD/8*4
  348. sub rcx, byte SIZEOF_XMMWORD/8
  349. psrldq xmmA, SIZEOF_XMMWORD/8*4
  350. .column_st7:
  351. ; Store one pixel (4 bytes) of xmmA to the output when it has enough
  352. ; space.
  353. test rcx, rcx
  354. jz short .endcolumn
  355. movd XMM_DWORD [rdi], xmmA
  356. %endif ; RGB_PIXELSIZE ; ---------------
  357. .endcolumn:
  358. sfence ; flush the write buffer
  359. .return:
  360. pop rbx
  361. uncollect_args 4
  362. mov rsp, rbp ; rsp <- aligned rbp
  363. pop rsp ; rsp <- original rbp
  364. pop rbp
  365. ret
  366. ; --------------------------------------------------------------------------
  367. ;
  368. ; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
  369. ;
  370. ; GLOBAL(void)
  371. ; jsimd_h2v2_merged_upsample_sse2(JDIMENSION output_width,
  372. ; JSAMPIMAGE input_buf,
  373. ; JDIMENSION in_row_group_ctr,
  374. ; JSAMPARRAY output_buf);
  375. ;
  376. ; r10d = JDIMENSION output_width
  377. ; r11 = JSAMPIMAGE input_buf
  378. ; r12d = JDIMENSION in_row_group_ctr
  379. ; r13 = JSAMPARRAY output_buf
  380. align 32
  381. GLOBAL_FUNCTION(jsimd_h2v2_merged_upsample_sse2)
  382. EXTN(jsimd_h2v2_merged_upsample_sse2):
  383. push rbp
  384. mov rax, rsp
  385. mov rbp, rsp
  386. collect_args 4
  387. push rbx
  388. mov eax, r10d
  389. mov rdi, r11
  390. mov ecx, r12d
  391. mov rsi, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
  392. mov rbx, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
  393. mov rdx, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
  394. mov rdi, r13
  395. lea rsi, [rsi+rcx*SIZEOF_JSAMPROW]
  396. push rdx ; inptr2
  397. push rbx ; inptr1
  398. push rsi ; inptr00
  399. mov rbx, rsp
  400. push rdi
  401. push rcx
  402. push rax
  403. %ifdef WIN64
  404. mov r8, rcx
  405. mov r9, rdi
  406. mov rcx, rax
  407. mov rdx, rbx
  408. %else
  409. mov rdx, rcx
  410. mov rcx, rdi
  411. mov rdi, rax
  412. mov rsi, rbx
  413. %endif
  414. call EXTN(jsimd_h2v1_merged_upsample_sse2)
  415. pop rax
  416. pop rcx
  417. pop rdi
  418. pop rsi
  419. pop rbx
  420. pop rdx
  421. add rdi, byte SIZEOF_JSAMPROW ; outptr1
  422. add rsi, byte SIZEOF_JSAMPROW ; inptr01
  423. push rdx ; inptr2
  424. push rbx ; inptr1
  425. push rsi ; inptr00
  426. mov rbx, rsp
  427. push rdi
  428. push rcx
  429. push rax
  430. %ifdef WIN64
  431. mov r8, rcx
  432. mov r9, rdi
  433. mov rcx, rax
  434. mov rdx, rbx
  435. %else
  436. mov rdx, rcx
  437. mov rcx, rdi
  438. mov rdi, rax
  439. mov rsi, rbx
  440. %endif
  441. call EXTN(jsimd_h2v1_merged_upsample_sse2)
  442. pop rax
  443. pop rcx
  444. pop rdi
  445. pop rsi
  446. pop rbx
  447. pop rdx
  448. pop rbx
  449. uncollect_args 4
  450. pop rbp
  451. ret
  452. ; For some reason, the OS X linker does not honor the request to align the
  453. ; segment unless we do this.
  454. align 32