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
|
/*
* Copyright (c) 2024 Zhao Zhili <quinkblack@foxmail.com>
*
* 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
*/
#include "libavutil/aarch64/asm.S"
.macro alf_luma_filter_pixel index, pix_size, addr1, addr2, offset1, offset2
.if \pix_size == 1
ldur d3, [\addr1, #\offset1]
ldur d4, [\addr2, #\offset2]
uxtl v6.8h, v3.8b
uxtl v7.8h, v4.8b
.else
ldur q6, [\addr1, #(2*\offset1)]
ldur q7, [\addr2, #(2*\offset2)]
.endif
.if \index < 8
dup v17.4h, v0.h[\index] // clip
dup v18.4h, v16.h[\index] // -clip
dup v19.4h, v1.h[\index] // filter
dup v26.4h, v22.h[\index] // clip
dup v27.4h, v23.h[\index] // -clip
dup v28.4h, v24.h[\index] // filter
.else
dup v17.4h, v0.h[\index - 8] // clip
dup v18.4h, v16.h[\index - 8] // -clip
dup v19.4h, v1.h[\index - 8] // filter
dup v26.4h, v22.h[\index - 8] // clip
dup v27.4h, v23.h[\index - 8] // -clip
dup v28.4h, v24.h[\index - 8] // filter
.endif
ins v17.d[1], v26.d[0]
ins v18.d[1], v27.d[0]
ins v19.d[1], v28.d[0]
sub v6.8h, v6.8h, v5.8h
sub v7.8h, v7.8h, v5.8h
smin v6.8h, v6.8h, v17.8h
smin v7.8h, v7.8h, v17.8h
smax v6.8h, v6.8h, v18.8h
smax v7.8h, v7.8h, v18.8h
add v6.8h, v6.8h, v7.8h
smlal v20.4s, v19.4h, v6.4h // v20: sum
smlal2 v21.4s, v19.8h, v6.8h // v21: sum
.endm
/* x0: dst
* x1: pp
* x2: filter
* x3: clip
* w4: is_near_vb
* w5: pix_max
*/
.macro alf_filter_luma_kernel, pix_size
dst .req x0
pp .req x1
filter .req x2
clip .req x3
is_near_vb .req w4
pix_max .req w5
.if \pix_size > 1
dup v25.8h, pix_max // pix_max
.endif
ldr q0, [clip] // clip
ldr q1, [filter] // filter
ldur q22, [clip, #24] // clip
ldur q24, [filter, #24] // filter
ldr x5, [pp] // x5: p0
ldr x6, [pp, #(5*8)] // x6: p5
ldr x7, [pp, #(6*8)] // x7: p6
neg v16.8h, v0.8h // -clip
neg v23.8h, v22.8h // -clip
.if \pix_size == 1
ldr d2, [x5] // curr
.else
ldr q5, [x5] // curr
.endif
movi v20.4s, #64
cbz is_near_vb, 1f
shl v20.4s, v20.4s, #3
1:
.if \pix_size == 1
uxtl v5.8h, v2.8b
.endif
mov v21.16b, v20.16b
ldr x8, [pp, #(3*8)] // p3
ldr x9, [pp, #(4*8)] // p4
alf_luma_filter_pixel 0, \pix_size, x6, x7, 0, 0
ldr x6, [pp, #(1*8)] // p1
ldr x7, [pp, #(2*8)] // p2
alf_luma_filter_pixel 1, \pix_size, x8, x9, 1, -1
alf_luma_filter_pixel 2, \pix_size, x8, x9, 0, 0
alf_luma_filter_pixel 3, \pix_size, x8, x9, -1, 1
alf_luma_filter_pixel 4, \pix_size, x6, x7, 2, -2
alf_luma_filter_pixel 5, \pix_size, x6, x7, 1, -1
alf_luma_filter_pixel 6, \pix_size, x6, x7, 0, 0
alf_luma_filter_pixel 7, \pix_size, x6, x7, -1, 1
ldr d0, [clip, #16] // clip
ldr d1, [filter, #16] // filter
neg v16.4h, v0.4h // -clip
ldr d22, [clip, #40] // clip
ldr d24, [filter, #40] // filter
neg v23.4h, v22.4h // -clip
alf_luma_filter_pixel 8, \pix_size, x6, x7, -2, 2
alf_luma_filter_pixel 9, \pix_size, x5, x5, 3, -3
alf_luma_filter_pixel 10, \pix_size, x5, x5, 2, -2
alf_luma_filter_pixel 11, \pix_size, x5, x5, 1, -1
cbz is_near_vb, 2f
sshr v20.4s, v20.4s, #10
sshr v21.4s, v21.4s, #10
b 3f
2:
sshr v20.4s, v20.4s, #7
sshr v21.4s, v21.4s, #7
3:
uxtl v22.4s, v5.4h
uxtl2 v23.4s, v5.8h
add v20.4s, v20.4s, v22.4s
add v21.4s, v21.4s, v23.4s
sqxtun v20.4h, v20.4s
sqxtun2 v20.8h, v21.4s
.if \pix_size == 1
sqxtun v20.8b, v20.8h
str d20, [dst]
.else
smin v20.8h, v20.8h, v25.8h
str q20, [dst]
.endif
ret
.unreq dst
.unreq pp
.unreq filter
.unreq clip
.unreq is_near_vb
.unreq pix_max
.endm
.macro alf_chroma_filter_pixel index, pix_size, addr1, addr2, offset1, offset2
.if \pix_size == 1
ldur s3, [\addr1, #\offset1]
ldur s4, [\addr2, #\offset2]
uxtl v6.8h, v3.8b
uxtl v7.8h, v4.8b
.else
ldur d6, [\addr1, #(2*\offset1)]
ldur d7, [\addr2, #(2*\offset2)]
.endif
.if \index < 8
dup v17.4h, v0.h[\index] // v17: clip[0]
dup v18.4h, v16.h[\index] // v18: -clip[0]
dup v19.4h, v1.h[\index] // v19: filter[0]
.else
dup v17.4h, v0.h[\index - 8] // v17: clip[0]
dup v18.4h, v16.h[\index - 8] // v18: -clip[0]
dup v19.4h, v1.h[\index - 8] // v19: filter[0]
.endif
sub v6.4h, v6.4h, v5.4h
sub v7.4h, v7.4h, v5.4h
smin v6.4h, v6.4h, v17.4h
smin v7.4h, v7.4h, v17.4h
smax v6.4h, v6.4h, v18.4h
smax v7.4h, v7.4h, v18.4h
add v6.4h, v6.4h, v7.4h
smlal v20.4s, v19.4h, v6.4h // v20: sum
.endm
/* x0: dst
* x1: pp
* x2: filter
* x3: clip
* w4: is_near_vb
* w5: pix_max
*/
.macro alf_filter_chroma_kernel, pix_size
dst .req x0
pp .req x1
filter .req x2
clip .req x3
is_near_vb .req w4
pix_max .req w5
.if \pix_size > 1
dup v25.4h, pix_max // pix_max
.endif
ldr q0, [clip] // clip
ldr q1, [filter] // filter
ldr x5, [pp] // p0
ldr x6, [pp, #(3*8)] // p3
ldr x7, [pp, #(4*8)] // p4
neg v16.8h, v0.8h // -clip
.if \pix_size == 1
ldr s2, [x5] // curr
.else
ldr d5, [x5] // curr
.endif
movi v20.4s, #64
cbz is_near_vb, 1f
shl v20.4s, v20.4s, #3
1:
.if \pix_size == 1
uxtl v5.8h, v2.8b
.endif
ldr x8, [pp, #(1*8)] // p1
ldr x9, [pp, #(2*8)] // p2
alf_chroma_filter_pixel 0, \pix_size, x6, x7, 0, 0
alf_chroma_filter_pixel 1, \pix_size, x8, x9, 1, -1
alf_chroma_filter_pixel 2, \pix_size, x8, x9, 0, 0
alf_chroma_filter_pixel 3, \pix_size, x8, x9, -1, 1
alf_chroma_filter_pixel 4, \pix_size, x5, x5, 2, -2
alf_chroma_filter_pixel 5, \pix_size, x5, x5, 1, -1
uxtl v22.4s, v5.4h
cbz is_near_vb, 2f
sshr v20.4s, v20.4s, #10
b 3f
2:
sshr v20.4s, v20.4s, #7
3:
add v20.4s, v20.4s, v22.4s
sqxtun v20.4h, v20.4s
.if \pix_size == 1
sqxtun v20.8b, v20.8h
str s20, [dst]
.else
smin v20.4h, v20.4h, v25.4h
str d20, [dst]
.endif
ret
.unreq dst
.unreq pp
.unreq filter
.unreq clip
.unreq is_near_vb
.unreq pix_max
.endm
function ff_alf_filter_luma_kernel_8_neon, export=1
alf_filter_luma_kernel 1
endfunc
function ff_alf_filter_luma_kernel_12_neon, export=1
mov w5, #4095
b 1f
endfunc
function ff_alf_filter_luma_kernel_10_neon, export=1
mov w5, #1023
1:
alf_filter_luma_kernel 2
endfunc
function ff_alf_filter_chroma_kernel_8_neon, export=1
alf_filter_chroma_kernel 1
endfunc
function ff_alf_filter_chroma_kernel_12_neon, export=1
mov w5, #4095
b 1f
endfunc
function ff_alf_filter_chroma_kernel_10_neon, export=1
mov w5, #1023
1:
alf_filter_chroma_kernel 2
endfunc
|