jdcolext-sse2-64.asm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. ;
  2. ; jdcolext.asm - colorspace 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. ; 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. ; r10 = JDIMENSION out_width
  29. ; r11 = JSAMPIMAGE input_buf
  30. ; r12 = JDIMENSION input_row
  31. ; r13 = JSAMPARRAY output_buf
  32. ; r14 = int num_rows
  33. %define wk(i) rbp-(WK_NUM-(i))*SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
  34. %define WK_NUM 2
  35. align 16
  36. global EXTN(jsimd_ycc_rgb_convert_sse2)
  37. EXTN(jsimd_ycc_rgb_convert_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 ; num_cols
  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. lea rsi, [rsi+rcx*SIZEOF_JSAMPROW]
  57. lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
  58. lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
  59. pop rcx
  60. mov rdi, r13
  61. mov eax, r14d
  62. test rax,rax
  63. jle near .return
  64. .rowloop:
  65. push rax
  66. push rdi
  67. push rdx
  68. push rbx
  69. push rsi
  70. push rcx ; col
  71. mov rsi, JSAMPROW [rsi] ; inptr0
  72. mov rbx, JSAMPROW [rbx] ; inptr1
  73. mov rdx, JSAMPROW [rdx] ; inptr2
  74. mov rdi, JSAMPROW [rdi] ; outptr
  75. .columnloop:
  76. movdqa xmm5, XMMWORD [rbx] ; xmm5=Cb(0123456789ABCDEF)
  77. movdqa xmm1, XMMWORD [rdx] ; xmm1=Cr(0123456789ABCDEF)
  78. pcmpeqw xmm4,xmm4
  79. pcmpeqw xmm7,xmm7
  80. psrlw xmm4,BYTE_BIT
  81. psllw xmm7,7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
  82. movdqa xmm0,xmm4 ; xmm0=xmm4={0xFF 0x00 0xFF 0x00 ..}
  83. pand xmm4,xmm5 ; xmm4=Cb(02468ACE)=CbE
  84. psrlw xmm5,BYTE_BIT ; xmm5=Cb(13579BDF)=CbO
  85. pand xmm0,xmm1 ; xmm0=Cr(02468ACE)=CrE
  86. psrlw xmm1,BYTE_BIT ; xmm1=Cr(13579BDF)=CrO
  87. paddw xmm4,xmm7
  88. paddw xmm5,xmm7
  89. paddw xmm0,xmm7
  90. paddw xmm1,xmm7
  91. ; (Original)
  92. ; R = Y + 1.40200 * Cr
  93. ; G = Y - 0.34414 * Cb - 0.71414 * Cr
  94. ; B = Y + 1.77200 * Cb
  95. ;
  96. ; (This implementation)
  97. ; R = Y + 0.40200 * Cr + Cr
  98. ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
  99. ; B = Y - 0.22800 * Cb + Cb + Cb
  100. movdqa xmm2,xmm4 ; xmm2=CbE
  101. movdqa xmm3,xmm5 ; xmm3=CbO
  102. paddw xmm4,xmm4 ; xmm4=2*CbE
  103. paddw xmm5,xmm5 ; xmm5=2*CbO
  104. movdqa xmm6,xmm0 ; xmm6=CrE
  105. movdqa xmm7,xmm1 ; xmm7=CrO
  106. paddw xmm0,xmm0 ; xmm0=2*CrE
  107. paddw xmm1,xmm1 ; xmm1=2*CrO
  108. pmulhw xmm4,[rel PW_MF0228] ; xmm4=(2*CbE * -FIX(0.22800))
  109. pmulhw xmm5,[rel PW_MF0228] ; xmm5=(2*CbO * -FIX(0.22800))
  110. pmulhw xmm0,[rel PW_F0402] ; xmm0=(2*CrE * FIX(0.40200))
  111. pmulhw xmm1,[rel PW_F0402] ; xmm1=(2*CrO * FIX(0.40200))
  112. paddw xmm4,[rel PW_ONE]
  113. paddw xmm5,[rel PW_ONE]
  114. psraw xmm4,1 ; xmm4=(CbE * -FIX(0.22800))
  115. psraw xmm5,1 ; xmm5=(CbO * -FIX(0.22800))
  116. paddw xmm0,[rel PW_ONE]
  117. paddw xmm1,[rel PW_ONE]
  118. psraw xmm0,1 ; xmm0=(CrE * FIX(0.40200))
  119. psraw xmm1,1 ; xmm1=(CrO * FIX(0.40200))
  120. paddw xmm4,xmm2
  121. paddw xmm5,xmm3
  122. paddw xmm4,xmm2 ; xmm4=(CbE * FIX(1.77200))=(B-Y)E
  123. paddw xmm5,xmm3 ; xmm5=(CbO * FIX(1.77200))=(B-Y)O
  124. paddw xmm0,xmm6 ; xmm0=(CrE * FIX(1.40200))=(R-Y)E
  125. paddw xmm1,xmm7 ; xmm1=(CrO * FIX(1.40200))=(R-Y)O
  126. movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=(B-Y)E
  127. movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(B-Y)O
  128. movdqa xmm4,xmm2
  129. movdqa xmm5,xmm3
  130. punpcklwd xmm2,xmm6
  131. punpckhwd xmm4,xmm6
  132. pmaddwd xmm2,[rel PW_MF0344_F0285]
  133. pmaddwd xmm4,[rel PW_MF0344_F0285]
  134. punpcklwd xmm3,xmm7
  135. punpckhwd xmm5,xmm7
  136. pmaddwd xmm3,[rel PW_MF0344_F0285]
  137. pmaddwd xmm5,[rel PW_MF0344_F0285]
  138. paddd xmm2,[rel PD_ONEHALF]
  139. paddd xmm4,[rel PD_ONEHALF]
  140. psrad xmm2,SCALEBITS
  141. psrad xmm4,SCALEBITS
  142. paddd xmm3,[rel PD_ONEHALF]
  143. paddd xmm5,[rel PD_ONEHALF]
  144. psrad xmm3,SCALEBITS
  145. psrad xmm5,SCALEBITS
  146. packssdw xmm2,xmm4 ; xmm2=CbE*-FIX(0.344)+CrE*FIX(0.285)
  147. packssdw xmm3,xmm5 ; xmm3=CbO*-FIX(0.344)+CrO*FIX(0.285)
  148. psubw xmm2,xmm6 ; xmm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E
  149. psubw xmm3,xmm7 ; xmm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O
  150. movdqa xmm5, XMMWORD [rsi] ; xmm5=Y(0123456789ABCDEF)
  151. pcmpeqw xmm4,xmm4
  152. psrlw xmm4,BYTE_BIT ; xmm4={0xFF 0x00 0xFF 0x00 ..}
  153. pand xmm4,xmm5 ; xmm4=Y(02468ACE)=YE
  154. psrlw xmm5,BYTE_BIT ; xmm5=Y(13579BDF)=YO
  155. paddw xmm0,xmm4 ; xmm0=((R-Y)E+YE)=RE=R(02468ACE)
  156. paddw xmm1,xmm5 ; xmm1=((R-Y)O+YO)=RO=R(13579BDF)
  157. packuswb xmm0,xmm0 ; xmm0=R(02468ACE********)
  158. packuswb xmm1,xmm1 ; xmm1=R(13579BDF********)
  159. paddw xmm2,xmm4 ; xmm2=((G-Y)E+YE)=GE=G(02468ACE)
  160. paddw xmm3,xmm5 ; xmm3=((G-Y)O+YO)=GO=G(13579BDF)
  161. packuswb xmm2,xmm2 ; xmm2=G(02468ACE********)
  162. packuswb xmm3,xmm3 ; xmm3=G(13579BDF********)
  163. paddw xmm4, XMMWORD [wk(0)] ; xmm4=(YE+(B-Y)E)=BE=B(02468ACE)
  164. paddw xmm5, XMMWORD [wk(1)] ; xmm5=(YO+(B-Y)O)=BO=B(13579BDF)
  165. packuswb xmm4,xmm4 ; xmm4=B(02468ACE********)
  166. packuswb xmm5,xmm5 ; xmm5=B(13579BDF********)
  167. %if RGB_PIXELSIZE == 3 ; ---------------
  168. ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
  169. ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
  170. ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
  171. ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
  172. punpcklbw xmmA,xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
  173. punpcklbw xmmE,xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
  174. punpcklbw xmmD,xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
  175. movdqa xmmG,xmmA
  176. movdqa xmmH,xmmA
  177. punpcklwd xmmA,xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
  178. punpckhwd xmmG,xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
  179. psrldq xmmH,2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
  180. psrldq xmmE,2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
  181. movdqa xmmC,xmmD
  182. movdqa xmmB,xmmD
  183. punpcklwd xmmD,xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
  184. punpckhwd xmmC,xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
  185. psrldq xmmB,2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
  186. movdqa xmmF,xmmE
  187. punpcklwd xmmE,xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
  188. punpckhwd xmmF,xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
  189. pshufd xmmH,xmmA,0x4E; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
  190. movdqa xmmB,xmmE
  191. punpckldq xmmA,xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
  192. punpckldq xmmE,xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
  193. punpckhdq xmmD,xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
  194. pshufd xmmH,xmmG,0x4E; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
  195. movdqa xmmB,xmmF
  196. punpckldq xmmG,xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
  197. punpckldq xmmF,xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
  198. punpckhdq xmmC,xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
  199. punpcklqdq xmmA,xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
  200. punpcklqdq xmmD,xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
  201. punpcklqdq xmmF,xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
  202. cmp rcx, byte SIZEOF_XMMWORD
  203. jb short .column_st32
  204. test rdi, SIZEOF_XMMWORD-1
  205. jnz short .out1
  206. ; --(aligned)-------------------
  207. movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  208. movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  209. movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
  210. jmp short .out0
  211. .out1: ; --(unaligned)-----------------
  212. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  213. movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  214. movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
  215. .out0:
  216. add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
  217. sub rcx, byte SIZEOF_XMMWORD
  218. jz near .nextrow
  219. add rsi, byte SIZEOF_XMMWORD ; inptr0
  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 .nextrow
  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 .nextrow
  321. add rsi, byte SIZEOF_XMMWORD ; inptr0
  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 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 .nextrow
  355. movd XMM_DWORD [rdi], xmmA
  356. %endif ; RGB_PIXELSIZE ; ---------------
  357. .nextrow:
  358. pop rcx
  359. pop rsi
  360. pop rbx
  361. pop rdx
  362. pop rdi
  363. pop rax
  364. add rsi, byte SIZEOF_JSAMPROW
  365. add rbx, byte SIZEOF_JSAMPROW
  366. add rdx, byte SIZEOF_JSAMPROW
  367. add rdi, byte SIZEOF_JSAMPROW ; output_buf
  368. dec rax ; num_rows
  369. jg near .rowloop
  370. sfence ; flush the write buffer
  371. .return:
  372. pop rbx
  373. uncollect_args
  374. mov rsp,rbp ; rsp <- aligned rbp
  375. pop rsp ; rsp <- original rbp
  376. pop rbp
  377. ret
  378. ; For some reason, the OS X linker does not honor the request to align the
  379. ; segment unless we do this.
  380. align 16