summaryrefslogtreecommitdiffstats
path: root/media/libvpx/vp8/encoder/x86/quantize_mmx.asm
blob: 2864ce16d99c58b0c6efe3889f616b0124a2ae3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
;
;  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
;
;  Use of this source code is governed by a BSD-style license
;  that can be found in the LICENSE file in the root of the source
;  tree. An additional intellectual property rights grant can be found
;  in the file PATENTS.  All contributing project authors may
;  be found in the AUTHORS file in the root of the source tree.
;


%include "vpx_ports/x86_abi_support.asm"

;int vp8_fast_quantize_b_impl_mmx(short *coeff_ptr, short *zbin_ptr,
;                           short *qcoeff_ptr,short *dequant_ptr,
;                           short *scan_mask, short *round_ptr,
;                           short *quant_ptr, short *dqcoeff_ptr);
global sym(vp8_fast_quantize_b_impl_mmx) PRIVATE
sym(vp8_fast_quantize_b_impl_mmx):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 8
    push rsi
    push rdi
    ; end prolog


        mov             rsi,        arg(0) ;coeff_ptr
        movq            mm0,        [rsi]

        mov             rax,        arg(1) ;zbin_ptr
        movq            mm1,        [rax]

        movq            mm3,        mm0
        psraw           mm0,        15

        pxor            mm3,        mm0
        psubw           mm3,        mm0         ; abs

        movq            mm2,        mm3
        pcmpgtw         mm1,        mm2

        pandn           mm1,        mm2
        movq            mm3,        mm1

        mov             rdx,        arg(6) ;quant_ptr
        movq            mm1,        [rdx]

        mov             rcx,        arg(5) ;round_ptr
        movq            mm2,        [rcx]

        paddw           mm3,        mm2
        pmulhuw         mm3,        mm1

        pxor            mm3,        mm0
        psubw           mm3,        mm0     ;gain the sign back

        mov             rdi,        arg(2) ;qcoeff_ptr
        movq            mm0,        mm3

        movq            [rdi],      mm3

        mov             rax,        arg(3) ;dequant_ptr
        movq            mm2,        [rax]

        pmullw          mm3,        mm2
        mov             rax,        arg(7) ;dqcoeff_ptr

        movq            [rax],      mm3

        ; next 8
        movq            mm4,        [rsi+8]

        mov             rax,        arg(1) ;zbin_ptr
        movq            mm5,        [rax+8]

        movq            mm7,        mm4
        psraw           mm4,        15

        pxor            mm7,        mm4
        psubw           mm7,        mm4         ; abs

        movq            mm6,        mm7
        pcmpgtw         mm5,        mm6

        pandn           mm5,        mm6
        movq            mm7,        mm5

        movq            mm5,        [rdx+8]
        movq            mm6,        [rcx+8]

        paddw           mm7,        mm6
        pmulhuw         mm7,        mm5

        pxor            mm7,        mm4
        psubw           mm7,        mm4;gain the sign back

        mov             rdi,        arg(2) ;qcoeff_ptr

        movq            mm1,        mm7
        movq            [rdi+8],    mm7

        mov             rax,        arg(3) ;dequant_ptr
        movq            mm6,        [rax+8]

        pmullw          mm7,        mm6
        mov             rax,        arg(7) ;dqcoeff_ptr

        movq            [rax+8],    mm7


                ; next 8
        movq            mm4,        [rsi+16]

        mov             rax,        arg(1) ;zbin_ptr
        movq            mm5,        [rax+16]

        movq            mm7,        mm4
        psraw           mm4,        15

        pxor            mm7,        mm4
        psubw           mm7,        mm4         ; abs

        movq            mm6,        mm7
        pcmpgtw         mm5,        mm6

        pandn           mm5,        mm6
        movq            mm7,        mm5

        movq            mm5,        [rdx+16]
        movq            mm6,        [rcx+16]

        paddw           mm7,        mm6
        pmulhuw         mm7,        mm5

        pxor            mm7,        mm4
        psubw           mm7,        mm4;gain the sign back

        mov             rdi,        arg(2) ;qcoeff_ptr

        movq            mm1,        mm7
        movq            [rdi+16],   mm7

        mov             rax,        arg(3) ;dequant_ptr
        movq            mm6,        [rax+16]

        pmullw          mm7,        mm6
        mov             rax,        arg(7) ;dqcoeff_ptr

        movq            [rax+16],   mm7


                ; next 8
        movq            mm4,        [rsi+24]

        mov             rax,        arg(1) ;zbin_ptr
        movq            mm5,        [rax+24]

        movq            mm7,        mm4
        psraw           mm4,        15

        pxor            mm7,        mm4
        psubw           mm7,        mm4         ; abs

        movq            mm6,        mm7
        pcmpgtw         mm5,        mm6

        pandn           mm5,        mm6
        movq            mm7,        mm5

        movq            mm5,        [rdx+24]
        movq            mm6,        [rcx+24]

        paddw           mm7,        mm6
        pmulhuw         mm7,        mm5

        pxor            mm7,        mm4
        psubw           mm7,        mm4;gain the sign back

        mov             rdi,        arg(2) ;qcoeff_ptr

        movq            mm1,        mm7
        movq            [rdi+24],   mm7

        mov             rax,        arg(3) ;dequant_ptr
        movq            mm6,        [rax+24]

        pmullw          mm7,        mm6
        mov             rax,        arg(7) ;dqcoeff_ptr

        movq            [rax+24],   mm7



        mov             rdi,        arg(4) ;scan_mask
        mov             rsi,        arg(2) ;qcoeff_ptr

        pxor            mm5,        mm5
        pxor            mm7,        mm7

        movq            mm0,        [rsi]
        movq            mm1,        [rsi+8]

        movq            mm2,        [rdi]
        movq            mm3,        [rdi+8];

        pcmpeqw         mm0,        mm7
        pcmpeqw         mm1,        mm7

        pcmpeqw         mm6,        mm6
        pxor            mm0,        mm6

        pxor            mm1,        mm6
        psrlw           mm0,        15

        psrlw           mm1,        15
        pmaddwd         mm0,        mm2

        pmaddwd         mm1,        mm3
        movq            mm5,        mm0

        paddd           mm5,        mm1

        movq            mm0,        [rsi+16]
        movq            mm1,        [rsi+24]

        movq            mm2,        [rdi+16]
        movq            mm3,        [rdi+24];

        pcmpeqw         mm0,        mm7
        pcmpeqw         mm1,        mm7

        pcmpeqw         mm6,        mm6
        pxor            mm0,        mm6

        pxor            mm1,        mm6
        psrlw           mm0,        15

        psrlw           mm1,        15
        pmaddwd         mm0,        mm2

        pmaddwd         mm1,        mm3
        paddd           mm5,        mm0

        paddd           mm5,        mm1
        movq            mm0,        mm5

        psrlq           mm5,        32
        paddd           mm0,        mm5

        ; eob adjustment begins here
        movq            rcx,        mm0
        and             rcx,        0xffff

        xor             rdx,        rdx
        sub             rdx,        rcx ; rdx=-rcx

        bsr             rax,        rcx
        inc             rax

        sar             rdx,        31
        and             rax,        rdx
        ; Substitute the sse assembly for the old mmx mixed assembly/C. The
        ; following is kept as reference
        ;    movq            rcx,        mm0
        ;    bsr             rax,        rcx
        ;
        ;    mov             eob,        rax
        ;    mov             eee,        rcx
        ;
        ;if(eee==0)
        ;{
        ;    eob=-1;
        ;}
        ;else if(eee<0)
        ;{
        ;    eob=15;
        ;}
        ;d->eob = eob+1;

    ; begin epilog
    pop rdi
    pop rsi
    UNSHADOW_ARGS
    pop         rbp
    ret