vp8_loopfilter_mmx.asm 68.8 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
;
2
;  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
;
4
;  Use of this source code is governed by a BSD-style license
5
6
;  that can be found in the LICENSE file in the root of the source
;  tree. An additional intellectual property rights grant can be found
7
;  in the file PATENTS.  All contributing project authors may
8
;  be found in the AUTHORS file in the root of the source tree.
John Koleszar's avatar
John Koleszar committed
9
10
11
12
13
14
15
16
17
18
;


%include "vpx_ports/x86_abi_support.asm"


;void vp8_loop_filter_horizontal_edge_mmx
;(
;    unsigned char *src_ptr,
;    int src_pixel_step,
Johann's avatar
Johann committed
19
;    const char *blimit,
John Koleszar's avatar
John Koleszar committed
20
21
22
23
;    const char *limit,
;    const char *thresh,
;    int  count
;)
24
global sym(vp8_loop_filter_horizontal_edge_mmx) PRIVATE
John Koleszar's avatar
John Koleszar committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
sym(vp8_loop_filter_horizontal_edge_mmx):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 6
    GET_GOT     rbx
    push        rsi
    push        rdi
    ; end prolog

    ALIGN_STACK 16, rax
    sub         rsp, 32                         ; reserve 32 bytes
    %define t0 [rsp + 0]    ;__declspec(align(16)) char t0[8];
    %define t1 [rsp + 16]   ;__declspec(align(16)) char t1[8];

        mov         rsi, arg(0) ;src_ptr
        movsxd      rax, dword ptr arg(1) ;src_pixel_step     ; destination pitch?

        movsxd      rcx, dword ptr arg(5) ;count
43
.next8_h:
John Koleszar's avatar
John Koleszar committed
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
        mov         rdx, arg(3) ;limit
        movq        mm7, [rdx]
        mov         rdi, rsi              ; rdi points to row +1 for indirect addressing
        add         rdi, rax

        ; calculate breakout conditions
        movq        mm2, [rdi+2*rax]      ; q3
        movq        mm1, [rsi+2*rax]      ; q2
        movq        mm6, mm1              ; q2
        psubusb     mm1, mm2              ; q2-=q3
        psubusb     mm2, mm6              ; q3-=q2
        por         mm1, mm2              ; abs(q3-q2)
        psubusb     mm1, mm7              ;


        movq        mm4, [rsi+rax]        ; q1
        movq        mm3, mm4              ; q1
        psubusb     mm4, mm6              ; q1-=q2
        psubusb     mm6, mm3              ; q2-=q1
        por         mm4, mm6              ; abs(q2-q1)

        psubusb     mm4, mm7
        por        mm1, mm4

        movq        mm4, [rsi]            ; q0
        movq        mm0, mm4              ; q0
        psubusb     mm4, mm3              ; q0-=q1
        psubusb     mm3, mm0              ; q1-=q0
        por         mm4, mm3              ; abs(q0-q1)
        movq        t0, mm4               ; save to t0
        psubusb     mm4, mm7
        por        mm1, mm4


        neg         rax                   ; negate pitch to deal with above border

        movq        mm2, [rsi+4*rax]      ; p3
        movq        mm4, [rdi+4*rax]      ; p2
        movq        mm5, mm4              ; p2
        psubusb     mm4, mm2              ; p2-=p3
        psubusb     mm2, mm5              ; p3-=p2
        por         mm4, mm2              ; abs(p3 - p2)
        psubusb     mm4, mm7
        por        mm1, mm4


        movq        mm4, [rsi+2*rax]      ; p1
        movq        mm3, mm4              ; p1
        psubusb     mm4, mm5              ; p1-=p2
        psubusb     mm5, mm3              ; p2-=p1
        por         mm4, mm5              ; abs(p2 - p1)
        psubusb     mm4, mm7
        por        mm1, mm4

        movq        mm2, mm3              ; p1

        movq        mm4, [rsi+rax]        ; p0
        movq        mm5, mm4              ; p0
        psubusb     mm4, mm3              ; p0-=p1
        psubusb     mm3, mm5              ; p1-=p0
        por         mm4, mm3              ; abs(p1 - p0)
        movq        t1, mm4               ; save to t1
        psubusb     mm4, mm7
        por        mm1, mm4

        movq        mm3, [rdi]            ; q1
        movq        mm4, mm3              ; q1
        psubusb     mm3, mm2              ; q1-=p1
        psubusb     mm2, mm4              ; p1-=q1
        por         mm2, mm3              ; abs(p1-q1)
114
        pand        mm2, [GLOBAL(tfe)]    ; set lsb of each byte to zero
John Koleszar's avatar
John Koleszar committed
115
116
117
118
119
120
121
122
123
124
        psrlw       mm2, 1                ; abs(p1-q1)/2

        movq        mm6, mm5              ; p0
        movq        mm3, [rsi]            ; q0
        psubusb     mm5, mm3              ; p0-=q0
        psubusb     mm3, mm6              ; q0-=p0
        por         mm5, mm3              ; abs(p0 - q0)
        paddusb     mm5, mm5              ; abs(p0-q0)*2
        paddusb     mm5, mm2              ; abs (p0 - q0) *2 + abs(p1-q1)/2

Johann's avatar
Johann committed
125
126
        mov         rdx, arg(2) ;blimit           ; get blimit
        movq        mm7, [rdx]            ; blimit
John Koleszar's avatar
John Koleszar committed
127

Johann's avatar
Johann committed
128
        psubusb     mm5,    mm7           ; abs (p0 - q0) *2 + abs(p1-q1)/2  > blimit
