xref: /aosp_15_r20/external/libjpeg-turbo/simd/x86_64/jdmrgext-sse2.asm (revision dfc6aa5c1cfd4bc4e2018dc74aa96e29ee49c6da)
1*dfc6aa5cSAndroid Build Coastguard Worker;
2*dfc6aa5cSAndroid Build Coastguard Worker; jdmrgext.asm - merged upsampling/color conversion (64-bit SSE2)
3*dfc6aa5cSAndroid Build Coastguard Worker;
4*dfc6aa5cSAndroid Build Coastguard Worker; Copyright 2009, 2012 Pierre Ossman <ossman@cendio.se> for Cendio AB
5*dfc6aa5cSAndroid Build Coastguard Worker; Copyright (C) 2009, 2012, 2016, D. R. Commander.
6*dfc6aa5cSAndroid Build Coastguard Worker; Copyright (C) 2018, Matthias Räncker.
7*dfc6aa5cSAndroid Build Coastguard Worker;
8*dfc6aa5cSAndroid Build Coastguard Worker; Based on the x86 SIMD extension for IJG JPEG library
9*dfc6aa5cSAndroid Build Coastguard Worker; Copyright (C) 1999-2006, MIYASAKA Masaru.
10*dfc6aa5cSAndroid Build Coastguard Worker; For conditions of distribution and use, see copyright notice in jsimdext.inc
11*dfc6aa5cSAndroid Build Coastguard Worker;
12*dfc6aa5cSAndroid Build Coastguard Worker; This file should be assembled with NASM (Netwide Assembler),
13*dfc6aa5cSAndroid Build Coastguard Worker; can *not* be assembled with Microsoft's MASM or any compatible
14*dfc6aa5cSAndroid Build Coastguard Worker; assembler (including Borland's Turbo Assembler).
15*dfc6aa5cSAndroid Build Coastguard Worker; NASM is available from http://nasm.sourceforge.net/ or
16*dfc6aa5cSAndroid Build Coastguard Worker; http://sourceforge.net/project/showfiles.php?group_id=6208
17*dfc6aa5cSAndroid Build Coastguard Worker
18*dfc6aa5cSAndroid Build Coastguard Worker%include "jcolsamp.inc"
19*dfc6aa5cSAndroid Build Coastguard Worker
20*dfc6aa5cSAndroid Build Coastguard Worker; --------------------------------------------------------------------------
21*dfc6aa5cSAndroid Build Coastguard Worker;
22*dfc6aa5cSAndroid Build Coastguard Worker; Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.
23*dfc6aa5cSAndroid Build Coastguard Worker;
24*dfc6aa5cSAndroid Build Coastguard Worker; GLOBAL(void)
25*dfc6aa5cSAndroid Build Coastguard Worker; jsimd_h2v1_merged_upsample_sse2(JDIMENSION output_width,
26*dfc6aa5cSAndroid Build Coastguard Worker;                                 JSAMPIMAGE input_buf,
27*dfc6aa5cSAndroid Build Coastguard Worker;                                 JDIMENSION in_row_group_ctr,
28*dfc6aa5cSAndroid Build Coastguard Worker;                                 JSAMPARRAY output_buf);
29*dfc6aa5cSAndroid Build Coastguard Worker;
30*dfc6aa5cSAndroid Build Coastguard Worker
31*dfc6aa5cSAndroid Build Coastguard Worker; r10d = JDIMENSION output_width
32*dfc6aa5cSAndroid Build Coastguard Worker; r11 = JSAMPIMAGE input_buf
33*dfc6aa5cSAndroid Build Coastguard Worker; r12d = JDIMENSION in_row_group_ctr
34*dfc6aa5cSAndroid Build Coastguard Worker; r13 = JSAMPARRAY output_buf
35*dfc6aa5cSAndroid Build Coastguard Worker
36*dfc6aa5cSAndroid Build Coastguard Worker%define wk(i)   rbp - (WK_NUM - (i)) * SIZEOF_XMMWORD  ; xmmword wk[WK_NUM]
37*dfc6aa5cSAndroid Build Coastguard Worker%define WK_NUM  3
38*dfc6aa5cSAndroid Build Coastguard Worker
39*dfc6aa5cSAndroid Build Coastguard Worker    align       32
40*dfc6aa5cSAndroid Build Coastguard Worker    GLOBAL_FUNCTION(jsimd_h2v1_merged_upsample_sse2)
41*dfc6aa5cSAndroid Build Coastguard Worker
42*dfc6aa5cSAndroid Build Coastguard WorkerEXTN(jsimd_h2v1_merged_upsample_sse2):
43*dfc6aa5cSAndroid Build Coastguard Worker    push        rbp
44*dfc6aa5cSAndroid Build Coastguard Worker    mov         rax, rsp                     ; rax = original rbp
45*dfc6aa5cSAndroid Build Coastguard Worker    sub         rsp, byte 4
46*dfc6aa5cSAndroid Build Coastguard Worker    and         rsp, byte (-SIZEOF_XMMWORD)  ; align to 128 bits
47*dfc6aa5cSAndroid Build Coastguard Worker    mov         [rsp], rax
48*dfc6aa5cSAndroid Build Coastguard Worker    mov         rbp, rsp                     ; rbp = aligned rbp
49*dfc6aa5cSAndroid Build Coastguard Worker    lea         rsp, [wk(0)]
50*dfc6aa5cSAndroid Build Coastguard Worker    collect_args 4
51*dfc6aa5cSAndroid Build Coastguard Worker    push        rbx
52*dfc6aa5cSAndroid Build Coastguard Worker
53*dfc6aa5cSAndroid Build Coastguard Worker    mov         ecx, r10d               ; col
54*dfc6aa5cSAndroid Build Coastguard Worker    test        rcx, rcx
55*dfc6aa5cSAndroid Build Coastguard Worker    jz          near .return
56*dfc6aa5cSAndroid Build Coastguard Worker
57*dfc6aa5cSAndroid Build Coastguard Worker    push        rcx
58*dfc6aa5cSAndroid Build Coastguard Worker
59*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdi, r11
60*dfc6aa5cSAndroid Build Coastguard Worker    mov         ecx, r12d
61*dfc6aa5cSAndroid Build Coastguard Worker    mov         rsip, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
62*dfc6aa5cSAndroid Build Coastguard Worker    mov         rbxp, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
63*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdxp, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
64*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdi, r13
65*dfc6aa5cSAndroid Build Coastguard Worker    mov         rsip, JSAMPROW [rsi+rcx*SIZEOF_JSAMPROW]  ; inptr0
66*dfc6aa5cSAndroid Build Coastguard Worker    mov         rbxp, JSAMPROW [rbx+rcx*SIZEOF_JSAMPROW]  ; inptr1
67*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdxp, JSAMPROW [rdx+rcx*SIZEOF_JSAMPROW]  ; inptr2
68*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdip, JSAMPROW [rdi]                      ; outptr
69*dfc6aa5cSAndroid Build Coastguard Worker
70*dfc6aa5cSAndroid Build Coastguard Worker    pop         rcx                     ; col
71*dfc6aa5cSAndroid Build Coastguard Worker
72*dfc6aa5cSAndroid Build Coastguard Worker.columnloop:
73*dfc6aa5cSAndroid Build Coastguard Worker
74*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, XMMWORD [rbx]     ; xmm6=Cb(0123456789ABCDEF)
75*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, XMMWORD [rdx]     ; xmm7=Cr(0123456789ABCDEF)
76*dfc6aa5cSAndroid Build Coastguard Worker
77*dfc6aa5cSAndroid Build Coastguard Worker    pxor        xmm1, xmm1              ; xmm1=(all 0's)
78*dfc6aa5cSAndroid Build Coastguard Worker    pcmpeqw     xmm3, xmm3
79*dfc6aa5cSAndroid Build Coastguard Worker    psllw       xmm3, 7                 ; xmm3={0xFF80 0xFF80 0xFF80 0xFF80 ..}
80*dfc6aa5cSAndroid Build Coastguard Worker
81*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm4, xmm6
82*dfc6aa5cSAndroid Build Coastguard Worker    punpckhbw   xmm6, xmm1              ; xmm6=Cb(89ABCDEF)=CbH
83*dfc6aa5cSAndroid Build Coastguard Worker    punpcklbw   xmm4, xmm1              ; xmm4=Cb(01234567)=CbL
84*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, xmm7
85*dfc6aa5cSAndroid Build Coastguard Worker    punpckhbw   xmm7, xmm1              ; xmm7=Cr(89ABCDEF)=CrH
86*dfc6aa5cSAndroid Build Coastguard Worker    punpcklbw   xmm0, xmm1              ; xmm0=Cr(01234567)=CrL
87*dfc6aa5cSAndroid Build Coastguard Worker
88*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm6, xmm3
89*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm4, xmm3
90*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm7, xmm3
91*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm0, xmm3
92*dfc6aa5cSAndroid Build Coastguard Worker
93*dfc6aa5cSAndroid Build Coastguard Worker    ; (Original)
94*dfc6aa5cSAndroid Build Coastguard Worker    ; R = Y                + 1.40200 * Cr
95*dfc6aa5cSAndroid Build Coastguard Worker    ; G = Y - 0.34414 * Cb - 0.71414 * Cr
96*dfc6aa5cSAndroid Build Coastguard Worker    ; B = Y + 1.77200 * Cb
97*dfc6aa5cSAndroid Build Coastguard Worker    ;
98*dfc6aa5cSAndroid Build Coastguard Worker    ; (This implementation)
99*dfc6aa5cSAndroid Build Coastguard Worker    ; R = Y                + 0.40200 * Cr + Cr
100*dfc6aa5cSAndroid Build Coastguard Worker    ; G = Y - 0.34414 * Cb + 0.28586 * Cr - Cr
101*dfc6aa5cSAndroid Build Coastguard Worker    ; B = Y - 0.22800 * Cb + Cb + Cb
102*dfc6aa5cSAndroid Build Coastguard Worker
103*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, xmm6              ; xmm5=CbH
104*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, xmm4              ; xmm2=CbL
105*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm6, xmm6              ; xmm6=2*CbH
106*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm4, xmm4              ; xmm4=2*CbL
107*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, xmm7              ; xmm1=CrH
108*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm3, xmm0              ; xmm3=CrL
109*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm7, xmm7              ; xmm7=2*CrH
110*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm0, xmm0              ; xmm0=2*CrL
111*dfc6aa5cSAndroid Build Coastguard Worker
112*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm6, [rel PW_MF0228]   ; xmm6=(2*CbH * -FIX(0.22800))
113*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm4, [rel PW_MF0228]   ; xmm4=(2*CbL * -FIX(0.22800))
114*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm7, [rel PW_F0402]    ; xmm7=(2*CrH * FIX(0.40200))
115*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm0, [rel PW_F0402]    ; xmm0=(2*CrL * FIX(0.40200))
116*dfc6aa5cSAndroid Build Coastguard Worker
117*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm6, [rel PW_ONE]
118*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm4, [rel PW_ONE]
119*dfc6aa5cSAndroid Build Coastguard Worker    psraw       xmm6, 1                 ; xmm6=(CbH * -FIX(0.22800))
120*dfc6aa5cSAndroid Build Coastguard Worker    psraw       xmm4, 1                 ; xmm4=(CbL * -FIX(0.22800))
121*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm7, [rel PW_ONE]
122*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm0, [rel PW_ONE]
123*dfc6aa5cSAndroid Build Coastguard Worker    psraw       xmm7, 1                 ; xmm7=(CrH * FIX(0.40200))
124*dfc6aa5cSAndroid Build Coastguard Worker    psraw       xmm0, 1                 ; xmm0=(CrL * FIX(0.40200))
125*dfc6aa5cSAndroid Build Coastguard Worker
126*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm6, xmm5
127*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm4, xmm2
128*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm6, xmm5              ; xmm6=(CbH * FIX(1.77200))=(B-Y)H
129*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm4, xmm2              ; xmm4=(CbL * FIX(1.77200))=(B-Y)L
130*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm7, xmm1              ; xmm7=(CrH * FIX(1.40200))=(R-Y)H
131*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm0, xmm3              ; xmm0=(CrL * FIX(1.40200))=(R-Y)L
132*dfc6aa5cSAndroid Build Coastguard Worker
133*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(0)], xmm6   ; wk(0)=(B-Y)H
134*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(1)], xmm7   ; wk(1)=(R-Y)H
135*dfc6aa5cSAndroid Build Coastguard Worker
136*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, xmm5
137*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, xmm2
138*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmm5, xmm1
139*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmm6, xmm1
140*dfc6aa5cSAndroid Build Coastguard Worker    pmaddwd     xmm5, [rel PW_MF0344_F0285]
141*dfc6aa5cSAndroid Build Coastguard Worker    pmaddwd     xmm6, [rel PW_MF0344_F0285]
142*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmm2, xmm3
143*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmm7, xmm3
144*dfc6aa5cSAndroid Build Coastguard Worker    pmaddwd     xmm2, [rel PW_MF0344_F0285]
145*dfc6aa5cSAndroid Build Coastguard Worker    pmaddwd     xmm7, [rel PW_MF0344_F0285]
146*dfc6aa5cSAndroid Build Coastguard Worker
147*dfc6aa5cSAndroid Build Coastguard Worker    paddd       xmm5, [rel PD_ONEHALF]
148*dfc6aa5cSAndroid Build Coastguard Worker    paddd       xmm6, [rel PD_ONEHALF]
149*dfc6aa5cSAndroid Build Coastguard Worker    psrad       xmm5, SCALEBITS
150*dfc6aa5cSAndroid Build Coastguard Worker    psrad       xmm6, SCALEBITS
151*dfc6aa5cSAndroid Build Coastguard Worker    paddd       xmm2, [rel PD_ONEHALF]
152*dfc6aa5cSAndroid Build Coastguard Worker    paddd       xmm7, [rel PD_ONEHALF]
153*dfc6aa5cSAndroid Build Coastguard Worker    psrad       xmm2, SCALEBITS
154*dfc6aa5cSAndroid Build Coastguard Worker    psrad       xmm7, SCALEBITS
155*dfc6aa5cSAndroid Build Coastguard Worker
156*dfc6aa5cSAndroid Build Coastguard Worker    packssdw    xmm5, xmm6              ; xmm5=CbH*-FIX(0.344)+CrH*FIX(0.285)
157*dfc6aa5cSAndroid Build Coastguard Worker    packssdw    xmm2, xmm7              ; xmm2=CbL*-FIX(0.344)+CrL*FIX(0.285)
158*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm5, xmm1              ; xmm5=CbH*-FIX(0.344)+CrH*-FIX(0.714)=(G-Y)H
159*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm2, xmm3              ; xmm2=CbL*-FIX(0.344)+CrL*-FIX(0.714)=(G-Y)L
160*dfc6aa5cSAndroid Build Coastguard Worker
161*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(2)], xmm5   ; wk(2)=(G-Y)H
162*dfc6aa5cSAndroid Build Coastguard Worker
163*dfc6aa5cSAndroid Build Coastguard Worker    mov         al, 2                   ; Yctr
164*dfc6aa5cSAndroid Build Coastguard Worker    jmp         short .Yloop_1st
165*dfc6aa5cSAndroid Build Coastguard Worker
166*dfc6aa5cSAndroid Build Coastguard Worker.Yloop_2nd:
167*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, XMMWORD [wk(1)]   ; xmm0=(R-Y)H
168*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, XMMWORD [wk(2)]   ; xmm2=(G-Y)H
169*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm4, XMMWORD [wk(0)]   ; xmm4=(B-Y)H
170*dfc6aa5cSAndroid Build Coastguard Worker
171*dfc6aa5cSAndroid Build Coastguard Worker.Yloop_1st:
172*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, XMMWORD [rsi]     ; xmm7=Y(0123456789ABCDEF)
173*dfc6aa5cSAndroid Build Coastguard Worker
174*dfc6aa5cSAndroid Build Coastguard Worker    pcmpeqw     xmm6, xmm6
175*dfc6aa5cSAndroid Build Coastguard Worker    psrlw       xmm6, BYTE_BIT          ; xmm6={0xFF 0x00 0xFF 0x00 ..}
176*dfc6aa5cSAndroid Build Coastguard Worker    pand        xmm6, xmm7              ; xmm6=Y(02468ACE)=YE
177*dfc6aa5cSAndroid Build Coastguard Worker    psrlw       xmm7, BYTE_BIT          ; xmm7=Y(13579BDF)=YO
178*dfc6aa5cSAndroid Build Coastguard Worker
179*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, xmm0              ; xmm1=xmm0=(R-Y)(L/H)
180*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm3, xmm2              ; xmm3=xmm2=(G-Y)(L/H)
181*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, xmm4              ; xmm5=xmm4=(B-Y)(L/H)
182*dfc6aa5cSAndroid Build Coastguard Worker
183*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm0, xmm6              ; xmm0=((R-Y)+YE)=RE=R(02468ACE)
184*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm1, xmm7              ; xmm1=((R-Y)+YO)=RO=R(13579BDF)
185*dfc6aa5cSAndroid Build Coastguard Worker    packuswb    xmm0, xmm0              ; xmm0=R(02468ACE********)
186*dfc6aa5cSAndroid Build Coastguard Worker    packuswb    xmm1, xmm1              ; xmm1=R(13579BDF********)
187*dfc6aa5cSAndroid Build Coastguard Worker
188*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm2, xmm6              ; xmm2=((G-Y)+YE)=GE=G(02468ACE)
189*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm3, xmm7              ; xmm3=((G-Y)+YO)=GO=G(13579BDF)
190*dfc6aa5cSAndroid Build Coastguard Worker    packuswb    xmm2, xmm2              ; xmm2=G(02468ACE********)
191*dfc6aa5cSAndroid Build Coastguard Worker    packuswb    xmm3, xmm3              ; xmm3=G(13579BDF********)
192*dfc6aa5cSAndroid Build Coastguard Worker
193*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm4, xmm6              ; xmm4=((B-Y)+YE)=BE=B(02468ACE)
194*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm5, xmm7              ; xmm5=((B-Y)+YO)=BO=B(13579BDF)
195*dfc6aa5cSAndroid Build Coastguard Worker    packuswb    xmm4, xmm4              ; xmm4=B(02468ACE********)
196*dfc6aa5cSAndroid Build Coastguard Worker    packuswb    xmm5, xmm5              ; xmm5=B(13579BDF********)
197*dfc6aa5cSAndroid Build Coastguard Worker
198*dfc6aa5cSAndroid Build Coastguard Worker%if RGB_PIXELSIZE == 3  ; ---------------
199*dfc6aa5cSAndroid Build Coastguard Worker
200*dfc6aa5cSAndroid Build Coastguard Worker    ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
201*dfc6aa5cSAndroid Build Coastguard Worker    ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
202*dfc6aa5cSAndroid Build Coastguard Worker    ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
203*dfc6aa5cSAndroid Build Coastguard Worker    ; xmmG=(** ** ** ** ** ** ** ** **), xmmH=(** ** ** ** ** ** ** ** **)
204*dfc6aa5cSAndroid Build Coastguard Worker
205*dfc6aa5cSAndroid Build Coastguard Worker    punpcklbw   xmmA, xmmC        ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
206*dfc6aa5cSAndroid Build Coastguard Worker    punpcklbw   xmmE, xmmB        ; xmmE=(20 01 22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F)
207*dfc6aa5cSAndroid Build Coastguard Worker    punpcklbw   xmmD, xmmF        ; xmmD=(11 21 13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F)
208*dfc6aa5cSAndroid Build Coastguard Worker
209*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmG, xmmA
210*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmH, xmmA
211*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmmA, xmmE        ; xmmA=(00 10 20 01 02 12 22 03 04 14 24 05 06 16 26 07)
212*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmmG, xmmE        ; xmmG=(08 18 28 09 0A 1A 2A 0B 0C 1C 2C 0D 0E 1E 2E 0F)
213*dfc6aa5cSAndroid Build Coastguard Worker
214*dfc6aa5cSAndroid Build Coastguard Worker    psrldq      xmmH, 2           ; xmmH=(02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E -- --)
215*dfc6aa5cSAndroid Build Coastguard Worker    psrldq      xmmE, 2           ; xmmE=(22 03 24 05 26 07 28 09 2A 0B 2C 0D 2E 0F -- --)
216*dfc6aa5cSAndroid Build Coastguard Worker
217*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmC, xmmD
218*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmB, xmmD
219*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmmD, xmmH        ; xmmD=(11 21 02 12 13 23 04 14 15 25 06 16 17 27 08 18)
220*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmmC, xmmH        ; xmmC=(19 29 0A 1A 1B 2B 0C 1C 1D 2D 0E 1E 1F 2F -- --)
221*dfc6aa5cSAndroid Build Coastguard Worker
222*dfc6aa5cSAndroid Build Coastguard Worker    psrldq      xmmB, 2           ; xmmB=(13 23 15 25 17 27 19 29 1B 2B 1D 2D 1F 2F -- --)
223*dfc6aa5cSAndroid Build Coastguard Worker
224*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmF, xmmE
225*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmmE, xmmB        ; xmmE=(22 03 13 23 24 05 15 25 26 07 17 27 28 09 19 29)
226*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmmF, xmmB        ; xmmF=(2A 0B 1B 2B 2C 0D 1D 2D 2E 0F 1F 2F -- -- -- --)
227*dfc6aa5cSAndroid Build Coastguard Worker
228*dfc6aa5cSAndroid Build Coastguard Worker    pshufd      xmmH, xmmA, 0x4E  ; xmmH=(04 14 24 05 06 16 26 07 00 10 20 01 02 12 22 03)
229*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmB, xmmE
230*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmmA, xmmD        ; xmmA=(00 10 20 01 11 21 02 12 02 12 22 03 13 23 04 14)
231*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmmE, xmmH        ; xmmE=(22 03 13 23 04 14 24 05 24 05 15 25 06 16 26 07)
232*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmmD, xmmB        ; xmmD=(15 25 06 16 26 07 17 27 17 27 08 18 28 09 19 29)
233*dfc6aa5cSAndroid Build Coastguard Worker
234*dfc6aa5cSAndroid Build Coastguard Worker    pshufd      xmmH, xmmG, 0x4E  ; xmmH=(0C 1C 2C 0D 0E 1E 2E 0F 08 18 28 09 0A 1A 2A 0B)
235*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmB, xmmF
236*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmmG, xmmC        ; xmmG=(08 18 28 09 19 29 0A 1A 0A 1A 2A 0B 1B 2B 0C 1C)
237*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmmF, xmmH        ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 2C 0D 1D 2D 0E 1E 2E 0F)
238*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmmC, xmmB        ; xmmC=(1D 2D 0E 1E 2E 0F 1F 2F 1F 2F -- -- -- -- -- --)
239*dfc6aa5cSAndroid Build Coastguard Worker
240*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmmA, xmmE        ; xmmA=(00 10 20 01 11 21 02 12 22 03 13 23 04 14 24 05)
241*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmmD, xmmG        ; xmmD=(15 25 06 16 26 07 17 27 08 18 28 09 19 29 0A 1A)
242*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmmF, xmmC        ; xmmF=(2A 0B 1B 2B 0C 1C 2C 0D 1D 2D 0E 1E 2E 0F 1F 2F)
243*dfc6aa5cSAndroid Build Coastguard Worker
244*dfc6aa5cSAndroid Build Coastguard Worker    cmp         rcx, byte SIZEOF_XMMWORD
245*dfc6aa5cSAndroid Build Coastguard Worker    jb          short .column_st32
246*dfc6aa5cSAndroid Build Coastguard Worker
247*dfc6aa5cSAndroid Build Coastguard Worker    test        rdi, SIZEOF_XMMWORD-1
248*dfc6aa5cSAndroid Build Coastguard Worker    jnz         short .out1
249*dfc6aa5cSAndroid Build Coastguard Worker    ; --(aligned)-------------------
250*dfc6aa5cSAndroid Build Coastguard Worker    movntdq     XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
251*dfc6aa5cSAndroid Build Coastguard Worker    movntdq     XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
252*dfc6aa5cSAndroid Build Coastguard Worker    movntdq     XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
253*dfc6aa5cSAndroid Build Coastguard Worker    jmp         short .out0
254*dfc6aa5cSAndroid Build Coastguard Worker.out1:  ; --(unaligned)-----------------
255*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
256*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
257*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmF
258*dfc6aa5cSAndroid Build Coastguard Worker.out0:
259*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD  ; outptr
260*dfc6aa5cSAndroid Build Coastguard Worker    sub         rcx, byte SIZEOF_XMMWORD
261*dfc6aa5cSAndroid Build Coastguard Worker    jz          near .endcolumn
262*dfc6aa5cSAndroid Build Coastguard Worker
263*dfc6aa5cSAndroid Build Coastguard Worker    add         rsi, byte SIZEOF_XMMWORD  ; inptr0
264*dfc6aa5cSAndroid Build Coastguard Worker    dec         al                        ; Yctr
265*dfc6aa5cSAndroid Build Coastguard Worker    jnz         near .Yloop_2nd
266*dfc6aa5cSAndroid Build Coastguard Worker
267*dfc6aa5cSAndroid Build Coastguard Worker    add         rbx, byte SIZEOF_XMMWORD  ; inptr1
268*dfc6aa5cSAndroid Build Coastguard Worker    add         rdx, byte SIZEOF_XMMWORD  ; inptr2
269*dfc6aa5cSAndroid Build Coastguard Worker    jmp         near .columnloop
270*dfc6aa5cSAndroid Build Coastguard Worker
271*dfc6aa5cSAndroid Build Coastguard Worker.column_st32:
272*dfc6aa5cSAndroid Build Coastguard Worker    lea         rcx, [rcx+rcx*2]            ; imul ecx, RGB_PIXELSIZE
273*dfc6aa5cSAndroid Build Coastguard Worker    cmp         rcx, byte 2*SIZEOF_XMMWORD
274*dfc6aa5cSAndroid Build Coastguard Worker    jb          short .column_st16
275*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
276*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
277*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte 2*SIZEOF_XMMWORD  ; outptr
278*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmA, xmmF
279*dfc6aa5cSAndroid Build Coastguard Worker    sub         rcx, byte 2*SIZEOF_XMMWORD
280*dfc6aa5cSAndroid Build Coastguard Worker    jmp         short .column_st15
281*dfc6aa5cSAndroid Build Coastguard Worker.column_st16:
282*dfc6aa5cSAndroid Build Coastguard Worker    cmp         rcx, byte SIZEOF_XMMWORD
283*dfc6aa5cSAndroid Build Coastguard Worker    jb          short .column_st15
284*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
285*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte SIZEOF_XMMWORD    ; outptr
286*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmA, xmmD
287*dfc6aa5cSAndroid Build Coastguard Worker    sub         rcx, byte SIZEOF_XMMWORD
288*dfc6aa5cSAndroid Build Coastguard Worker.column_st15:
289*dfc6aa5cSAndroid Build Coastguard Worker    ; Store the lower 8 bytes of xmmA to the output when it has enough
290*dfc6aa5cSAndroid Build Coastguard Worker    ; space.
291*dfc6aa5cSAndroid Build Coastguard Worker    cmp         rcx, byte SIZEOF_MMWORD
292*dfc6aa5cSAndroid Build Coastguard Worker    jb          short .column_st7
293*dfc6aa5cSAndroid Build Coastguard Worker    movq        XMM_MMWORD [rdi], xmmA
294*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte SIZEOF_MMWORD
295*dfc6aa5cSAndroid Build Coastguard Worker    sub         rcx, byte SIZEOF_MMWORD
296*dfc6aa5cSAndroid Build Coastguard Worker    psrldq      xmmA, SIZEOF_MMWORD
297*dfc6aa5cSAndroid Build Coastguard Worker.column_st7:
298*dfc6aa5cSAndroid Build Coastguard Worker    ; Store the lower 4 bytes of xmmA to the output when it has enough
299*dfc6aa5cSAndroid Build Coastguard Worker    ; space.
300*dfc6aa5cSAndroid Build Coastguard Worker    cmp         rcx, byte SIZEOF_DWORD
301*dfc6aa5cSAndroid Build Coastguard Worker    jb          short .column_st3
302*dfc6aa5cSAndroid Build Coastguard Worker    movd        XMM_DWORD [rdi], xmmA
303*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte SIZEOF_DWORD
304*dfc6aa5cSAndroid Build Coastguard Worker    sub         rcx, byte SIZEOF_DWORD
305*dfc6aa5cSAndroid Build Coastguard Worker    psrldq      xmmA, SIZEOF_DWORD
306*dfc6aa5cSAndroid Build Coastguard Worker.column_st3:
307*dfc6aa5cSAndroid Build Coastguard Worker    ; Store the lower 2 bytes of rax to the output when it has enough
308*dfc6aa5cSAndroid Build Coastguard Worker    ; space.
309*dfc6aa5cSAndroid Build Coastguard Worker    movd        eax, xmmA
310*dfc6aa5cSAndroid Build Coastguard Worker    cmp         rcx, byte SIZEOF_WORD
311*dfc6aa5cSAndroid Build Coastguard Worker    jb          short .column_st1
312*dfc6aa5cSAndroid Build Coastguard Worker    mov         word [rdi], ax
313*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte SIZEOF_WORD
314*dfc6aa5cSAndroid Build Coastguard Worker    sub         rcx, byte SIZEOF_WORD
315*dfc6aa5cSAndroid Build Coastguard Worker    shr         rax, 16
316*dfc6aa5cSAndroid Build Coastguard Worker.column_st1:
317*dfc6aa5cSAndroid Build Coastguard Worker    ; Store the lower 1 byte of rax to the output when it has enough
318*dfc6aa5cSAndroid Build Coastguard Worker    ; space.
319*dfc6aa5cSAndroid Build Coastguard Worker    test        rcx, rcx
320*dfc6aa5cSAndroid Build Coastguard Worker    jz          short .endcolumn
321*dfc6aa5cSAndroid Build Coastguard Worker    mov         byte [rdi], al
322*dfc6aa5cSAndroid Build Coastguard Worker
323*dfc6aa5cSAndroid Build Coastguard Worker%else  ; RGB_PIXELSIZE == 4 ; -----------
324*dfc6aa5cSAndroid Build Coastguard Worker
325*dfc6aa5cSAndroid Build Coastguard Worker%ifdef RGBX_FILLER_0XFF
326*dfc6aa5cSAndroid Build Coastguard Worker    pcmpeqb     xmm6, xmm6              ; xmm6=XE=X(02468ACE********)
327*dfc6aa5cSAndroid Build Coastguard Worker    pcmpeqb     xmm7, xmm7              ; xmm7=XO=X(13579BDF********)
328*dfc6aa5cSAndroid Build Coastguard Worker%else
329*dfc6aa5cSAndroid Build Coastguard Worker    pxor        xmm6, xmm6              ; xmm6=XE=X(02468ACE********)
330*dfc6aa5cSAndroid Build Coastguard Worker    pxor        xmm7, xmm7              ; xmm7=XO=X(13579BDF********)
331*dfc6aa5cSAndroid Build Coastguard Worker%endif
332*dfc6aa5cSAndroid Build Coastguard Worker    ; xmmA=(00 02 04 06 08 0A 0C 0E **), xmmB=(01 03 05 07 09 0B 0D 0F **)
333*dfc6aa5cSAndroid Build Coastguard Worker    ; xmmC=(10 12 14 16 18 1A 1C 1E **), xmmD=(11 13 15 17 19 1B 1D 1F **)
334*dfc6aa5cSAndroid Build Coastguard Worker    ; xmmE=(20 22 24 26 28 2A 2C 2E **), xmmF=(21 23 25 27 29 2B 2D 2F **)
335*dfc6aa5cSAndroid Build Coastguard Worker    ; xmmG=(30 32 34 36 38 3A 3C 3E **), xmmH=(31 33 35 37 39 3B 3D 3F **)
336*dfc6aa5cSAndroid Build Coastguard Worker
337*dfc6aa5cSAndroid Build Coastguard Worker    punpcklbw   xmmA, xmmC  ; xmmA=(00 10 02 12 04 14 06 16 08 18 0A 1A 0C 1C 0E 1E)
338*dfc6aa5cSAndroid Build Coastguard Worker    punpcklbw   xmmE, xmmG  ; xmmE=(20 30 22 32 24 34 26 36 28 38 2A 3A 2C 3C 2E 3E)
339*dfc6aa5cSAndroid Build Coastguard Worker    punpcklbw   xmmB, xmmD  ; xmmB=(01 11 03 13 05 15 07 17 09 19 0B 1B 0D 1D 0F 1F)
340*dfc6aa5cSAndroid Build Coastguard Worker    punpcklbw   xmmF, xmmH  ; xmmF=(21 31 23 33 25 35 27 37 29 39 2B 3B 2D 3D 2F 3F)
341*dfc6aa5cSAndroid Build Coastguard Worker
342*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmC, xmmA
343*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmmA, xmmE  ; xmmA=(00 10 20 30 02 12 22 32 04 14 24 34 06 16 26 36)
344*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmmC, xmmE  ; xmmC=(08 18 28 38 0A 1A 2A 3A 0C 1C 2C 3C 0E 1E 2E 3E)
345*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmG, xmmB
346*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmmB, xmmF  ; xmmB=(01 11 21 31 03 13 23 33 05 15 25 35 07 17 27 37)
347*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmmG, xmmF  ; xmmG=(09 19 29 39 0B 1B 2B 3B 0D 1D 2D 3D 0F 1F 2F 3F)
348*dfc6aa5cSAndroid Build Coastguard Worker
349*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmD, xmmA
350*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmmA, xmmB  ; xmmA=(00 10 20 30 01 11 21 31 02 12 22 32 03 13 23 33)
351*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmmD, xmmB  ; xmmD=(04 14 24 34 05 15 25 35 06 16 26 36 07 17 27 37)
352*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmH, xmmC
353*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmmC, xmmG  ; xmmC=(08 18 28 38 09 19 29 39 0A 1A 2A 3A 0B 1B 2B 3B)
354*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmmH, xmmG  ; xmmH=(0C 1C 2C 3C 0D 1D 2D 3D 0E 1E 2E 3E 0F 1F 2F 3F)
355*dfc6aa5cSAndroid Build Coastguard Worker
356*dfc6aa5cSAndroid Build Coastguard Worker    cmp         rcx, byte SIZEOF_XMMWORD
357*dfc6aa5cSAndroid Build Coastguard Worker    jb          short .column_st32
358*dfc6aa5cSAndroid Build Coastguard Worker
359*dfc6aa5cSAndroid Build Coastguard Worker    test        rdi, SIZEOF_XMMWORD-1
360*dfc6aa5cSAndroid Build Coastguard Worker    jnz         short .out1
361*dfc6aa5cSAndroid Build Coastguard Worker    ; --(aligned)-------------------
362*dfc6aa5cSAndroid Build Coastguard Worker    movntdq     XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
363*dfc6aa5cSAndroid Build Coastguard Worker    movntdq     XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
364*dfc6aa5cSAndroid Build Coastguard Worker    movntdq     XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
365*dfc6aa5cSAndroid Build Coastguard Worker    movntdq     XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
366*dfc6aa5cSAndroid Build Coastguard Worker    jmp         short .out0
367*dfc6aa5cSAndroid Build Coastguard Worker.out1:  ; --(unaligned)-----------------
368*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
369*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
370*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+2*SIZEOF_XMMWORD], xmmC
371*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+3*SIZEOF_XMMWORD], xmmH
372*dfc6aa5cSAndroid Build Coastguard Worker.out0:
373*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte RGB_PIXELSIZE*SIZEOF_XMMWORD  ; outptr
374*dfc6aa5cSAndroid Build Coastguard Worker    sub         rcx, byte SIZEOF_XMMWORD
375*dfc6aa5cSAndroid Build Coastguard Worker    jz          near .endcolumn
376*dfc6aa5cSAndroid Build Coastguard Worker
377*dfc6aa5cSAndroid Build Coastguard Worker    add         rsi, byte SIZEOF_XMMWORD  ; inptr0
378*dfc6aa5cSAndroid Build Coastguard Worker    dec         al                        ; Yctr
379*dfc6aa5cSAndroid Build Coastguard Worker    jnz         near .Yloop_2nd
380*dfc6aa5cSAndroid Build Coastguard Worker
381*dfc6aa5cSAndroid Build Coastguard Worker    add         rbx, byte SIZEOF_XMMWORD  ; inptr1
382*dfc6aa5cSAndroid Build Coastguard Worker    add         rdx, byte SIZEOF_XMMWORD  ; inptr2
383*dfc6aa5cSAndroid Build Coastguard Worker    jmp         near .columnloop
384*dfc6aa5cSAndroid Build Coastguard Worker
385*dfc6aa5cSAndroid Build Coastguard Worker.column_st32:
386*dfc6aa5cSAndroid Build Coastguard Worker    cmp         rcx, byte SIZEOF_XMMWORD/2
387*dfc6aa5cSAndroid Build Coastguard Worker    jb          short .column_st16
388*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
389*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+1*SIZEOF_XMMWORD], xmmD
390*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte 2*SIZEOF_XMMWORD  ; outptr
391*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmA, xmmC
392*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmD, xmmH
393*dfc6aa5cSAndroid Build Coastguard Worker    sub         rcx, byte SIZEOF_XMMWORD/2
394*dfc6aa5cSAndroid Build Coastguard Worker.column_st16:
395*dfc6aa5cSAndroid Build Coastguard Worker    cmp         rcx, byte SIZEOF_XMMWORD/4
396*dfc6aa5cSAndroid Build Coastguard Worker    jb          short .column_st15
397*dfc6aa5cSAndroid Build Coastguard Worker    movdqu      XMMWORD [rdi+0*SIZEOF_XMMWORD], xmmA
398*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte SIZEOF_XMMWORD    ; outptr
399*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmmA, xmmD
400*dfc6aa5cSAndroid Build Coastguard Worker    sub         rcx, byte SIZEOF_XMMWORD/4
401*dfc6aa5cSAndroid Build Coastguard Worker.column_st15:
402*dfc6aa5cSAndroid Build Coastguard Worker    ; Store two pixels (8 bytes) of xmmA to the output when it has enough
403*dfc6aa5cSAndroid Build Coastguard Worker    ; space.
404*dfc6aa5cSAndroid Build Coastguard Worker    cmp         rcx, byte SIZEOF_XMMWORD/8
405*dfc6aa5cSAndroid Build Coastguard Worker    jb          short .column_st7
406*dfc6aa5cSAndroid Build Coastguard Worker    movq        XMM_MMWORD [rdi], xmmA
407*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte SIZEOF_XMMWORD/8*4
408*dfc6aa5cSAndroid Build Coastguard Worker    sub         rcx, byte SIZEOF_XMMWORD/8
409*dfc6aa5cSAndroid Build Coastguard Worker    psrldq      xmmA, SIZEOF_XMMWORD/8*4
410*dfc6aa5cSAndroid Build Coastguard Worker.column_st7:
411*dfc6aa5cSAndroid Build Coastguard Worker    ; Store one pixel (4 bytes) of xmmA to the output when it has enough
412*dfc6aa5cSAndroid Build Coastguard Worker    ; space.
413*dfc6aa5cSAndroid Build Coastguard Worker    test        rcx, rcx
414*dfc6aa5cSAndroid Build Coastguard Worker    jz          short .endcolumn
415*dfc6aa5cSAndroid Build Coastguard Worker    movd        XMM_DWORD [rdi], xmmA
416*dfc6aa5cSAndroid Build Coastguard Worker
417*dfc6aa5cSAndroid Build Coastguard Worker%endif  ; RGB_PIXELSIZE ; ---------------
418*dfc6aa5cSAndroid Build Coastguard Worker
419*dfc6aa5cSAndroid Build Coastguard Worker.endcolumn:
420*dfc6aa5cSAndroid Build Coastguard Worker    sfence                              ; flush the write buffer
421*dfc6aa5cSAndroid Build Coastguard Worker
422*dfc6aa5cSAndroid Build Coastguard Worker.return:
423*dfc6aa5cSAndroid Build Coastguard Worker    pop         rbx
424*dfc6aa5cSAndroid Build Coastguard Worker    uncollect_args 4
425*dfc6aa5cSAndroid Build Coastguard Worker    mov         rsp, rbp                ; rsp <- aligned rbp
426*dfc6aa5cSAndroid Build Coastguard Worker    pop         rsp                     ; rsp <- original rbp
427*dfc6aa5cSAndroid Build Coastguard Worker    pop         rbp
428*dfc6aa5cSAndroid Build Coastguard Worker    ret
429*dfc6aa5cSAndroid Build Coastguard Worker
430*dfc6aa5cSAndroid Build Coastguard Worker; --------------------------------------------------------------------------
431*dfc6aa5cSAndroid Build Coastguard Worker;
432*dfc6aa5cSAndroid Build Coastguard Worker; Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.
433*dfc6aa5cSAndroid Build Coastguard Worker;
434*dfc6aa5cSAndroid Build Coastguard Worker; GLOBAL(void)
435*dfc6aa5cSAndroid Build Coastguard Worker; jsimd_h2v2_merged_upsample_sse2(JDIMENSION output_width,
436*dfc6aa5cSAndroid Build Coastguard Worker;                                 JSAMPIMAGE input_buf,
437*dfc6aa5cSAndroid Build Coastguard Worker;                                 JDIMENSION in_row_group_ctr,
438*dfc6aa5cSAndroid Build Coastguard Worker;                                 JSAMPARRAY output_buf);
439*dfc6aa5cSAndroid Build Coastguard Worker;
440*dfc6aa5cSAndroid Build Coastguard Worker
441*dfc6aa5cSAndroid Build Coastguard Worker; r10d = JDIMENSION output_width
442*dfc6aa5cSAndroid Build Coastguard Worker; r11 = JSAMPIMAGE input_buf
443*dfc6aa5cSAndroid Build Coastguard Worker; r12d = JDIMENSION in_row_group_ctr
444*dfc6aa5cSAndroid Build Coastguard Worker; r13 = JSAMPARRAY output_buf
445*dfc6aa5cSAndroid Build Coastguard Worker
446*dfc6aa5cSAndroid Build Coastguard Worker    align       32
447*dfc6aa5cSAndroid Build Coastguard Worker    GLOBAL_FUNCTION(jsimd_h2v2_merged_upsample_sse2)
448*dfc6aa5cSAndroid Build Coastguard Worker
449*dfc6aa5cSAndroid Build Coastguard WorkerEXTN(jsimd_h2v2_merged_upsample_sse2):
450*dfc6aa5cSAndroid Build Coastguard Worker    push        rbp
451*dfc6aa5cSAndroid Build Coastguard Worker    mov         rax, rsp
452*dfc6aa5cSAndroid Build Coastguard Worker    mov         rbp, rsp
453*dfc6aa5cSAndroid Build Coastguard Worker    collect_args 4
454*dfc6aa5cSAndroid Build Coastguard Worker    push        rbx
455*dfc6aa5cSAndroid Build Coastguard Worker
456*dfc6aa5cSAndroid Build Coastguard Worker    mov         eax, r10d
457*dfc6aa5cSAndroid Build Coastguard Worker
458*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdi, r11
459*dfc6aa5cSAndroid Build Coastguard Worker    mov         ecx, r12d
460*dfc6aa5cSAndroid Build Coastguard Worker    mov         rsip, JSAMPARRAY [rdi+0*SIZEOF_JSAMPARRAY]
461*dfc6aa5cSAndroid Build Coastguard Worker    mov         rbxp, JSAMPARRAY [rdi+1*SIZEOF_JSAMPARRAY]
462*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdxp, JSAMPARRAY [rdi+2*SIZEOF_JSAMPARRAY]
463*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdi, r13
464*dfc6aa5cSAndroid Build Coastguard Worker    lea         rsi, [rsi+rcx*SIZEOF_JSAMPROW]
465*dfc6aa5cSAndroid Build Coastguard Worker
466*dfc6aa5cSAndroid Build Coastguard Worker    sub         rsp, SIZEOF_JSAMPARRAY*4
467*dfc6aa5cSAndroid Build Coastguard Worker    mov         JSAMPARRAY [rsp+0*SIZEOF_JSAMPARRAY], rsip  ; intpr00
468*dfc6aa5cSAndroid Build Coastguard Worker    mov         JSAMPARRAY [rsp+1*SIZEOF_JSAMPARRAY], rbxp  ; intpr1
469*dfc6aa5cSAndroid Build Coastguard Worker    mov         JSAMPARRAY [rsp+2*SIZEOF_JSAMPARRAY], rdxp  ; intpr2
470*dfc6aa5cSAndroid Build Coastguard Worker    mov         rbx, rsp
471*dfc6aa5cSAndroid Build Coastguard Worker
472*dfc6aa5cSAndroid Build Coastguard Worker    push        rdi
473*dfc6aa5cSAndroid Build Coastguard Worker    push        rcx
474*dfc6aa5cSAndroid Build Coastguard Worker    push        rax
475*dfc6aa5cSAndroid Build Coastguard Worker
476*dfc6aa5cSAndroid Build Coastguard Worker    %ifdef WIN64
477*dfc6aa5cSAndroid Build Coastguard Worker    mov         r8, rcx
478*dfc6aa5cSAndroid Build Coastguard Worker    mov         r9, rdi
479*dfc6aa5cSAndroid Build Coastguard Worker    mov         rcx, rax
480*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdx, rbx
481*dfc6aa5cSAndroid Build Coastguard Worker    %else
482*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdx, rcx
483*dfc6aa5cSAndroid Build Coastguard Worker    mov         rcx, rdi
484*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdi, rax
485*dfc6aa5cSAndroid Build Coastguard Worker    mov         rsi, rbx
486*dfc6aa5cSAndroid Build Coastguard Worker    %endif
487*dfc6aa5cSAndroid Build Coastguard Worker
488*dfc6aa5cSAndroid Build Coastguard Worker    call        EXTN(jsimd_h2v1_merged_upsample_sse2)
489*dfc6aa5cSAndroid Build Coastguard Worker
490*dfc6aa5cSAndroid Build Coastguard Worker    pop         rax
491*dfc6aa5cSAndroid Build Coastguard Worker    pop         rcx
492*dfc6aa5cSAndroid Build Coastguard Worker    pop         rdi
493*dfc6aa5cSAndroid Build Coastguard Worker    mov         rsip, JSAMPARRAY [rsp+0*SIZEOF_JSAMPARRAY]
494*dfc6aa5cSAndroid Build Coastguard Worker    mov         rbxp, JSAMPARRAY [rsp+1*SIZEOF_JSAMPARRAY]
495*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdxp, JSAMPARRAY [rsp+2*SIZEOF_JSAMPARRAY]
496*dfc6aa5cSAndroid Build Coastguard Worker
497*dfc6aa5cSAndroid Build Coastguard Worker    add         rdi, byte SIZEOF_JSAMPROW  ; outptr1
498*dfc6aa5cSAndroid Build Coastguard Worker    add         rsi, byte SIZEOF_JSAMPROW  ; inptr01
499*dfc6aa5cSAndroid Build Coastguard Worker
500*dfc6aa5cSAndroid Build Coastguard Worker    mov         JSAMPARRAY [rsp+0*SIZEOF_JSAMPARRAY], rsip  ; intpr00
501*dfc6aa5cSAndroid Build Coastguard Worker    mov         JSAMPARRAY [rsp+1*SIZEOF_JSAMPARRAY], rbxp  ; intpr1
502*dfc6aa5cSAndroid Build Coastguard Worker    mov         JSAMPARRAY [rsp+2*SIZEOF_JSAMPARRAY], rdxp  ; intpr2
503*dfc6aa5cSAndroid Build Coastguard Worker    mov         rbx, rsp
504*dfc6aa5cSAndroid Build Coastguard Worker
505*dfc6aa5cSAndroid Build Coastguard Worker    push        rdi
506*dfc6aa5cSAndroid Build Coastguard Worker    push        rcx
507*dfc6aa5cSAndroid Build Coastguard Worker    push        rax
508*dfc6aa5cSAndroid Build Coastguard Worker
509*dfc6aa5cSAndroid Build Coastguard Worker    %ifdef WIN64
510*dfc6aa5cSAndroid Build Coastguard Worker    mov         r8, rcx
511*dfc6aa5cSAndroid Build Coastguard Worker    mov         r9, rdi
512*dfc6aa5cSAndroid Build Coastguard Worker    mov         rcx, rax
513*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdx, rbx
514*dfc6aa5cSAndroid Build Coastguard Worker    %else
515*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdx, rcx
516*dfc6aa5cSAndroid Build Coastguard Worker    mov         rcx, rdi
517*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdi, rax
518*dfc6aa5cSAndroid Build Coastguard Worker    mov         rsi, rbx
519*dfc6aa5cSAndroid Build Coastguard Worker    %endif
520*dfc6aa5cSAndroid Build Coastguard Worker
521*dfc6aa5cSAndroid Build Coastguard Worker    call        EXTN(jsimd_h2v1_merged_upsample_sse2)
522*dfc6aa5cSAndroid Build Coastguard Worker
523*dfc6aa5cSAndroid Build Coastguard Worker    pop         rax
524*dfc6aa5cSAndroid Build Coastguard Worker    pop         rcx
525*dfc6aa5cSAndroid Build Coastguard Worker    pop         rdi
526*dfc6aa5cSAndroid Build Coastguard Worker    mov         rsip, JSAMPARRAY [rsp+0*SIZEOF_JSAMPARRAY]
527*dfc6aa5cSAndroid Build Coastguard Worker    mov         rbxp, JSAMPARRAY [rsp+1*SIZEOF_JSAMPARRAY]
528*dfc6aa5cSAndroid Build Coastguard Worker    mov         rdxp, JSAMPARRAY [rsp+2*SIZEOF_JSAMPARRAY]
529*dfc6aa5cSAndroid Build Coastguard Worker    add         rsp, SIZEOF_JSAMPARRAY*4
530*dfc6aa5cSAndroid Build Coastguard Worker
531*dfc6aa5cSAndroid Build Coastguard Worker    pop         rbx
532*dfc6aa5cSAndroid Build Coastguard Worker    uncollect_args 4
533*dfc6aa5cSAndroid Build Coastguard Worker    pop         rbp
534*dfc6aa5cSAndroid Build Coastguard Worker    ret
535*dfc6aa5cSAndroid Build Coastguard Worker
536*dfc6aa5cSAndroid Build Coastguard Worker; For some reason, the OS X linker does not honor the request to align the
537*dfc6aa5cSAndroid Build Coastguard Worker; segment unless we do this.
538*dfc6aa5cSAndroid Build Coastguard Worker    align       32
539