jdmrgext-sse2.asm 21 KB

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