John Koleszar's avatar
John Koleszar committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
        por         mm1,    mm5
        pxor        mm5,    mm5
        pcmpeqb     mm1,    mm5           ; mask mm1

        ; calculate high edge variance
        mov         rdx, arg(4) ;thresh           ; get thresh
        movq        mm7, [rdx]            ;
        movq        mm4, t0               ; get abs (q1 - q0)
        psubusb     mm4, mm7
        movq        mm3, t1               ; get abs (p1 - p0)
        psubusb     mm3, mm7
        paddb       mm4, mm3              ; abs(q1 - q0) > thresh || abs(p1 - p0) > thresh

        pcmpeqb     mm4,        mm5

        pcmpeqb     mm5,        mm5
        pxor        mm4,        mm5


        ; start work on filters
        movq        mm2, [rsi+2*rax]      ; p1
        movq        mm7, [rdi]            ; q1
151
152
        pxor        mm2, [GLOBAL(t80)]    ; p1 offset to convert to signed values
        pxor        mm7, [GLOBAL(t80)]    ; q1 offset to convert to signed values
John Koleszar's avatar
John Koleszar committed
153
154
        psubsb      mm2, mm7              ; p1 - q1
        pand        mm2, mm4              ; high var mask (hvm)(p1 - q1)
155
156
        pxor        mm6, [GLOBAL(t80)]    ; offset to convert to signed values
        pxor        mm0, [GLOBAL(t80)]    ; offset to convert to signed values
John Koleszar's avatar
John Koleszar committed
157
158
159
160
161
162
163
        movq        mm3, mm0              ; q0
        psubsb      mm0, mm6              ; q0 - p0
        paddsb      mm2, mm0              ; 1 * (q0 - p0) + hvm(p1 - q1)
        paddsb      mm2, mm0              ; 2 * (q0 - p0) + hvm(p1 - q1)
        paddsb      mm2, mm0              ; 3 * (q0 - p0) + hvm(p1 - q1)
        pand        mm1, mm2                  ; mask filter values we don't care about
        movq        mm2, mm1
164
165
        paddsb      mm1, [GLOBAL(t4)]     ; 3* (q0 - p0) + hvm(p1 - q1) + 4
        paddsb      mm2, [GLOBAL(t3)]     ; 3* (q0 - p0) + hvm(p1 - q1) + 3
John Koleszar's avatar
John Koleszar committed
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

        pxor        mm0, mm0             ;
        pxor        mm5, mm5
        punpcklbw   mm0, mm2            ;
        punpckhbw   mm5, mm2            ;
        psraw       mm0, 11             ;
        psraw       mm5, 11
        packsswb    mm0, mm5
        movq        mm2, mm0            ;  (3* (q0 - p0) + hvm(p1 - q1) + 3) >> 3;

        pxor        mm0, mm0              ; 0
        movq        mm5, mm1              ; abcdefgh
        punpcklbw   mm0, mm1              ; e0f0g0h0
        psraw       mm0, 11               ; sign extended shift right by 3
        pxor        mm1, mm1              ; 0
        punpckhbw   mm1, mm5              ; a0b0c0d0
        psraw       mm1, 11               ; sign extended shift right by 3
        movq        mm5, mm0              ; save results

        packsswb    mm0, mm1              ; (3* (q0 - p0) + hvm(p1 - q1) + 4) >>3
186
187
        paddsw      mm5, [GLOBAL(ones)]
        paddsw      mm1, [GLOBAL(ones)]
John Koleszar's avatar
John Koleszar committed
188
189
190
191
192
193
        psraw       mm5, 1                ; partial shifted one more time for 2nd tap
        psraw       mm1, 1                ; partial shifted one more time for 2nd tap
        packsswb    mm5, mm1              ; (3* (q0 - p0) + hvm(p1 - q1) + 4) >>4
        pandn       mm4, mm5              ; high edge variance additive

        paddsb      mm6, mm2              ; p0+= p0 add
194
        pxor        mm6, [GLOBAL(t80)]    ; unoffset
John Koleszar's avatar
John Koleszar committed
195
196
197
        movq        [rsi+rax], mm6        ; write back

        movq        mm6, [rsi+2*rax]      ; p1
198
        pxor        mm6, [GLOBAL(t80)]    ; reoffset
John Koleszar's avatar
John Koleszar committed
199
        paddsb      mm6, mm4              ; p1+= p1 add
200
        pxor        mm6, [GLOBAL(t80)]    ; unoffset
John Koleszar's avatar
John Koleszar committed
201
202
203
        movq        [rsi+2*rax], mm6      ; write back

        psubsb      mm3, mm0              ; q0-= q0 add
204
        pxor        mm3, [GLOBAL(t80)]    ; unoffset
John Koleszar's avatar
John Koleszar committed
205
206
207
        movq        [rsi], mm3            ; write back

        psubsb      mm7, mm4              ; q1-= q1 add
208
        pxor        mm7, [GLOBAL(t80)]    ; unoffset
John Koleszar's avatar
John Koleszar committed
209
210
211
212
213
        movq        [rdi], mm7            ; write back

        add         rsi,8
        neg         rax
        dec         rcx
214
        jnz         .next8_h
John Koleszar's avatar
John Koleszar committed
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230

    add rsp, 32
    pop rsp
    ; begin epilog
    pop rdi
    pop rsi
    RESTORE_GOT
    UNSHADOW_ARGS
    pop         rbp
    ret


;void vp8_loop_filter_vertical_edge_mmx
;(
;    unsigned char *src_ptr,
;    int  src_pixel_step,
Johann's avatar
Johann committed
231
;    const char *blimit,
John Koleszar's avatar
John Koleszar committed
232
233
234
235
;    const char *limit,
;    const char *thresh,
;    int count
;)
236
global sym(vp8_loop_filter_vertical_edge_mmx) PRIVATE
John Koleszar's avatar
John Koleszar committed
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
sym(vp8_loop_filter_vertical_edge_mmx):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 6
    GET_GOT     rbx
    push        rsi
    push        rdi
    ; end prolog

    ALIGN_STACK 16, rax
    sub          rsp, 64      ; reserve 64 bytes
    %define t0   [rsp + 0]    ;__declspec(align(16)) char t0[8];
    %define t1   [rsp + 16]   ;__declspec(align(16)) char t1[8];
    %define srct [rsp + 32]   ;__declspec(align(16)) char srct[32];

        mov         rsi,        arg(0) ;src_ptr
        movsxd      rax,        dword ptr arg(1) ;src_pixel_step     ; destination pitch?

        lea         rsi,        [rsi + rax*4 - 4]

        movsxd      rcx,        dword ptr arg(5) ;count
