FFmpeg
me_cmp_init.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 Institue of Software Chinese Academy of Sciences (ISCAS).
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "config.h"
22 
23 #include "libavutil/attributes.h"
24 #include "libavutil/cpu.h"
25 #include "libavutil/riscv/cpu.h"
26 #include "libavcodec/me_cmp.h"
27 #include "libavcodec/mpegvideo.h"
28 
29 int ff_pix_abs16_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
30  ptrdiff_t stride, int h);
31 int ff_pix_abs8_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
32  ptrdiff_t stride, int h);
33 int ff_pix_abs16_x2_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
34  ptrdiff_t stride, int h);
35 int ff_pix_abs8_x2_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
36  ptrdiff_t stride, int h);
37 int ff_pix_abs16_y2_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
38  ptrdiff_t stride, int h);
39 int ff_pix_abs8_y2_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
40  ptrdiff_t stride, int h);
41 
42 int ff_sse16_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
43  ptrdiff_t stride, int h);
44 int ff_sse8_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
45  ptrdiff_t stride, int h);
46 int ff_sse4_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2,
47  ptrdiff_t stride, int h);
48 
49 int ff_vsse16_rvv(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h);
50 int ff_vsse8_rvv(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h);
51 int ff_vsse_intra16_rvv(MpegEncContext *c, const uint8_t *s, const uint8_t *dummy, ptrdiff_t stride, int h);
52 int ff_vsse_intra8_rvv(MpegEncContext *c, const uint8_t *s, const uint8_t *dummy, ptrdiff_t stride, int h);
53 int ff_vsad16_rvv(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h);
54 int ff_vsad8_rvv(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h);
55 int ff_vsad_intra16_rvv(MpegEncContext *c, const uint8_t *s, const uint8_t *dummy, ptrdiff_t stride, int h);
56 int ff_vsad_intra8_rvv(MpegEncContext *c, const uint8_t *s, const uint8_t *dummy, ptrdiff_t stride, int h);
57 int ff_nsse16_rvv(int multiplier, const uint8_t *s1, const uint8_t *s2,
58  ptrdiff_t stride, int h);
59 int ff_nsse8_rvv(int multiplier, const uint8_t *s1, const uint8_t *s2,
60  ptrdiff_t stride, int h);
61 
62 static int nsse16_rvv_wrapper(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2,
63  ptrdiff_t stride, int h)
64 {
65  if (c)
66  return ff_nsse16_rvv(c->avctx->nsse_weight, s1, s2, stride, h);
67  else
68  return ff_nsse16_rvv(8, s1, s2, stride, h);
69 }
70 
71 static int nsse8_rvv_wrapper(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2,
72  ptrdiff_t stride, int h)
73 {
74  if (c)
75  return ff_nsse8_rvv(c->avctx->nsse_weight, s1, s2, stride, h);
76  else
77  return ff_nsse8_rvv(8, s1, s2, stride, h);
78 }
79 
81 {
82 #if HAVE_RVV
83  int flags = av_get_cpu_flags();
84 
85  if (flags & AV_CPU_FLAG_RVV_I32 && ff_get_rv_vlenb() >= 16) {
86  c->pix_abs[0][0] = ff_pix_abs16_rvv;
87  c->sad[0] = ff_pix_abs16_rvv;
88  c->pix_abs[1][0] = ff_pix_abs8_rvv;
89  c->sad[1] = ff_pix_abs8_rvv;
90  c->pix_abs[0][1] = ff_pix_abs16_x2_rvv;
91  c->pix_abs[1][1] = ff_pix_abs8_x2_rvv;
92  c->pix_abs[0][2] = ff_pix_abs16_y2_rvv;
93  c->pix_abs[1][2] = ff_pix_abs8_y2_rvv;
94 
95  c->sse[0] = ff_sse16_rvv;
96  c->sse[1] = ff_sse8_rvv;
97  c->sse[2] = ff_sse4_rvv;
98 
99  c->vsse[0] = ff_vsse16_rvv;
100  c->vsse[1] = ff_vsse8_rvv;
101  c->vsse[4] = ff_vsse_intra16_rvv;
102  c->vsse[5] = ff_vsse_intra8_rvv;
103  c->vsad[0] = ff_vsad16_rvv;
104  c->vsad[1] = ff_vsad8_rvv;
105  c->vsad[4] = ff_vsad_intra16_rvv;
106  c->vsad[5] = ff_vsad_intra8_rvv;
107 
108  c->nsse[0] = nsse16_rvv_wrapper;
109  c->nsse[1] = nsse8_rvv_wrapper;
110  }
111 #endif
112 }
ff_nsse16_rvv
int ff_nsse16_rvv(int multiplier, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h)
ff_pix_abs8_x2_rvv
int ff_pix_abs8_x2_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
ff_pix_abs8_rvv
int ff_pix_abs8_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
ff_pix_abs16_rvv
int ff_pix_abs16_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
ff_pix_abs8_y2_rvv
int ff_pix_abs8_y2_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
ff_vsad_intra8_rvv
int ff_vsad_intra8_rvv(MpegEncContext *c, const uint8_t *s, const uint8_t *dummy, ptrdiff_t stride, int h)
mpegvideo.h
av_get_cpu_flags
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:103
ff_vsse8_rvv
int ff_vsse8_rvv(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h)
dummy
int dummy
Definition: motion.c:66
ff_vsse16_rvv
int ff_vsse16_rvv(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h)
ff_pix_abs16_y2_rvv
int ff_pix_abs16_y2_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
av_cold
#define av_cold
Definition: attributes.h:90
ff_sse8_rvv
int ff_sse8_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_sse4_rvv
int ff_sse4_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
cpu.h
s1
#define s1
Definition: regdef.h:38
ff_vsad_intra16_rvv
int ff_vsad_intra16_rvv(MpegEncContext *c, const uint8_t *s, const uint8_t *dummy, ptrdiff_t stride, int h)
ff_vsad16_rvv
int ff_vsad16_rvv(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h)
MECmpContext
Definition: me_cmp.h:55
nsse8_rvv_wrapper
static int nsse8_rvv_wrapper(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h)
Definition: me_cmp_init.c:71
ff_me_cmp_init_riscv
av_cold void ff_me_cmp_init_riscv(MECmpContext *c, AVCodecContext *avctx)
Definition: me_cmp_init.c:80
ff_vsad8_rvv
int ff_vsad8_rvv(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h)
ff_sse16_rvv
int ff_sse16_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
ff_vsse_intra8_rvv
int ff_vsse_intra8_rvv(MpegEncContext *c, const uint8_t *s, const uint8_t *dummy, ptrdiff_t stride, int h)
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
nsse16_rvv_wrapper
static int nsse16_rvv_wrapper(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h)
Definition: me_cmp_init.c:62
s2
#define s2
Definition: regdef.h:39
cpu.h
ff_vsse_intra16_rvv
int ff_vsse_intra16_rvv(MpegEncContext *c, const uint8_t *s, const uint8_t *dummy, ptrdiff_t stride, int h)
ff_nsse8_rvv
int ff_nsse8_rvv(int multiplier, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h)
attributes.h
AV_CPU_FLAG_RVV_I32
#define AV_CPU_FLAG_RVV_I32
Vectors of 8/16/32-bit int's *‍/.
Definition: cpu.h:87
stride
#define stride
Definition: h264pred_template.c:537
ff_pix_abs16_x2_rvv
int ff_pix_abs16_x2_rvv(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h)
me_cmp.h
AVCodecContext
main external API structure.
Definition: avcodec.h:445
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
h
h
Definition: vp9dsp_template.c:2038
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:67