jdcolext-sse2.asm 17 KB

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