258
.next8_v:
John Koleszar's avatar
John Koleszar committed
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
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
        mov         rdi,        rsi           ; rdi points to row +1 for indirect addressing
        add         rdi,        rax


        ;transpose
        movq        mm6,        [rsi+2*rax]                 ; 67 66 65 64 63 62 61 60
        movq        mm7,        mm6                         ; 77 76 75 74 73 72 71 70

        punpckhbw   mm7,        [rdi+2*rax]                 ; 77 67 76 66 75 65 74 64
        punpcklbw   mm6,        [rdi+2*rax]                 ; 73 63 72 62 71 61 70 60

        movq        mm4,        [rsi]                       ; 47 46 45 44 43 42 41 40
        movq        mm5,        mm4                         ; 47 46 45 44 43 42 41 40

        punpckhbw   mm5,        [rsi+rax]                   ; 57 47 56 46 55 45 54 44
        punpcklbw   mm4,        [rsi+rax]                   ; 53 43 52 42 51 41 50 40

        movq        mm3,        mm5                         ; 57 47 56 46 55 45 54 44
        punpckhwd   mm5,        mm7                         ; 77 67 57 47 76 66 56 46

        punpcklwd   mm3,        mm7                         ; 75 65 55 45 74 64 54 44
        movq        mm2,        mm4                         ; 53 43 52 42 51 41 50 40

        punpckhwd   mm4,        mm6                         ; 73 63 53 43 72 62 52 42
        punpcklwd   mm2,        mm6                         ; 71 61 51 41 70 60 50 40

        neg         rax
        movq        mm6,        [rsi+rax*2]                 ; 27 26 25 24 23 22 21 20

        movq        mm1,        mm6                         ; 27 26 25 24 23 22 21 20
        punpckhbw   mm6,        [rsi+rax]                   ; 37 27 36 36 35 25 34 24

        punpcklbw   mm1,        [rsi+rax]                   ; 33 23 32 22 31 21 30 20
        movq        mm7,        [rsi+rax*4];                ; 07 06 05 04 03 02 01 00

        punpckhbw   mm7,        [rdi+rax*4]                 ; 17 07 16 06 15 05 14 04
        movq        mm0,        mm7                         ; 17 07 16 06 15 05 14 04

        punpckhwd   mm7,        mm6                         ; 37 27 17 07 36 26 16 06
        punpcklwd   mm0,        mm6                         ; 35 25 15 05 34 24 14 04

        movq        mm6,        mm7                         ; 37 27 17 07 36 26 16 06
        punpckhdq   mm7,        mm5                         ; 77 67 57 47 37 27 17 07  = q3

        punpckldq   mm6,        mm5                         ; 76 66 56 46 36 26 16 06  = q2

        movq        mm5,        mm6                         ; 76 66 56 46 36 26 16 06
        psubusb     mm5,        mm7                         ; q2-q3

        psubusb     mm7,        mm6                         ; q3-q2
        por         mm7,        mm5;                        ; mm7=abs (q3-q2)

        movq        mm5,        mm0                         ; 35 25 15 05 34 24 14 04
        punpckhdq   mm5,        mm3                         ; 75 65 55 45 35 25 15 05 = q1

        punpckldq   mm0,        mm3                         ; 74 64 54 44 34 24 15 04 = q0
        movq        mm3,        mm5                         ; 75 65 55 45 35 25 15 05 = q1

        psubusb     mm3,        mm6                         ; q1-q2
        psubusb     mm6,        mm5                         ; q2-q1

        por         mm6,        mm3                         ; mm6=abs(q2-q1)
        lea         rdx,        srct

        movq        [rdx+24],   mm5                         ; save q1
        movq        [rdx+16],   mm0                         ; save q0

        movq        mm3,        [rsi+rax*4]                 ; 07 06 05 04 03 02 01 00
        punpcklbw   mm3,        [rdi+rax*4]                 ; 13 03 12 02 11 01 10 00

        movq        mm0,        mm3                         ; 13 03 12 02 11 01 10 00
        punpcklwd   mm0,        mm1                         ; 31 21 11 01 30 20 10 00

        punpckhwd   mm3,        mm1                         ; 33 23 13 03 32 22 12 02
        movq        mm1,        mm0                         ; 31 21 11 01 30 20 10 00

        punpckldq   mm0,        mm2                         ; 70 60 50 40 30 20 10 00  =p3
        punpckhdq   mm1,        mm2                         ; 71 61 51 41 31 21 11 01  =p2

        movq        mm2,        mm1                         ; 71 61 51 41 31 21 11 01  =p2
        psubusb     mm2,        mm0                         ; p2-p3

        psubusb     mm0,        mm1                         ; p3-p2
        por         mm0,        mm2                         ; mm0=abs(p3-p2)

        movq        mm2,        mm3                         ; 33 23 13 03 32 22 12 02
        punpckldq   mm2,        mm4                         ; 72 62 52 42 32 22 12 02 = p1

        punpckhdq   mm3,        mm4                         ; 73 63 53 43 33 23 13 03 = p0
        movq        [rdx+8],    mm3                         ; save p0

        movq        [rdx],      mm2                         ; save p1
        movq        mm5,        mm2                         ; mm5 = p1

        psubusb     mm2,        mm1                         ; p1-p2
        psubusb     mm1,        mm5                         ; p2-p1

        por         mm1,        mm2                         ; mm1=abs(p2-p1)
        mov         rdx,        arg(3) ;limit

        movq        mm4,        [rdx]                       ; mm4 = limit
        psubusb     mm7,        mm4

        psubusb     mm0,        mm4
        psubusb     mm1,        mm4

        psubusb     mm6,        mm4
        por         mm7,        mm6

        por         mm0,        mm1
        por         mm0,        mm7                         ;   abs(q3-q2) > limit || abs(p3-p2) > limit ||abs(p2-p1) > limit || abs(q2-q1) > limit

        movq        mm1,        mm5                         ; p1

        movq        mm7,        mm3                         ; mm3=mm7=p0
        psubusb     mm7,        mm5                         ; p0 - p1

        psubusb     mm5,        mm3                         ; p1 - p0
        por         mm5,        mm7                         ; abs(p1-p0)

        movq        t0,         mm5                         ; save abs(p1-p0)
        lea         rdx,        srct

        psubusb     mm5,        mm4
        por         mm0,        mm5                         ; mm0=mask

        movq        mm5,        [rdx+16]                    ; mm5=q0
        movq        mm7,        [rdx+24]                    ; mm7=q1

        movq        mm6,        mm5                         ; mm6=q0
        movq        mm2,        mm7                         ; q1
        psubusb     mm5,        mm7                         ; q0-q1

        psubusb     mm7,        mm6                         ; q1-q0
        por         mm7,        mm5                         ; abs(q1-q0)

        movq        t1,         mm7                         ; save abs(q1-q0)
        psubusb     mm7,        mm4

        por         mm0,        mm7                         ; mask

        movq        mm5,        mm2                         ; q1
        psubusb     mm5,        mm1                         ; q1-=p1
        psubusb     mm1,        mm2                         ; p1-=q1
        por         mm5,        mm1                         ; abs(p1-q1)
