xref: /aosp_15_r20/external/libjpeg-turbo/simd/i386/jfdctfst-sse2.asm (revision dfc6aa5c1cfd4bc4e2018dc74aa96e29ee49c6da)
1*dfc6aa5cSAndroid Build Coastguard Worker;
2*dfc6aa5cSAndroid Build Coastguard Worker; jfdctfst.asm - fast integer FDCT (SSE2)
3*dfc6aa5cSAndroid Build Coastguard Worker;
4*dfc6aa5cSAndroid Build Coastguard Worker; Copyright 2009 Pierre Ossman <ossman@cendio.se> for Cendio AB
5*dfc6aa5cSAndroid Build Coastguard Worker; Copyright (C) 2016, D. R. Commander.
6*dfc6aa5cSAndroid Build Coastguard Worker;
7*dfc6aa5cSAndroid Build Coastguard Worker; Based on the x86 SIMD extension for IJG JPEG library
8*dfc6aa5cSAndroid Build Coastguard Worker; Copyright (C) 1999-2006, MIYASAKA Masaru.
9*dfc6aa5cSAndroid Build Coastguard Worker; For conditions of distribution and use, see copyright notice in jsimdext.inc
10*dfc6aa5cSAndroid Build Coastguard Worker;
11*dfc6aa5cSAndroid Build Coastguard Worker; This file should be assembled with NASM (Netwide Assembler),
12*dfc6aa5cSAndroid Build Coastguard Worker; can *not* be assembled with Microsoft's MASM or any compatible
13*dfc6aa5cSAndroid Build Coastguard Worker; assembler (including Borland's Turbo Assembler).
14*dfc6aa5cSAndroid Build Coastguard Worker; NASM is available from http://nasm.sourceforge.net/ or
15*dfc6aa5cSAndroid Build Coastguard Worker; http://sourceforge.net/project/showfiles.php?group_id=6208
16*dfc6aa5cSAndroid Build Coastguard Worker;
17*dfc6aa5cSAndroid Build Coastguard Worker; This file contains a fast, not so accurate integer implementation of
18*dfc6aa5cSAndroid Build Coastguard Worker; the forward DCT (Discrete Cosine Transform). The following code is
19*dfc6aa5cSAndroid Build Coastguard Worker; based directly on the IJG's original jfdctfst.c; see the jfdctfst.c
20*dfc6aa5cSAndroid Build Coastguard Worker; for more details.
21*dfc6aa5cSAndroid Build Coastguard Worker
22*dfc6aa5cSAndroid Build Coastguard Worker%include "jsimdext.inc"
23*dfc6aa5cSAndroid Build Coastguard Worker%include "jdct.inc"
24*dfc6aa5cSAndroid Build Coastguard Worker
25*dfc6aa5cSAndroid Build Coastguard Worker; --------------------------------------------------------------------------
26*dfc6aa5cSAndroid Build Coastguard Worker
27*dfc6aa5cSAndroid Build Coastguard Worker%define CONST_BITS  8  ; 14 is also OK.
28*dfc6aa5cSAndroid Build Coastguard Worker
29*dfc6aa5cSAndroid Build Coastguard Worker%if CONST_BITS == 8
30*dfc6aa5cSAndroid Build Coastguard WorkerF_0_382 equ  98  ; FIX(0.382683433)
31*dfc6aa5cSAndroid Build Coastguard WorkerF_0_541 equ 139  ; FIX(0.541196100)
32*dfc6aa5cSAndroid Build Coastguard WorkerF_0_707 equ 181  ; FIX(0.707106781)
33*dfc6aa5cSAndroid Build Coastguard WorkerF_1_306 equ 334  ; FIX(1.306562965)
34*dfc6aa5cSAndroid Build Coastguard Worker%else
35*dfc6aa5cSAndroid Build Coastguard Worker; NASM cannot do compile-time arithmetic on floating-point constants.
36*dfc6aa5cSAndroid Build Coastguard Worker%define DESCALE(x, n)  (((x) + (1 << ((n) - 1))) >> (n))
37*dfc6aa5cSAndroid Build Coastguard WorkerF_0_382 equ DESCALE( 410903207, 30 - CONST_BITS)  ; FIX(0.382683433)
38*dfc6aa5cSAndroid Build Coastguard WorkerF_0_541 equ DESCALE( 581104887, 30 - CONST_BITS)  ; FIX(0.541196100)
39*dfc6aa5cSAndroid Build Coastguard WorkerF_0_707 equ DESCALE( 759250124, 30 - CONST_BITS)  ; FIX(0.707106781)
40*dfc6aa5cSAndroid Build Coastguard WorkerF_1_306 equ DESCALE(1402911301, 30 - CONST_BITS)  ; FIX(1.306562965)
41*dfc6aa5cSAndroid Build Coastguard Worker%endif
42*dfc6aa5cSAndroid Build Coastguard Worker
43*dfc6aa5cSAndroid Build Coastguard Worker; --------------------------------------------------------------------------
44*dfc6aa5cSAndroid Build Coastguard Worker    SECTION     SEG_CONST
45*dfc6aa5cSAndroid Build Coastguard Worker
46*dfc6aa5cSAndroid Build Coastguard Worker; PRE_MULTIPLY_SCALE_BITS <= 2 (to avoid overflow)
47*dfc6aa5cSAndroid Build Coastguard Worker; CONST_BITS + CONST_SHIFT + PRE_MULTIPLY_SCALE_BITS == 16 (for pmulhw)
48*dfc6aa5cSAndroid Build Coastguard Worker
49*dfc6aa5cSAndroid Build Coastguard Worker%define PRE_MULTIPLY_SCALE_BITS  2
50*dfc6aa5cSAndroid Build Coastguard Worker%define CONST_SHIFT              (16 - PRE_MULTIPLY_SCALE_BITS - CONST_BITS)
51*dfc6aa5cSAndroid Build Coastguard Worker
52*dfc6aa5cSAndroid Build Coastguard Worker    alignz      32
53*dfc6aa5cSAndroid Build Coastguard Worker    GLOBAL_DATA(jconst_fdct_ifast_sse2)
54*dfc6aa5cSAndroid Build Coastguard Worker
55*dfc6aa5cSAndroid Build Coastguard WorkerEXTN(jconst_fdct_ifast_sse2):
56*dfc6aa5cSAndroid Build Coastguard Worker
57*dfc6aa5cSAndroid Build Coastguard WorkerPW_F0707 times 8 dw F_0_707 << CONST_SHIFT
58*dfc6aa5cSAndroid Build Coastguard WorkerPW_F0382 times 8 dw F_0_382 << CONST_SHIFT
59*dfc6aa5cSAndroid Build Coastguard WorkerPW_F0541 times 8 dw F_0_541 << CONST_SHIFT
60*dfc6aa5cSAndroid Build Coastguard WorkerPW_F1306 times 8 dw F_1_306 << CONST_SHIFT
61*dfc6aa5cSAndroid Build Coastguard Worker
62*dfc6aa5cSAndroid Build Coastguard Worker    alignz      32
63*dfc6aa5cSAndroid Build Coastguard Worker
64*dfc6aa5cSAndroid Build Coastguard Worker; --------------------------------------------------------------------------
65*dfc6aa5cSAndroid Build Coastguard Worker    SECTION     SEG_TEXT
66*dfc6aa5cSAndroid Build Coastguard Worker    BITS        32
67*dfc6aa5cSAndroid Build Coastguard Worker;
68*dfc6aa5cSAndroid Build Coastguard Worker; Perform the forward DCT on one block of samples.
69*dfc6aa5cSAndroid Build Coastguard Worker;
70*dfc6aa5cSAndroid Build Coastguard Worker; GLOBAL(void)
71*dfc6aa5cSAndroid Build Coastguard Worker; jsimd_fdct_ifast_sse2(DCTELEM *data)
72*dfc6aa5cSAndroid Build Coastguard Worker;
73*dfc6aa5cSAndroid Build Coastguard Worker
74*dfc6aa5cSAndroid Build Coastguard Worker%define data(b)       (b) + 8           ; DCTELEM *data
75*dfc6aa5cSAndroid Build Coastguard Worker
76*dfc6aa5cSAndroid Build Coastguard Worker%define original_ebp  ebp + 0
77*dfc6aa5cSAndroid Build Coastguard Worker%define wk(i)         ebp - (WK_NUM - (i)) * SIZEOF_XMMWORD
78*dfc6aa5cSAndroid Build Coastguard Worker                                        ; xmmword wk[WK_NUM]
79*dfc6aa5cSAndroid Build Coastguard Worker%define WK_NUM        2
80*dfc6aa5cSAndroid Build Coastguard Worker
81*dfc6aa5cSAndroid Build Coastguard Worker    align       32
82*dfc6aa5cSAndroid Build Coastguard Worker    GLOBAL_FUNCTION(jsimd_fdct_ifast_sse2)
83*dfc6aa5cSAndroid Build Coastguard Worker
84*dfc6aa5cSAndroid Build Coastguard WorkerEXTN(jsimd_fdct_ifast_sse2):
85*dfc6aa5cSAndroid Build Coastguard Worker    push        ebp
86*dfc6aa5cSAndroid Build Coastguard Worker    mov         eax, esp                     ; eax = original ebp
87*dfc6aa5cSAndroid Build Coastguard Worker    sub         esp, byte 4
88*dfc6aa5cSAndroid Build Coastguard Worker    and         esp, byte (-SIZEOF_XMMWORD)  ; align to 128 bits
89*dfc6aa5cSAndroid Build Coastguard Worker    mov         [esp], eax
90*dfc6aa5cSAndroid Build Coastguard Worker    mov         ebp, esp                     ; ebp = aligned ebp
91*dfc6aa5cSAndroid Build Coastguard Worker    lea         esp, [wk(0)]
92*dfc6aa5cSAndroid Build Coastguard Worker    pushpic     ebx
93*dfc6aa5cSAndroid Build Coastguard Worker;   push        ecx                     ; unused
94*dfc6aa5cSAndroid Build Coastguard Worker;   push        edx                     ; need not be preserved
95*dfc6aa5cSAndroid Build Coastguard Worker;   push        esi                     ; unused
96*dfc6aa5cSAndroid Build Coastguard Worker;   push        edi                     ; unused
97*dfc6aa5cSAndroid Build Coastguard Worker
98*dfc6aa5cSAndroid Build Coastguard Worker    get_GOT     ebx                     ; get GOT address
99*dfc6aa5cSAndroid Build Coastguard Worker
100*dfc6aa5cSAndroid Build Coastguard Worker    ; ---- Pass 1: process rows.
101*dfc6aa5cSAndroid Build Coastguard Worker
102*dfc6aa5cSAndroid Build Coastguard Worker    mov         edx, POINTER [data(eax)]  ; (DCTELEM *)
103*dfc6aa5cSAndroid Build Coastguard Worker
104*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_DCTELEM)]
105*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_DCTELEM)]
106*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_DCTELEM)]
107*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm3, XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_DCTELEM)]
108*dfc6aa5cSAndroid Build Coastguard Worker
109*dfc6aa5cSAndroid Build Coastguard Worker    ; xmm0=(00 01 02 03 04 05 06 07), xmm2=(20 21 22 23 24 25 26 27)
110*dfc6aa5cSAndroid Build Coastguard Worker    ; xmm1=(10 11 12 13 14 15 16 17), xmm3=(30 31 32 33 34 35 36 37)
111*dfc6aa5cSAndroid Build Coastguard Worker
112*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm4, xmm0              ; transpose coefficients(phase 1)
113*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmm0, xmm1              ; xmm0=(00 10 01 11 02 12 03 13)
114*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmm4, xmm1              ; xmm4=(04 14 05 15 06 16 07 17)
115*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, xmm2              ; transpose coefficients(phase 1)
116*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmm2, xmm3              ; xmm2=(20 30 21 31 22 32 23 33)
117*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmm5, xmm3              ; xmm5=(24 34 25 35 26 36 27 37)
118*dfc6aa5cSAndroid Build Coastguard Worker
119*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_DCTELEM)]
120*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_DCTELEM)]
121*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_DCTELEM)]
122*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm3, XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_DCTELEM)]
123*dfc6aa5cSAndroid Build Coastguard Worker
124*dfc6aa5cSAndroid Build Coastguard Worker    ; xmm6=( 4 12 20 28 36 44 52 60), xmm1=( 6 14 22 30 38 46 54 62)
125*dfc6aa5cSAndroid Build Coastguard Worker    ; xmm7=( 5 13 21 29 37 45 53 61), xmm3=( 7 15 23 31 39 47 55 63)
126*dfc6aa5cSAndroid Build Coastguard Worker
127*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(0)], xmm2   ; wk(0)=(20 30 21 31 22 32 23 33)
128*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(1)], xmm5   ; wk(1)=(24 34 25 35 26 36 27 37)
129*dfc6aa5cSAndroid Build Coastguard Worker
130*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, xmm6              ; transpose coefficients(phase 1)
131*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmm6, xmm7              ; xmm6=(40 50 41 51 42 52 43 53)
132*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmm2, xmm7              ; xmm2=(44 54 45 55 46 56 47 57)
133*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, xmm1              ; transpose coefficients(phase 1)
134*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmm1, xmm3              ; xmm1=(60 70 61 71 62 72 63 73)
135*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmm5, xmm3              ; xmm5=(64 74 65 75 66 76 67 77)
136*dfc6aa5cSAndroid Build Coastguard Worker
137*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, xmm6              ; transpose coefficients(phase 2)
138*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmm6, xmm1              ; xmm6=(40 50 60 70 41 51 61 71)
139*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmm7, xmm1              ; xmm7=(42 52 62 72 43 53 63 73)
140*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm3, xmm2              ; transpose coefficients(phase 2)
141*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmm2, xmm5              ; xmm2=(44 54 64 74 45 55 65 75)
142*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmm3, xmm5              ; xmm3=(46 56 66 76 47 57 67 77)
143*dfc6aa5cSAndroid Build Coastguard Worker
144*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, XMMWORD [wk(0)]   ; xmm1=(20 30 21 31 22 32 23 33)
145*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, XMMWORD [wk(1)]   ; xmm5=(24 34 25 35 26 36 27 37)
146*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(0)], xmm7   ; wk(0)=(42 52 62 72 43 53 63 73)
147*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(1)], xmm2   ; wk(1)=(44 54 64 74 45 55 65 75)
148*dfc6aa5cSAndroid Build Coastguard Worker
149*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, xmm0              ; transpose coefficients(phase 2)
150*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmm0, xmm1              ; xmm0=(00 10 20 30 01 11 21 31)
151*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmm7, xmm1              ; xmm7=(02 12 22 32 03 13 23 33)
152*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, xmm4              ; transpose coefficients(phase 2)
153*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmm4, xmm5              ; xmm4=(04 14 24 34 05 15 25 35)
154*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmm2, xmm5              ; xmm2=(06 16 26 36 07 17 27 37)
155*dfc6aa5cSAndroid Build Coastguard Worker
156*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, xmm0              ; transpose coefficients(phase 3)
157*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmm0, xmm6              ; xmm0=(00 10 20 30 40 50 60 70)=data0
158*dfc6aa5cSAndroid Build Coastguard Worker    punpckhqdq  xmm1, xmm6              ; xmm1=(01 11 21 31 41 51 61 71)=data1
159*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, xmm2              ; transpose coefficients(phase 3)
160*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmm2, xmm3              ; xmm2=(06 16 26 36 46 56 66 76)=data6
161*dfc6aa5cSAndroid Build Coastguard Worker    punpckhqdq  xmm5, xmm3              ; xmm5=(07 17 27 37 47 57 67 77)=data7
162*dfc6aa5cSAndroid Build Coastguard Worker
163*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, xmm1
164*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm3, xmm0
165*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm1, xmm2              ; xmm1=data1-data6=tmp6
166*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm0, xmm5              ; xmm0=data0-data7=tmp7
167*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm6, xmm2              ; xmm6=data1+data6=tmp1
168*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm3, xmm5              ; xmm3=data0+data7=tmp0
169*dfc6aa5cSAndroid Build Coastguard Worker
170*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, XMMWORD [wk(0)]   ; xmm2=(42 52 62 72 43 53 63 73)
171*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, XMMWORD [wk(1)]   ; xmm5=(44 54 64 74 45 55 65 75)
172*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(0)], xmm1   ; wk(0)=tmp6
173*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(1)], xmm0   ; wk(1)=tmp7
174*dfc6aa5cSAndroid Build Coastguard Worker
175*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, xmm7              ; transpose coefficients(phase 3)
176*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmm7, xmm2              ; xmm7=(02 12 22 32 42 52 62 72)=data2
177*dfc6aa5cSAndroid Build Coastguard Worker    punpckhqdq  xmm1, xmm2              ; xmm1=(03 13 23 33 43 53 63 73)=data3
178*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, xmm4              ; transpose coefficients(phase 3)
179*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmm4, xmm5              ; xmm4=(04 14 24 34 44 54 64 74)=data4
180*dfc6aa5cSAndroid Build Coastguard Worker    punpckhqdq  xmm0, xmm5              ; xmm0=(05 15 25 35 45 55 65 75)=data5
181*dfc6aa5cSAndroid Build Coastguard Worker
182*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, xmm1
183*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, xmm7
184*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm1, xmm4              ; xmm1=data3+data4=tmp3
185*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm7, xmm0              ; xmm7=data2+data5=tmp2
186*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm2, xmm4              ; xmm2=data3-data4=tmp4
187*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm5, xmm0              ; xmm5=data2-data5=tmp5
188*dfc6aa5cSAndroid Build Coastguard Worker
189*dfc6aa5cSAndroid Build Coastguard Worker    ; -- Even part
190*dfc6aa5cSAndroid Build Coastguard Worker
191*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm4, xmm3
192*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, xmm6
193*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm3, xmm1              ; xmm3=tmp13
194*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm6, xmm7              ; xmm6=tmp12
195*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm4, xmm1              ; xmm4=tmp10
196*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm0, xmm7              ; xmm0=tmp11
197*dfc6aa5cSAndroid Build Coastguard Worker
198*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm6, xmm3
199*dfc6aa5cSAndroid Build Coastguard Worker    psllw       xmm6, PRE_MULTIPLY_SCALE_BITS
200*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm6, [GOTOFF(ebx,PW_F0707)]  ; xmm6=z1
201*dfc6aa5cSAndroid Build Coastguard Worker
202*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, xmm4
203*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, xmm3
204*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm4, xmm0              ; xmm4=data4
205*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm3, xmm6              ; xmm3=data6
206*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm1, xmm0              ; xmm1=data0
207*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm7, xmm6              ; xmm7=data2
208*dfc6aa5cSAndroid Build Coastguard Worker
209*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, XMMWORD [wk(0)]   ; xmm0=tmp6
210*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, XMMWORD [wk(1)]   ; xmm6=tmp7
211*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(0)], xmm4   ; wk(0)=data4
212*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(1)], xmm3   ; wk(1)=data6
213*dfc6aa5cSAndroid Build Coastguard Worker
214*dfc6aa5cSAndroid Build Coastguard Worker    ; -- Odd part
215*dfc6aa5cSAndroid Build Coastguard Worker
216*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm2, xmm5              ; xmm2=tmp10
217*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm5, xmm0              ; xmm5=tmp11
218*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm0, xmm6              ; xmm0=tmp12, xmm6=tmp7
219*dfc6aa5cSAndroid Build Coastguard Worker
220*dfc6aa5cSAndroid Build Coastguard Worker    psllw       xmm2, PRE_MULTIPLY_SCALE_BITS
221*dfc6aa5cSAndroid Build Coastguard Worker    psllw       xmm0, PRE_MULTIPLY_SCALE_BITS
222*dfc6aa5cSAndroid Build Coastguard Worker
223*dfc6aa5cSAndroid Build Coastguard Worker    psllw       xmm5, PRE_MULTIPLY_SCALE_BITS
224*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm5, [GOTOFF(ebx,PW_F0707)]  ; xmm5=z3
225*dfc6aa5cSAndroid Build Coastguard Worker
226*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm4, xmm2                    ; xmm4=tmp10
227*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm2, xmm0
228*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm2, [GOTOFF(ebx,PW_F0382)]  ; xmm2=z5
229*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm4, [GOTOFF(ebx,PW_F0541)]  ; xmm4=MULTIPLY(tmp10,FIX_0_541196)
230*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm0, [GOTOFF(ebx,PW_F1306)]  ; xmm0=MULTIPLY(tmp12,FIX_1_306562)
231*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm4, xmm2                    ; xmm4=z2
232*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm0, xmm2                    ; xmm0=z4
233*dfc6aa5cSAndroid Build Coastguard Worker
234*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm3, xmm6
235*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm6, xmm5              ; xmm6=z13
236*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm3, xmm5              ; xmm3=z11
237*dfc6aa5cSAndroid Build Coastguard Worker
238*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, xmm6
239*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, xmm3
240*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm6, xmm4              ; xmm6=data3
241*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm3, xmm0              ; xmm3=data7
242*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm2, xmm4              ; xmm2=data5
243*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm5, xmm0              ; xmm5=data1
244*dfc6aa5cSAndroid Build Coastguard Worker
245*dfc6aa5cSAndroid Build Coastguard Worker    ; ---- Pass 2: process columns.
246*dfc6aa5cSAndroid Build Coastguard Worker
247*dfc6aa5cSAndroid Build Coastguard Worker;   mov         edx, POINTER [data(eax)]  ; (DCTELEM *)
248*dfc6aa5cSAndroid Build Coastguard Worker
249*dfc6aa5cSAndroid Build Coastguard Worker    ; xmm1=(00 10 20 30 40 50 60 70), xmm7=(02 12 22 32 42 52 62 72)
250*dfc6aa5cSAndroid Build Coastguard Worker    ; xmm5=(01 11 21 31 41 51 61 71), xmm6=(03 13 23 33 43 53 63 73)
251*dfc6aa5cSAndroid Build Coastguard Worker
252*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm4, xmm1              ; transpose coefficients(phase 1)
253*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmm1, xmm5              ; xmm1=(00 01 10 11 20 21 30 31)
254*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmm4, xmm5              ; xmm4=(40 41 50 51 60 61 70 71)
255*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, xmm7              ; transpose coefficients(phase 1)
256*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmm7, xmm6              ; xmm7=(02 03 12 13 22 23 32 33)
257*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmm0, xmm6              ; xmm0=(42 43 52 53 62 63 72 73)
258*dfc6aa5cSAndroid Build Coastguard Worker
259*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, XMMWORD [wk(0)]   ; xmm5=col4
260*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, XMMWORD [wk(1)]   ; xmm6=col6
261*dfc6aa5cSAndroid Build Coastguard Worker
262*dfc6aa5cSAndroid Build Coastguard Worker    ; xmm5=(04 14 24 34 44 54 64 74), xmm6=(06 16 26 36 46 56 66 76)
263*dfc6aa5cSAndroid Build Coastguard Worker    ; xmm2=(05 15 25 35 45 55 65 75), xmm3=(07 17 27 37 47 57 67 77)
264*dfc6aa5cSAndroid Build Coastguard Worker
265*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(0)], xmm7   ; wk(0)=(02 03 12 13 22 23 32 33)
266*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(1)], xmm0   ; wk(1)=(42 43 52 53 62 63 72 73)
267*dfc6aa5cSAndroid Build Coastguard Worker
268*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, xmm5              ; transpose coefficients(phase 1)
269*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmm5, xmm2              ; xmm5=(04 05 14 15 24 25 34 35)
270*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmm7, xmm2              ; xmm7=(44 45 54 55 64 65 74 75)
271*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, xmm6              ; transpose coefficients(phase 1)
272*dfc6aa5cSAndroid Build Coastguard Worker    punpcklwd   xmm6, xmm3              ; xmm6=(06 07 16 17 26 27 36 37)
273*dfc6aa5cSAndroid Build Coastguard Worker    punpckhwd   xmm0, xmm3              ; xmm0=(46 47 56 57 66 67 76 77)
274*dfc6aa5cSAndroid Build Coastguard Worker
275*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, xmm5              ; transpose coefficients(phase 2)
276*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmm5, xmm6              ; xmm5=(04 05 06 07 14 15 16 17)
277*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmm2, xmm6              ; xmm2=(24 25 26 27 34 35 36 37)
278*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm3, xmm7              ; transpose coefficients(phase 2)
279*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmm7, xmm0              ; xmm7=(44 45 46 47 54 55 56 57)
280*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmm3, xmm0              ; xmm3=(64 65 66 67 74 75 76 77)
281*dfc6aa5cSAndroid Build Coastguard Worker
282*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, XMMWORD [wk(0)]   ; xmm6=(02 03 12 13 22 23 32 33)
283*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, XMMWORD [wk(1)]   ; xmm0=(42 43 52 53 62 63 72 73)
284*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(0)], xmm2   ; wk(0)=(24 25 26 27 34 35 36 37)
285*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(1)], xmm7   ; wk(1)=(44 45 46 47 54 55 56 57)
286*dfc6aa5cSAndroid Build Coastguard Worker
287*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, xmm1              ; transpose coefficients(phase 2)
288*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmm1, xmm6              ; xmm1=(00 01 02 03 10 11 12 13)
289*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmm2, xmm6              ; xmm2=(20 21 22 23 30 31 32 33)
290*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, xmm4              ; transpose coefficients(phase 2)
291*dfc6aa5cSAndroid Build Coastguard Worker    punpckldq   xmm4, xmm0              ; xmm4=(40 41 42 43 50 51 52 53)
292*dfc6aa5cSAndroid Build Coastguard Worker    punpckhdq   xmm7, xmm0              ; xmm7=(60 61 62 63 70 71 72 73)
293*dfc6aa5cSAndroid Build Coastguard Worker
294*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, xmm1              ; transpose coefficients(phase 3)
295*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmm1, xmm5              ; xmm1=(00 01 02 03 04 05 06 07)=data0
296*dfc6aa5cSAndroid Build Coastguard Worker    punpckhqdq  xmm6, xmm5              ; xmm6=(10 11 12 13 14 15 16 17)=data1
297*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, xmm7              ; transpose coefficients(phase 3)
298*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmm7, xmm3              ; xmm7=(60 61 62 63 64 65 66 67)=data6
299*dfc6aa5cSAndroid Build Coastguard Worker    punpckhqdq  xmm0, xmm3              ; xmm0=(70 71 72 73 74 75 76 77)=data7
300*dfc6aa5cSAndroid Build Coastguard Worker
301*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, xmm6
302*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm3, xmm1
303*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm6, xmm7              ; xmm6=data1-data6=tmp6
304*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm1, xmm0              ; xmm1=data0-data7=tmp7
305*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm5, xmm7              ; xmm5=data1+data6=tmp1
306*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm3, xmm0              ; xmm3=data0+data7=tmp0
307*dfc6aa5cSAndroid Build Coastguard Worker
308*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, XMMWORD [wk(0)]   ; xmm7=(24 25 26 27 34 35 36 37)
309*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, XMMWORD [wk(1)]   ; xmm0=(44 45 46 47 54 55 56 57)
310*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(0)], xmm6   ; wk(0)=tmp6
311*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [wk(1)], xmm1   ; wk(1)=tmp7
312*dfc6aa5cSAndroid Build Coastguard Worker
313*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, xmm2              ; transpose coefficients(phase 3)
314*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmm2, xmm7              ; xmm2=(20 21 22 23 24 25 26 27)=data2
315*dfc6aa5cSAndroid Build Coastguard Worker    punpckhqdq  xmm6, xmm7              ; xmm6=(30 31 32 33 34 35 36 37)=data3
316*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, xmm4              ; transpose coefficients(phase 3)
317*dfc6aa5cSAndroid Build Coastguard Worker    punpcklqdq  xmm4, xmm0              ; xmm4=(40 41 42 43 44 45 46 47)=data4
318*dfc6aa5cSAndroid Build Coastguard Worker    punpckhqdq  xmm1, xmm0              ; xmm1=(50 51 52 53 54 55 56 57)=data5
319*dfc6aa5cSAndroid Build Coastguard Worker
320*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm7, xmm6
321*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm0, xmm2
322*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm6, xmm4              ; xmm6=data3+data4=tmp3
323*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm2, xmm1              ; xmm2=data2+data5=tmp2
324*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm7, xmm4              ; xmm7=data3-data4=tmp4
325*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm0, xmm1              ; xmm0=data2-data5=tmp5
326*dfc6aa5cSAndroid Build Coastguard Worker
327*dfc6aa5cSAndroid Build Coastguard Worker    ; -- Even part
328*dfc6aa5cSAndroid Build Coastguard Worker
329*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm4, xmm3
330*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, xmm5
331*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm3, xmm6              ; xmm3=tmp13
332*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm5, xmm2              ; xmm5=tmp12
333*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm4, xmm6              ; xmm4=tmp10
334*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm1, xmm2              ; xmm1=tmp11
335*dfc6aa5cSAndroid Build Coastguard Worker
336*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm5, xmm3
337*dfc6aa5cSAndroid Build Coastguard Worker    psllw       xmm5, PRE_MULTIPLY_SCALE_BITS
338*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm5, [GOTOFF(ebx,PW_F0707)]  ; xmm5=z1
339*dfc6aa5cSAndroid Build Coastguard Worker
340*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, xmm4
341*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, xmm3
342*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm4, xmm1              ; xmm4=data4
343*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm3, xmm5              ; xmm3=data6
344*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm6, xmm1              ; xmm6=data0
345*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm2, xmm5              ; xmm2=data2
346*dfc6aa5cSAndroid Build Coastguard Worker
347*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [XMMBLOCK(4,0,edx,SIZEOF_DCTELEM)], xmm4
348*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [XMMBLOCK(6,0,edx,SIZEOF_DCTELEM)], xmm3
349*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [XMMBLOCK(0,0,edx,SIZEOF_DCTELEM)], xmm6
350*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [XMMBLOCK(2,0,edx,SIZEOF_DCTELEM)], xmm2
351*dfc6aa5cSAndroid Build Coastguard Worker
352*dfc6aa5cSAndroid Build Coastguard Worker    ; -- Odd part
353*dfc6aa5cSAndroid Build Coastguard Worker
354*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm1, XMMWORD [wk(0)]   ; xmm1=tmp6
355*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm5, XMMWORD [wk(1)]   ; xmm5=tmp7
356*dfc6aa5cSAndroid Build Coastguard Worker
357*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm7, xmm0              ; xmm7=tmp10
358*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm0, xmm1              ; xmm0=tmp11
359*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm1, xmm5              ; xmm1=tmp12, xmm5=tmp7
360*dfc6aa5cSAndroid Build Coastguard Worker
361*dfc6aa5cSAndroid Build Coastguard Worker    psllw       xmm7, PRE_MULTIPLY_SCALE_BITS
362*dfc6aa5cSAndroid Build Coastguard Worker    psllw       xmm1, PRE_MULTIPLY_SCALE_BITS
363*dfc6aa5cSAndroid Build Coastguard Worker
364*dfc6aa5cSAndroid Build Coastguard Worker    psllw       xmm0, PRE_MULTIPLY_SCALE_BITS
365*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm0, [GOTOFF(ebx,PW_F0707)]  ; xmm0=z3
366*dfc6aa5cSAndroid Build Coastguard Worker
367*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm4, xmm7                    ; xmm4=tmp10
368*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm7, xmm1
369*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm7, [GOTOFF(ebx,PW_F0382)]  ; xmm7=z5
370*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm4, [GOTOFF(ebx,PW_F0541)]  ; xmm4=MULTIPLY(tmp10,FIX_0_541196)
371*dfc6aa5cSAndroid Build Coastguard Worker    pmulhw      xmm1, [GOTOFF(ebx,PW_F1306)]  ; xmm1=MULTIPLY(tmp12,FIX_1_306562)
372*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm4, xmm7                    ; xmm4=z2
373*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm1, xmm7                    ; xmm1=z4
374*dfc6aa5cSAndroid Build Coastguard Worker
375*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm3, xmm5
376*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm5, xmm0              ; xmm5=z13
377*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm3, xmm0              ; xmm3=z11
378*dfc6aa5cSAndroid Build Coastguard Worker
379*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm6, xmm5
380*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      xmm2, xmm3
381*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm5, xmm4              ; xmm5=data3
382*dfc6aa5cSAndroid Build Coastguard Worker    psubw       xmm3, xmm1              ; xmm3=data7
383*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm6, xmm4              ; xmm6=data5
384*dfc6aa5cSAndroid Build Coastguard Worker    paddw       xmm2, xmm1              ; xmm2=data1
385*dfc6aa5cSAndroid Build Coastguard Worker
386*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [XMMBLOCK(3,0,edx,SIZEOF_DCTELEM)], xmm5
387*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [XMMBLOCK(7,0,edx,SIZEOF_DCTELEM)], xmm3
388*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [XMMBLOCK(5,0,edx,SIZEOF_DCTELEM)], xmm6
389*dfc6aa5cSAndroid Build Coastguard Worker    movdqa      XMMWORD [XMMBLOCK(1,0,edx,SIZEOF_DCTELEM)], xmm2
390*dfc6aa5cSAndroid Build Coastguard Worker
391*dfc6aa5cSAndroid Build Coastguard Worker;   pop         edi                     ; unused
392*dfc6aa5cSAndroid Build Coastguard Worker;   pop         esi                     ; unused
393*dfc6aa5cSAndroid Build Coastguard Worker;   pop         edx                     ; need not be preserved
394*dfc6aa5cSAndroid Build Coastguard Worker;   pop         ecx                     ; unused
395*dfc6aa5cSAndroid Build Coastguard Worker    poppic      ebx
396*dfc6aa5cSAndroid Build Coastguard Worker    mov         esp, ebp                ; esp <- aligned ebp
397*dfc6aa5cSAndroid Build Coastguard Worker    pop         esp                     ; esp <- original ebp
398*dfc6aa5cSAndroid Build Coastguard Worker    pop         ebp
399*dfc6aa5cSAndroid Build Coastguard Worker    ret
400*dfc6aa5cSAndroid Build Coastguard Worker
401*dfc6aa5cSAndroid Build Coastguard Worker; For some reason, the OS X linker does not honor the request to align the
402*dfc6aa5cSAndroid Build Coastguard Worker; segment unless we do this.
403*dfc6aa5cSAndroid Build Coastguard Worker    align       32
404