jdcolext-sse2.asm 18 KB

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