404
        pand        mm5,        [GLOBAL(tfe)]               ; set lsb of each byte to zero
John Koleszar's avatar
John Koleszar committed
405
406
        psrlw       mm5,        1                           ; abs(p1-q1)/2

Johann's avatar
Johann committed
407
        mov         rdx,        arg(2) ;blimit                      ;
John Koleszar's avatar
John Koleszar committed
408

Johann's avatar
Johann committed
409
        movq        mm4,        [rdx]                       ;blimit
John Koleszar's avatar
John Koleszar committed
410
411
412
413
414
415
416
417
418
419
        movq        mm1,        mm3                         ; mm1=mm3=p0

        movq        mm7,        mm6                         ; mm7=mm6=q0
        psubusb     mm1,        mm7                         ; p0-q0

        psubusb     mm7,        mm3                         ; q0-p0
        por         mm1,        mm7                         ; abs(q0-p0)
        paddusb     mm1,        mm1                         ; abs(q0-p0)*2
        paddusb     mm1,        mm5                         ; abs (p0 - q0) *2 + abs(p1-q1)/2

Johann's avatar
Johann committed
420
        psubusb     mm1,        mm4                         ; abs (p0 - q0) *2 + abs(p1-q1)/2  > blimit
John Koleszar's avatar
John Koleszar committed
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
        por         mm1,        mm0;                        ; mask

        pxor        mm0,        mm0
        pcmpeqb     mm1,        mm0

        ; calculate high edge variance
        mov         rdx,        arg(4) ;thresh            ; get thresh
        movq        mm7,        [rdx]
        ;
        movq        mm4,        t0              ; get abs (q1 - q0)
        psubusb     mm4,        mm7

        movq        mm3,        t1              ; get abs (p1 - p0)
        psubusb     mm3,        mm7

        por         mm4,        mm3             ; abs(q1 - q0) > thresh || abs(p1 - p0) > thresh
        pcmpeqb     mm4,        mm0

        pcmpeqb     mm0,        mm0
        pxor        mm4,        mm0



        ; start work on filters
        lea         rdx,        srct

        movq        mm2,        [rdx]           ; p1
        movq        mm7,        [rdx+24]        ; q1

        movq        mm6,        [rdx+8]         ; p0
        movq        mm0,        [rdx+16]        ; q0

453
454
        pxor        mm2,        [GLOBAL(t80)]   ; p1 offset to convert to signed values
        pxor        mm7,        [GLOBAL(t80)]   ; q1 offset to convert to signed values
John Koleszar's avatar
John Koleszar committed
455
456
457
458

        psubsb      mm2,        mm7             ; p1 - q1
        pand        mm2,        mm4             ; high var mask (hvm)(p1 - q1)

459
460
        pxor        mm6,        [GLOBAL(t80)]   ; offset to convert to signed values
        pxor        mm0,        [GLOBAL(t80)]   ; offset to convert to signed values
John Koleszar's avatar
John Koleszar committed
461
462
463
464
465
466
467
468
469
470
471

        movq        mm3,        mm0             ; q0
        psubsb      mm0,        mm6             ; q0 - p0

        paddsb      mm2,        mm0             ; 1 * (q0 - p0) + hvm(p1 - q1)
        paddsb      mm2,        mm0             ; 2 * (q0 - p0) + hvm(p1 - q1)

        paddsb      mm2,        mm0             ; 3 * (q0 - p0) + hvm(p1 - q1)
        pand       mm1,        mm2              ; mask filter values we don't care about

        movq        mm2,        mm1
472
        paddsb      mm1,        [GLOBAL(t4)]      ; 3* (q0 - p0) + hvm(p1 - q1) + 4
John Koleszar's avatar
John Koleszar committed
473

474
        paddsb      mm2,        [GLOBAL(t3)]      ; 3* (q0 - p0) + hvm(p1 - q1) + 3
John Koleszar's avatar
John Koleszar committed
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
        pxor        mm0,        mm0          ;

        pxor        mm5,        mm5
        punpcklbw   mm0,        mm2         ;

        punpckhbw   mm5,        mm2         ;
        psraw       mm0,        11              ;

        psraw       mm5,        11
        packsswb    mm0,        mm5

        movq        mm2,        mm0         ;  (3* (q0 - p0) + hvm(p1 - q1) + 3) >> 3;

        pxor        mm0,        mm0           ; 0
        movq        mm5,        mm1           ; abcdefgh

        punpcklbw   mm0,        mm1           ; e0f0g0h0
        psraw       mm0,        11                ; sign extended shift right by 3

        pxor        mm1,        mm1           ; 0
        punpckhbw   mm1,        mm5           ; a0b0c0d0

        psraw       mm1,        11                ; sign extended shift right by 3
        movq        mm5,        mm0              ; save results

        packsswb    mm0,        mm1           ; (3* (q0 - p0) + hvm(p1 - q1) + 4) >>3
