jccolext-sse2-64.asm 18 KB

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