History

avcodec/hevc: Add add_residual_4/8/16/32 asm opt

After this patch, the peformance of decoding H265 4K 30FPS 30Mbps on 3A6000 with 8 threads improves 2fps (45fps-->47fsp).

jinbo committed 2 years ago

Commit cfbdda61 parent c915dc44 files · +174 −1Browse files

Showing the changes to libavcodec (4 of 4 files). Show all

Unified · Split

4 files
  1. libavcodec/loongarch/Makefile +2 −1
  2. libavcodec/loongarch/hevc_add_res.S +162 −0
  3. libavcodec/loongarch/hevcdsp_init_loongarch.c +5 −0
  4. libavcodec/loongarch/hevcdsp_lsx.h +5 −0
libavcodec/loongarch/Makefile+2−1
@@ -27,7 +27,8 @@ LSX-OBJS-$(CONFIG_HEVC_DECODER) += loongarch/hevcdsp_lsx.o \ · 26 unmodified lines
2727 loongarch/hevc_lpf_sao_lsx.o \
2828 loongarch/hevc_mc_bi_lsx.o \
2929 loongarch/hevc_mc_uni_lsx.o \
30− loongarch/hevc_mc_uniw_lsx.o
30+ loongarch/hevc_mc_uniw_lsx.o \
31+ loongarch/hevc_add_res.o
3132 LSX-OBJS-$(CONFIG_H264DSP) += loongarch/h264idct.o \
3233 loongarch/h264idct_loongarch.o \
3334 loongarch/h264dsp.o
libavcodec/loongarch/hevc_add_res.S+162−0
@@ -0,0 +1,162 @@
1+/*
2+ * Loongson LSX optimized add_residual functions for HEVC decoding
3+ *
4+ * Copyright (c) 2023 Loongson Technology Corporation Limited
5+ * Contributed by jinbo <jinbo@loongson.cn>
6+ *
7+ * This file is part of FFmpeg.
8+ *
9+ * FFmpeg is free software; you can redistribute it and/or
10+ * modify it under the terms of the GNU Lesser General Public
11+ * License as published by the Free Software Foundation; either
12+ * version 2.1 of the License, or (at your option) any later version.
13+ *
14+ * FFmpeg is distributed in the hope that it will be useful,
15+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+ * Lesser General Public License for more details.
18+ *
19+ * You should have received a copy of the GNU Lesser General Public
20+ * License along with FFmpeg; if not, write to the Free Software
21+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22+ */
23+
24+#include "loongson_asm.S"
25+
26+/*
27+ * void ff_hevc_add_residual4x4_lsx(uint8_t *dst, const int16_t *res, ptrdiff_t stride)
28+ */
29+.macro ADD_RES_LSX_4x4_8
30+ vldrepl.w vr0, a0, 0
31+ add.d t0, a0, a2
32+ vldrepl.w vr1, t0, 0
33+ vld vr2, a1, 0
34+
35+ vilvl.w vr1, vr1, vr0
36+ vsllwil.hu.bu vr1, vr1, 0
37+ vadd.h vr1, vr1, vr2
38+ vssrani.bu.h vr1, vr1, 0
39+
40+ vstelm.w vr1, a0, 0, 0
41+ vstelm.w vr1, t0, 0, 1
42+.endm
43+
44+function ff_hevc_add_residual4x4_8_lsx
45+ ADD_RES_LSX_4x4_8
46+ alsl.d a0, a2, a0, 1
47+ addi.d a1, a1, 16
48+ ADD_RES_LSX_4x4_8
49+endfunc
50+
51+/*
52+ * void ff_hevc_add_residual8x8_8_lsx(uint8_t *dst, const int16_t *res, ptrdiff_t stride)
53+ */
54+.macro ADD_RES_LSX_8x8_8
55+ vldrepl.d vr0, a0, 0
56+ add.d t0, a0, a2
57+ vldrepl.d vr1, t0, 0
58+ add.d t1, t0, a2
59+ vldrepl.d vr2, t1, 0
60+ add.d t2, t1, a2
61+ vldrepl.d vr3, t2, 0
62+
63+ vld vr4, a1, 0
64+ addi.d t3, zero, 16
65+ vldx vr5, a1, t3
66+ addi.d t4, a1, 32
67+ vld vr6, t4, 0
68+ vldx vr7, t4, t3
69+
70+ vsllwil.hu.bu vr0, vr0, 0
71+ vsllwil.hu.bu vr1, vr1, 0
72+ vsllwil.hu.bu vr2, vr2, 0
73+ vsllwil.hu.bu vr3, vr3, 0
74+ vadd.h vr0, vr0, vr4
75+ vadd.h vr1, vr1, vr5
76+ vadd.h vr2, vr2, vr6
77+ vadd.h vr3, vr3, vr7
78+ vssrani.bu.h vr1, vr0, 0
79+ vssrani.bu.h vr3, vr2, 0
80+
81+ vstelm.d vr1, a0, 0, 0
82+ vstelm.d vr1, t0, 0, 1
83+ vstelm.d vr3, t1, 0, 0
84+ vstelm.d vr3, t2, 0, 1
85+.endm
86+
87+function ff_hevc_add_residual8x8_8_lsx
88+ ADD_RES_LSX_8x8_8
89+ alsl.d a0, a2, a0, 2
90+ addi.d a1, a1, 64
91+ ADD_RES_LSX_8x8_8
92+endfunc
93+
94+/*
95+ * void ff_hevc_add_residual16x16_8_lsx(uint8_t *dst, const int16_t *res, ptrdiff_t stride)
96+ */
97+function ff_hevc_add_residual16x16_8_lsx
98+.rept 8
99+ vld vr0, a0, 0
100+ vldx vr2, a0, a2
101+
102+ vld vr4, a1, 0
103+ addi.d t0, zero, 16
104+ vldx vr5, a1, t0
105+ addi.d t1, a1, 32
106+ vld vr6, t1, 0
107+ vldx vr7, t1, t0
108+
109+ vexth.hu.bu vr1, vr0
110+ vsllwil.hu.bu vr0, vr0, 0
111+ vexth.hu.bu vr3, vr2
112+ vsllwil.hu.bu vr2, vr2, 0
113+ vadd.h vr0, vr0, vr4
114+ vadd.h vr1, vr1, vr5
115+ vadd.h vr2, vr2, vr6
116+ vadd.h vr3, vr3, vr7
117+
118+ vssrani.bu.h vr1, vr0, 0
119+ vssrani.bu.h vr3, vr2, 0
120+
121+ vst vr1, a0, 0
122+ vstx vr3, a0, a2
123+
124+ alsl.d a0, a2, a0, 1
125+ addi.d a1, a1, 64
126+.endr
127+endfunc
128+
129+/*
130+ * void ff_hevc_add_residual32x32_8_lsx(uint8_t *dst, const int16_t *res, ptrdiff_t stride)
131+ */
132+function ff_hevc_add_residual32x32_8_lsx
133+.rept 32
134+ vld vr0, a0, 0
135+ addi.w t0, zero, 16
136+ vldx vr2, a0, t0
137+
138+ vld vr4, a1, 0
139+ vldx vr5, a1, t0
140+ addi.d t1, a1, 32
141+ vld vr6, t1, 0
142+ vldx vr7, t1, t0
143+
144+ vexth.hu.bu vr1, vr0
145+ vsllwil.hu.bu vr0, vr0, 0
146+ vexth.hu.bu vr3, vr2
147+ vsllwil.hu.bu vr2, vr2, 0
148+ vadd.h vr0, vr0, vr4
149+ vadd.h vr1, vr1, vr5
150+ vadd.h vr2, vr2, vr6
151+ vadd.h vr3, vr3, vr7
152+
153+ vssrani.bu.h vr1, vr0, 0
154+ vssrani.bu.h vr3, vr2, 0
155+
156+ vst vr1, a0, 0
157+ vstx vr3, a0, t0
158+
159+ add.d a0, a0, a2
160+ addi.d a1, a1, 64
161+.endr
162+endfunc
libavcodec/loongarch/hevcdsp_init_loongarch.c+5−0
@@ -189,6 +189,11 @@ void ff_hevc_dsp_init_loongarch(HEVCDSPContext *c, const int bit_depth) · 188 unmodified lines
189189 c->idct[1] = ff_hevc_idct_8x8_lsx;
190190 c->idct[2] = ff_hevc_idct_16x16_lsx;
191191 c->idct[3] = ff_hevc_idct_32x32_lsx;
192+
193+ c->add_residual[0] = ff_hevc_add_residual4x4_8_lsx;
194+ c->add_residual[1] = ff_hevc_add_residual8x8_8_lsx;
195+ c->add_residual[2] = ff_hevc_add_residual16x16_8_lsx;
196+ c->add_residual[3] = ff_hevc_add_residual32x32_8_lsx;
192197 }
193198 }
194199 }
libavcodec/loongarch/hevcdsp_lsx.h+5−0
@@ -227,4 +227,9 @@ void ff_hevc_idct_8x8_lsx(int16_t *coeffs, int col_limit); · 226 unmodified lines
227227 void ff_hevc_idct_16x16_lsx(int16_t *coeffs, int col_limit);
228228 void ff_hevc_idct_32x32_lsx(int16_t *coeffs, int col_limit);
229229
230+void ff_hevc_add_residual4x4_8_lsx(uint8_t *dst, const int16_t *res, ptrdiff_t stride);
231+void ff_hevc_add_residual8x8_8_lsx(uint8_t *dst, const int16_t *res, ptrdiff_t stride);
232+void ff_hevc_add_residual16x16_8_lsx(uint8_t *dst, const int16_t *res, ptrdiff_t stride);
233+void ff_hevc_add_residual32x32_8_lsx(uint8_t *dst, const int16_t *res, ptrdiff_t stride);
234+
230235 #endif // #ifndef AVCODEC_LOONGARCH_HEVCDSP_LSX_H

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t