501
        paddsw      mm5,        [GLOBAL(ones)]
John Koleszar's avatar
John Koleszar committed
502

503
        paddsw      mm1,        [GLOBAL(ones)]
John Koleszar's avatar
John Koleszar committed
504
505
506
507
508
509
510
511
        psraw       mm5,        1                 ; partial shifted one more time for 2nd tap

        psraw       mm1,        1                 ; partial shifted one more time for 2nd tap
        packsswb    mm5,        mm1           ; (3* (q0 - p0) + hvm(p1 - q1) + 4) >>4

        pandn       mm4,        mm5             ; high edge variance additive

        paddsb      mm6,        mm2             ; p0+= p0 add
512
        pxor        mm6,        [GLOBAL(t80)]   ; unoffset
John Koleszar's avatar
John Koleszar committed
513
514
515

        ; mm6=p0                               ;
        movq        mm1,        [rdx]           ; p1
516
        pxor        mm1,        [GLOBAL(t80)]   ; reoffset
John Koleszar's avatar
John Koleszar committed
517
518

        paddsb      mm1,        mm4                 ; p1+= p1 add
519
        pxor        mm1,        [GLOBAL(t80)]       ; unoffset
John Koleszar's avatar
John Koleszar committed
520
521
522
        ; mm6 = p0 mm1 = p1

        psubsb      mm3,        mm0                 ; q0-= q0 add
523
        pxor        mm3,        [GLOBAL(t80)]       ; unoffset
John Koleszar's avatar
John Koleszar committed
524
525
526

        ; mm3 = q0
        psubsb      mm7,        mm4                 ; q1-= q1 add
527
        pxor        mm7,        [GLOBAL(t80)]       ; unoffset
John Koleszar's avatar
John Koleszar committed
528
529
        ; mm7 = q1

530
        ; transpose and write back
John Koleszar's avatar
John Koleszar committed
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
        ; mm1 =    72 62 52 42 32 22 12 02
        ; mm6 =    73 63 53 43 33 23 13 03
        ; mm3 =    74 64 54 44 34 24 14 04
        ; mm7 =    75 65 55 45 35 25 15 05

        movq        mm2,        mm1             ; 72 62 52 42 32 22 12 02
        punpcklbw   mm2,        mm6             ; 33 32 23 22 13 12 03 02

        movq        mm4,        mm3             ; 74 64 54 44 34 24 14 04
        punpckhbw   mm1,        mm6             ; 73 72 63 62 53 52 43 42

        punpcklbw   mm4,        mm7             ; 35 34 25 24 15 14 05 04
        punpckhbw   mm3,        mm7             ; 75 74 65 64 55 54 45 44

        movq        mm6,        mm2             ; 33 32 23 22 13 12 03 02
        punpcklwd   mm2,        mm4             ; 15 14 13 12 05 04 03 02

        punpckhwd   mm6,        mm4             ; 35 34 33 32 25 24 23 22
        movq        mm5,        mm1             ; 73 72 63 62 53 52 43 42

        punpcklwd   mm1,        mm3             ; 55 54 53 52 45 44 43 42
        punpckhwd   mm5,        mm3             ; 75 74 73 72 65 64 63 62


        ; mm2 = 15 14 13 12 05 04 03 02
        ; mm6 = 35 34 33 32 25 24 23 22
        ; mm5 = 55 54 53 52 45 44 43 42
        ; mm1 = 75 74 73 72 65 64 63 62



        movd        [rsi+rax*4+2], mm2
        psrlq       mm2,        32

        movd        [rdi+rax*4+2], mm2
        movd        [rsi+rax*2+2], mm6

        psrlq       mm6,        32
        movd        [rsi+rax+2],mm6

        movd        [rsi+2],    mm1
        psrlq       mm1,        32

        movd        [rdi+2],    mm1
        neg         rax

        movd        [rdi+rax+2],mm5
        psrlq       mm5,        32

        movd        [rdi+rax*2+2], mm5

        lea         rsi,        [rsi+rax*8]
        dec         rcx
584
        jnz         .next8_v
John Koleszar's avatar
John Koleszar committed
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600

    add rsp, 64
    pop rsp
    ; begin epilog
    pop rdi
    pop rsi
    RESTORE_GOT
    UNSHADOW_ARGS
    pop         rbp
    ret


;void vp8_mbloop_filter_horizontal_edge_mmx
;(
;    unsigned char *src_ptr,
;    int  src_pixel_step,
Johann's avatar
Johann committed
601
;    const char *blimit,
John Koleszar's avatar
John Koleszar committed
602
603
604
605
;    const char *limit,
;    const char *thresh,
;    int count
;)
606
global sym(vp8_mbloop_filter_horizontal_edge_mmx) PRIVATE
John Koleszar's avatar
John Koleszar committed
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
sym(vp8_mbloop_filter_horizontal_edge_mmx):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 6
    GET_GOT     rbx
    push        rsi
    push        rdi
    ; end prolog

    ALIGN_STACK 16, rax
    sub          rsp, 32      ; reserve 32 bytes
    %define t0   [rsp + 0]    ;__declspec(align(16)) char t0[8];
    %define t1   [rsp + 16]   ;__declspec(align(16)) char t1[8];

        mov         rsi, arg(0) ;src_ptr
        movsxd      rax, dword ptr arg(1) ;src_pixel_step     ; destination pitch?

        movsxd      rcx, dword ptr arg(5) ;count
