aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/x86/vf_atadenoise.asm
blob: 5466d1f2d45dacbbd984b270e3970c545aee5eb8 (plain) (blame)
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
;*****************************************************************************
;* x86-optimized functions for blend filter
;*
;* Copyright (C) 2019 Paul B Mahol
;*
;* This file is part of FFmpeg.
;*
;* FFmpeg is free software; you can redistribute it and/or
;* modify it under the terms of the GNU Lesser General Public
;* License as published by the Free Software Foundation; either
;* version 2.1 of the License, or (at your option) any later version.
;*
;* FFmpeg is distributed in the hope that it will be useful,
;* but WITHOUT ANY WARRANTY; without even the implied warranty of
;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;* Lesser General Public License for more details.
;*
;* You should have received a copy of the GNU Lesser General Public
;* License along with FFmpeg; if not, write to the Free Software
;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;******************************************************************************

%if ARCH_X86_64

%include "libavutil/x86/x86util.asm"

SECTION_RODATA
pw_one:  times 8 dw 1
pw_ones: times 8 dw 65535

SECTION .text

;------------------------------------------------------------------------------
; void ff_filter_row(const uint8_t *src, uint8_t *dst,
;                    const uint8_t **srcf,
;                    int w, int mid, int size,
;                    int thra, int thrb)
;------------------------------------------------------------------------------

INIT_XMM sse4
cglobal atadenoise_filter_row8, 8,10,13, src, dst, srcf, w, mid, size, i, j, srcfx, x
    movsxdifnidn    wq, wd
    movsxdifnidn  midq, midd
    movsxdifnidn sizeq, sized
    add           srcq, wq
    add           dstq, wq
    mov             xq, wq
    dec          sizeq
    neg             xq
    movd            m4, r6m
    SPLATW          m4, m4
    movd            m5, r7m
    SPLATW          m5, m5
    pxor            m2, m2
    mova           m10, [pw_ones]

    .loop:
        mov         iq, midq
        mov         jq, midq
        pxor        m3, m3
        pxor       m11, m11
        movu        m0, [srcq + xq]
        punpcklbw   m0, m2
        mova        m7, m0
        mova        m8, [pw_one]
        mova       m12, [pw_ones]

        .loop0:
            inc              iq
            dec              jq

            mov          srcfxq, [srcfq + jq * 8]
            add          srcfxq, wq

            movu             m1, [srcfxq + xq]
            punpcklbw        m1, m2
            mova             m9, m1
            psubw            m1, m0
            pabsw            m1, m1
            paddw           m11, m1
            pcmpgtw          m1, m4
            mova             m6, m11
            pcmpgtw          m6, m5
            por              m6, m1
            pxor             m6, m10
            pand            m12, m6
            pand             m9, m12
            paddw            m7, m9
            mova             m6, m12
            psrlw            m6, 15
            paddw            m8, m6

            mov          srcfxq, [srcfq + iq * 8]
            add          srcfxq, wq

            movu             m1, [srcfxq + xq]
            punpcklbw        m1, m2
            mova             m9, m1
            psubw            m1, m0
            pabsw            m1, m1
            paddw            m3, m1
            pcmpgtw          m1, m4
            mova             m6, m3
            pcmpgtw          m6, m5
            por              m6, m1
            pxor             m6, m10
            pand            m12, m6
            pand             m9, m12
            paddw            m7, m9
            mova             m6, m12
            psrlw            m6, 15
            paddw            m8, m6

            ptest           m12, m12
            jz .finish

            cmp              iq, sizeq
            jl .loop0

    .finish:
        mova                 m9, m8
        psrlw                m9, 1
        paddw                m7, m9

        mova                 m1, m7
        mova                 m6, m8

        punpcklwd            m7, m2
        punpcklwd            m8, m2
        cvtdq2ps             m7, m7
        cvtdq2ps             m8, m8
        divps                m7, m8
        cvttps2dq            m7, m7
        packssdw             m7, m7
        packuswb             m7, m7

        movd        [dstq + xq], m7

        punpckhwd            m1, m2
        punpckhwd            m6, m2
        cvtdq2ps             m1, m1
        cvtdq2ps             m6, m6
        divps                m1, m6
        cvttps2dq            m1, m1
        packssdw             m1, m1
        packuswb             m1, m1

        movd    [dstq + xq + 4], m1

        add                  xq, mmsize/2
    jl .loop
    RET

INIT_XMM sse4
cglobal atadenoise_filter_row8_serial, 8,10,13, src, dst, srcf, w, mid, size, i, j, srcfx, x
    movsxdifnidn    wq, wd
    movsxdifnidn  midq, midd
    movsxdifnidn sizeq, sized
    add           srcq, wq
    add           dstq, wq
    mov             xq, wq
    dec          sizeq
    neg             xq
    movd            m4, r6m
    SPLATW          m4, m4
    movd            m5, r7m
    SPLATW          m5, m5
    pxor            m2, m2
    mova           m10, [pw_ones]

    .loop:
        mov         iq, midq
        mov         jq, midq
        pxor        m3, m3
        pxor       m11, m11
        movu        m0, [srcq + xq]
        punpcklbw   m0, m2
        mova        m7, m0
        mova        m8, [pw_one]
        mova       m12, [pw_ones]

        .loop0:
            dec              jq

            mov          srcfxq, [srcfq + jq * 8]
            add          srcfxq, wq

            movu             m1, [srcfxq + xq]
            punpcklbw        m1, m2
            mova             m9, m1
            psubw            m1, m0
            pabsw            m1, m1
            paddw           m11, m1
            pcmpgtw          m1, m4
            mova             m6, m11
            pcmpgtw          m6, m5
            por              m6, m1
            pxor             m6, m10
            pand            m12, m6
            pand             m9, m12
            paddw            m7, m9
            mova             m6, m12
            psrlw            m6, 15
            paddw            m8, m6

            ptest           m12, m12
            jz .end_loop0

            cmp              jq, 0
            jg .loop0

        .end_loop0:
            mova       m12, [pw_ones]

        .loop1:
            inc              iq

            mov          srcfxq, [srcfq + iq * 8]
            add          srcfxq, wq

            movu             m1, [srcfxq + xq]
            punpcklbw        m1, m2
            mova             m9, m1
            psubw            m1, m0
            pabsw            m1, m1
            paddw            m3, m1
            pcmpgtw          m1, m4
            mova             m6, m3
            pcmpgtw          m6, m5
            por              m6, m1
            pxor             m6, m10
            pand            m12, m6
            pand             m9, m12
            paddw            m7, m9
            mova             m6, m12
            psrlw            m6, 15
            paddw            m8, m6

            ptest           m12, m12
            jz .finish

            cmp              iq, sizeq
            jl .loop1

    .finish:
        mova                 m9, m8
        psrlw                m9, 1
        paddw                m7, m9

        mova                 m1, m7
        mova                 m6, m8

        punpcklwd            m7, m2
        punpcklwd            m8, m2
        cvtdq2ps             m7, m7
        cvtdq2ps             m8, m8
        divps                m7, m8
        cvttps2dq            m7, m7
        packssdw             m7, m7
        packuswb             m7, m7

        movd        [dstq + xq], m7

        punpckhwd            m1, m2
        punpckhwd            m6, m2
        cvtdq2ps             m1, m1
        cvtdq2ps             m6, m6
        divps                m1, m6
        cvttps2dq            m1, m1
        packssdw             m1, m1
        packuswb             m1, m1

        movd    [dstq + xq + 4], m1

        add                  xq, mmsize/2
    jl .loop
    RET

%endif