summaryrefslogtreecommitdiffstats
path: root/media/libvpx/vp8/encoder/x86/encodeopt.asm
blob: fe26b18e5611e273c64c983060b37f481c78c782 (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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
;
;  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_block_error_xmm(short *coeff_ptr,  short *dcoef_ptr)
global sym(vp8_block_error_xmm) PRIVATE
sym(vp8_block_error_xmm):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 2
    push rsi
    push rdi
    ; end prologue

        mov         rsi,        arg(0) ;coeff_ptr
        mov         rdi,        arg(1) ;dcoef_ptr

        movdqa      xmm0,       [rsi]
        movdqa      xmm1,       [rdi]

        movdqa      xmm2,       [rsi+16]
        movdqa      xmm3,       [rdi+16]

        psubw       xmm0,       xmm1
        psubw       xmm2,       xmm3

        pmaddwd     xmm0,       xmm0
        pmaddwd     xmm2,       xmm2

        paddd       xmm0,       xmm2

        pxor        xmm5,       xmm5
        movdqa      xmm1,       xmm0

        punpckldq   xmm0,       xmm5
        punpckhdq   xmm1,       xmm5

        paddd       xmm0,       xmm1
        movdqa      xmm1,       xmm0

        psrldq      xmm0,       8
        paddd       xmm0,       xmm1

        movq        rax,        xmm0

    pop rdi
    pop rsi
    ; begin epilog
    UNSHADOW_ARGS
    pop         rbp
    ret

;int vp8_block_error_mmx(short *coeff_ptr,  short *dcoef_ptr)
global sym(vp8_block_error_mmx) PRIVATE
sym(vp8_block_error_mmx):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 2
    push rsi
    push rdi
    ; end prolog


        mov         rsi,        arg(0) ;coeff_ptr
        pxor        mm7,        mm7

        mov         rdi,        arg(1) ;dcoef_ptr
        movq        mm3,        [rsi]

        movq        mm4,        [rdi]
        movq        mm5,        [rsi+8]

        movq        mm6,        [rdi+8]
        pxor        mm1,        mm1 ; from movd mm1, dc ; dc =0

        movq        mm2,        mm7
        psubw       mm5,        mm6

        por         mm1,        mm2
        pmaddwd     mm5,        mm5

        pcmpeqw     mm1,        mm7
        psubw       mm3,        mm4

        pand        mm1,        mm3
        pmaddwd     mm1,        mm1

        paddd       mm1,        mm5
        movq        mm3,        [rsi+16]

        movq        mm4,        [rdi+16]
        movq        mm5,        [rsi+24]

        movq        mm6,        [rdi+24]
        psubw       mm5,        mm6

        pmaddwd     mm5,        mm5
        psubw       mm3,        mm4

        pmaddwd     mm3,        mm3
        paddd       mm3,        mm5

        paddd       mm1,        mm3
        movq        mm0,        mm1

        psrlq       mm1,        32
        paddd       mm0,        mm1

        movq        rax,        mm0

    pop rdi
    pop rsi
    ; begin epilog
    UNSHADOW_ARGS
    pop         rbp
    ret


;int vp8_mbblock_error_mmx_impl(short *coeff_ptr, short *dcoef_ptr, int dc);
global sym(vp8_mbblock_error_mmx_impl) PRIVATE
sym(vp8_mbblock_error_mmx_impl):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 3
    push rsi
    push rdi
    ; end prolog


        mov         rsi,        arg(0) ;coeff_ptr
        pxor        mm7,        mm7

        mov         rdi,        arg(1) ;dcoef_ptr
        pxor        mm2,        mm2

        movd        mm1,        dword ptr arg(2) ;dc
        por         mm1,        mm2

        pcmpeqw     mm1,        mm7
        mov         rcx,        16

.mberror_loop_mmx:
        movq        mm3,       [rsi]
        movq        mm4,       [rdi]

        movq        mm5,       [rsi+8]
        movq        mm6,       [rdi+8]


        psubw       mm5,        mm6
        pmaddwd     mm5,        mm5

        psubw       mm3,        mm4
        pand        mm3,        mm1

        pmaddwd     mm3,        mm3
        paddd       mm2,        mm5

        paddd       mm2,        mm3
        movq        mm3,       [rsi+16]

        movq        mm4,       [rdi+16]
        movq        mm5,       [rsi+24]

        movq        mm6,       [rdi+24]
        psubw       mm5,        mm6

        pmaddwd     mm5,        mm5
        psubw       mm3,        mm4

        pmaddwd     mm3,        mm3
        paddd       mm2,        mm5

        paddd       mm2,        mm3
        add         rsi,        32

        add         rdi,        32
        sub         rcx,        1

        jnz         .mberror_loop_mmx

        movq        mm0,        mm2
        psrlq       mm2,        32

        paddd       mm0,        mm2
        movq        rax,        mm0

    pop rdi
    pop rsi
    ; begin epilog
    UNSHADOW_ARGS
    pop         rbp
    ret


;int vp8_mbblock_error_xmm_impl(short *coeff_ptr, short *dcoef_ptr, int dc);
global sym(vp8_mbblock_error_xmm_impl) PRIVATE
sym(vp8_mbblock_error_xmm_impl):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 3
    SAVE_XMM 6
    push rsi
    push rdi
    ; end prolog


        mov         rsi,        arg(0) ;coeff_ptr
        pxor        xmm6,       xmm6

        mov         rdi,        arg(1) ;dcoef_ptr
        pxor        xmm4,       xmm4

        movd        xmm5,       dword ptr arg(2) ;dc
        por         xmm5,       xmm4

        pcmpeqw     xmm5,       xmm6
        mov         rcx,        16

.mberror_loop:
        movdqa      xmm0,       [rsi]
        movdqa      xmm1,       [rdi]

        movdqa      xmm2,       [rsi+16]
        movdqa      xmm3,       [rdi+16]


        psubw       xmm2,       xmm3
        pmaddwd     xmm2,       xmm2

        psubw       xmm0,       xmm1
        pand        xmm0,       xmm5

        pmaddwd     xmm0,       xmm0
        add         rsi,        32

        add         rdi,        32

        sub         rcx,        1
        paddd       xmm4,       xmm2

        paddd       xmm4,       xmm0
        jnz         .mberror_loop

        movdqa      xmm0,       xmm4
        punpckldq   xmm0,       xmm6

        punpckhdq   xmm4,       xmm6
        paddd       xmm0,       xmm4

        movdqa      xmm1,       xmm0
        psrldq      xmm0,       8

        paddd       xmm0,       xmm1
        movq        rax,        xmm0

    pop rdi
    pop rsi
    ; begin epilog
    RESTORE_XMM
    UNSHADOW_ARGS
    pop         rbp
    ret


;int vp8_mbuverror_mmx_impl(short *s_ptr, short *d_ptr);
global sym(vp8_mbuverror_mmx_impl) PRIVATE
sym(vp8_mbuverror_mmx_impl):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 2
    push rsi
    push rdi
    ; end prolog


        mov             rsi,        arg(0) ;s_ptr
        mov             rdi,        arg(1) ;d_ptr

        mov             rcx,        16
        pxor            mm7,        mm7

.mbuverror_loop_mmx:

        movq            mm1,        [rsi]
        movq            mm2,        [rdi]

        psubw           mm1,        mm2
        pmaddwd         mm1,        mm1


        movq            mm3,        [rsi+8]
        movq            mm4,        [rdi+8]

        psubw           mm3,        mm4
        pmaddwd         mm3,        mm3


        paddd           mm7,        mm1
        paddd           mm7,        mm3


        add             rsi,        16
        add             rdi,        16

        dec             rcx
        jnz             .mbuverror_loop_mmx

        movq            mm0,        mm7
        psrlq           mm7,        32

        paddd           mm0,        mm7
        movq            rax,        mm0

    pop rdi
    pop rsi
    ; begin epilog
    UNSHADOW_ARGS
    pop         rbp
    ret


;int vp8_mbuverror_xmm_impl(short *s_ptr, short *d_ptr);
global sym(vp8_mbuverror_xmm_impl) PRIVATE
sym(vp8_mbuverror_xmm_impl):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 2
    push rsi
    push rdi
    ; end prolog


        mov             rsi,        arg(0) ;s_ptr
        mov             rdi,        arg(1) ;d_ptr

        mov             rcx,        16
        pxor            xmm3,       xmm3

.mbuverror_loop:

        movdqa          xmm1,       [rsi]
        movdqa          xmm2,       [rdi]

        psubw           xmm1,       xmm2
        pmaddwd         xmm1,       xmm1

        paddd           xmm3,       xmm1

        add             rsi,        16
        add             rdi,        16

        dec             rcx
        jnz             .mbuverror_loop

        pxor        xmm0,           xmm0
        movdqa      xmm1,           xmm3

        movdqa      xmm2,           xmm1
        punpckldq   xmm1,           xmm0

        punpckhdq   xmm2,           xmm0
        paddd       xmm1,           xmm2

        movdqa      xmm2,           xmm1

        psrldq      xmm1,           8
        paddd       xmm1,           xmm2

        movq            rax,            xmm1

    pop rdi
    pop rsi
    ; begin epilog
    UNSHADOW_ARGS
    pop         rbp
    ret