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
|
/*
* Copyright (c) 2024 Institue of Software Chinese Academy of Sciences (ISCAS).
*
* 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/riscv/asm.S"
.macro vsetvlstatic8 w, vlen
.if \w == 2 && \vlen == 128
vsetivli zero, \w, e8, mf8, ta, ma
.elseif \w == 4 && \vlen == 128
vsetivli zero, \w, e8, mf4, ta, ma
.elseif \w == 8 && \vlen == 128
vsetivli zero, \w, e8, mf2, ta, ma
.elseif \w == 16 && \vlen == 128
vsetivli zero, \w, e8, m1, ta, ma
.elseif \w == 32 && \vlen == 128
li t0, \w
vsetvli zero, t0, e8, m2, ta, ma
.elseif \w <= 4 && \vlen == 256
vsetivli zero, \w, e8, mf8, ta, ma
.elseif \w == 8 && \vlen == 256
vsetivli zero, \w, e8, mf4, ta, ma
.elseif \w == 16 && \vlen == 256
vsetivli zero, \w, e8, mf2, ta, ma
.elseif \w == 32 && \vlen == 256
li t0, \w
vsetvli zero, t0, e8, m1, ta, ma
.elseif \w == 64 && \vlen == 256
li t0, \w
vsetvli zero, t0, e8, m2, ta, ma
.else
li t0, \w
vsetvli zero, t0, e8, m4, ta, ma
.endif
.endm
.macro vsetvlstatic16 w, vlen
.if \w == 2 && \vlen == 128
vsetivli zero, \w, e16, mf4, ta, ma
.elseif \w == 4 && \vlen == 128
vsetivli zero, \w, e16, mf2, ta, ma
.elseif \w == 8 && \vlen == 128
vsetivli zero, \w, e16, m1, ta, ma
.elseif \w == 16 && \vlen == 128
vsetivli zero, \w, e16, m2, ta, ma
.elseif \w == 32 && \vlen == 128
li t0, \w
vsetvli zero, t0, e16, m4, ta, ma
.elseif \w <= 4 && \vlen == 256
vsetivli zero, \w, e16, mf4, ta, ma
.elseif \w == 8 && \vlen == 256
vsetivli zero, \w, e16, mf2, ta, ma
.elseif \w == 16 && \vlen == 256
vsetivli zero, \w, e16, m1, ta, ma
.elseif \w == 32 && \vlen == 256
li t0, \w
vsetvli zero, t0, e16, m2, ta, ma
.elseif \w == 64 && \vlen == 256
li t0, \w
vsetvli zero, t0, e16, m4, ta, ma
.else
li t0, \w
vsetvli zero, t0, e16, m8, ta, ma
.endif
.endm
.macro vsetvlstatic32 w, vlen
.if \w == 2
vsetivli zero, \w, e32, mf2, ta, ma
.elseif \w == 4 && \vlen == 128
vsetivli zero, \w, e32, m1, ta, ma
.elseif \w == 8 && \vlen == 128
vsetivli zero, \w, e32, m2, ta, ma
.elseif \w == 16 && \vlen == 128
vsetivli zero, \w, e32, m4, ta, ma
.elseif \w == 4 && \vlen == 256
vsetivli zero, \w, e32, mf2, ta, ma
.elseif \w == 8 && \vlen == 256
vsetivli zero, \w, e32, m1, ta, ma
.elseif \w == 16 && \vlen == 256
vsetivli zero, \w, e32, m2, ta, ma
.elseif \w == 32 && \vlen == 256
li t0, \w
vsetvli zero, t0, e32, m4, ta, ma
.else
li t0, \w
vsetvli zero, t0, e32, m8, ta, ma
.endif
.endm
.macro avg w, vlen, id
\id\w\vlen:
.if \w < 128
vsetvlstatic16 \w, \vlen
addi t0, a2, 128*2
addi t1, a3, 128*2
add t2, a0, a1
vle16.v v0, (a2)
vle16.v v8, (a3)
addi a5, a5, -2
vle16.v v16, (t0)
vle16.v v24, (t1)
vadd.vv v8, v8, v0
vadd.vv v24, v24, v16
vmax.vx v8, v8, zero
vmax.vx v24, v24, zero
vsetvlstatic8 \w, \vlen
addi a2, a2, 128*4
vnclipu.wi v8, v8, 7
vnclipu.wi v24, v24, 7
addi a3, a3, 128*4
vse8.v v8, (a0)
vse8.v v24, (t2)
sh1add a0, a1, a0
.else
addi a5, a5, -1
mv t1, a0
mv t2, a2
mv t3, a3
mv t4, a4
1:
vsetvli t0, a4, e16, m8, ta, ma
sub a4, a4, t0
vle16.v v0, (a2)
vle16.v v8, (a3)
vadd.vv v8, v8, v0
vmax.vx v8, v8, zero
vsetvli zero, zero, e8, m4, ta, ma
vnclipu.wi v8, v8, 7
vse8.v v8, (a0)
sh1add a2, t0, a2
sh1add a3, t0, a3
add a0, a0, t0
bnez a4, 1b
add a0, t1, a1
addi a2, t2, 128*2
addi a3, t3, 128*2
mv a4, t4
.endif
bnez a5, \id\w\vlen\()b
ret
.endm
.macro AVG_JMP_TABLE id, vlen
const jmp_table_\id\vlen
.4byte \id\()2\vlen\()f - jmp_table_\id\vlen
.4byte \id\()4\vlen\()f - jmp_table_\id\vlen
.4byte \id\()8\vlen\()f - jmp_table_\id\vlen
.4byte \id\()16\vlen\()f - jmp_table_\id\vlen
.4byte \id\()32\vlen\()f - jmp_table_\id\vlen
.4byte \id\()64\vlen\()f - jmp_table_\id\vlen
.4byte \id\()128\vlen\()f - jmp_table_\id\vlen
endconst
.endm
.macro AVG_J vlen, id
clz t1, a4
neg t1, t1
lla t5, jmp_table_\id\vlen
sh2add t1, t1, t5
lw t1, ((__riscv_xlen-2)<<2)(t1)
add t1, t1, t5
jr t1
.endm
.macro func_avg vlen
func ff_vvc_avg_8_rvv_\vlen\(), zve32x, zbb, zba
lpad 0
AVG_JMP_TABLE 1, \vlen
csrwi vxrm, 0
AVG_J \vlen, 1
.irp w,2,4,8,16,32,64,128
avg \w, \vlen, 1
.endr
endfunc
.endm
func_avg 128
func_avg 256
#if (__riscv_xlen == 64)
.macro w_avg w, vlen, id
\id\w\vlen:
.if \w <= 32 || (\w == 64 && \vlen == 256)
vsetvlstatic16 \w, \vlen
addi t0, a2, 128*2
addi t1, a3, 128*2
vle16.v v0, (a2)
vle16.v v4, (a3)
addi a5, a5, -2
vle16.v v8, (t0)
vle16.v v12, (t1)
vwmul.vx v16, v0, a7
vwmul.vx v24, v8, a7
vwmacc.vx v16, t3, v4
vwmacc.vx v24, t3, v12
vsetvlstatic32 \w, \vlen
add t2, a0, a1
vadd.vx v16, v16, t4
vadd.vx v24, v24, t4
vsetvlstatic16 \w, \vlen
vnsrl.wx v16, v16, t6
vnsrl.wx v24, v24, t6
vmax.vx v16, v16, zero
vmax.vx v24, v24, zero
vsetvlstatic8 \w, \vlen
addi a2, a2, 128*4
vnclipu.wi v16, v16, 0
vnclipu.wi v24, v24, 0
vse8.v v16, (a0)
addi a3, a3, 128*4
vse8.v v24, (t2)
sh1add a0, a1, a0
.else
addi a5, a5, -1
mv t1, a0
mv t2, a2
mv t5, a3
mv a6, a4
1:
vsetvli t0, a4, e16, m4, ta, ma
sub a4, a4, t0
vle16.v v0, (a2)
vle16.v v4, (a3)
vwmul.vx v16, v0, a7
vwmacc.vx v16, t3, v4
vsetvli zero, zero, e32, m8, ta, ma
vadd.vx v16, v16, t4
vsetvli zero, zero, e16, m4, ta, ma
vnsrl.wx v16, v16, t6
vmax.vx v16, v16, zero
vsetvli zero, zero, e8, m2, ta, ma
vnclipu.wi v16, v16, 0
vse8.v v16, (a0)
sh1add a2, t0, a2
sh1add a3, t0, a3
add a0, a0, t0
bnez a4, 1b
add a0, t1, a1
addi a2, t2, 128*2
addi a3, t5, 128*2
mv a4, a6
.endif
bnez a5, \id\w\vlen\()b
ret
.endm
.macro func_w_avg vlen
func ff_vvc_w_avg_8_rvv_\vlen\(), zve32x, zbb, zba
lpad 0
AVG_JMP_TABLE 2, \vlen
csrwi vxrm, 0
addi t6, a6, 7
ld t3, (sp)
ld t4, 8(sp)
ld t5, 16(sp)
addi t4, t4, 1 // o0 + o1 + 1
add t4, t4, t5
addi t5, t6, -1 // shift - 1
sll t4, t4, t5
AVG_J \vlen, 2
.irp w,2,4,8,16,32,64,128
w_avg \w, \vlen, 2
.endr
endfunc
.endm
func_w_avg 128
func_w_avg 256
#endif
|