History

lavc/sbrdsp: R-V V autocorrelate

With 5 accumulator vectors and 6 inputs, this can only use LMUL=2. Also the number of vector loop iterations is small, just 5 on 128-bit vector hardware. The vector loop is somewhat unusual in that it processes data in descending memory order, in order to save on vector slides: in descending order, we can extract elements to carry over to the next iteration from the bottom of the vectors directly. With ascending order (see in the Opus postfilter function), there are no ways to get the top elements directly. On the downside, this requires the use of separate shift and sub (the would-be SH3SUB instruction does not exist), with a small pipeline stall on the vector load address. The edge cases in scalar are done in scalar as this saves on loads and remains significantly faster than C. autocorrelate_c: 669.2 autocorrelate_rvv_f32: 421.0

Rémi Denis-Courmont committed 3 years ago

Commit cd7b3521 parent f576a082 files · +97 −4Browse files

Unified · Split

2 files
  1. libavcodec/riscv/sbrdsp_init.c +8 −4
  2. libavcodec/riscv/sbrdsp_rvv.S +89 −0
libavcodec/riscv/sbrdsp_init.c+8−4
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 void ff_sbr_sum64x5_rvv(float *z);
2727 float ff_sbr_sum_square_rvv(float (*x)[2], int n);
2828 void ff_sbr_neg_odd_64_rvv(float *x);
29+void ff_sbr_autocorrelate_rvv(const float x[40][2], float phi[3][2][2]);
2930 void ff_sbr_hf_g_filt_rvv(float (*Y)[2], const float (*X_high)[40][2],
3031 const float *g_filt, int m_max, intptr_t ixh);
3132
@@ -34,10 +35,13 @@ av_cold void ff_sbrdsp_init_riscv(SBRDSPContext *c) · 2 unmodified lines
3435 #if HAVE_RVV
3536 int flags = av_get_cpu_flags();
3637
37− if ((flags & AV_CPU_FLAG_RVV_F32) && (flags & AV_CPU_FLAG_RVB_ADDR)) {
38− c->sum64x5 = ff_sbr_sum64x5_rvv;
39− c->sum_square = ff_sbr_sum_square_rvv;
40− c->hf_g_filt = ff_sbr_hf_g_filt_rvv;
38+ if (flags & AV_CPU_FLAG_RVV_F32) {
39+ if (flags & AV_CPU_FLAG_RVB_ADDR) {
40+ c->sum64x5 = ff_sbr_sum64x5_rvv;
41+ c->sum_square = ff_sbr_sum_square_rvv;
42+ c->hf_g_filt = ff_sbr_hf_g_filt_rvv;
43+ }
44+ c->autocorrelate = ff_sbr_autocorrelate_rvv;
4145 }
4246 #if __riscv_xlen >= 64
4347 if ((flags & AV_CPU_FLAG_RVV_I64) && (flags & AV_CPU_FLAG_RVB_ADDR))
libavcodec/riscv/sbrdsp_rvv.S+89−0
@@ -85,6 +85,95 @@ func ff_sbr_neg_odd_64_rvv, zve64x · 84 unmodified lines
8585 endfunc
8686 #endif
8787
88+func ff_sbr_autocorrelate_rvv, zve32f
89+ vsetvli t0, zero, e32, m4, ta, ma
90+ vmv.v.x v0, zero
91+ flw fa0, (a0)
92+ vmv.v.x v4, zero
93+ flw fa1, 4(a0)
94+ vmv.v.x v8, zero
95+ flw fa2, 8(a0)
96+ li a2, 37
97+ flw fa3, 12(a0)
98+ fmul.s ft10, fa0, fa0
99+ flw fa4, 16(a0)
100+ fmul.s ft6, fa0, fa2
101+ flw fa5, 20(a0)
102+ addi a0, a0, 38 * 8
103+ fmul.s ft7, fa0, fa3
104+ fmul.s ft2, fa0, fa4
105+ fmul.s ft3, fa0, fa5
106+ flw fa0, (a0)
107+ fmadd.s ft10, fa1, fa1, ft10
108+ fmadd.s ft6, fa1, fa3, ft6
109+ flw fa3, 12(a0)
110+ fnmsub.s ft7, fa1, fa2, ft7
111+ flw fa2, 8(a0)
112+ fmadd.s ft2, fa1, fa5, ft2
113+ fnmsub.s ft3, fa1, fa4, ft3
114+ flw fa1, 4(a0)
115+ fmul.s ft4, fa0, fa0
116+ fmul.s ft0, fa0, fa2
117+ fmul.s ft1, fa0, fa3
118+ fmadd.s ft4, fa1, fa1, ft4
119+ fmadd.s ft0, fa1, fa3, ft0
120+ fnmsub.s ft1, fa1, fa2, ft1
121+1:
122+ vsetvli t0, a2, e32, m2, tu, ma
123+ slli t1, t0, 3
124+ sub a0, a0, t1
125+ vlseg2e32.v v16, (a0)
126+ sub a2, a2, t0
127+ vfmacc.vv v0, v16, v16
128+ vfslide1down.vf v20, v16, fa0
129+ vfmacc.vv v4, v16, v20
130+ vfslide1down.vf v22, v18, fa1
131+ vfmacc.vv v0, v18, v18
132+ vfslide1down.vf v24, v20, fa2
133+ vfmacc.vv v4, v18, v22
134+ vfslide1down.vf v26, v22, fa3
135+ vfmacc.vv v6, v16, v22
136+ vfmv.f.s fa0, v16
137+ vfmacc.vv v8, v16, v24
138+ vfmv.f.s fa1, v18
139+ vfmacc.vv v10, v16, v26
140+ vfmv.f.s fa2, v20
141+ vfnmsac.vv v6, v18, v20
142+ vfmv.f.s fa3, v22
143+ vfmacc.vv v8, v18, v26
144+ vfnmsac.vv v10, v18, v24
145+ bnez a2, 1b
146+
147+ vsetvli t0, zero, e32, m2, ta, ma
148+ vfredusum.vs v0, v0, v2
149+ vfredusum.vs v4, v4, v2
150+ vfmv.f.s fa0, v0
151+ vfredusum.vs v6, v6, v2
152+ vfmv.f.s fa2, v4
153+ fadd.s ft4, ft4, fa0
154+ vfredusum.vs v8, v8, v2
155+ vfmv.f.s fa3, v6
156+ fadd.s ft0, ft0, fa2
157+ vfredusum.vs v10, v10, v2
158+ vfmv.f.s fa4, v8
159+ fadd.s ft1, ft1, fa3
160+ vfmv.f.s fa5, v10
161+ fsw ft0, (a1)
162+ fadd.s ft2, ft2, fa4
163+ fsw ft1, 4(a1)
164+ fadd.s ft3, ft3, fa5
165+ fsw ft2, 8(a1)
166+ fadd.s ft6, ft6, fa2
167+ fsw ft3, 12(a1)
168+ fadd.s ft7, ft7, fa3
169+ fsw ft4, 16(a1)
170+ fadd.s ft10, ft10, fa0
171+ fsw ft6, 24(a1)
172+ fsw ft7, 28(a1)
173+ fsw ft10, 40(a1)
174+ ret
175+endfunc
176+
88177 func ff_sbr_hf_g_filt_rvv, zve32f
89178 li t1, 40 * 2 * 4
90179 sh3add a1, a4, a1

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