jccolext-avx2.asm 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. ;
  2. ; jccolext.asm - colorspace conversion (64-bit AVX2)
  3. ;
  4. ; Copyright (C) 2009, 2016, D. R. Commander.
  5. ; Copyright (C) 2015, Intel Corporation.
  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_rgb_ycc_convert_avx2(JDIMENSION img_width, JSAMPARRAY input_buf,
  23. ; JSAMPIMAGE output_buf, JDIMENSION output_row,
  24. ; int num_rows);
  25. ;
  26. ; r10d = JDIMENSION img_width
  27. ; r11 = JSAMPARRAY input_buf
  28. ; r12 = JSAMPIMAGE output_buf
  29. ; r13d = JDIMENSION output_row
  30. ; r14d = int num_rows
  31. %define wk(i) rbp - (WK_NUM - (i)) * SIZEOF_YMMWORD ; ymmword wk[WK_NUM]
  32. %define WK_NUM 8
  33. align 32
  34. GLOBAL_FUNCTION(jsimd_rgb_ycc_convert_avx2)
  35. EXTN(jsimd_rgb_ycc_convert_avx2):
  36. push rbp
  37. mov rax, rsp ; rax = original rbp
  38. sub rsp, byte 4
  39. and rsp, byte (-SIZEOF_YMMWORD) ; align to 256 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
  46. test rcx, rcx
  47. jz near .return
  48. push rcx
  49. mov rsi, r12
  50. mov ecx, r13d
  51. mov rdi, JSAMPARRAY [rsi+0*SIZEOF_JSAMPARRAY]
  52. mov rbx, JSAMPARRAY [rsi+1*SIZEOF_JSAMPARRAY]
  53. mov rdx, JSAMPARRAY [rsi+2*SIZEOF_JSAMPARRAY]
  54. lea rdi, [rdi+rcx*SIZEOF_JSAMPROW]
  55. lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
  56. lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
  57. pop rcx
  58. mov rsi, r11
  59. mov eax, r14d
  60. test rax, rax
  61. jle near .return
  62. .rowloop:
  63. push rdx
  64. push rbx
  65. push rdi
  66. push rsi
  67. push rcx ; col
  68. mov rsi, JSAMPROW [rsi] ; inptr
  69. mov rdi, JSAMPROW [rdi] ; outptr0
  70. mov rbx, JSAMPROW [rbx] ; outptr1
  71. mov rdx, JSAMPROW [rdx] ; outptr2
  72. cmp rcx, byte SIZEOF_YMMWORD
  73. jae near .columnloop
  74. %if RGB_PIXELSIZE == 3 ; ---------------
  75. .column_ld1:
  76. push rax
  77. push rdx
  78. lea rcx, [rcx+rcx*2] ; imul ecx,RGB_PIXELSIZE
  79. test cl, SIZEOF_BYTE
  80. jz short .column_ld2
  81. sub rcx, byte SIZEOF_BYTE
  82. movzx rax, byte [rsi+rcx]
  83. .column_ld2:
  84. test cl, SIZEOF_WORD
  85. jz short .column_ld4
  86. sub rcx, byte SIZEOF_WORD
  87. movzx rdx, word [rsi+rcx]
  88. shl rax, WORD_BIT
  89. or rax, rdx
  90. .column_ld4:
  91. vmovd xmmA, eax
  92. pop rdx
  93. pop rax
  94. test cl, SIZEOF_DWORD
  95. jz short .column_ld8
  96. sub rcx, byte SIZEOF_DWORD
  97. vmovd xmmF, XMM_DWORD [rsi+rcx]
  98. vpslldq xmmA, xmmA, SIZEOF_DWORD
  99. vpor xmmA, xmmA, xmmF
  100. .column_ld8:
  101. test cl, SIZEOF_MMWORD
  102. jz short .column_ld16
  103. sub rcx, byte SIZEOF_MMWORD
  104. vmovq xmmB, XMM_MMWORD [rsi+rcx]
  105. vpslldq xmmA, xmmA, SIZEOF_MMWORD
  106. vpor xmmA, xmmA, xmmB
  107. .column_ld16:
  108. test cl, SIZEOF_XMMWORD
  109. jz short .column_ld32
  110. sub rcx, byte SIZEOF_XMMWORD
  111. vmovdqu xmmB, XMM_MMWORD [rsi+rcx]
  112. vperm2i128 ymmA, ymmA, ymmA, 1
  113. vpor ymmA, ymmB
  114. .column_ld32:
  115. test cl, SIZEOF_YMMWORD
  116. jz short .column_ld64
  117. sub rcx, byte SIZEOF_YMMWORD
  118. vmovdqa ymmF, ymmA
  119. vmovdqu ymmA, YMMWORD [rsi+0*SIZEOF_YMMWORD]
  120. .column_ld64:
  121. test cl, 2*SIZEOF_YMMWORD
  122. mov rcx, SIZEOF_YMMWORD
  123. jz short .rgb_ycc_cnv
  124. vmovdqa ymmB, ymmA
  125. vmovdqu ymmA, YMMWORD [rsi+0*SIZEOF_YMMWORD]
  126. vmovdqu ymmF, YMMWORD [rsi+1*SIZEOF_YMMWORD]
  127. jmp short .rgb_ycc_cnv
  128. .columnloop:
  129. vmovdqu ymmA, YMMWORD [rsi+0*SIZEOF_YMMWORD]
  130. vmovdqu ymmF, YMMWORD [rsi+1*SIZEOF_YMMWORD]
  131. vmovdqu ymmB, YMMWORD [rsi+2*SIZEOF_YMMWORD]
  132. .rgb_ycc_cnv:
  133. ; ymmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05
  134. ; 15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
  135. ; ymmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F
  136. ; 0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L)
  137. ; ymmB=(1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q
  138. ; 2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V)
  139. vmovdqu ymmC, ymmA
  140. vinserti128 ymmA, ymmF, xmmA, 0 ; ymmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05
  141. ; 0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L)
  142. vinserti128 ymmC, ymmC, xmmB, 0 ; ymmC=(1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q
  143. ; 15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
  144. vinserti128 ymmB, ymmB, xmmF, 0 ; ymmB=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F
  145. ; 2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V)
  146. vperm2i128 ymmF, ymmC, ymmC, 1 ; ymmF=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A
  147. ; 1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q)
  148. vmovdqa ymmG, ymmA
  149. vpslldq ymmA, ymmA, 8 ; ymmA=(-- -- -- -- -- -- -- -- 00 10 20 01 11 21 02 12
  150. ; 22 03 13 23 04 14 24 05 0G 1G 2G 0H 1H 2H 0I 1I)
  151. vpsrldq ymmG, ymmG, 8 ; ymmG=(22 03 13 23 04 14 24 05 0G 1G 2G 0H 1H 2H 0I 1I
  152. ; 2I 0J 1J 2J 0K 1K 2K 0L -- -- -- -- -- -- -- --)
  153. vpunpckhbw ymmA, ymmA, ymmF ; ymmA=(00 08 10 18 20 28 01 09 11 19 21 29 02 0A 12 1A
  154. ; 0G 0O 1G 1O 2G 2O 0H 0P 1H 1P 2H 2P 0I 0Q 1I 1Q)
  155. vpslldq ymmF, ymmF, 8 ; ymmF=(-- -- -- -- -- -- -- -- 15 25 06 16 26 07 17 27
  156. ; 08 18 28 09 19 29 0A 1A 1L 2L 0M 1M 2M 0N 1N 2N)
  157. vpunpcklbw ymmG, ymmG, ymmB ; ymmG=(22 2A 03 0B 13 1B 23 2B 04 0C 14 1C 24 2C 05 0D
  158. ; 2I 2Q 0J 0R 1J 1R 2J 2R 0K 0S 1K 1S 2K 2S 0L 0T)
  159. vpunpckhbw ymmF, ymmF, ymmB ; ymmF=(15 1D 25 2D 06 0E 16 1E 26 2E 07 0F 17 1F 27 2F
  160. ; 1L 1T 2L 2T 0M 0U 1M 1U 2M 2U 0N 0V 1N 1V 2N 2V)
  161. vmovdqa ymmD, ymmA
  162. vpslldq ymmA, ymmA, 8 ; ymmA=(-- -- -- -- -- -- -- -- 00 08 10 18 20 28 01 09
  163. ; 11 19 21 29 02 0A 12 1A 0G 0O 1G 1O 2G 2O 0H 0P)
  164. vpsrldq ymmD, ymmD, 8 ; ymmD=(11 19 21 29 02 0A 12 1A 0G 0O 1G 1O 2G 2O 0H 0P
  165. ; 1H 1P 2H 2P 0I 0Q 1I 1Q -- -- -- -- -- -- -- --)
  166. vpunpckhbw ymmA, ymmA, ymmG ; ymmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 01 05 09 0D
  167. ; 0G 0K 0O 0S 1G 1K 1O 1S 2G 2K 2O 2S 0H 0L 0P 0T)
  168. vpslldq ymmG, ymmG, 8 ; ymmG=(-- -- -- -- -- -- -- -- 22 2A 03 0B 13 1B 23 2B
  169. ; 04 0C 14 1C 24 2C 05 0D 2I 2Q 0J 0R 1J 1R 2J 2R)
  170. vpunpcklbw ymmD, ymmD, ymmF ; ymmD=(11 15 19 1D 21 25 29 2D 02 06 0A 0E 12 16 1A 1E
  171. ; 1H 1L 1P 1T 2H 2L 2P 2T 0I 0M 0Q 0U 1I 1M 1Q 1U)
  172. vpunpckhbw ymmG, ymmG, ymmF ; ymmG=(22 26 2A 2E 03 07 0B 0F 13 17 1B 1F 23 27 2B 2F
  173. ; 2I 2M 2Q 2U 0J 0N 0R 0V 1J 1N 1R 1V 2J 2N 2R 2V)
  174. vmovdqa ymmE, ymmA
  175. vpslldq ymmA, ymmA, 8 ; ymmA=(-- -- -- -- -- -- -- -- 00 04 08 0C 10 14 18 1C
  176. ; 20 24 28 2C 01 05 09 0D 0G 0K 0O 0S 1G 1K 1O 1S)
  177. vpsrldq ymmE, ymmE, 8 ; ymmE=(20 24 28 2C 01 05 09 0D 0G 0K 0O 0S 1G 1K 1O 1S
  178. ; 2G 2K 2O 2S 0H 0L 0P 0T -- -- -- -- -- -- -- --)
  179. vpunpckhbw ymmA, ymmA, ymmD ; ymmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E
  180. ; 0G 0I 0K 0M 0O 0Q 0S 0U 1G 1I 1K 1M 1O 1Q 1S 1U)
  181. vpslldq ymmD, ymmD, 8 ; ymmD=(-- -- -- -- -- -- -- -- 11 15 19 1D 21 25 29 2D
  182. ; 02 06 0A 0E 12 16 1A 1E 1H 1L 1P 1T 2H 2L 2P 2T)
  183. vpunpcklbw ymmE, ymmE, ymmG ; ymmE=(20 22 24 26 28 2A 2C 2E 01 03 05 07 09 0B 0D 0F
  184. ; 2G 2I 2K 2M 2O 2Q 2S 2U 0H 0J 0L 0N 0P 0R 0T 0V)
  185. vpunpckhbw ymmD, ymmD, ymmG ; ymmD=(11 13 15 17 19 1B 1D 1F 21 23 25 27 29 2B 2D 2F
  186. ; 1H 1J 1L 1N 1P 1R 1T 1V 2H 2J 2L 2N 2P 2R 2T 2V)
  187. vpxor ymmH, ymmH, ymmH
  188. vmovdqa ymmC, ymmA
  189. vpunpcklbw ymmA, ymmA, ymmH ; ymmA=(00 02 04 06 08 0A 0C 0E 0G 0I 0K 0M 0O 0Q 0S 0U)
  190. vpunpckhbw ymmC, ymmC, ymmH ; ymmC=(10 12 14 16 18 1A 1C 1E 1G 1I 1K 1M 1O 1Q 1S 1U)
  191. vmovdqa ymmB, ymmE
  192. vpunpcklbw ymmE, ymmE, ymmH ; ymmE=(20 22 24 26 28 2A 2C 2E 2G 2I 2K 2M 2O 2Q 2S 2U)
  193. vpunpckhbw ymmB, ymmB, ymmH ; ymmB=(01 03 05 07 09 0B 0D 0F 0H 0J 0L 0N 0P 0R 0T 0V)
  194. vmovdqa ymmF, ymmD
  195. vpunpcklbw ymmD, ymmD, ymmH ; ymmD=(11 13 15 17 19 1B 1D 1F 1H 1J 1L 1N 1P 1R 1T 1V)
  196. vpunpckhbw ymmF, ymmF, ymmH ; ymmF=(21 23 25 27 29 2B 2D 2F 2H 2J 2L 2N 2P 2R 2T 2V)
  197. %else ; RGB_PIXELSIZE == 4 ; -----------
  198. .column_ld1:
  199. test cl, SIZEOF_XMMWORD/16
  200. jz short .column_ld2
  201. sub rcx, byte SIZEOF_XMMWORD/16
  202. vmovd xmmA, XMM_DWORD [rsi+rcx*RGB_PIXELSIZE]
  203. .column_ld2:
  204. test cl, SIZEOF_XMMWORD/8
  205. jz short .column_ld4
  206. sub rcx, byte SIZEOF_XMMWORD/8
  207. vmovq xmmF, XMM_MMWORD [rsi+rcx*RGB_PIXELSIZE]
  208. vpslldq xmmA, xmmA, SIZEOF_MMWORD
  209. vpor xmmA, xmmA, xmmF
  210. .column_ld4:
  211. test cl, SIZEOF_XMMWORD/4
  212. jz short .column_ld8
  213. sub rcx, byte SIZEOF_XMMWORD/4
  214. vmovdqa xmmF, xmmA
  215. vperm2i128 ymmF, ymmF, ymmF, 1
  216. vmovdqu xmmA, XMMWORD [rsi+rcx*RGB_PIXELSIZE]
  217. vpor ymmA, ymmA, ymmF
  218. .column_ld8:
  219. test cl, SIZEOF_XMMWORD/2
  220. jz short .column_ld16
  221. sub rcx, byte SIZEOF_XMMWORD/2
  222. vmovdqa ymmF, ymmA
  223. vmovdqu ymmA, YMMWORD [rsi+rcx*RGB_PIXELSIZE]
  224. .column_ld16:
  225. test cl, SIZEOF_XMMWORD
  226. mov rcx, SIZEOF_YMMWORD
  227. jz short .rgb_ycc_cnv
  228. vmovdqa ymmE, ymmA
  229. vmovdqa ymmH, ymmF
  230. vmovdqu ymmA, YMMWORD [rsi+0*SIZEOF_YMMWORD]
  231. vmovdqu ymmF, YMMWORD [rsi+1*SIZEOF_YMMWORD]
  232. jmp short .rgb_ycc_cnv
  233. .columnloop:
  234. vmovdqu ymmA, YMMWORD [rsi+0*SIZEOF_YMMWORD]
  235. vmovdqu ymmF, YMMWORD [rsi+1*SIZEOF_YMMWORD]
  236. vmovdqu ymmE, YMMWORD [rsi+2*SIZEOF_YMMWORD]
  237. vmovdqu ymmH, YMMWORD [rsi+3*SIZEOF_YMMWORD]
  238. .rgb_ycc_cnv:
  239. ; ymmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
  240. ; 04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
  241. ; ymmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B
  242. ; 0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
  243. ; ymmE=(0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J
  244. ; 0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N)
  245. ; ymmH=(0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R
  246. ; 0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V)
  247. vmovdqa ymmB, ymmA
  248. vinserti128 ymmA, ymmA, xmmE, 1 ; ymmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
  249. ; 0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J)
  250. vperm2i128 ymmE, ymmB, ymmE, 0x31 ; ymmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37
  251. ; 0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N)
  252. vmovdqa ymmB, ymmF
  253. vinserti128 ymmF, ymmF, xmmH, 1 ; ymmF=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B
  254. ; 0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R)
  255. vperm2i128 ymmH, ymmB, ymmH, 0x31 ; ymmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F
  256. ; 0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V)
  257. vmovdqa ymmD, ymmA
  258. vpunpcklbw ymmA, ymmA, ymmE ; ymmA=(00 04 10 14 20 24 30 34 01 05 11 15 21 25 31 35
  259. ; 0G 0K 1G 1K 2G 2K 3G 3K 0H 0L 1H 1L 2H 2L 3H 3L)
  260. vpunpckhbw ymmD, ymmD, ymmE ; ymmD=(02 06 12 16 22 26 32 36 03 07 13 17 23 27 33 37
  261. ; 0I 0M 1I 1M 2I 2M 3I 3M 0J 0N 1J 1N 2J 2N 3J 3N)
  262. vmovdqa ymmC, ymmF
  263. vpunpcklbw ymmF, ymmF, ymmH ; ymmF=(08 0C 18 1C 28 2C 38 3C 09 0D 19 1D 29 2D 39 3D
  264. ; 0O 0S 1O 1S 2O 2S 3O 3S 0P 0T 1P 1T 2P 2T 3P 3T)
  265. vpunpckhbw ymmC, ymmC, ymmH ; ymmC=(0A 0E 1A 1E 2A 2E 3A 3E 0B 0F 1B 1F 2B 2F 3B 3F
  266. ; 0Q 0U 1Q 1U 2Q 2U 3Q 3U 0R 0V 1R 1V 2R 2V 3R 3V)
  267. vmovdqa ymmB, ymmA
  268. vpunpcklwd ymmA, ymmA, ymmF ; ymmA=(00 04 08 0C 10 14 18 1C 20 24 28 2C 30 34 38 3C
  269. ; 0G 0K 0O 0S 1G 1K 1O 1S 2G 2K 2O 2S 3G 3K 3O 3S)
  270. vpunpckhwd ymmB, ymmB, ymmF ; ymmB=(01 05 09 0D 11 15 19 1D 21 25 29 2D 31 35 39 3D
  271. ; 0H 0L 0P 0T 1H 1L 1P 1T 2H 2L 2P 2T 3H 3L 3P 3T)
  272. vmovdqa ymmG, ymmD
  273. vpunpcklwd ymmD, ymmD, ymmC ; ymmD=(02 06 0A 0E 12 16 1A 1E 22 26 2A 2E 32 36 3A 3E
  274. ; 0I 0M 0Q 0U 1I 1M 1Q 1U 2I 2M 2Q 2U 3I 3M 3Q 3U)
  275. vpunpckhwd ymmG, ymmG, ymmC ; ymmG=(03 07 0B 0F 13 17 1B 1F 23 27 2B 2F 33 37 3B 3F
  276. ; 0J 0N 0R 0V 1J 1N 1R 1V 2J 2N 2R 2V 3J 3N 3R 3V)
  277. vmovdqa ymmE, ymmA
  278. vpunpcklbw ymmA, ymmA, ymmD ; ymmA=(00 02 04 06 08 0A 0C 0E 10 12 14 16 18 1A 1C 1E
  279. ; 0G 0I 0K 0M 0O 0Q 0S 0U 1G 1I 1K 1M 1O 1Q 1S 1U)
  280. vpunpckhbw ymmE, ymmE, ymmD ; ymmE=(20 22 24 26 28 2A 2C 2E 30 32 34 36 38 3A 3C 3E
  281. ; 2G 2I 2K 2M 2O 2Q 2S 2U 3G 3I 3K 3M 3O 3Q 3S 3U)
  282. vmovdqa ymmH, ymmB
  283. vpunpcklbw ymmB, ymmB, ymmG ; ymmB=(01 03 05 07 09 0B 0D 0F 11 13 15 17 19 1B 1D 1F
  284. ; 0H 0J 0L 0N 0P 0R 0T 0V 1H 1J 1L 1N 1P 1R 1T 1V)
  285. vpunpckhbw ymmH, ymmH, ymmG ; ymmH=(21 23 25 27 29 2B 2D 2F 31 33 35 37 39 3B 3D 3F
  286. ; 2H 2J 2L 2N 2P 2R 2T 2V 3H 3J 3L 3N 3P 3R 3T 3V)
  287. vpxor ymmF, ymmF, ymmF
  288. vmovdqa ymmC, ymmA
  289. vpunpcklbw ymmA, ymmA, ymmF ; ymmA=(00 02 04 06 08 0A 0C 0E 0G 0I 0K 0M 0O 0Q 0S 0U)
  290. vpunpckhbw ymmC, ymmC, ymmF ; ymmC=(10 12 14 16 18 1A 1C 1E 1G 1I 1K 1M 1O 1Q 1S 1U)
  291. vmovdqa ymmD, ymmB
  292. vpunpcklbw ymmB, ymmB, ymmF ; ymmB=(01 03 05 07 09 0B 0D 0F 0H 0J 0L 0N 0P 0R 0T 0V)
  293. vpunpckhbw ymmD, ymmD, ymmF ; ymmD=(11 13 15 17 19 1B 1D 1F 1H 1J 1L 1N 1P 1R 1T 1V)
  294. vmovdqa ymmG, ymmE
  295. vpunpcklbw ymmE, ymmE, ymmF ; ymmE=(20 22 24 26 28 2A 2C 2E 2G 2I 2K 2M 2O 2Q 2S 2U)
  296. vpunpckhbw ymmG, ymmG, ymmF ; ymmG=(30 32 34 36 38 3A 3C 3E 3G 3I 3K 3M 3O 3Q 3S 3U)
  297. vpunpcklbw ymmF, ymmF, ymmH
  298. vpunpckhbw ymmH, ymmH, ymmH
  299. vpsrlw ymmF, ymmF, BYTE_BIT ; ymmF=(21 23 25 27 29 2B 2D 2F 2H 2J 2L 2N 2P 2R 2T 2V)
  300. vpsrlw ymmH, ymmH, BYTE_BIT ; ymmH=(31 33 35 37 39 3B 3D 3F 3H 3J 3L 3N 3P 3R 3T 3V)
  301. %endif ; RGB_PIXELSIZE ; ---------------
  302. ; ymm0=R(02468ACEGIKMOQSU)=RE, ymm2=G(02468ACEGIKMOQSU)=GE, ymm4=B(02468ACEGIKMOQSU)=BE
  303. ; ymm1=R(13579BDFHJLNPRTV)=RO, ymm3=G(13579BDFHJLNPRTV)=GO, ymm5=B(13579BDFHJLNPRTV)=BO
  304. ; (Original)
  305. ; Y = 0.29900 * R + 0.58700 * G + 0.11400 * B
  306. ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
  307. ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
  308. ;
  309. ; (This implementation)
  310. ; Y = 0.29900 * R + 0.33700 * G + 0.11400 * B + 0.25000 * G
  311. ; Cb = -0.16874 * R - 0.33126 * G + 0.50000 * B + CENTERJSAMPLE
  312. ; Cr = 0.50000 * R - 0.41869 * G - 0.08131 * B + CENTERJSAMPLE
  313. vmovdqa YMMWORD [wk(0)], ymm0 ; wk(0)=RE
  314. vmovdqa YMMWORD [wk(1)], ymm1 ; wk(1)=RO
  315. vmovdqa YMMWORD [wk(2)], ymm4 ; wk(2)=BE
  316. vmovdqa YMMWORD [wk(3)], ymm5 ; wk(3)=BO
  317. vmovdqa ymm6, ymm1
  318. vpunpcklwd ymm1, ymm1, ymm3
  319. vpunpckhwd ymm6, ymm6, ymm3
  320. vmovdqa ymm7, ymm1
  321. vmovdqa ymm4, ymm6
  322. vpmaddwd ymm1, ymm1, [rel PW_F0299_F0337] ; ymm1=ROL*FIX(0.299)+GOL*FIX(0.337)
  323. vpmaddwd ymm6, ymm6, [rel PW_F0299_F0337] ; ymm6=ROH*FIX(0.299)+GOH*FIX(0.337)
  324. vpmaddwd ymm7, ymm7, [rel PW_MF016_MF033] ; ymm7=ROL*-FIX(0.168)+GOL*-FIX(0.331)
  325. vpmaddwd ymm4, ymm4, [rel PW_MF016_MF033] ; ymm4=ROH*-FIX(0.168)+GOH*-FIX(0.331)
  326. vmovdqa YMMWORD [wk(4)], ymm1 ; wk(4)=ROL*FIX(0.299)+GOL*FIX(0.337)
  327. vmovdqa YMMWORD [wk(5)], ymm6 ; wk(5)=ROH*FIX(0.299)+GOH*FIX(0.337)
  328. vpxor ymm1, ymm1, ymm1
  329. vpxor ymm6, ymm6, ymm6
  330. vpunpcklwd ymm1, ymm1, ymm5 ; ymm1=BOL
  331. vpunpckhwd ymm6, ymm6, ymm5 ; ymm6=BOH
  332. vpsrld ymm1, ymm1, 1 ; ymm1=BOL*FIX(0.500)
  333. vpsrld ymm6, ymm6, 1 ; ymm6=BOH*FIX(0.500)
  334. vmovdqa ymm5, [rel PD_ONEHALFM1_CJ] ; ymm5=[PD_ONEHALFM1_CJ]
  335. vpaddd ymm7, ymm7, ymm1
  336. vpaddd ymm4, ymm4, ymm6
  337. vpaddd ymm7, ymm7, ymm5
  338. vpaddd ymm4, ymm4, ymm5
  339. vpsrld ymm7, ymm7, SCALEBITS ; ymm7=CbOL
  340. vpsrld ymm4, ymm4, SCALEBITS ; ymm4=CbOH
  341. vpackssdw ymm7, ymm7, ymm4 ; ymm7=CbO
  342. vmovdqa ymm1, YMMWORD [wk(2)] ; ymm1=BE
  343. vmovdqa ymm6, ymm0
  344. vpunpcklwd ymm0, ymm0, ymm2
  345. vpunpckhwd ymm6, ymm6, ymm2
  346. vmovdqa ymm5, ymm0
  347. vmovdqa ymm4, ymm6
  348. vpmaddwd ymm0, ymm0, [rel PW_F0299_F0337] ; ymm0=REL*FIX(0.299)+GEL*FIX(0.337)
  349. vpmaddwd ymm6, ymm6, [rel PW_F0299_F0337] ; ymm6=REH*FIX(0.299)+GEH*FIX(0.337)
  350. vpmaddwd ymm5, ymm5, [rel PW_MF016_MF033] ; ymm5=REL*-FIX(0.168)+GEL*-FIX(0.331)
  351. vpmaddwd ymm4, ymm4, [rel PW_MF016_MF033] ; ymm4=REH*-FIX(0.168)+GEH*-FIX(0.331)
  352. vmovdqa YMMWORD [wk(6)], ymm0 ; wk(6)=REL*FIX(0.299)+GEL*FIX(0.337)
  353. vmovdqa YMMWORD [wk(7)], ymm6 ; wk(7)=REH*FIX(0.299)+GEH*FIX(0.337)
  354. vpxor ymm0, ymm0, ymm0
  355. vpxor ymm6, ymm6, ymm6
  356. vpunpcklwd ymm0, ymm0, ymm1 ; ymm0=BEL
  357. vpunpckhwd ymm6, ymm6, ymm1 ; ymm6=BEH
  358. vpsrld ymm0, ymm0, 1 ; ymm0=BEL*FIX(0.500)
  359. vpsrld ymm6, ymm6, 1 ; ymm6=BEH*FIX(0.500)
  360. vmovdqa ymm1, [rel PD_ONEHALFM1_CJ] ; ymm1=[PD_ONEHALFM1_CJ]
  361. vpaddd ymm5, ymm5, ymm0
  362. vpaddd ymm4, ymm4, ymm6
  363. vpaddd ymm5, ymm5, ymm1
  364. vpaddd ymm4, ymm4, ymm1
  365. vpsrld ymm5, ymm5, SCALEBITS ; ymm5=CbEL
  366. vpsrld ymm4, ymm4, SCALEBITS ; ymm4=CbEH
  367. vpackssdw ymm5, ymm5, ymm4 ; ymm5=CbE
  368. vpsllw ymm7, ymm7, BYTE_BIT
  369. vpor ymm5, ymm5, ymm7 ; ymm5=Cb
  370. vmovdqu YMMWORD [rbx], ymm5 ; Save Cb
  371. vmovdqa ymm0, YMMWORD [wk(3)] ; ymm0=BO
  372. vmovdqa ymm6, YMMWORD [wk(2)] ; ymm6=BE
  373. vmovdqa ymm1, YMMWORD [wk(1)] ; ymm1=RO
  374. vmovdqa ymm4, ymm0
  375. vpunpcklwd ymm0, ymm0, ymm3
  376. vpunpckhwd ymm4, ymm4, ymm3
  377. vmovdqa ymm7, ymm0
  378. vmovdqa ymm5, ymm4
  379. vpmaddwd ymm0, ymm0, [rel PW_F0114_F0250] ; ymm0=BOL*FIX(0.114)+GOL*FIX(0.250)
  380. vpmaddwd ymm4, ymm4, [rel PW_F0114_F0250] ; ymm4=BOH*FIX(0.114)+GOH*FIX(0.250)
  381. vpmaddwd ymm7, ymm7, [rel PW_MF008_MF041] ; ymm7=BOL*-FIX(0.081)+GOL*-FIX(0.418)
  382. vpmaddwd ymm5, ymm5, [rel PW_MF008_MF041] ; ymm5=BOH*-FIX(0.081)+GOH*-FIX(0.418)
  383. vmovdqa ymm3, [rel PD_ONEHALF] ; ymm3=[PD_ONEHALF]
  384. vpaddd ymm0, ymm0, YMMWORD [wk(4)]
  385. vpaddd ymm4, ymm4, YMMWORD [wk(5)]
  386. vpaddd ymm0, ymm0, ymm3
  387. vpaddd ymm4, ymm4, ymm3
  388. vpsrld ymm0, ymm0, SCALEBITS ; ymm0=YOL
  389. vpsrld ymm4, ymm4, SCALEBITS ; ymm4=YOH
  390. vpackssdw ymm0, ymm0, ymm4 ; ymm0=YO
  391. vpxor ymm3, ymm3, ymm3
  392. vpxor ymm4, ymm4, ymm4
  393. vpunpcklwd ymm3, ymm3, ymm1 ; ymm3=ROL
  394. vpunpckhwd ymm4, ymm4, ymm1 ; ymm4=ROH
  395. vpsrld ymm3, ymm3, 1 ; ymm3=ROL*FIX(0.500)
  396. vpsrld ymm4, ymm4, 1 ; ymm4=ROH*FIX(0.500)
  397. vmovdqa ymm1, [rel PD_ONEHALFM1_CJ] ; ymm1=[PD_ONEHALFM1_CJ]
  398. vpaddd ymm7, ymm7, ymm3
  399. vpaddd ymm5, ymm5, ymm4
  400. vpaddd ymm7, ymm7, ymm1
  401. vpaddd ymm5, ymm5, ymm1
  402. vpsrld ymm7, ymm7, SCALEBITS ; ymm7=CrOL
  403. vpsrld ymm5, ymm5, SCALEBITS ; ymm5=CrOH
  404. vpackssdw ymm7, ymm7, ymm5 ; ymm7=CrO
  405. vmovdqa ymm3, YMMWORD [wk(0)] ; ymm3=RE
  406. vmovdqa ymm4, ymm6
  407. vpunpcklwd ymm6, ymm6, ymm2
  408. vpunpckhwd ymm4, ymm4, ymm2
  409. vmovdqa ymm1, ymm6
  410. vmovdqa ymm5, ymm4
  411. vpmaddwd ymm6, ymm6, [rel PW_F0114_F0250] ; ymm6=BEL*FIX(0.114)+GEL*FIX(0.250)
  412. vpmaddwd ymm4, ymm4, [rel PW_F0114_F0250] ; ymm4=BEH*FIX(0.114)+GEH*FIX(0.250)
  413. vpmaddwd ymm1, ymm1, [rel PW_MF008_MF041] ; ymm1=BEL*-FIX(0.081)+GEL*-FIX(0.418)
  414. vpmaddwd ymm5, ymm5, [rel PW_MF008_MF041] ; ymm5=BEH*-FIX(0.081)+GEH*-FIX(0.418)
  415. vmovdqa ymm2, [rel PD_ONEHALF] ; ymm2=[PD_ONEHALF]
  416. vpaddd ymm6, ymm6, YMMWORD [wk(6)]
  417. vpaddd ymm4, ymm4, YMMWORD [wk(7)]
  418. vpaddd ymm6, ymm6, ymm2
  419. vpaddd ymm4, ymm4, ymm2
  420. vpsrld ymm6, ymm6, SCALEBITS ; ymm6=YEL
  421. vpsrld ymm4, ymm4, SCALEBITS ; ymm4=YEH
  422. vpackssdw ymm6, ymm6, ymm4 ; ymm6=YE
  423. vpsllw ymm0, ymm0, BYTE_BIT
  424. vpor ymm6, ymm6, ymm0 ; ymm6=Y
  425. vmovdqu YMMWORD [rdi], ymm6 ; Save Y
  426. vpxor ymm2, ymm2, ymm2
  427. vpxor ymm4, ymm4, ymm4
  428. vpunpcklwd ymm2, ymm2, ymm3 ; ymm2=REL
  429. vpunpckhwd ymm4, ymm4, ymm3 ; ymm4=REH
  430. vpsrld ymm2, ymm2, 1 ; ymm2=REL*FIX(0.500)
  431. vpsrld ymm4, ymm4, 1 ; ymm4=REH*FIX(0.500)
  432. vmovdqa ymm0, [rel PD_ONEHALFM1_CJ] ; ymm0=[PD_ONEHALFM1_CJ]
  433. vpaddd ymm1, ymm1, ymm2
  434. vpaddd ymm5, ymm5, ymm4
  435. vpaddd ymm1, ymm1, ymm0
  436. vpaddd ymm5, ymm5, ymm0
  437. vpsrld ymm1, ymm1, SCALEBITS ; ymm1=CrEL
  438. vpsrld ymm5, ymm5, SCALEBITS ; ymm5=CrEH
  439. vpackssdw ymm1, ymm1, ymm5 ; ymm1=CrE
  440. vpsllw ymm7, ymm7, BYTE_BIT
  441. vpor ymm1, ymm1, ymm7 ; ymm1=Cr
  442. vmovdqu YMMWORD [rdx], ymm1 ; Save Cr
  443. sub rcx, byte SIZEOF_YMMWORD
  444. add rsi, RGB_PIXELSIZE*SIZEOF_YMMWORD ; inptr
  445. add rdi, byte SIZEOF_YMMWORD ; outptr0
  446. add rbx, byte SIZEOF_YMMWORD ; outptr1
  447. add rdx, byte SIZEOF_YMMWORD ; outptr2
  448. cmp rcx, byte SIZEOF_YMMWORD
  449. jae near .columnloop
  450. test rcx, rcx
  451. jnz near .column_ld1
  452. pop rcx ; col
  453. pop rsi
  454. pop rdi
  455. pop rbx
  456. pop rdx
  457. add rsi, byte SIZEOF_JSAMPROW ; input_buf
  458. add rdi, byte SIZEOF_JSAMPROW
  459. add rbx, byte SIZEOF_JSAMPROW
  460. add rdx, byte SIZEOF_JSAMPROW
  461. dec rax ; num_rows
  462. jg near .rowloop
  463. .return:
  464. pop rbx
  465. vzeroupper
  466. uncollect_args 5
  467. mov rsp, rbp ; rsp <- aligned rbp
  468. pop rsp ; rsp <- original rbp
  469. pop rbp
  470. ret
  471. ; For some reason, the OS X linker does not honor the request to align the
  472. ; segment unless we do this.
  473. align 32