625
.next8_mbh:
John Koleszar's avatar
John Koleszar committed
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
        mov         rdx, arg(3) ;limit
        movq        mm7, [rdx]
        mov         rdi, rsi              ; rdi points to row +1 for indirect addressing
        add         rdi, rax

        ; calculate breakout conditions
        movq        mm2, [rdi+2*rax]      ; q3

        movq        mm1, [rsi+2*rax]      ; q2
        movq        mm6, mm1              ; q2
        psubusb     mm1, mm2              ; q2-=q3
        psubusb     mm2, mm6              ; q3-=q2
        por         mm1, mm2              ; abs(q3-q2)
        psubusb     mm1, mm7


        ; mm1 = abs(q3-q2), mm6 =q2, mm7 = limit
        movq        mm4, [rsi+rax]        ; q1
        movq        mm3, mm4              ; q1
        psubusb     mm4, mm6              ; q1-=q2
        psubusb     mm6, mm3              ; q2-=q1
        por         mm4, mm6              ; abs(q2-q1)
        psubusb     mm4, mm7
        por        mm1, mm4


        ; mm1 = mask,      mm3=q1, mm7 = limit

        movq        mm4, [rsi]            ; q0
        movq        mm0, mm4              ; q0
        psubusb     mm4, mm3              ; q0-=q1
        psubusb     mm3, mm0              ; q1-=q0
        por         mm4, mm3              ; abs(q0-q1)
        movq        t0, mm4               ; save to t0
        psubusb     mm4, mm7
        por        mm1, mm4


        ; mm1 = mask, mm0=q0,  mm7 = limit, t0 = abs(q0-q1)

        neg         rax                   ; negate pitch to deal with above border

        movq        mm2, [rsi+4*rax]      ; p3
        movq        mm4, [rdi+4*rax]      ; p2
        movq        mm5, mm4              ; p2
        psubusb     mm4, mm2              ; p2-=p3
        psubusb     mm2, mm5              ; p3-=p2
        por         mm4, mm2              ; abs(p3 - p2)
        psubusb     mm4, mm7
        por        mm1, mm4
        ; mm1 = mask, mm0=q0,  mm7 = limit, t0 = abs(q0-q1)

        movq        mm4, [rsi+2*rax]      ; p1
        movq        mm3, mm4              ; p1
        psubusb     mm4, mm5              ; p1-=p2
        psubusb     mm5, mm3              ; p2-=p1
        por         mm4, mm5              ; abs(p2 - p1)
        psubusb     mm4, mm7
        por        mm1, mm4

        movq        mm2, mm3              ; p1


        ; mm1 = mask, mm0=q0,  mm7 = limit, t0 = abs(q0-q1)

        movq        mm4, [rsi+rax]        ; p0
        movq        mm5, mm4              ; p0
        psubusb     mm4, mm3              ; p0-=p1
        psubusb     mm3, mm5              ; p1-=p0
        por         mm4, mm3              ; abs(p1 - p0)
        movq        t1, mm4               ; save to t1
        psubusb     mm4, mm7
        por        mm1, mm4
        ; mm1 = mask, mm0=q0,  mm7 = limit, t0 = abs(q0-q1) t1 = abs(p1-p0)
        ; mm5 = p0
        movq        mm3, [rdi]            ; q1
        movq        mm4, mm3              ; q1
        psubusb     mm3, mm2              ; q1-=p1
        psubusb     mm2, mm4              ; p1-=q1
        por         mm2, mm3              ; abs(p1-q1)
706
        pand        mm2, [GLOBAL(tfe)]    ; set lsb of each byte to zero
John Koleszar's avatar
John Koleszar committed
707
708
709
710
711
712
713
714
715
716
        psrlw       mm2, 1                ; abs(p1-q1)/2

        movq        mm6, mm5              ; p0
        movq        mm3, mm0              ; q0
        psubusb     mm5, mm3              ; p0-=q0
        psubusb     mm3, mm6              ; q0-=p0
        por         mm5, mm3              ; abs(p0 - q0)
        paddusb     mm5, mm5              ; abs(p0-q0)*2
        paddusb     mm5, mm2              ; abs (p0 - q0) *2 + abs(p1-q1)/2

Johann's avatar
Johann committed
717
718
        mov         rdx, arg(2) ;blimit           ; get blimit
        movq        mm7, [rdx]            ; blimit
John Koleszar's avatar
John Koleszar committed
719

Johann's avatar
Johann committed
720
        psubusb     mm5,    mm7           ; abs (p0 - q0) *2 + abs(p1-q1)/2  > blimit
John Koleszar's avatar
John Koleszar committed
721
722
723
724
        por         mm1,    mm5
        pxor        mm5,    mm5
        pcmpeqb     mm1,    mm5           ; mask mm1

Johann's avatar
Johann committed
725
        ; mm1 = mask, mm0=q0,  mm7 = blimit, t0 = abs(q0-q1) t1 = abs(p1-p0)
John Koleszar's avatar
John Koleszar committed
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
        ; mm6 = p0,

        ; calculate high edge variance
        mov         rdx, arg(4) ;thresh           ; get thresh
        movq        mm7, [rdx]            ;
        movq        mm4, t0               ; get abs (q1 - q0)
        psubusb     mm4, mm7
        movq        mm3, t1               ; get abs (p1 - p0)
        psubusb     mm3, mm7
        paddb       mm4, mm3              ; abs(q1 - q0) > thresh || abs(p1 - p0) > thresh

        pcmpeqb     mm4,        mm5

        pcmpeqb     mm5,        mm5
        pxor        mm4,        mm5



        ; mm1 = mask, mm0=q0,  mm7 = thresh, t0 = abs(q0-q1) t1 = abs(p1-p0)
        ; mm6 = p0, mm4=hev
        ; start work on filters
        movq        mm2, [rsi+2*rax]      ; p1
        movq        mm7, [rdi]            ; q1
749
750
        pxor        mm2, [GLOBAL(t80)]    ; p1 offset to convert to signed values
        pxor        mm7, [GLOBAL(t80)]    ; q1 offset to convert to signed values
John Koleszar's avatar
John Koleszar committed
751
752
        psubsb      mm2, mm7              ; p1 - q1

