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
21#include "config.h"21#include "config.h"
22 22
23#include <stdint.h>23#include <stdint.h>
24#include <string.h>
24 25
25#include "libavutil/attributes.h"26#include "libavutil/attributes.h"
26#include "libavutil/cpu.h"27#include "libavutil/cpu.h"
27#include "libavutil/riscv/cpu.h"28#include "libavutil/riscv/cpu.h"
28#include "libavcodec/h264dsp.h"29#include "libavcodec/h264dsp.h"
29 30
31extern const h264_weight_func ff_h264_weight_funcs_8_rvv[];
32
30void ff_h264_v_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,33void ff_h264_v_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,
31 int alpha, int beta, int8_t *tc0);34 int alpha, int beta, int8_t *tc0);
32void ff_h264_h_loop_filter_luma_8_rvv(uint8_t *pix, ptrdiff_t stride,35void 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
60# if HAVE_RVV63# if HAVE_RVV
61 if (flags & AV_CPU_FLAG_RVV_I32) {64 if (flags & AV_CPU_FLAG_RVV_I32) {
62 if (bit_depth == 8 && ff_rv_vlen_least(128)) {65 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
63 dsp->h264_v_loop_filter_luma = ff_h264_v_loop_filter_luma_8_rvv;70 dsp->h264_v_loop_filter_luma = ff_h264_v_loop_filter_luma_8_rvv;
64 dsp->h264_h_loop_filter_luma = ff_h264_h_loop_filter_luma_8_rvv;71 dsp->h264_h_loop_filter_luma = ff_h264_h_loop_filter_luma_8_rvv;
65 dsp->h264_h_loop_filter_luma_mbaff =72 dsp->h264_h_loop_filter_luma_mbaff =
libavcodec/riscv/h264dsp_rvv.S+83−0
@@ -26,6 +26,89 @@ · 25 unmodified lines
26 26
27#include "libavutil/riscv/asm.S"27#include "libavutil/riscv/asm.S"
28 28
29func ff_h264_weight_pixels_simple_8_rvv, zve32x
30 csrwi vxrm, 0
31 sll a5, a5, a3
321:
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
49endfunc
50
51func ff_h264_weight_pixels_8_rvv, zve32x
52 csrwi vxrm, 0
53 sll a5, a5, a3
541:
55 mv t0, a0
56 mv t6, a6
572:
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
85endfunc
86
87.irp w, 16, 8, 4, 2
88func 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
95endfunc
96.endr
97
98 .global ff_h264_weight_funcs_8_rvv
99 .hidden ff_h264_weight_funcs_8_rvv
100const 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
110endconst
111
29 .variant_cc ff_h264_loop_filter_luma_8_rvv112 .variant_cc ff_h264_loop_filter_luma_8_rvv
30func ff_h264_loop_filter_luma_8_rvv, zve32x113func ff_h264_loop_filter_luma_8_rvv, zve32x
31 # p2: v8, p1: v9, p0: v10, q0: v11, q1: v12, q2: v13114 # 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