jccolext-sse2.asm 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. ;
  2. ; jccolext.asm - colorspace conversion (64-bit SSE2)
  3. ;
  4. ; Copyright (C) 2009, 2016, D. R. Commander.
  5. ;
  6. ; Based on the x86 SIMD extension for IJG JPEG library
  7. ; Copyright (C) 1999-2006, MIYASAKA Masaru.
  8. ; For conditions of distribution and use, see copyright notice in jsimdext.inc
  9. ;
  10. ; This file should be assembled with NASM (Netwide Assembler),
  11. ; can *not* be assembled with Microsoft's MASM or any compatible
  12. ; assembler (including Borland's Turbo Assembler).
  13. ; NASM is available from http://nasm.sourceforge.net/ or
  14. ; http://sourceforge.net/project/showfiles.php?group_id=6208
  15. %include "jcolsamp.inc"
  16. ; --------------------------------------------------------------------------
  17. ;
  18. ; Convert some rows of samples to the output colorspace.
  19. ;
  20. ; GLOBAL(void)
  21. ; jsimd_rgb_ycc_convert_sse2(JDIMENSION img_width, JSAMPARRAY input_buf,
  22. ; JSAMPIMAGE output_buf, JDIMENSION output_row,
  23. ; int num_rows);
  24. ;
  25. ; r10d = JDIMENSION img_width
  26. ; r11 = JSAMPARRAY input_buf
  27. ; r12 = JSAMPIMAGE output_buf
  28. ; r13d = JDIMENSION output_row
  29. ; r14d = int num_rows
  30. %define wk(i) rbp - (WK_NUM - (i)) * SIZEOF_XMMWORD ; xmmword wk[WK_NUM]
  31. %define WK_NUM 8
  32. align 32
  33. GLOBAL_FUNCTION(jsimd_rgb_ycc_convert_sse2)
  34. EXTN(jsimd_rgb_ycc_convert_sse2):
  35. push rbp
  36. mov rax, rsp ; rax = original rbp
  37. sub rsp, byte 4
  38. and rsp, byte (-SIZEOF_XMMWORD) ; align to 128 bits
  39. mov [rsp], rax
  40. mov rbp, rsp ; rbp = aligned rbp
  41. lea rsp, [wk(0)]
  42. collect_args 5
  43. push rbx
  44. mov ecx, r10d
  45. test rcx, rcx
  46. jz near .return
  47. push rcx
  48. mov rsi, r12
  49. mov ecx, r13d
  50. mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
  51. mov rbx, JSAMPARRAY [rsi+1*SIZEOF_JSAMPARRAY]
  52. mov rdx, JSAMPARRAY [rsi+2*SIZEOF_JSAMPARRAY]
  53. lea rdi, [rdi+rcx*SIZEOF_JSAMPROW]
  54. lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
  55. lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
  56. pop rcx
  57. mov rsi, r11
  58. mov eax, r14d
  59. test rax, rax
  60. jle near .return
  61. .rowloop:
  62. push rdx
  63. push rbx
  64. push rdi
  65. push rsi
  66. push rcx ; col
  67. mov rsi, JSAMPROW [rsi] ; inptr
  68. mov rdi, JSAMPROW [rdi] ; outptr0
  69. mov rbx, JSAMPROW [rbx] ; outptr1
  70. mov rdx, JSAMPROW [rdx] ; outptr2
  71. cmp rcx, byte SIZEOF_XMMWORD
  72. jae near .columnloop
  73. %if RGB_PIXELSIZE == 3 ; ---------------
  74. .column_ld1:
  75. push rax
  76. push rdx
  77. lea rcx, [rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE
  78. test cl, SIZEOF_BYTE
  79. jz short .column_ld2
  80. sub rcx, byte SIZEOF_BYTE
  81. movzx rax, byte [rsi+rcx]
  82. .column_ld2:
  83. test cl, SIZEOF_WORD
  84. jz short .column_ld4
  85. sub rcx, byte SIZEOF_WORD
  86. movzx rdx, word [rsi+rcx]
  87. shl rax, WORD_BIT
  88. or rax, rdx
  89. .column_ld4:
  90. movd xmmA, eax
  91. pop rdx
  92. pop rax
  93. test cl, SIZEOF_DWORD
  94. jz short .column_ld8
  95. sub rcx, byte SIZEOF_DWORD
  96. movd xmmF, XMM_DWORD [rsi+rcx]
  97. pslldq xmmA, SIZEOF_DWORD
  98. por xmmA, xmmF
  99. .column_ld8:
  100. test cl, SIZEOF_MMWORD
  101. jz short .column_ld16
  102. sub rcx, byte SIZEOF_MMWORD
  103. movq xmmB, XMM_MMWORD [rsi+rcx]
  104. pslldq xmmA, SIZEOF_MMWORD
  105. por xmmA, xmmB
  106. .column_ld16:
  107. test cl, SIZEOF_XMMWORD
  108. jz short .column_ld32
  109. movdqa xmmF, xmmA
  110. movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
  111. mov rcx, SIZEOF_XMMWORD
  112. jmp short .rgb_ycc_cnv
  113. .column_ld32:
  114. test cl, 2*SIZEOF_XMMWORD
  115. mov rcx, SIZEOF_XMMWORD
  116. jz short .rgb_ycc_cnv
  117. movdqa xmmB, xmmA
  118. movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
  119. movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
  120. jmp short .rgb_ycc_cnv
  121. .columnloop:
  122. movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
  123. movdqu xmmF, XMMWORD [rsi+1*SIZEOF_XMMWORD]
  124. movdqu xmmB, XMMWORD [rsi+2*SIZEOF_XMMWORD]
  125. .rgb_ycc_cnv:
  126. ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
  127. ; xmmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
  128. ; xmmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
  129. movdqa xmmG, xmmA
  130. pslldq xmmA, 8 ; xmmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12)
  131. psrldq xmmG, 8 ; xmmG=(22 03 13 23 04 14 24 05 -- -- -- -- -- -- -- --)
  132. punpckhbw xmmA, xmmF ; xmmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A)
  133. pslldq xmmF, 8 ; xmmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27)
  134. punpcklbw xmmG, xmmB ; xmmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D)
  135. punpckhbw xmmF, xmmB ; xmmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F)
  136. movdqa xmmD, xmmA
  137. pslldq xmmA, 8 ; xmmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09)
  138. psrldq xmmD, 8 ; xmmD=(11 19 21 29 02 0A 12 1A -- -- -- -- -- -- -- --)
  139. punpckhbw xmmA, xmmG ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D)
  140. pslldq xmmG, 8 ; xmmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B)
  141. punpcklbw xmmD, xmmF ; xmmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E)
  142. punpckhbw xmmG, xmmF ; xmmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F)
  143. movdqa xmmE, xmmA
  144. pslldq xmmA, 8 ; xmmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C)
  145. psrldq xmmE, 8 ; xmmE=(20 24 28 2C 01 05 09 0D -- -- -- -- -- -- -- --)
  146. punpckhbw xmmA, xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
  147. pslldq xmmD, 8 ; xmmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D)
  148. punpcklbw xmmE, xmmG ; xmmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F)
  149. punpckhbw xmmD, xmmG ; xmmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F)
  150. pxor xmmH, xmmH
  151. movdqa xmmC, xmmA
  152. punpcklbw xmmA, xmmH ; xmmA=(00 02 04 06 08 0A 0C 0E)
  153. punpckhbw xmmC, xmmH ; xmmC=(10 12 14 16 18 1A 1C 1E)
  154. movdqa xmmB, xmmE
  155. punpcklbw xmmE, xmmH ; xmmE=(20 22 24 26 28 2A 2C 2E)
  156. punpckhbw xmmB, xmmH ; xmmB=(01 03 05 07 09 0B 0D 0F)
  157. movdqa xmmF, xmmD
  158. punpcklbw xmmD, xmmH ; xmmD=(11 13 15 17 19 1B 1D 1F)
  159. punpckhbw xmmF, xmmH ; xmmF=(21 23 25 27 29 2B 2D 2F)
  160. %else ; RGB_PIXELSIZE == 4 ; -----------
  161. .column_ld1:
  162. test cl, SIZEOF_XMMWORD/16
  163. jz short .column_ld2
  164. sub rcx, byte SIZEOF_XMMWORD/16
  165. movd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE]
  166. .column_ld2:
  167. test cl, SIZEOF_XMMWORD/8
  168. jz short .column_ld4
  169. sub rcx, byte SIZEOF_XMMWORD/8
  170. movq xmmE, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE]
  171. pslldq xmmA, SIZEOF_MMWORD
  172. por xmmA, xmmE
  173. .column_ld4:
  174. test cl, SIZEOF_XMMWORD/4
  175. jz short .column_ld8
  176. sub rcx, byte SIZEOF_XMMWORD/4
  177. movdqa xmmE, xmmA
  178. movdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
  179. .column_ld8:
  180. test cl, SIZEOF_XMMWORD/2
  181. mov rcx, SIZEOF_XMMWORD
  182. jz short .rgb_ycc_cnv
  183. movdqa xmmF, xmmA
  184. movdqa xmmH, xmmE
  185. movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
  186. movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
  187. jmp short .rgb_ycc_cnv
  188. .columnloop:
  189. movdqu xmmA, XMMWORD [rsi+0*SIZEOF_XMMWORD]
  190. movdqu xmmE, XMMWORD [rsi+1*SIZEOF_XMMWORD]
  191. movdqu xmmF, XMMWORD [rsi+2*SIZEOF_XMMWORD]
  192. movdqu xmmH, XMMWORD [rsi+3*SIZEOF_XMMWORD]
  193. .rgb_ycc_cnv:
  194. ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
  195. ; xmmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
  196. ; xmmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
  197. ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
  198. movdqa xmmD, xmmA
  199. punpcklbw xmmA, xmmE ; xmmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35)
  200. punpckhbw xmmD, xmmE ; xmmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37)
  201. movdqa xmmC, xmmF
  202. punpcklbw xmmF, xmmH ; xmmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D)
  203. punpckhbw xmmC, xmmH ; xmmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F)
  204. movdqa xmmB, xmmA
  205. punpcklwd xmmA, xmmF ; xmmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C)
  206. punpckhwd xmmB, xmmF ; xmmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D)
  207. movdqa xmmG, xmmD
  208. punpcklwd xmmD, xmmC ; xmmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E)
  209. punpckhwd xmmG, xmmC ; xmmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F)
  210. movdqa xmmE, xmmA
  211. punpcklbw xmmA, xmmD ; xmmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E)
  212. punpckhbw xmmE, xmmD ; xmmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E)
  213. movdqa xmmH, xmmB
  214. punpcklbw xmmB, xmmG ; xmmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F)
  215. punpckhbw xmmH, xmmG ; xmmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F)
  216. pxor xmmF, xmmF
  217. movdqa xmmC, xmmA
  218. punpcklbw xmmA, xmmF ; xmmA=(00 02 04 06 08 0A 0C 0E)
  219. punpckhbw xmmC, xmmF ; xmmC=(10 12 14 16 18 1A 1C 1E)
  220. movdqa xmmD, xmmB
  221. punpcklbw xmmB, xmmF ; xmmB=(01 03 05 07 09 0B 0D 0F)
  222. punpckhbw xmmD, xmmF ; xmmD=(11 13 15 17 19 1B 1D 1F)
  223. movdqa xmmG, xmmE
  224. punpcklbw xmmE, xmmF ; xmmE=(20 22 24 26 28 2A 2C 2E)
  225. punpckhbw xmmG, xmmF ; xmmG=(30 32 34 36 38 3A 3C 3E)
  226. punpcklbw xmmF, xmmH
  227. punpckhbw xmmH, xmmH
  228. psrlw xmmF, BYTE_BIT ; xmmF=(21 23 25 27 29 2B 2D 2F)
  229. psrlw xmmH, BYTE_BIT ; xmmH=(31 33 35 37 39 3B 3D 3F)
  230. %endif ; RGB_PIXELSIZE ; ---------------
  231. ; xmm0=R(02468ACE)=RE, xmm2=G(02468ACE)=GE, xmm4=B(02468ACE)=BE
  232. ; xmm1=R(13579BDF)=RO, xmm3=G(13579BDF)=GO, xmm5=B(13579BDF)=BO
  233. ; (Original)
  234. ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
  235. ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
  236. ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
  237. ;
  238. ; (This implementation)
  239. ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
  240. ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
  241. ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
  242. movdqa XMMWORD [wk(0)], xmm0 ; wk(0)=RE
  243. movdqa XMMWORD [wk(1)], xmm1 ; wk(1)=RO
  244. movdqa XMMWORD [wk(2)], xmm4 ; wk(2)=BE
  245. movdqa XMMWORD [wk(3)], xmm5 ; wk(3)=BO
  246. movdqa xmm6, xmm1
  247. punpcklwd xmm1, xmm3
  248. punpckhwd xmm6, xmm3
  249. movdqa xmm7, xmm1
  250. movdqa xmm4, xmm6
  251. pmaddwd xmm1, [rel PW_F0299_F0337] ; xmm1=ROL*FIX(0.299)+GOL*FIX(0.337)
  252. pmaddwd xmm6, [rel PW_F0299_F0337] ; xmm6=ROH*FIX(0.299)+GOH*FIX(0.337)
  253. pmaddwd xmm7, [rel PW_MF016_MF033] ; xmm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
  254. pmaddwd xmm4, [rel PW_MF016_MF033] ; xmm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
  255. movdqa XMMWORD [wk(4)], xmm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
  256. movdqa XMMWORD [wk(5)], xmm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
  257. pxor xmm1, xmm1
  258. pxor xmm6, xmm6
  259. punpcklwd xmm1, xmm5 ; xmm1=BOL
  260. punpckhwd xmm6, xmm5 ; xmm6=BOH
  261. psrld xmm1, 1 ; xmm1=BOL*FIX(0.500)
  262. psrld xmm6, 1 ; xmm6=BOH*FIX(0.500)
  263. movdqa xmm5, [rel PD_ONEHALFM1_CJ] ; xmm5=[PD_ONEHALFM1_CJ]
  264. paddd xmm7, xmm1
  265. paddd xmm4, xmm6
  266. paddd xmm7, xmm5
  267. paddd xmm4, xmm5
  268. psrld xmm7, SCALEBITS ; xmm7=CbOL
  269. psrld xmm4, SCALEBITS ; xmm4=CbOH
  270. packssdw xmm7, xmm4 ; xmm7=CbO
  271. movdqa xmm1, XMMWORD [wk(2)] ; xmm1=BE
  272. movdqa xmm6, xmm0
  273. punpcklwd xmm0, xmm2
  274. punpckhwd xmm6, xmm2
  275. movdqa xmm5, xmm0
  276. movdqa xmm4, xmm6
  277. pmaddwd xmm0, [rel PW_F0299_F0337] ; xmm0=REL*FIX(0.299)+GEL*FIX(0.337)
  278. pmaddwd xmm6, [rel PW_F0299_F0337] ; xmm6=REH*FIX(0.299)+GEH*FIX(0.337)
  279. pmaddwd xmm5, [rel PW_MF016_MF033] ; xmm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
  280. pmaddwd xmm4, [rel PW_MF016_MF033] ; xmm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
  281. movdqa XMMWORD [wk(6)], xmm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
  282. movdqa XMMWORD [wk(7)], xmm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
  283. pxor xmm0, xmm0
  284. pxor xmm6, xmm6
  285. punpcklwd xmm0, xmm1 ; xmm0=BEL
  286. punpckhwd xmm6, xmm1 ; xmm6=BEH
  287. psrld xmm0, 1 ; xmm0=BEL*FIX(0.500)
  288. psrld xmm6, 1 ; xmm6=BEH*FIX(0.500)
  289. movdqa xmm1, [rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
  290. paddd xmm5, xmm0
  291. paddd xmm4, xmm6
  292. paddd xmm5, xmm1
  293. paddd xmm4, xmm1
  294. psrld xmm5, SCALEBITS ; xmm5=CbEL
  295. psrld xmm4, SCALEBITS ; xmm4=CbEH
  296. packssdw xmm5, xmm4 ; xmm5=CbE
  297. psllw xmm7, BYTE_BIT
  298. por xmm5, xmm7 ; xmm5=Cb
  299. movdqa XMMWORD [rbx], xmm5 ; Save Cb
  300. movdqa xmm0, XMMWORD [wk(3)] ; xmm0=BO
  301. movdqa xmm6, XMMWORD [wk(2)] ; xmm6=BE
  302. movdqa xmm1, XMMWORD [wk(1)] ; xmm1=RO
  303. movdqa xmm4, xmm0
  304. punpcklwd xmm0, xmm3
  305. punpckhwd xmm4, xmm3
  306. movdqa xmm7, xmm0
  307. movdqa xmm5, xmm4
  308. pmaddwd xmm0, [rel PW_F0114_F0250] ; xmm0=BOL*FIX(0.114)+GOL*FIX(0.250)
  309. pmaddwd xmm4, [rel PW_F0114_F0250] ; xmm4=BOH*FIX(0.114)+GOH*FIX(0.250)
  310. pmaddwd xmm7, [rel PW_MF008_MF041] ; xmm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
  311. pmaddwd xmm5, [rel PW_MF008_MF041] ; xmm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
  312. movdqa xmm3, [rel PD_ONEHALF] ; xmm3=[PD_ONEHALF]
  313. paddd xmm0, XMMWORD [wk(4)]
  314. paddd xmm4, XMMWORD [wk(5)]
  315. paddd xmm0, xmm3
  316. paddd xmm4, xmm3
  317. psrld xmm0, SCALEBITS ; xmm0=YOL
  318. psrld xmm4, SCALEBITS ; xmm4=YOH
  319. packssdw xmm0, xmm4 ; xmm0=YO
  320. pxor xmm3, xmm3
  321. pxor xmm4, xmm4
  322. punpcklwd xmm3, xmm1 ; xmm3=ROL
  323. punpckhwd xmm4, xmm1 ; xmm4=ROH
  324. psrld xmm3, 1 ; xmm3=ROL*FIX(0.500)
  325. psrld xmm4, 1 ; xmm4=ROH*FIX(0.500)
  326. movdqa xmm1, [rel PD_ONEHALFM1_CJ] ; xmm1=[PD_ONEHALFM1_CJ]
  327. paddd xmm7, xmm3
  328. paddd xmm5, xmm4
  329. paddd xmm7, xmm1
  330. paddd xmm5, xmm1
  331. psrld xmm7, SCALEBITS ; xmm7=CrOL
  332. psrld xmm5, SCALEBITS ; xmm5=CrOH
  333. packssdw xmm7, xmm5 ; xmm7=CrO
  334. movdqa xmm3, XMMWORD [wk(0)] ; xmm3=RE
  335. movdqa xmm4, xmm6
  336. punpcklwd xmm6, xmm2
  337. punpckhwd xmm4, xmm2
  338. movdqa xmm1, xmm6
  339. movdqa xmm5, xmm4
  340. pmaddwd xmm6, [rel PW_F0114_F0250] ; xmm6=BEL*FIX(0.114)+GEL*FIX(0.250)
  341. pmaddwd xmm4, [rel PW_F0114_F0250] ; xmm4=BEH*FIX(0.114)+GEH*FIX(0.250)
  342. pmaddwd xmm1, [rel PW_MF008_MF041] ; xmm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
  343. pmaddwd xmm5, [rel PW_MF008_MF041] ; xmm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
  344. movdqa xmm2, [rel PD_ONEHALF] ; xmm2=[PD_ONEHALF]
  345. paddd xmm6, XMMWORD [wk(6)]
  346. paddd xmm4, XMMWORD [wk(7)]
  347. paddd xmm6, xmm2
  348. paddd xmm4, xmm2
  349. psrld xmm6, SCALEBITS ; xmm6=YEL
  350. psrld xmm4, SCALEBITS ; xmm4=YEH
  351. packssdw xmm6, xmm4 ; xmm6=YE
  352. psllw xmm0, BYTE_BIT
  353. por xmm6, xmm0 ; xmm6=Y
  354. movdqa XMMWORD [rdi], xmm6 ; Save Y
  355. pxor xmm2, xmm2
  356. pxor xmm4, xmm4
  357. punpcklwd xmm2, xmm3 ; xmm2=REL
  358. punpckhwd xmm4, xmm3 ; xmm4=REH
  359. psrld xmm2, 1 ; xmm2=REL*FIX(0.500)
  360. psrld xmm4, 1 ; xmm4=REH*FIX(0.500)
  361. movdqa xmm0, [rel PD_ONEHALFM1_CJ] ; xmm0=[PD_ONEHALFM1_CJ]
  362. paddd xmm1, xmm2
  363. paddd xmm5, xmm4
  364. paddd xmm1, xmm0
  365. paddd xmm5, xmm0
  366. psrld xmm1, SCALEBITS ; xmm1=CrEL
  367. psrld xmm5, SCALEBITS ; xmm5=CrEH
  368. packssdw xmm1, xmm5 ; xmm1=CrE
  369. psllw xmm7, BYTE_BIT
  370. por xmm1, xmm7 ; xmm1=Cr
  371. movdqa XMMWORD [rdx], xmm1 ; Save Cr
  372. sub rcx, byte SIZEOF_XMMWORD
  373. add rsi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD ; inptr
  374. add rdi, byte SIZEOF_XMMWORD ; outptr0
  375. add rbx, byte SIZEOF_XMMWORD ; outptr1
  376. add rdx, byte SIZEOF_XMMWORD ; outptr2
  377. cmp rcx, byte SIZEOF_XMMWORD
  378. jae near .columnloop
  379. test rcx, rcx
  380. jnz near .column_ld1
  381. pop rcx ; col
  382. pop rsi
  383. pop rdi
  384. pop rbx
  385. pop rdx
  386. add rsi, byte SIZEOF_JSAMPROW ; input_buf
  387. add rdi, byte SIZEOF_JSAMPROW
  388. add rbx, byte SIZEOF_JSAMPROW
  389. add rdx, byte SIZEOF_JSAMPROW
  390. dec rax ; num_rows
  391. jg near .rowloop
  392. .return:
  393. pop rbx
  394. uncollect_args 5
  395. mov rsp, rbp ; rsp <- aligned rbp
  396. pop rsp ; rsp <- original rbp
  397. pop rbp
  398. ret
  399. ; For some reason, the OS X linker does not honor the request to align the
  400. ; segment unless we do this.
  401. align 32