753
754
        pxor        mm6, [GLOBAL(t80)]    ; offset to convert to signed values
        pxor        mm0, [GLOBAL(t80)]    ; offset to convert to signed values
John Koleszar's avatar
John Koleszar committed
755
756
757
758
759
760
761
762
763
764
765
766
767
        movq        mm3, mm0              ; q0
        psubsb      mm0, mm6              ; q0 - p0
        paddsb      mm2, mm0              ; 1 * (q0 - p0) + (p1 - q1)
        paddsb      mm2, mm0              ; 2 * (q0 - p0)
        paddsb      mm2, mm0              ; 3 * (q0 - p0) + (p1 - q1)
        pand        mm1, mm2              ; mask filter values we don't care about


        ; mm1 = vp8_filter, mm4=hev, mm6=ps0, mm3=qs0
        movq        mm2, mm1              ; vp8_filter
        pand        mm2, mm4;             ; Filter2 = vp8_filter & hev

        movq        mm5,        mm2       ;
768
        paddsb      mm5,        [GLOBAL(t3)];
John Koleszar's avatar
John Koleszar committed
769
770
771
772
773
774
775
776
777
778
779
780

        pxor        mm0, mm0              ; 0
        pxor        mm7, mm7              ; 0

        punpcklbw   mm0, mm5              ; e0f0g0h0
        psraw       mm0, 11               ; sign extended shift right by 3
        punpckhbw   mm7, mm5              ; a0b0c0d0
        psraw       mm7, 11               ; sign extended shift right by 3
        packsswb    mm0, mm7              ; Filter2 >>=3;

        movq        mm5, mm0              ; Filter2

781
        paddsb      mm2, [GLOBAL(t4)]     ; vp8_signed_char_clamp(Filter2 + 4)
John Koleszar's avatar
John Koleszar committed
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
        pxor        mm0, mm0              ; 0
        pxor        mm7, mm7              ; 0

        punpcklbw   mm0, mm2              ; e0f0g0h0
        psraw       mm0, 11               ; sign extended shift right by 3
        punpckhbw   mm7, mm2              ; a0b0c0d0
        psraw       mm7, 11               ; sign extended shift right by 3
        packsswb    mm0, mm7              ; Filter2 >>=3;

        ; mm0= filter2 mm1 = vp8_filter,  mm3 =qs0 mm5=s mm4 =hev mm6=ps0
        psubsb      mm3, mm0              ; qs0 =qs0 - filter1
        paddsb      mm6, mm5              ; ps0 =ps0 + Fitler2

        ; mm1=vp8_filter, mm3=qs0, mm4 =hev mm6=ps0
        ; vp8_filter &= ~hev;
        ; Filter2 = vp8_filter;
        pandn       mm4, mm1              ; vp8_filter&=~hev


        ; mm3=qs0, mm4=filter2, mm6=ps0

        ; u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7);
        ; s = vp8_signed_char_clamp(qs0 - u);
        ; *oq0 = s^0x80;
        ; s = vp8_signed_char_clamp(ps0 + u);
        ; *op0 = s^0x80;
        pxor        mm0, mm0

        pxor        mm1, mm1
        pxor        mm2, mm2
        punpcklbw   mm1, mm4
        punpckhbw   mm2, mm4
814
815
816
817
        pmulhw      mm1, [GLOBAL(s27)]
        pmulhw      mm2, [GLOBAL(s27)]
        paddw       mm1, [GLOBAL(s63)]
        paddw       mm2, [GLOBAL(s63)]
John Koleszar's avatar
John Koleszar committed
818
819
820
821
822
823
824
        psraw       mm1, 7
        psraw       mm2, 7
        packsswb    mm1, mm2

        psubsb      mm3, mm1
        paddsb      mm6, mm1

825
826
        pxor        mm3, [GLOBAL(t80)]
        pxor        mm6, [GLOBAL(t80)]
John Koleszar's avatar
John Koleszar committed
827
828
829
830
831
832
833
834
835
836
837
838
839
        movq        [rsi+rax], mm6
        movq        [rsi],     mm3

        ; roughly 2/7th difference across boundary
        ; u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7);
        ; s = vp8_signed_char_clamp(qs1 - u);
        ; *oq1 = s^0x80;
        ; s = vp8_signed_char_clamp(ps1 + u);
        ; *op1 = s^0x80;
        pxor        mm1, mm1
        pxor        mm2, mm2
        punpcklbw   mm1, mm4
        punpckhbw   mm2, mm4
840
841
842
843
        pmulhw      mm1, [GLOBAL(s18)]
        pmulhw      mm2, [GLOBAL(s18)]
        paddw       mm1, [GLOBAL(s63)]
        paddw       mm2, [GLOBAL(s63)]
John Koleszar's avatar
John Koleszar committed
844
845
846
847
848
849
850
        psraw       mm1, 7
        psraw       mm2, 7
        packsswb    mm1, mm2

        movq        mm3, [rdi]
        movq        mm6, [rsi+rax*2]       ; p1

851
852
        pxor        mm3, [GLOBAL(t80)]
        pxor        mm6, [GLOBAL(t80)]
John Koleszar's avatar
John Koleszar committed
853
854
855
856

        paddsb      mm6, mm1
        psubsb      mm3, mm1

857
858
        pxor        mm6, [GLOBAL(t80)]
        pxor        mm3, [GLOBAL(t80)]
John Koleszar's avatar
John Koleszar committed
859
860
861
862
863
864
865
866
867
868
869
870
871
        movq        [rdi], mm3
        movq        [rsi+rax*2], mm6

        ; roughly 1/7th difference across boundary
        ; u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7);
        ; s = vp8_signed_char_clamp(qs2 - u);
        ; *oq2 = s^0x80;
        ; s = vp8_signed_char_clamp(ps2 + u);
        ; *op2 = s^0x80;
        pxor        mm1, mm1
        pxor        mm2, mm2
        punpcklbw   mm1, mm4
        punpckhbw   mm2, mm4
