jdcolext-sse2.asm 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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, 2016, D. R. Commander.
  6. ; Copyright (C) 2018, Matthias Räncker.
  7. ;
  8. ; Based on the x86 SIMD extension for IJG JPEG library
  9. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
  10. ; For conditions of distribution and use, see copyright notice in jsimdext.inc
  11. ;
  12. ; This file should be assembled with NASM (Netwide Assembler),
  13. ; can *not* be assembled with Microsoft's MASM or any compatible
  14. ; assembler (including Borland's Turbo Assembler).
  15. ; NASM is available from http://nasm.sourceforge.net/ or
  16. ; http://sourceforge.net/project/showfiles.php?group_id=6208
  17. %include "jcolsamp.inc"
  18. ; --------------------------------------------------------------------------
  19. ;
  20. ; Convert some rows of samples to the output colorspace.
  21. ;
  22. ; GLOBAL(void)
  23. ; jsimd_ycc_rgb_convert_sse2(JDIMENSION out_width, JSAMPIMAGE input_buf,
  24. ; JDIMENSION input_row, JSAMPARRAY output_buf,
  25. ; int num_rows)
  26. ;
  27. ; r10d = JDIMENSION out_width
  28. ; r11 = JSAMPIMAGE input_buf
  29. ; r12d = JDIMENSION input_row
  30. ; r13 = JSAMPARRAY output_buf
  31. ; r14d = int num_rows
  32. %define wk(i) rbp - (WK_NUM - (i)) * SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
  33. %define WK_NUM 2
  34. align 32
  35. GLOBAL_FUNCTION(jsimd_ycc_rgb_convert_sse2)
  36. EXTN(jsimd_ycc_rgb_convert_sse2):
  37. push rbp
  38. mov rax, rsp ; rax = original rbp
  39. sub rsp, byte 4
  40. and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
  41. mov [rsp], rax
  42. mov rbp, rsp ; rbp = aligned rbp
  43. lea rsp, [wk(0)]
  44. collect_args 5
  45. push rbx
  46. mov ecx, r10d ; num_cols
  47. test rcx, rcx
  48. jz near .return
  49. push rcx
  50. mov rdi, r11
  51. mov ecx, r12d
  52. mov rsip, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
  53. mov rbxp, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
  54. mov rdxp, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
  55. lea rsi, [rsi+rcx*SIZEOF_JSAMPROW]
  56. lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
  57. lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
  58. pop rcx
  59. mov rdi, r13
  60. mov eax, r14d
  61. test rax, rax
  62. jle near .return
  63. .rowloop:
  64. push rax
  65. push rdi
  66. push rdx
  67. push rbx
  68. push rsi
  69. push rcx ; col
  70. mov rsip, JSAMPROW [rsi] ; inptr0
  71. mov rbxp, JSAMPROW [rbx] ; inptr1
  72. mov rdxp, JSAMPROW [rdx] ; inptr2
  73. mov rdip, JSAMPROW [rdi] ; outptr
  74. .columnloop:
  75. movdqa xmm5, XMMWORD [rbx] ; xmm5=Cb(0123456789ABCDEF)
  76. movdqa xmm1, XMMWORD [rdx] ; xmm1=Cr(0123456789ABCDEF)
  77. pcmpeqw xmm4, xmm4
  78. pcmpeqw xmm7, xmm7
  79. psrlw xmm4, BYTE_BIT
  80. psllw xmm7, 7 ; xmm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
  81. movdqa xmm0, xmm4 ; xmm0=xmm4={0xFF 0x00 0xFF 0x00 ..}
  82. pand xmm4, xmm5 ; xmm4=Cb(02468ACE)=CbE
  83. psrlw xmm5, BYTE_BIT ; xmm5=Cb(13579BDF)=CbO
  84. pand xmm0, xmm1 ; xmm0=Cr(02468ACE)=CrE
  85. psrlw xmm1, BYTE_BIT ; xmm1=Cr(13579BDF)=CrO
  86. paddw xmm4, xmm7
  87. paddw xmm5, xmm7
  88. paddw xmm0, xmm7
  89. paddw xmm1, xmm7
  90. ; (Original)
  91. ; R = Y + 1.40200 * Cr
  92. ; G = Y - 0.34414 * Cb - 0.71414 * Cr
  93. ; B = Y + 1.77200 * Cb
  94. ;
  95. ; (This implementation)
  96. ; R = Y + 0.40200 * Cr + Cr
  97. ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
  98. ; B = Y - 0.22800 * Cb + Cb + Cb
  99. movdqa xmm2, xmm4 ; xmm2=CbE
  100. movdqa xmm3, xmm5 ; xmm3=CbO
  101. paddw xmm4, xmm4 ; xmm4=2*CbE
  102. paddw xmm5, xmm5 ; xmm5=2*CbO
  103. movdqa xmm6, xmm0 ; xmm6=CrE
  104. movdqa xmm7, xmm1 ; xmm7=CrO
  105. paddw xmm0, xmm0 ; xmm0=2*CrE
  106. paddw xmm1, xmm1 ; xmm1=2*CrO
  107. pmulhw xmm4, [rel PW_MF0228] ; xmm4=(2*CbE * -FIX(0.22800))
  108. pmulhw xmm5, [rel PW_MF0228] ; xmm5=(2*CbO * -FIX(0.22800))
  109. pmulhw xmm0, [rel PW_F0402] ; xmm0=(2*CrE * FIX(0.40200))
  110. pmulhw xmm1, [rel PW_F0402] ; xmm1=(2*CrO * FIX(0.40200))
  111. paddw xmm4, [rel PW_ONE]
  112. paddw xmm5, [rel PW_ONE]
  113. psraw xmm4, 1 ; xmm4=(CbE * -FIX(0.22800))
  114. psraw xmm5, 1 ; xmm5=(CbO * -FIX(0.22800))
  115. paddw xmm0, [rel PW_ONE]
  116. paddw xmm1, [rel PW_ONE]
  117. psraw xmm0, 1 ; xmm0=(CrE * FIX(0.40200))
  118. psraw xmm1, 1 ; xmm1=(CrO * FIX(0.40200))
  119. paddw xmm4, xmm2
  120. paddw xmm5, xmm3
  121. paddw xmm4, xmm2 ; xmm4=(CbE * FIX(1.77200))=(B-Y)E
  122. paddw xmm5, xmm3 ; xmm5=(CbO * FIX(1.77200))=(B-Y)O
  123. paddw xmm0, xmm6 ; xmm0=(CrE * FIX(1.40200))=(R-Y)E
  124. paddw xmm1, xmm7 ; xmm1=(CrO * FIX(1.40200))=(R-Y)O
  125. movdqa XMMWORD [wk(0)], xmm4 ; wk(0)=(B-Y)E
  126. movdqa XMMWORD [wk(1)], xmm5 ; wk(1)=(B-Y)O
  127. movdqa xmm4, xmm2
  128. movdqa xmm5, xmm3
  129. punpcklwd xmm2, xmm6
  130. punpckhwd xmm4, xmm6
  131. pmaddwd xmm2, [rel PW_MF0344_F0285]
  132. pmaddwd xmm4, [rel PW_MF0344_F0285]
  133. punpcklwd xmm3, xmm7
  134. punpckhwd xmm5, xmm7
  135. pmaddwd xmm3, [rel PW_MF0344_F0285]
  136. pmaddwd xmm5, [rel PW_MF0344_F0285]
  137. paddd xmm2, [rel PD_ONEHALF]
  138. paddd xmm4, [rel PD_ONEHALF]
  139. psrad xmm2, SCALEBITS
  140. psrad xmm4, SCALEBITS
  141. paddd xmm3, [rel PD_ONEHALF]
  142. paddd xmm5, [rel PD_ONEHALF]
  143. psrad xmm3, SCALEBITS
  144. psrad xmm5, SCALEBITS
  145. packssdw xmm2, xmm4 ; xmm2=CbE*-FIX(0.344)+CrE*FIX(0.285)
  146. packssdw xmm3, xmm5 ; xmm3=CbO*-FIX(0.344)+CrO*FIX(0.285)
  147. psubw xmm2, xmm6 ; xmm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E
  148. psubw xmm3, xmm7 ; xmm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O
  149. movdqa xmm5, XMMWORD [rsi] ; xmm5=Y(0123456789ABCDEF)
  150. pcmpeqw xmm4, xmm4
  151. psrlw xmm4, BYTE_BIT ; xmm4={0xFF 0x00 0xFF 0x00 ..}
  152. pand xmm4, xmm5 ; xmm4=Y(02468ACE)=YE
  153. psrlw xmm5, BYTE_BIT ; xmm5=Y(13579BDF)=YO
  154. paddw xmm0, xmm4 ; xmm0=((R-Y)E+YE)=RE=R(02468ACE)
  155. paddw xmm1, xmm5 ; xmm1=((R-Y)O+YO)=RO=R(13579BDF)
  156. packuswb xmm0, xmm0 ; xmm0=R(02468ACE********)
  157. packuswb xmm1, xmm1 ; xmm1=R(13579BDF********)
  158. paddw xmm2, xmm4 ; xmm2=((G-Y)E+YE)=GE=G(02468ACE)
  159. paddw xmm3, xmm5 ; xmm3=((G-Y)O+YO)=GO=G(13579BDF)
  160. packuswb xmm2, xmm2 ; xmm2=G(02468ACE********)
  161. packuswb xmm3, xmm3 ; xmm3=G(13579BDF********)
  162. paddw xmm4, XMMWORD [wk(0)] ; xmm4=(YE+(B-Y)E)=BE=B(02468ACE)
  163. paddw xmm5, XMMWORD [wk(1)] ; xmm5=(YO+(B-Y)O)=BO=B(13579BDF)
  164. packuswb xmm4, xmm4 ; xmm4=B(02468ACE********)
  165. packuswb xmm5, xmm5 ; xmm5=B(13579BDF********)
  166. %if RGB_PIXELSIZE == 3 ; ---------------
  167. ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
  168. ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
  169. ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
  170. ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
  171. punpcklbw xmmA, xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
  172. punpcklbw xmmE, xmmB ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
  173. punpcklbw xmmD, xmmF ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
  174. movdqa xmmG, xmmA
  175. movdqa xmmH, xmmA
  176. punpcklwd xmmA, xmmE ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
  177. punpckhwd xmmG, xmmE ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
  178. psrldq xmmH, 2 ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
  179. psrldq xmmE, 2 ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
  180. movdqa xmmC, xmmD
  181. movdqa xmmB, xmmD
  182. punpcklwd xmmD, xmmH ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
  183. punpckhwd xmmC, xmmH ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
  184. psrldq xmmB, 2 ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
  185. movdqa xmmF, xmmE
  186. punpcklwd xmmE, xmmB ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
  187. punpckhwd xmmF, xmmB ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
  188. pshufd xmmH, xmmA, 0x4E ; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
  189. movdqa xmmB, xmmE
  190. punpckldq xmmA, xmmD ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
  191. punpckldq xmmE, xmmH ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
  192. punpckhdq xmmD, xmmB ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
  193. pshufd xmmH, xmmG, 0x4E ; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
  194. movdqa xmmB, xmmF
  195. punpckldq xmmG, xmmC ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
  196. punpckldq xmmF, xmmH ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
  197. punpckhdq xmmC, xmmB ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
  198. punpcklqdq xmmA, xmmE ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
  199. punpcklqdq xmmD, xmmG ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
  200. punpcklqdq xmmF, xmmC ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
  201. cmp rcx, byte SIZEOF_XMMWORD
  202. jb short .column_st32
  203. test rdi, SIZEOF_XMMWORD-1
  204. jnz short .out1
  205. ; --(aligned)-------------------
  206. movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  207. movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  208. movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
  209. jmp short .out0
  210. .out1: ; --(unaligned)-----------------
  211. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  212. movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  213. movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
  214. .out0:
  215. add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
  216. sub rcx, byte SIZEOF_XMMWORD
  217. jz near .nextrow
  218. add rsi, byte SIZEOF_XMMWORD ; inptr0
  219. add rbx, byte SIZEOF_XMMWORD ; inptr1
  220. add rdx, byte SIZEOF_XMMWORD ; inptr2
  221. jmp near .columnloop
  222. .column_st32:
  223. lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE
  224. cmp rcx, byte 2*SIZEOF_XMMWORD
  225. jb short .column_st16
  226. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  227. movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  228. add rdi, byte 2*SIZEOF_XMMWORD ; outptr
  229. movdqa xmmA, xmmF
  230. sub rcx, byte 2*SIZEOF_XMMWORD
  231. jmp short .column_st15
  232. .column_st16:
  233. cmp rcx, byte SIZEOF_XMMWORD
  234. jb short .column_st15
  235. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  236. add rdi, byte SIZEOF_XMMWORD ; outptr
  237. movdqa xmmA, xmmD
  238. sub rcx, byte SIZEOF_XMMWORD
  239. .column_st15:
  240. ; Store the lower 8 bytes of xmmA to the output when it has enough
  241. ; space.
  242. cmp rcx, byte SIZEOF_MMWORD
  243. jb short .column_st7
  244. movq XMM_MMWORD [rdi], xmmA
  245. add rdi, byte SIZEOF_MMWORD
  246. sub rcx, byte SIZEOF_MMWORD
  247. psrldq xmmA, SIZEOF_MMWORD
  248. .column_st7:
  249. ; Store the lower 4 bytes of xmmA to the output when it has enough
  250. ; space.
  251. cmp rcx, byte SIZEOF_DWORD
  252. jb short .column_st3
  253. movd XMM_DWORD [rdi], xmmA
  254. add rdi, byte SIZEOF_DWORD
  255. sub rcx, byte SIZEOF_DWORD
  256. psrldq xmmA, SIZEOF_DWORD
  257. .column_st3:
  258. ; Store the lower 2 bytes of rax to the output when it has enough
  259. ; space.
  260. movd eax, xmmA
  261. cmp rcx, byte SIZEOF_WORD
  262. jb short .column_st1
  263. mov word [rdi], ax
  264. add rdi, byte SIZEOF_WORD
  265. sub rcx, byte SIZEOF_WORD
  266. shr rax, 16
  267. .column_st1:
  268. ; Store the lower 1 byte of rax to the output when it has enough
  269. ; space.
  270. test rcx, rcx
  271. jz short .nextrow
  272. mov byte [rdi], al
  273. %else ; RGB_PIXELSIZE == 4 ; -----------
  274. %ifdef RGBX_FILLER_0XFF
  275. pcmpeqb xmm6, xmm6 ; xmm6=XE=X(02468ACE********)
  276. pcmpeqb xmm7, xmm7 ; xmm7=XO=X(13579BDF********)
  277. %else
  278. pxor xmm6, xmm6 ; xmm6=XE=X(02468ACE********)
  279. pxor xmm7, xmm7 ; xmm7=XO=X(13579BDF********)
  280. %endif
  281. ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
  282. ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
  283. ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
  284. ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
  285. punpcklbw xmmA, xmmC ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
  286. punpcklbw xmmE, xmmG ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
  287. punpcklbw xmmB, xmmD ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
  288. punpcklbw xmmF, xmmH ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
  289. movdqa xmmC, xmmA
  290. punpcklwd xmmA, xmmE ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
  291. punpckhwd xmmC, xmmE ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
  292. movdqa xmmG, xmmB
  293. punpcklwd xmmB, xmmF ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
  294. punpckhwd xmmG, xmmF ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
  295. movdqa xmmD, xmmA
  296. punpckldq xmmA, xmmB ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
  297. punpckhdq xmmD, xmmB ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
  298. movdqa xmmH, xmmC
  299. punpckldq xmmC, xmmG ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
  300. punpckhdq xmmH, xmmG ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
  301. cmp rcx, byte SIZEOF_XMMWORD
  302. jb short .column_st32
  303. test rdi, SIZEOF_XMMWORD-1
  304. jnz short .out1
  305. ; --(aligned)-------------------
  306. movntdq XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  307. movntdq XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  308. movntdq XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
  309. movntdq XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
  310. jmp short .out0
  311. .out1: ; --(unaligned)-----------------
  312. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  313. movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  314. movdqu XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
  315. movdqu XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
  316. .out0:
  317. add rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; outptr
  318. sub rcx, byte SIZEOF_XMMWORD
  319. jz near .nextrow
  320. add rsi, byte SIZEOF_XMMWORD ; inptr0
  321. add rbx, byte SIZEOF_XMMWORD ; inptr1
  322. add rdx, byte SIZEOF_XMMWORD ; inptr2
  323. jmp near .columnloop
  324. .column_st32:
  325. cmp rcx, byte SIZEOF_XMMWORD/2
  326. jb short .column_st16
  327. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  328. movdqu XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
  329. add rdi, byte 2*SIZEOF_XMMWORD ; outptr
  330. movdqa xmmA, xmmC
  331. movdqa xmmD, xmmH
  332. sub rcx, byte SIZEOF_XMMWORD/2
  333. .column_st16:
  334. cmp rcx, byte SIZEOF_XMMWORD/4
  335. jb short .column_st15
  336. movdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
  337. add rdi, byte SIZEOF_XMMWORD ; outptr
  338. movdqa xmmA, xmmD
  339. sub rcx, byte SIZEOF_XMMWORD/4
  340. .column_st15:
  341. ; Store two pixels (8 bytes) of xmmA to the output when it has enough
  342. ; space.
  343. cmp rcx, byte SIZEOF_XMMWORD/8
  344. jb short .column_st7
  345. movq MMWORD [rdi], xmmA
  346. add rdi, byte SIZEOF_XMMWORD/8*4
  347. sub rcx, byte SIZEOF_XMMWORD/8
  348. psrldq xmmA, SIZEOF_XMMWORD/8*4
  349. .column_st7:
  350. ; Store one pixel (4 bytes) of xmmA to the output when it has enough
  351. ; space.
  352. test rcx, rcx
  353. jz short .nextrow
  354. movd XMM_DWORD [rdi], xmmA
  355. %endif ; RGB_PIXELSIZE ; ---------------
  356. .nextrow:
  357. pop rcx
  358. pop rsi
  359. pop rbx
  360. pop rdx
  361. pop rdi
  362. pop rax
  363. add rsi, byte SIZEOF_JSAMPROW
  364. add rbx, byte SIZEOF_JSAMPROW
  365. add rdx, byte SIZEOF_JSAMPROW
  366. add rdi, byte SIZEOF_JSAMPROW ; output_buf
  367. dec rax ; num_rows
  368. jg near .rowloop
  369. sfence ; flush the write buffer
  370. .return:
  371. pop rbx
  372. uncollect_args 5
  373. mov rsp, rbp ; rsp <- aligned rbp
  374. pop rsp ; rsp <- original rbp
  375. pop rbp
  376. ret
  377. ; For some reason, the OS X linker does not honor the request to align the
  378. ; segment unless we do this.
  379. align 32