jdmrgext-sse2-64.asm 20 KB

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