2 ; jdcolext.asm - colorspace conversion (64-bit AVX2)
4 ; Copyright 2009, 2012 Pierre Ossman <ossman@cendio.se> for Cendio AB
5 ; Copyright (C) 2009, 2012, 2016, D. R. Commander.
6 ; Copyright (C) 2015, Intel Corporation.
7 ; Copyright (C) 2018, Matthias Räncker.
8 ; Copyright (C) 2023, Aliaksiej Kandracienka.
10 ; Based on the x86 SIMD extension for IJG JPEG library
11 ; Copyright (C) 1999-2006, MIYASAKA Masaru.
12 ; For conditions of distribution and use, see copyright notice in jsimdext.inc
14 ; This file should be assembled with NASM (Netwide Assembler),
15 ; can *not* be assembled with Microsoft's MASM or any compatible
16 ; assembler (including Borland's Turbo Assembler).
17 ; NASM is available from http://nasm.sourceforge.net/ or
18 ; http://sourceforge.net/project/showfiles.php?group_id=6208
20 %include "jcolsamp.inc"
22 ; --------------------------------------------------------------------------
24 ; Convert some rows of samples to the output colorspace.
27 ; jsimd_ycc_rgb_convert_avx2(JDIMENSION out_width, JSAMPIMAGE input_buf,
28 ; JDIMENSION input_row, JSAMPARRAY output_buf,
32 ; r10d = JDIMENSION out_width
33 ; r11 = JSAMPIMAGE input_buf
34 ; r12d = JDIMENSION input_row
35 ; r13 = JSAMPARRAY output_buf
38 %define wk(i) r15 - (WK_NUM - (i)) * SIZEOF_YMMWORD ; ymmword wk[WK_NUM]
42 GLOBAL_FUNCTION(jsimd_ycc_rgb_convert_avx2)
44 EXTN(jsimd_ycc_rgb_convert_avx2):
48 and rsp, byte (-SIZEOF_YMMWORD) ; align to 256 bits
49 ; Allocate stack space for wk array. r15 is used to access it.
51 sub rsp, byte (WK_NUM * SIZEOF_YMMWORD)
55 mov ecx, r10d ; num_cols
63 mov rsip, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
64 mov rbxp, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
65 mov rdxp, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
66 lea rsi, [rsi+rcx*SIZEOF_JSAMPROW]
67 lea rbx, [rbx+rcx*SIZEOF_JSAMPROW]
68 lea rdx, [rdx+rcx*SIZEOF_JSAMPROW]
84 mov rsip, JSAMPROW [rsi] ; inptr0
85 mov rbxp, JSAMPROW [rbx] ; inptr1
86 mov rdxp, JSAMPROW [rdx] ; inptr2
87 mov rdip, JSAMPROW [rdi] ; outptr
90 vmovdqu ymm5, YMMWORD [rbx] ; ymm5=Cb(0123456789ABCDEFGHIJKLMNOPQRSTUV)
91 vmovdqu ymm1, YMMWORD [rdx] ; ymm1=Cr(0123456789ABCDEFGHIJKLMNOPQRSTUV)
93 vpcmpeqw ymm0, ymm0, ymm0
94 vpcmpeqw ymm7, ymm7, ymm7
95 vpsrlw ymm0, ymm0, BYTE_BIT ; ymm0={0xFF 0x00 0xFF 0x00 ..}
96 vpsllw ymm7, ymm7, 7 ; ymm7={0xFF80 0xFF80 0xFF80 0xFF80 ..}
98 vpand ymm4, ymm0, ymm5 ; ymm4=Cb(02468ACEGIKMOQSU)=CbE
99 vpsrlw ymm5, ymm5, BYTE_BIT ; ymm5=Cb(13579BDFHJLNPRTV)=CbO
100 vpand ymm0, ymm0, ymm1 ; ymm0=Cr(02468ACEGIKMOQSU)=CrE
101 vpsrlw ymm1, ymm1, BYTE_BIT ; ymm1=Cr(13579BDFHJLNPRTV)=CrO
103 vpaddw ymm2, ymm4, ymm7
104 vpaddw ymm3, ymm5, ymm7
105 vpaddw ymm6, ymm0, ymm7
106 vpaddw ymm7, ymm1, ymm7
109 ; R = Y + 1.40200 * Cr
110 ; G = Y - 0.34414 * Cb - 0.71414 * Cr
111 ; B = Y + 1.77200 * Cb
113 ; (This implementation)
114 ; R = Y + 0.40200 * Cr + Cr
115 ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
116 ; B = Y - 0.22800 * Cb + Cb + Cb
118 vpaddw ymm4, ymm2, ymm2 ; ymm4=2*CbE
119 vpaddw ymm5, ymm3, ymm3 ; ymm5=2*CbO
120 vpaddw ymm0, ymm6, ymm6 ; ymm0=2*CrE
121 vpaddw ymm1, ymm7, ymm7 ; ymm1=2*CrO
123 vpmulhw ymm4, ymm4, [rel PW_MF0228] ; ymm4=(2*CbE * -FIX(0.22800))
124 vpmulhw ymm5, ymm5, [rel PW_MF0228] ; ymm5=(2*CbO * -FIX(0.22800))
125 vpmulhw ymm0, ymm0, [rel PW_F0402] ; ymm0=(2*CrE * FIX(0.40200))
126 vpmulhw ymm1, ymm1, [rel PW_F0402] ; ymm1=(2*CrO * FIX(0.40200))
128 vpaddw ymm4, ymm4, [rel PW_ONE]
129 vpaddw ymm5, ymm5, [rel PW_ONE]
130 vpsraw ymm4, ymm4, 1 ; ymm4=(CbE * -FIX(0.22800))
131 vpsraw ymm5, ymm5, 1 ; ymm5=(CbO * -FIX(0.22800))
132 vpaddw ymm0, ymm0, [rel PW_ONE]
133 vpaddw ymm1, ymm1, [rel PW_ONE]
134 vpsraw ymm0, ymm0, 1 ; ymm0=(CrE * FIX(0.40200))
135 vpsraw ymm1, ymm1, 1 ; ymm1=(CrO * FIX(0.40200))
137 vpaddw ymm4, ymm4, ymm2
138 vpaddw ymm5, ymm5, ymm3
139 vpaddw ymm4, ymm4, ymm2 ; ymm4=(CbE * FIX(1.77200))=(B-Y)E
140 vpaddw ymm5, ymm5, ymm3 ; ymm5=(CbO * FIX(1.77200))=(B-Y)O
141 vpaddw ymm0, ymm0, ymm6 ; ymm0=(CrE * FIX(1.40200))=(R-Y)E
142 vpaddw ymm1, ymm1, ymm7 ; ymm1=(CrO * FIX(1.40200))=(R-Y)O
144 vmovdqa YMMWORD [wk(0)], ymm4 ; wk(0)=(B-Y)E
145 vmovdqa YMMWORD [wk(1)], ymm5 ; wk(1)=(B-Y)O
147 vpunpckhwd ymm4, ymm2, ymm6
148 vpunpcklwd ymm2, ymm2, ymm6
149 vpmaddwd ymm2, ymm2, [rel PW_MF0344_F0285]
150 vpmaddwd ymm4, ymm4, [rel PW_MF0344_F0285]
151 vpunpckhwd ymm5, ymm3, ymm7
152 vpunpcklwd ymm3, ymm3, ymm7
153 vpmaddwd ymm3, ymm3, [rel PW_MF0344_F0285]
154 vpmaddwd ymm5, ymm5, [rel PW_MF0344_F0285]
156 vpaddd ymm2, ymm2, [rel PD_ONEHALF]
157 vpaddd ymm4, ymm4, [rel PD_ONEHALF]
158 vpsrad ymm2, ymm2, SCALEBITS
159 vpsrad ymm4, ymm4, SCALEBITS
160 vpaddd ymm3, ymm3, [rel PD_ONEHALF]
161 vpaddd ymm5, ymm5, [rel PD_ONEHALF]
162 vpsrad ymm3, ymm3, SCALEBITS
163 vpsrad ymm5, ymm5, SCALEBITS
165 vpackssdw ymm2, ymm2, ymm4 ; ymm2=CbE*-FIX(0.344)+CrE*FIX(0.285)
166 vpackssdw ymm3, ymm3, ymm5 ; ymm3=CbO*-FIX(0.344)+CrO*FIX(0.285)
167 vpsubw ymm2, ymm2, ymm6 ; ymm2=CbE*-FIX(0.344)+CrE*-FIX(0.714)=(G-Y)E
168 vpsubw ymm3, ymm3, ymm7 ; ymm3=CbO*-FIX(0.344)+CrO*-FIX(0.714)=(G-Y)O
170 vmovdqu ymm5, YMMWORD [rsi] ; ymm5=Y(0123456789ABCDEFGHIJKLMNOPQRSTUV)
172 vpcmpeqw ymm4, ymm4, ymm4
173 vpsrlw ymm4, ymm4, BYTE_BIT ; ymm4={0xFF 0x00 0xFF 0x00 ..}
174 vpand ymm4, ymm4, ymm5 ; ymm4=Y(02468ACEGIKMOQSU)=YE
175 vpsrlw ymm5, ymm5, BYTE_BIT ; ymm5=Y(13579BDFHJLNPRTV)=YO
177 vpaddw ymm0, ymm0, ymm4 ; ymm0=((R-Y)E+YE)=RE=R(02468ACEGIKMOQSU)
178 vpaddw ymm1, ymm1, ymm5 ; ymm1=((R-Y)O+YO)=RO=R(13579BDFHJLNPRTV)
179 vpackuswb ymm0, ymm0, ymm0 ; ymm0=R(02468ACE********GIKMOQSU********)
180 vpackuswb ymm1, ymm1, ymm1 ; ymm1=R(13579BDF********HJLNPRTV********)
182 vpaddw ymm2, ymm2, ymm4 ; ymm2=((G-Y)E+YE)=GE=G(02468ACEGIKMOQSU)
183 vpaddw ymm3, ymm3, ymm5 ; ymm3=((G-Y)O+YO)=GO=G(13579BDFHJLNPRTV)
184 vpackuswb ymm2, ymm2, ymm2 ; ymm2=G(02468ACE********GIKMOQSU********)
185 vpackuswb ymm3, ymm3, ymm3 ; ymm3=G(13579BDF********HJLNPRTV********)
187 vpaddw ymm4, ymm4, YMMWORD [wk(0)] ; ymm4=(YE+(B-Y)E)=BE=B(02468ACEGIKMOQSU)
188 vpaddw ymm5, ymm5, YMMWORD [wk(1)] ; ymm5=(YO+(B-Y)O)=BO=B(13579BDFHJLNPRTV)
189 vpackuswb ymm4, ymm4, ymm4 ; ymm4=B(02468ACE********GIKMOQSU********)
190 vpackuswb ymm5, ymm5, ymm5 ; ymm5=B(13579BDF********HJLNPRTV********)
192 %if RGB_PIXELSIZE == 3 ; ---------------
194 ; ymmA=(00 02 04 06 08 0A 0C 0E ** 0G 0I 0K 0M 0O 0Q 0S 0U **)
195 ; ymmB=(01 03 05 07 09 0B 0D 0F ** 0H 0J 0L 0N 0P 0R 0T 0V **)
196 ; ymmC=(10 12 14 16 18 1A 1C 1E ** 1G 1I 1K 1M 1O 1Q 1S 1U **)
197 ; ymmD=(11 13 15 17 19 1B 1D 1F ** 1H 1J 1L 1N 1P 1R 1T 1V **)
198 ; ymmE=(20 22 24 26 28 2A 2C 2E ** 2G 2I 2K 2M 2O 2Q 2S 2U **)
199 ; ymmF=(21 23 25 27 29 2B 2D 2F ** 2H 2J 2L 2N 2P 2R 2T 2V **)
200 ; ymmG=(** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **)
201 ; ymmH=(** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** **)
203 vpunpcklbw ymmA, ymmA, ymmC ; ymmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E
204 ; 0G 1G 0I 1I 0K 1K 0M 1M 0O 1O 0Q 1Q 0S 1S 0U 1U)
205 vpunpcklbw ymmE, ymmE, ymmB ; ymmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F
206 ; 2G 0H 2I 0J 2K 0L 2M 0N 2O 0P 2Q 0R 2S 0T 2U 0V)
207 vpunpcklbw ymmD, ymmD, ymmF ; ymmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F
208 ; 1H 2H 1J 2J 1L 2L 1N 2N 1P 2P 1R 2R 1T 2T 1V 2V)
210 vpsrldq ymmH, ymmA, 2 ; ymmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E 0G 1G
211 ; 0I 1I 0K 1K 0M 1M 0O 1O 0Q 1Q 0S 1S 0U 1U -- --)
212 vpunpckhwd ymmG, ymmA, ymmE ; ymmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F
213 ; 0O 1O 2O 0P 0Q 1Q 2Q 0R 0S 1S 2S 0T 0U 1U 2U 0V)
214 vpunpcklwd ymmA, ymmA, ymmE ; ymmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07
215 ; 0G 1G 2G 0H 0I 1I 2I 0J 0K 1K 2K 0L 0M 1M 2M 0N)
217 vpsrldq ymmE, ymmE, 2 ; ymmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F 2G 0H
218 ; 2I 0J 2K 0L 2M 0N 2O 0P 2Q 0R 2S 0T 2U 0V -- --)
220 vpsrldq ymmB, ymmD, 2 ; ymmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F 1H 2H
221 ; 1J 2J 1L 2L 1N 2N 1P 2P 1R 2R 1T 2T 1V 2V -- --)
222 vpunpckhwd ymmC, ymmD, ymmH ; ymmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F 0G 1G
223 ; 1P 2P 0Q 1Q 1R 2R 0S 1S 1T 2T 0U 1U 1V 2V -- --)
224 vpunpcklwd ymmD, ymmD, ymmH ; ymmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18
225 ; 1H 2H 0I 1I 1J 2J 0K 1K 1L 2L 0M 1M 1N 2N 0O 1O)
227 vpunpckhwd ymmF, ymmE, ymmB ; ymmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F 2G 0H 1H 2H
228 ; 2Q 0R 1R 2R 2S 0T 1T 2T 2U 0V 1V 2V -- -- -- --)
229 vpunpcklwd ymmE, ymmE, ymmB ; ymmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29
230 ; 2I 0J 1J 2J 2K 0L 1L 2L 2M 0N 1N 2N 2O 0P 1P 2P)
232 vpshufd ymmH, ymmA, 0x4E ; ymmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03
233 ; 0K 1K 2K 0L 0M 1M 2M 0N 0G 1G 2G 0H 0I 1I 2I 0J)
234 vpunpckldq ymmA, ymmA, ymmD ; ymmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14
235 ; 0G 1G 2G 0H 1H 2H 0I 1I 0I 1I 2I 0J 1J 2J 0K 1K)
236 vpunpckhdq ymmD, ymmD, ymmE ; ymmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29
237 ; 1L 2L 0M 1M 2M 0N 1N 2N 1N 2N 0O 1O 2O 0P 1P 2P)
238 vpunpckldq ymmE, ymmE, ymmH ; ymmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07
239 ; 2I 0J 1J 2J 0K 1K 2K 0L 2K 0L 1L 2L 0M 1M 2M 0N)
241 vpshufd ymmH, ymmG, 0x4E ; ymmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B
242 ; 0S 1S 2S 0T 0U 1U 2U 0V 0O 1O 2O 0P 0Q 1Q 2Q 0R)
243 vpunpckldq ymmG, ymmG, ymmC ; ymmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C
244 ; 0O 1O 2O 0P 1P 2P 0Q 1Q 0Q 1Q 2Q 0R 1R 2R 0S 1S)
245 vpunpckhdq ymmC, ymmC, ymmF ; ymmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F 0G 1G 2G 0H 1H 2H
246 ; 1T 2T 0U 1U 2U 0V 1V 2V 1V 2V -- -- -- -- -- --)
247 vpunpckldq ymmF, ymmF, ymmH ; ymmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F
248 ; 2Q 0R 1R 2R 0S 1S 2S 0T 2S 0T 1T 2T 0U 1U 2U 0V)
250 vpunpcklqdq ymmH, ymmA, ymmE ; ymmH=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05
251 ; 0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L)
252 vpunpcklqdq ymmG, ymmD, ymmG ; ymmG=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A
253 ; 1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q)
254 vpunpcklqdq ymmC, ymmF, ymmC ; ymmC=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F
255 ; 2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V)
257 vperm2i128 ymmA, ymmH, ymmG, 0x20 ; ymmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05
258 ; 15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
259 vperm2i128 ymmD, ymmC, ymmH, 0x30 ; ymmD=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F
260 ; 0G 1G 2G 0H 1H 2H 0I 1I 2I 0J 1J 2J 0K 1K 2K 0L)
261 vperm2i128 ymmF, ymmG, ymmC, 0x31 ; ymmF=(1L 2L 0M 1M 2M 0N 1N 2N 0O 1O 2O 0P 1P 2P 0Q 1Q
262 ; 2Q 0R 1R 2R 0S 1S 2S 0T 1T 2T 0U 1U 2U 0V 1V 2V)
264 cmp rcx, byte SIZEOF_YMMWORD
265 jb short .column_st64
267 test rdi, SIZEOF_YMMWORD-1
269 ; --(aligned)-------------------
270 vmovntdq YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
271 vmovntdq YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
272 vmovntdq YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmF
274 .out1: ; --(unaligned)-----------------
275 vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
276 vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
277 vmovdqu YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmF
279 add rdi, byte RGB_PIXELSIZE*SIZEOF_YMMWORD ; outptr
280 sub rcx, byte SIZEOF_YMMWORD
283 add rsi, byte SIZEOF_YMMWORD ; inptr0
284 add rbx, byte SIZEOF_YMMWORD ; inptr1
285 add rdx, byte SIZEOF_YMMWORD ; inptr2
289 lea rcx, [rcx+rcx*2] ; imul ecx, RGB_PIXELSIZE
290 cmp rcx, byte 2*SIZEOF_YMMWORD
291 jb short .column_st32
292 vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
293 vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
294 add rdi, byte 2*SIZEOF_YMMWORD ; outptr
296 sub rcx, byte 2*SIZEOF_YMMWORD
297 jmp short .column_st31
299 cmp rcx, byte SIZEOF_YMMWORD
300 jb short .column_st31
301 vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
302 add rdi, byte SIZEOF_YMMWORD ; outptr
304 sub rcx, byte SIZEOF_YMMWORD
305 jmp short .column_st31
307 cmp rcx, byte SIZEOF_XMMWORD
308 jb short .column_st15
309 vmovdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
310 add rdi, byte SIZEOF_XMMWORD ; outptr
311 vperm2i128 ymmA, ymmA, ymmA, 1
312 sub rcx, byte SIZEOF_XMMWORD
314 ; Store the lower 8 bytes of xmmA to the output when it has enough
316 cmp rcx, byte SIZEOF_MMWORD
318 vmovq XMM_MMWORD [rdi], xmmA
319 add rdi, byte SIZEOF_MMWORD
320 sub rcx, byte SIZEOF_MMWORD
321 vpsrldq xmmA, xmmA, SIZEOF_MMWORD
323 ; Store the lower 4 bytes of xmmA to the output when it has enough
325 cmp rcx, byte SIZEOF_DWORD
327 vmovd XMM_DWORD [rdi], xmmA
328 add rdi, byte SIZEOF_DWORD
329 sub rcx, byte SIZEOF_DWORD
330 vpsrldq xmmA, xmmA, SIZEOF_DWORD
332 ; Store the lower 2 bytes of rax to the output when it has enough
335 cmp rcx, byte SIZEOF_WORD
338 add rdi, byte SIZEOF_WORD
339 sub rcx, byte SIZEOF_WORD
342 ; Store the lower 1 byte of rax to the output when it has enough
348 %else ; RGB_PIXELSIZE == 4 ; -----------
350 %ifdef RGBX_FILLER_0XFF
351 vpcmpeqb ymm6, ymm6, ymm6 ; ymm6=XE=X(02468ACE********GIKMOQSU********)
352 vpcmpeqb ymm7, ymm7, ymm7 ; ymm7=XO=X(13579BDF********HJLNPRTV********)
354 vpxor ymm6, ymm6, ymm6 ; ymm6=XE=X(02468ACE********GIKMOQSU********)
355 vpxor ymm7, ymm7, ymm7 ; ymm7=XO=X(13579BDF********HJLNPRTV********)
357 ; ymmA=(00 02 04 06 08 0A 0C 0E ** 0G 0I 0K 0M 0O 0Q 0S 0U **)
358 ; ymmB=(01 03 05 07 09 0B 0D 0F ** 0H 0J 0L 0N 0P 0R 0T 0V **)
359 ; ymmC=(10 12 14 16 18 1A 1C 1E ** 1G 1I 1K 1M 1O 1Q 1S 1U **)
360 ; ymmD=(11 13 15 17 19 1B 1D 1F ** 1H 1J 1L 1N 1P 1R 1T 1V **)
361 ; ymmE=(20 22 24 26 28 2A 2C 2E ** 2G 2I 2K 2M 2O 2Q 2S 2U **)
362 ; ymmF=(21 23 25 27 29 2B 2D 2F ** 2H 2J 2L 2N 2P 2R 2T 2V **)
363 ; ymmG=(30 32 34 36 38 3A 3C 3E ** 3G 3I 3K 3M 3O 3Q 3S 3U **)
364 ; ymmH=(31 33 35 37 39 3B 3D 3F ** 3H 3J 3L 3N 3P 3R 3T 3V **)
366 vpunpcklbw ymmA, ymmA, ymmC ; ymmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E
367 ; 0G 1G 0I 1I 0K 1K 0M 1M 0O 1O 0Q 1Q 0S 1S 0U 1U)
368 vpunpcklbw ymmE, ymmE, ymmG ; ymmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E
369 ; 2G 3G 2I 3I 2K 3K 2M 3M 2O 3O 2Q 3Q 2S 3S 2U 3U)
370 vpunpcklbw ymmB, ymmB, ymmD ; ymmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F
371 ; 0H 1H 0J 1J 0L 1L 0N 1N 0P 1P 0R 1R 0T 1T 0V 1V)
372 vpunpcklbw ymmF, ymmF, ymmH ; ymmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F
373 ; 2H 3H 2J 3J 2L 3L 2N 3N 2P 3P 2R 3R 2T 3T 2V 3V)
375 vpunpckhwd ymmC, ymmA, ymmE ; ymmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E
376 ; 0O 1O 2O 3O 0Q 1Q 2Q 3Q 0S 1S 2S 3S 0U 1U 2U 3U)
377 vpunpcklwd ymmA, ymmA, ymmE ; ymmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36
378 ; 0G 1G 2G 3G 0I 1I 2I 3I 0K 1K 2K 3K 0M 1M 2M 3M)
379 vpunpckhwd ymmG, ymmB, ymmF ; ymmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F
380 ; 0P 1P 2P 3P 0R 1R 2R 3R 0T 1T 2T 3T 0V 1V 2V 3V)
381 vpunpcklwd ymmB, ymmB, ymmF ; ymmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37
382 ; 0H 1H 2H 3H 0J 1J 2J 3J 0L 1L 2L 3L 0N 1N 2N 3N)
384 vpunpckhdq ymmE, ymmA, ymmB ; ymmE=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37
385 ; 0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N)
386 vpunpckldq ymmB, ymmA, ymmB ; ymmB=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
387 ; 0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J)
388 vpunpckhdq ymmF, ymmC, ymmG ; ymmF=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F
389 ; 0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V)
390 vpunpckldq ymmG, ymmC, ymmG ; ymmG=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B
391 ; 0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R)
393 vperm2i128 ymmA, ymmB, ymmE, 0x20 ; ymmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33
394 ; 04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
395 vperm2i128 ymmD, ymmG, ymmF, 0x20 ; ymmD=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B
396 ; 0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
397 vperm2i128 ymmC, ymmB, ymmE, 0x31 ; ymmC=(0G 1G 2G 3G 0H 1H 2H 3H 0I 1I 2I 3I 0J 1J 2J 3J
398 ; 0K 1K 2K 3K 0L 1L 2L 3L 0M 1M 2M 3M 0N 1N 2N 3N)
399 vperm2i128 ymmH, ymmG, ymmF, 0x31 ; ymmH=(0O 1O 2O 3O 0P 1P 2P 3P 0Q 1Q 2Q 3Q 0R 1R 2R 3R
400 ; 0S 1S 2S 3S 0T 1T 2T 3T 0U 1U 2U 3U 0V 1V 2V 3V)
402 cmp rcx, byte SIZEOF_YMMWORD
403 jb short .column_st64
405 test rdi, SIZEOF_YMMWORD-1
407 ; --(aligned)-------------------
408 vmovntdq YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
409 vmovntdq YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
410 vmovntdq YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmC
411 vmovntdq YMMWORD [rdi+3*SIZEOF_YMMWORD], ymmH
413 .out1: ; --(unaligned)-----------------
414 vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
415 vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
416 vmovdqu YMMWORD [rdi+2*SIZEOF_YMMWORD], ymmC
417 vmovdqu YMMWORD [rdi+3*SIZEOF_YMMWORD], ymmH
419 add rdi, RGB_PIXELSIZE*SIZEOF_YMMWORD ; outptr
420 sub rcx, byte SIZEOF_YMMWORD
423 add rsi, byte SIZEOF_YMMWORD ; inptr0
424 add rbx, byte SIZEOF_YMMWORD ; inptr1
425 add rdx, byte SIZEOF_YMMWORD ; inptr2
429 cmp rcx, byte SIZEOF_YMMWORD/2
430 jb short .column_st32
431 vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
432 vmovdqu YMMWORD [rdi+1*SIZEOF_YMMWORD], ymmD
433 add rdi, byte 2*SIZEOF_YMMWORD ; outptr
436 sub rcx, byte SIZEOF_YMMWORD/2
438 cmp rcx, byte SIZEOF_YMMWORD/4
439 jb short .column_st16
440 vmovdqu YMMWORD [rdi+0*SIZEOF_YMMWORD], ymmA
441 add rdi, byte SIZEOF_YMMWORD ; outptr
443 sub rcx, byte SIZEOF_YMMWORD/4
445 cmp rcx, byte SIZEOF_YMMWORD/8
446 jb short .column_st15
447 vmovdqu XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
448 vperm2i128 ymmA, ymmA, ymmA, 1
449 add rdi, byte SIZEOF_XMMWORD ; outptr
450 sub rcx, byte SIZEOF_YMMWORD/8
452 ; Store two pixels (8 bytes) of ymmA to the output when it has enough
454 cmp rcx, byte SIZEOF_YMMWORD/16
456 vmovq MMWORD [rdi], xmmA
457 add rdi, byte SIZEOF_YMMWORD/16*4
458 sub rcx, byte SIZEOF_YMMWORD/16
459 vpsrldq xmmA, SIZEOF_YMMWORD/16*4
461 ; Store one pixel (4 bytes) of ymmA to the output when it has enough
465 vmovd XMM_DWORD [rdi], xmmA
467 %endif ; RGB_PIXELSIZE ; ---------------
477 add rsi, byte SIZEOF_JSAMPROW
478 add rbx, byte SIZEOF_JSAMPROW
479 add rdx, byte SIZEOF_JSAMPROW
480 add rdi, byte SIZEOF_JSAMPROW ; output_buf
484 sfence ; flush the write buffer
495 ; For some reason, the OS X linker does not honor the request to align the
496 ; segment unless we do this.