aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/riscv/me_cmp_rvv.S
blob: 8989c91dded8b789ce307302d924a650b768f952 (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
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
/*
 * 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 pix_abs_ret
        vsetivli        zero, 1, e32, m1, ta, ma
        vmv.x.s         a0, v0
        ret
.endm

func ff_pix_abs16_rvv, zve32x
        lpad    0
        vsetivli        zero, 1, e32, m1, ta, ma
        vmv.s.x         v0, zero
1:
        vsetivli        zero, 16, e8, m1, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v12, (a2)
        addi            a4, a4, -1
        vwsubu.vv       v16, v4, v12
        add             a1, a1, a3
        vwsubu.vv       v20, v12, v4
        vsetvli         zero, zero, e16, m2, tu, ma
        vmax.vv         v16, v16, v20
        add             a2, a2, a3
        vwredsum.vs     v0, v16, v0
        bnez            a4, 1b

        pix_abs_ret
endfunc

func ff_pix_abs8_rvv, zve32x
        lpad    0
        vsetivli        zero, 1, e32, m1, ta, ma
        vmv.s.x         v0, zero
1:
        vsetivli        zero, 8, e8, mf2, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v12, (a2)
        addi            a4, a4, -1
        vwsubu.vv       v16, v4, v12
        add             a1, a1, a3
        vwsubu.vv       v20, v12, v4
        vsetvli         zero, zero, e16, m1, tu, ma
        vmax.vv         v16, v16, v20
        add             a2, a2, a3
        vwredsum.vs     v0, v16, v0
        bnez            a4, 1b

        pix_abs_ret
endfunc

func ff_pix_abs16_x2_rvv, zve32x
        lpad    0
        csrwi           vxrm, 0
        vsetivli        zero, 1, e32, m1, ta, ma
        li              t5, 1
        vmv.s.x         v0, zero
1:
        vsetivli        zero, 17, e8, m2, tu, ma
        vle8.v          v12, (a2)
        addi            a4, a4, -1
        vslide1down.vx  v24, v12, t5
        vsetivli        zero, 16, e8, m1, tu, ma
        vle8.v          v4, (a1)
        vaaddu.vv       v12, v12, v24
        vwsubu.vv       v16, v4, v12
        add             a1, a1, a3
        vwsubu.vv       v20, v12, v4
        vsetvli         zero, zero, e16, m2, tu, ma
        vmax.vv         v16, v16, v20
        add             a2, a2, a3
        vwredsum.vs     v0, v16, v0
        bnez            a4, 1b

        pix_abs_ret
endfunc

func ff_pix_abs8_x2_rvv, zve32x
        lpad    0
        csrwi           vxrm, 0
        vsetivli        zero, 1, e32, m1, ta, ma
        li              t5, 1
        vmv.s.x         v0, zero
1:
        vsetivli        zero, 9, e8, m1, tu, ma
        vle8.v          v12, (a2)
        addi            a4, a4, -1
        vslide1down.vx  v24, v12, t5
        vsetivli        zero, 8, e8, mf2, tu, ma
        vle8.v          v4, (a1)
        vaaddu.vv       v12, v12, v24
        vwsubu.vv       v16, v4, v12
        add             a1, a1, a3
        vwsubu.vv       v20, v12, v4
        vsetvli         zero, zero, e16, m1, tu, ma
        vmax.vv         v16, v16, v20
        add             a2, a2, a3
        vwredsum.vs     v0, v16, v0
        bnez            a4, 1b

        pix_abs_ret
endfunc

func ff_pix_abs16_y2_rvv, zve32x
        lpad    0
        csrwi           vxrm, 0
        vsetivli        zero, 1, e32, m1, ta, ma
        add             t1, a2, a3
        vmv.s.x         v0, zero
1:
        vsetivli        zero, 16, e8, m1, tu, ma
        vle8.v          v12, (a2)
        vle8.v          v24, (t1)
        addi            a4, a4, -1
        vle8.v          v4, (a1)
        vaaddu.vv       v12, v12, v24
        vwsubu.vv       v16, v4, v12
        vwsubu.vv       v20, v12, v4
        add             a1, a1, a3
        vsetvli         zero, zero, e16, m2, tu, ma
        add             a2, a2, a3
        vmax.vv         v16, v16, v20
        add             t1, t1, a3
        vwredsum.vs     v0, v16, v0
        bnez            a4, 1b

        pix_abs_ret
endfunc

func ff_pix_abs8_y2_rvv, zve32x
        lpad    0
        csrwi           vxrm, 0
        vsetivli        zero, 1, e32, m1, ta, ma
        add             t1, a2, a3
        vmv.s.x         v0, zero
1:
        vsetivli        zero, 8, e8, mf2, tu, ma
        vle8.v          v12, (a2)
        vle8.v          v24, (t1)
        addi            a4, a4, -1
        vle8.v          v4, (a1)
        vaaddu.vv       v12, v12, v24
        vwsubu.vv       v16, v4, v12
        vwsubu.vv       v20, v12, v4
        add             a1, a1, a3
        vsetvli         zero, zero, e16, m1, tu, ma
        add             a2, a2, a3
        vmax.vv         v16, v16, v20
        add             t1, t1, a3
        vwredsum.vs     v0, v16, v0
        bnez            a4, 1b

        pix_abs_ret
endfunc

func ff_sse16_rvv, zve32x
        lpad    0
        vsetivli        t0, 16, e32, m4, ta, ma
        vmv.v.x         v24, zero
        vmv.s.x         v0, zero
1:
        vsetvli         zero, zero, e8, m1, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v12, (a2)
        addi            a4, a4, -1
        vwsubu.vv       v16, v4, v12
        vsetvli         zero, zero, e16, m2, tu, ma
        vwmacc.vv       v24, v16, v16
        add             a1, a1, a3
        add             a2, a2, a3
        bnez            a4, 1b

        vsetvli         zero, zero, e32, m4, tu, ma
        vredsum.vs      v0, v24, v0
        vmv.x.s         a0, v0
        ret
endfunc

func ff_sse8_rvv, zve32x
        lpad    0
        vsetivli        t0, 8, e32, m2, ta, ma
        vmv.v.x         v24, zero
        vmv.s.x         v0, zero
1:
        vsetvli         zero, zero, e8, mf2, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v12, (a2)
        addi            a4, a4, -1
        vwsubu.vv       v16, v4, v12
        vsetvli         zero, zero, e16, m1, tu, ma
        vwmacc.vv       v24, v16, v16
        add             a1, a1, a3
        add             a2, a2, a3
        bnez            a4, 1b

        vsetvli         zero, zero, e32, m2, tu, ma
        vredsum.vs      v0, v24, v0
        vmv.x.s         a0, v0
        ret
endfunc

func ff_sse4_rvv, zve32x
        lpad    0
        vsetivli        t0, 4, e32, m1, ta, ma
        vmv.v.x         v24, zero
        vmv.s.x         v0, zero
1:
        vsetvli         zero, zero, e8, mf4, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v12, (a2)
        addi            a4, a4, -1
        vwsubu.vv       v16, v4, v12
        vsetvli         zero, zero, e16, mf2, tu, ma
        vwmacc.vv       v24, v16, v16
        add             a1, a1, a3
        add             a2, a2, a3
        bnez            a4, 1b

        vsetvli         zero, zero, e32, m1, tu, ma
        vredsum.vs      v0, v24, v0
        vmv.x.s         a0, v0
        ret
endfunc

.macro vabsaddu dst src tmp
        vneg.v          \tmp, \src
        vmax.vv         \tmp, \src, \tmp
        vwaddu.wv       \dst, \dst, \tmp
.endm

.macro  vsad_vsse16 type
        lpad    0
        vsetivli        t0, 16, e32, m4, ta, ma
        addi            a4, a4, -1
        add             t1, a1, a3
        add             t2, a2, a3
        vmv.v.x         v24, zero
        vmv.s.x         v0, zero
1:
        vsetvli         zero, zero, e8, m1, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v8, (t1)
        vle8.v          v12, (a2)
        vle8.v          v16, (t2)
        addi            a4, a4, -1
        vwsubu.vv       v28, v4, v12
        vwsubu.wv       v12, v28, v8
        vwaddu.wv       v28, v12, v16
        vsetvli         zero, zero, e16, m2, tu, ma

.ifc \type,abs
        vabsaddu        v24, v28, v12
.endif
.ifc \type,square
        vwmacc.vv       v24, v28, v28
.endif

        add             a1, a1, a3
        add             a2, a2, a3
        add             t1, t1, a3
        add             t2, t2, a3
        bnez            a4, 1b

        vsetvli         zero, zero, e32, m4, tu, ma
        vredsum.vs      v0, v24, v0
        vmv.x.s         a0, v0
        ret
.endm

.macro  vsad_vsse8 type
        lpad    0
        vsetivli        t0, 8, e32, m2, ta, ma
        addi            a4, a4, -1
        add             t1, a1, a3
        add             t2, a2, a3
        vmv.v.x         v24, zero
        vmv.s.x         v0, zero
1:
        vsetvli         zero, zero, e8, mf2, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v8, (t1)
        vle8.v          v12, (a2)
        vle8.v          v16, (t2)
        addi            a4, a4, -1
        vwsubu.vv       v28, v4, v12
        vwsubu.wv       v12, v28, v8
        vwaddu.wv       v28, v12, v16
        vsetvli         zero, zero, e16, m1, tu, ma

.ifc \type,abs
        vabsaddu        v24, v28, v12
.endif
.ifc \type,square
        vwmacc.vv       v24, v28, v28
.endif

        add             a1, a1, a3
        add             a2, a2, a3
        add             t1, t1, a3
        add             t2, t2, a3
        bnez            a4, 1b

        vsetvli         zero, zero, e32, m2, tu, ma
        vredsum.vs      v0, v24, v0
        vmv.x.s         a0, v0
        ret
.endm

.macro  vsad_vsse_intra16 type
        lpad    0
        vsetivli        t0, 16, e32, m4, ta, ma
        addi            a4, a4, -1
        add             t1, a1, a3
        vmv.v.x         v24, zero
        vmv.s.x         v0, zero
1:
        vsetvli         zero, zero, e8, m1, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v12, (t1)
        addi            a4, a4, -1
        vwsubu.vv       v16, v4, v12
        vsetvli         zero, zero, e16, m2, tu, ma

.ifc \type,abs
        vabsaddu        v24, v16, v12
.endif
.ifc \type,square
        vwmacc.vv       v24, v16, v16
.endif

        add             a1, a1, a3
        add             t1, t1, a3
        bnez            a4, 1b

        vsetvli         zero, zero, e32, m4, tu, ma
        vredsum.vs      v0, v24, v0
        vmv.x.s         a0, v0
        ret
.endm

.macro  vsad_vsse_intra8 type
        lpad    0
        vsetivli        t0, 8, e32, m2, ta, ma
        addi            a4, a4, -1
        add             t1, a1, a3
        vmv.v.x         v24, zero
        vmv.s.x         v0, zero
1:
        vsetvli         zero, zero, e8, mf2, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v12, (t1)
        addi            a4, a4, -1
        vwsubu.vv       v16, v4, v12
        vsetvli         zero, zero, e16, m1, tu, ma

.ifc \type,abs
        vabsaddu        v24, v16, v12
.endif
.ifc \type,square
        vwmacc.vv       v24, v16, v16
.endif

        add             a1, a1, a3
        add             t1, t1, a3
        bnez            a4, 1b

        vsetvli         zero, zero, e32, m2, tu, ma
        vredsum.vs      v0, v24, v0
        vmv.x.s         a0, v0
        ret
.endm

func ff_vsse16_rvv, zve32x
        vsad_vsse16 square
endfunc

func ff_vsse8_rvv, zve32x
        vsad_vsse8 square
endfunc

func ff_vsse_intra16_rvv, zve32x
        vsad_vsse_intra16 square
endfunc

func ff_vsse_intra8_rvv, zve32x
        vsad_vsse_intra8 square
endfunc

func ff_vsad16_rvv, zve32x
        vsad_vsse16 abs
endfunc

func ff_vsad8_rvv, zve32x
        vsad_vsse8 abs
endfunc

func ff_vsad_intra16_rvv, zve32x
        vsad_vsse_intra16 abs
endfunc

func ff_vsad_intra8_rvv, zve32x
        vsad_vsse_intra8 abs
endfunc

func ff_nsse16_rvv, zve32x
        lpad    0

        .macro squarediff16
        vsetivli        zero, 16, e8, m1, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v12, (a2)
        vwsubu.vv       v16, v4, v12
        vsetvli         zero, zero, e16, m2, tu, ma
        vwmacc.vv       v24, v16, v16
        .endm

        .macro gradiff16 srcx srcv
        vsetivli        zero, 16, e8, m1, tu, ma
        vle8.v          v8, (\srcx)
        vslide1down.vx  v0, \srcv, t5
        vslide1down.vx  v16, v8, t5
        vwsubu.vv       v20, \srcv, v0
        vwsubu.wv       v0, v20, v8
        vwaddu.wv       v20, v0, v16
        vsetivli        zero, 15, e16, m2, tu, ma
        vneg.v          v0, v20
        vmax.vv         v0, v20, v0
        .endm

        csrwi           vxrm, 0
        vsetivli        t0, 16, e32, m4, ta, ma
        addi            a4, a4, -1
        li              t5, 1
        vmv.v.x         v24, zero
        vmv.v.x         v28, zero
1:
        add             t1, a1, a3
        add             t2, a2, a3
        addi            a4, a4, -1
        squarediff16
        gradiff16       t1, v4
        vwaddu.wv       v28, v28, v0
        gradiff16       t2, v12
        vwsubu.wv       v28, v28, v0
        add             a1, a1, a3
        add             a2, a2, a3
        bnez            a4, 1b

        squarediff16
        vsetivli        zero, 16, e32, m4, tu, ma
        vmv.s.x         v0, zero
        vmv.s.x         v4, zero
        vredsum.vs      v0, v24, v0
        vredsum.vs      v4, v28, v4
        vmv.x.s         t1, v0
        vmv.x.s         t2, v4
        srai            t3, t2, 31
        xor             t2, t3, t2
        sub             t2, t2, t3
        mul             t2, t2, a0
        add             a0, t2, t1

        ret
endfunc

func ff_nsse8_rvv, zve32x
        lpad    0

        .macro squarediff8
        vsetivli        zero, 8, e8, mf2, tu, ma
        vle8.v          v4, (a1)
        vle8.v          v12, (a2)
        vwsubu.vv       v16, v4, v12
        vsetvli         zero, zero, e16, m1, tu, ma
        vwmacc.vv       v24, v16, v16
        .endm

        .macro gradiff8 srcx srcv
        vsetivli        zero, 8, e8, mf2, tu, ma
        vle8.v          v8, (\srcx)
        vslide1down.vx  v0, \srcv, t5
        vslide1down.vx  v16, v8, t5
        vwsubu.vv       v20, \srcv, v0
        vwsubu.wv       v0, v20, v8
        vwaddu.wv       v20, v0, v16
        vsetivli        zero, 7, e16, m1, tu, ma
        vneg.v          v0, v20
        vmax.vv         v0, v20, v0
        .endm

        csrwi           vxrm, 0
        vsetivli        t0, 8, e32, m2, ta, ma
        addi            a4, a4, -1
        li              t5, 1
        vmv.v.x         v24, zero
        vmv.v.x         v28, zero
1:
        add             t1, a1, a3
        add             t2, a2, a3
        addi            a4, a4, -1
        squarediff8
        gradiff8        t1, v4
        vwaddu.wv       v28, v28, v0
        gradiff8        t2, v12
        vwsubu.wv       v28, v28, v0
        add             a1, a1, a3
        add             a2, a2, a3
        bnez            a4, 1b

        squarediff8
        vsetivli        zero, 8, e32, m2, tu, ma
        vmv.s.x         v0, zero
        vmv.s.x         v4, zero
        vredsum.vs      v0, v24, v0
        vredsum.vs      v4, v28, v4
        vmv.x.s         t1, v0
        vmv.x.s         t2, v4
        srai            t3, t2, 31
        xor             t2, t3, t2
        sub             t2, t2, t3
        mul             t2, t2, a0
        add             a0, t2, t1

        ret
endfunc