872
873
874
875
        pmulhw      mm1, [GLOBAL(s9)]
        pmulhw      mm2, [GLOBAL(s9)]
        paddw       mm1, [GLOBAL(s63)]
        paddw       mm2, [GLOBAL(s63)]
John Koleszar's avatar
John Koleszar committed
876
877
878
879
880
881
882
883
884
        psraw       mm1, 7
        psraw       mm2, 7
        packsswb    mm1, mm2


        movq        mm6, [rdi+rax*4]
        neg         rax
        movq        mm3, [rdi+rax  ]

885
886
        pxor        mm6, [GLOBAL(t80)]
        pxor        mm3, [GLOBAL(t80)]
John Koleszar's avatar
John Koleszar committed
887
888
889
890

        paddsb      mm6, mm1
        psubsb      mm3, mm1

891
892
        pxor        mm6, [GLOBAL(t80)]
        pxor        mm3, [GLOBAL(t80)]
John Koleszar's avatar
John Koleszar committed
893
894
895
896
897
898
899
900
        movq        [rdi+rax  ], mm3
        neg         rax
        movq        [rdi+rax*4], mm6

;EARLY_BREAK_OUT:
        neg         rax
        add         rsi,8
        dec         rcx
901
        jnz         .next8_mbh
John Koleszar's avatar
John Koleszar committed
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917

    add rsp, 32
    pop rsp
    ; begin epilog
    pop rdi
    pop rsi
    RESTORE_GOT
    UNSHADOW_ARGS
    pop         rbp
    ret


;void vp8_mbloop_filter_vertical_edge_mmx
;(
;    unsigned char *src_ptr,
;    int  src_pixel_step,
Johann's avatar
Johann committed
918
;    const char *blimit,
John Koleszar's avatar
John Koleszar committed
919
920
921
922
;    const char *limit,
;    const char *thresh,
;    int count
;)
923
global sym(vp8_mbloop_filter_vertical_edge_mmx) PRIVATE
John Koleszar's avatar
John Koleszar committed
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
sym(vp8_mbloop_filter_vertical_edge_mmx):
    push        rbp
    mov         rbp, rsp
    SHADOW_ARGS_TO_STACK 6
    GET_GOT     rbx
    push        rsi
    push        rdi
    ; end prolog

    ALIGN_STACK 16, rax
    sub          rsp, 96      ; reserve 96 bytes
    %define t0   [rsp + 0]    ;__declspec(align(16)) char t0[8];
    %define t1   [rsp + 16]   ;__declspec(align(16)) char t1[8];
    %define srct [rsp + 32]   ;__declspec(align(16)) char srct[64];

        mov         rsi,        arg(0) ;src_ptr
        movsxd      rax,        dword ptr arg(1) ;src_pixel_step     ; destination pitch?

        lea         rsi,        [rsi + rax*4 - 4]

        movsxd      rcx,        dword ptr arg(5) ;count
945
.next8_mbv:
John Koleszar's avatar
John Koleszar committed
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
        lea         rdi,        [rsi + rax]  ; rdi points to row +1 for indirect addressing

        ;transpose
        movq        mm0,        [rdi+2*rax]                 ; 77 76 75 74 73 72 71 70
        movq        mm6,        [rsi+2*rax]                 ; 67 66 65 64 63 62 61 60

        movq        mm7,        mm6                         ; 77 76 75 74 73 72 71 70
        punpckhbw   mm7,        mm0                         ; 77 67 76 66 75 65 74 64

        punpcklbw   mm6,        mm0                         ; 73 63 72 62 71 61 70 60
        movq        mm0,        [rsi+rax]                   ; 57 56 55 54 53 52 51 50

        movq        mm4,        [rsi]                       ; 47 46 45 44 43 42 41 40
        movq        mm5,        mm4                         ; 47 46 45 44 43 42 41 40

        punpckhbw   mm5,        mm0                         ; 57 47 56 46 55 45 54 44
        punpcklbw   mm4,        mm0                         ; 53 43 52 42 51 41 50 40

        movq        mm3,        mm5                         ; 57 47 56 46 55 45 54 44
        punpckhwd   mm5,        mm7                         ; 77 67 57 47 76 66 56 46

        punpcklwd   mm3,        mm7                         ; 75 65 55 45 74 64 54 44
        movq        mm2,        mm4                         ; 53 43 52 42 51 41 50 40

        punpckhwd   mm4,        mm6                         ; 73 63 53 43 72 62 52 42
        punpcklwd   mm2,        mm6                         ; 71 61 51 41 70 60 50 40

        neg         rax

        movq        mm7,        [rsi+rax]                   ; 37 36 35 34 33 32 31 30
        movq        mm6,        [rsi+rax*2]                 ; 27 26 25 24 23 22 21 20

        movq        mm1,        mm6                         ; 27 26 25 24 23 22 21 20
        punpckhbw   mm6,        mm7                         ; 37 27 36 36 35 25 34 24

        punpcklbw   mm1,        mm7                         ; 33 23 32 22 31 21 30 20

        movq        mm7,        [rsi+rax*4];                ; 07 06 05 04 03 02 01 00
        punpckhbw   mm7,        [rdi+rax*4]                 ; 17 07 16 06 15 05 14 04

        movq        mm0,        mm7                         ; 17 07 16 06 15 05 14 04
        punpckhwd   mm7,        mm6                         ; 37 27 17 07 36 26 16 06

        punpcklwd   mm0,        mm6                         ; 35 25 15 05 34 24 14 04
        movq        mm6,        mm7                         ; 37 27 17 07 36 26 16 06

        punpckhdq   mm7,        mm5                         ; 77 67 57 47 37 27 17 07  = q3
        punpckldq   mm6,        mm5                         ; 76 66 56 46 36 26 16 06  = q2

        lea         rdx,        srct
        movq        mm5,        mm6                         ; 76 66 56 46 36 26 16 06

        movq        [rdx+56],   mm7
        psubusb     mm5,        mm7                         ; q2-q3

For faster browsing, not all history is shown. View entire blame