History

lavc/h264dsp: R-V V 8-bit h264_weight_pixels

There are two implementations here: - a generic scalable one processing two columns at a time, - a specialised processing one (fixed-size) row at a time. Unsurprisingly, the generic one works out better with smaller widths. With larger widths, the gains from filling vectors are outweighed by the extra cost of strided loads and stores. In other words, memory accesses become the bottleneck. T-Head C908: h264_weight2_8_c: 54.5 h264_weight2_8_rvv_i32: 13.7 h264_weight4_8_c: 101.7 h264_weight4_8_rvv_i32: 27.5 h264_weight8_8_c: 197.0 h264_weight8_8_rvv_i32: 75.5 h264_weight16_8_c: 385.0 h264_weight16_8_rvv_i32: 74.2 SpacemiT X60: h264_weight2_8_c: 48.5 h264_weight2_8_rvv_i32: 8.2 h264_weight4_8_c: 90.7 h264_weight4_8_rvv_i32: 16.5 h264_weight8_8_c: 175.0 h264_weight8_8_rvv_i32: 37.7 h264_weight16_8_c: 342.2 h264_weight16_8_rvv_i32: 66.0

Rémi Denis-Courmont committed 2 years ago

Commit 3606e591 parent 85706f52 files · +90 −0Browse files

Unified · Split

2 files
  1. libavcodec/riscv/h264dsp_init.c +7 −0
  2. libavcodec/riscv/h264dsp_rvv.S +83 −0
libavcodec/riscv/h264dsp_init.c+7−0
@@ -21,12 +21,15 @@ · 20 unmodified lines
2121 #include "config.h"
2222
2323 #include <stdint.h>
24+#include <string.h>
2425
2526 #include "libavutil/attributes.h"
2627 #include "libavutil/cpu.h"
2728 #include "libavutil/riscv/cpu.h"
2829 #include "libavcodec/h264dsp.h"
2930
31+extern const h264_weight_func ff_h264_weight_funcs_8_rvv[];
32+
3033 void ff_h264_v_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,
3134 int alpha, int beta, int8_t *tc0);
3235 void ff_h264_h_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,
@@ -60,6 +63,10 @@ av_cold void ff_h264dsp_init_riscv(H264DSPContext *dsp, const int bit_depth, · 27 unmodified lines
6063 # if HAVE_RVV
6164 if (flags & AV_CPU_FLAG_RVV_I32) {
6265 if (bit_depth == 8 && ff_rv_vlen_least(128)) {
66+ memcpy(dsp->weight_h264_pixels_tab,
67+ ff_h264_weight_funcs_8_rvv,
68+ sizeof (dsp->weight_h264_pixels_tab));
69+
6370 dsp->h264_v_loop_filter_luma = ff_h264_v_loop_filter_luma_8_rvv;
6471 dsp->h264_h_loop_filter_luma = ff_h264_h_loop_filter_luma_8_rvv;
6572 dsp->h264_h_loop_filter_luma_mbaff =
libavcodec/riscv/h264dsp_rvv.S+83−0
@@ -26,6 +26,89 @@ · 25 unmodified lines
2626
2727 #include "libavutil/riscv/asm.S"
2828
29+func ff_h264_weight_pixels_simple_8_rvv, zve32x
30+ csrwi vxrm, 0
31+ sll a5, a5, a3
32+1:
33+ vsetvli zero, a6, e32, m4, ta, ma
34+ vle8.v v8, (a0)
35+ addi a2, a2, -1
36+ vmv.v.x v16, a5
37+ vsetvli zero, zero, e16, m2, ta, ma
38+ vzext.vf2 v24, v8
39+ vwmaccsu.vx v16, a4, v24
40+ vnclip.wx v16, v16, a3
41+ vmax.vx v16, v16, zero
42+ vsetvli zero, zero, e8, m1, ta, ma
43+ vnclipu.wi v8, v16, 0
44+ vse8.v v8, (a0)
45+ add a0, a0, a1
46+ bnez a2, 1b
47+
48+ ret
49+endfunc
50+
51+func ff_h264_weight_pixels_8_rvv, zve32x
52+ csrwi vxrm, 0
53+ sll a5, a5, a3
54+1:
55+ mv t0, a0
56+ mv t6, a6
57+2:
58+ vsetvli t2, a2, e32, m8, ta, ma
59+ vlsseg2e8.v v0, (t0), a1
60+ addi t6, t6, -2
61+ vmv.v.x v16, a5
62+ vmv.v.x v24, a5
63+ vsetvli zero, zero, e16, m4, ta, ma
64+ vzext.vf2 v8, v0
65+ vzext.vf2 v12, v2
66+ vwmaccsu.vx v16, a4, v8
67+ vwmaccsu.vx v24, a4, v12
68+ vnclip.wx v8, v16, a3
69+ vnclip.wx v12, v24, a3
70+ vmax.vx v8, v8, zero
71+ vmax.vx v12, v12, zero
72+ vsetvli zero, zero, e8, m2, ta, ma
73+ vnclipu.wi v0, v8, 0
74+ vnclipu.wi v2, v12, 0
75+ vssseg2e8.v v0, (t0), a1
76+ addi t0, t0, 2
77+ bnez t6, 2b
78+
79+ mul t3, a1, t2
80+ sub a2, a2, t2
81+ add a0, a0, t3
82+ bnez a2, 1b
83+
84+ ret
85+endfunc
86+
87+.irp w, 16, 8, 4, 2
88+func ff_h264_weight_pixels\w\()_8_rvv, zve32x
89+ li a6, \w
90+ .if \w == 16
91+ j ff_h264_weight_pixels_simple_8_rvv
92+ .else
93+ j ff_h264_weight_pixels_8_rvv
94+ .endif
95+endfunc
96+.endr
97+
98+ .global ff_h264_weight_funcs_8_rvv
99+ .hidden ff_h264_weight_funcs_8_rvv
100+const ff_h264_weight_funcs_8_rvv
101+ .irp w, 16, 8, 4, 2
102+#if __riscv_xlen == 32
103+ .word ff_h264_weight_pixels\w\()_8_rvv
104+#elif __riscv_xlen == 64
105+ .dword ff_h264_weight_pixels\w\()_8_rvv
106+#else
107+ .qword ff_h264_weight_pixels\w\()_8_rvv
108+#endif
109+ .endr
110+endconst
111+
29112 .variant_cc ff_h264_loop_filter_luma_8_rvv
30113 func ff_h264_loop_filter_luma_8_rvv, zve32x
31114 # p2: v8, p1: v9, p0: v10, q0: v11, q1: v12, q2: v13

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