History

swscale/aarch64/yuv2rgb: add neon yuv42{0,2}p -> gbrp unscaled colorspace converters

checkasm --bench on a Raspberry Pi 5 Model B Rev 1.0: yuv420p_gbrp_128_c: 1243.0 yuv420p_gbrp_128_neon: 453.5 yuv420p_gbrp_1920_c: 18165.5 yuv420p_gbrp_1920_neon: 6700.0 yuv422p_gbrp_128_c: 1463.5 yuv422p_gbrp_128_neon: 471.5 yuv422p_gbrp_1920_c: 21343.7 yuv422p_gbrp_1920_neon: 6743.5

Ramiro Polla committed 2 years ago

Commit 181cd261 parent 87447642 files · +118 −13Browse files

Unified · Split

2 files
  1. libswscale/aarch64/swscale_unscaled.c +58 −0
  2. libswscale/aarch64/yuv2rgb_neon.S +60 −13
libswscale/aarch64/swscale_unscaled.c+58−0
@@ -52,11 +52,41 @@ static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], · 51 unmodified lines
52 c->yuv2rgb_y_coeff); \52 c->yuv2rgb_y_coeff); \
53} \53} \
54 54
55#define DECLARE_FF_YUVX_TO_GBRP_FUNCS(ifmt, ofmt) \
56int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
57 uint8_t *dst, int linesize, \
58 const uint8_t *srcY, int linesizeY, \
59 const uint8_t *srcU, int linesizeU, \
60 const uint8_t *srcV, int linesizeV, \
61 const int16_t *table, \
62 int y_offset, \
63 int y_coeff, \
64 uint8_t *dst1, int linesize1, \
65 uint8_t *dst2, int linesize2); \
66 \
67static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
68 int srcStride[], int srcSliceY, int srcSliceH, \
69 uint8_t *dst[], int dstStride[]) { \
70 const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
71 \
72 return ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
73 dst[0] + srcSliceY * dstStride[0], dstStride[0], \
74 src[0], srcStride[0], \
75 src[1], srcStride[1], \
76 src[2], srcStride[2], \
77 yuv2rgb_table, \
78 c->yuv2rgb_y_offset >> 6, \
79 c->yuv2rgb_y_coeff, \
80 dst[1] + srcSliceY * dstStride[1], dstStride[1], \
81 dst[2] + srcSliceY * dstStride[2], dstStride[2]); \
82} \
83
55#define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx) \84#define DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuvx) \
56DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb) \85DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, argb) \
57DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba) \86DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, rgba) \
58DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr) \87DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, abgr) \
59DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra) \88DECLARE_FF_YUVX_TO_RGBX_FUNCS(yuvx, bgra) \
89DECLARE_FF_YUVX_TO_GBRP_FUNCS(yuvx, gbrp) \
60 90
61DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv420p)91DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv420p)
62DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv422p)92DECLARE_FF_YUVX_TO_ALL_RGBX_FUNCS(yuv422p)
@@ -83,11 +113,38 @@ static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], · 20 unmodified lines
83 c->yuv2rgb_y_coeff); \113 c->yuv2rgb_y_coeff); \
84} \114} \
85 115
116#define DECLARE_FF_NVX_TO_GBRP_FUNCS(ifmt, ofmt) \
117int ff_##ifmt##_to_##ofmt##_neon(int w, int h, \
118 uint8_t *dst, int linesize, \
119 const uint8_t *srcY, int linesizeY, \
120 const uint8_t *srcC, int linesizeC, \
121 const int16_t *table, \
122 int y_offset, \
123 int y_coeff, \
124 uint8_t *dst1, int linesize1, \
125 uint8_t *dst2, int linesize2); \
126 \
127static int ifmt##_to_##ofmt##_neon_wrapper(SwsContext *c, const uint8_t *src[], \
128 int srcStride[], int srcSliceY, int srcSliceH, \
129 uint8_t *dst[], int dstStride[]) { \
130 const int16_t yuv2rgb_table[] = { YUV_TO_RGB_TABLE }; \
131 \
132 return ff_##ifmt##_to_##ofmt##_neon(c->srcW, srcSliceH, \
133 dst[0] + srcSliceY * dstStride[0], dstStride[0], \
134 src[0], srcStride[0], src[1], srcStride[1], \
135 yuv2rgb_table, \
136 c->yuv2rgb_y_offset >> 6, \
137 c->yuv2rgb_y_coeff, \
138 dst[1] + srcSliceY * dstStride[1], dstStride[1], \
139 dst[2] + srcSliceY * dstStride[2], dstStride[2]); \
140} \
141
86#define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \142#define DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nvx) \
87DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \143DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, argb) \
88DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \144DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, rgba) \
89DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \145DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, abgr) \
90DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \146DECLARE_FF_NVX_TO_RGBX_FUNCS(nvx, bgra) \
147DECLARE_FF_NVX_TO_GBRP_FUNCS(nvx, gbrp) \
91 148
92DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv12)149DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv12)
93DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21)150DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21)
@@ -110,6 +167,7 @@ DECLARE_FF_NVX_TO_ALL_RGBX_FUNCS(nv21) · 16 unmodified lines
110 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \167 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, rgba, RGBA, accurate_rnd); \
111 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \168 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, abgr, ABGR, accurate_rnd); \
112 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \169 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, bgra, BGRA, accurate_rnd); \
170 SET_FF_NVX_TO_RGBX_FUNC(nvx, NVX, gbrp, GBRP, accurate_rnd); \
113} while (0)171} while (0)
114 172
115static void get_unscaled_swscale_neon(SwsContext *c) {173static void get_unscaled_swscale_neon(SwsContext *c) {
libswscale/aarch64/yuv2rgb_neon.S+60−13
@@ -30,23 +30,43 @@ · 29 unmodified lines
30#endif30#endif
31.endm31.endm
32 32
33.macro load_args_nv1233.macro load_dst1_dst2 dst1 linesize1 dst2 linesize2
34#if defined(__APPLE__)
35#define DST_OFFSET 8
36#else
37#define DST_OFFSET 0
38#endif
39 ldr x10, [sp, #\dst1 - DST_OFFSET]
40 ldr w12, [sp, #\linesize1 - DST_OFFSET]
41 ldr x15, [sp, #\dst2 - DST_OFFSET]
42 ldr w16, [sp, #\linesize2 - DST_OFFSET]
43#undef DST_OFFSET
44 sub w12, w12, w0 // w12 = linesize1 - width (padding1)
45 sub w16, w16, w0 // w16 = linesize2 - width (padding2)
46.endm
47
48.macro load_args_nv12 ofmt
34 ldr x8, [sp] // table49 ldr x8, [sp] // table
35 load_yoff_ycoeff 8, 16 // y_offset, y_coeff50 load_yoff_ycoeff 8, 16 // y_offset, y_coeff
36 ld1 {v1.1d}, [x8]51 ld1 {v1.1d}, [x8]
37 dup v0.8h, w1052 dup v0.8h, w10
38 dup v3.8h, w953 dup v3.8h, w9
54.ifc \ofmt,gbrp
55 load_dst1_dst2 24, 32, 40, 48
56 sub w3, w3, w0 // w3 = linesize - width (padding)
57.else
39 sub w3, w3, w0, lsl #2 // w3 = linesize - width * 4 (padding)58 sub w3, w3, w0, lsl #2 // w3 = linesize - width * 4 (padding)
59.endif
40 sub w5, w5, w0 // w5 = linesizeY - width (paddingY)60 sub w5, w5, w0 // w5 = linesizeY - width (paddingY)
41 sub w7, w7, w0 // w7 = linesizeC - width (paddingC)61 sub w7, w7, w0 // w7 = linesizeC - width (paddingC)
42 neg w11, w062 neg w11, w0
43.endm63.endm
44 64
45.macro load_args_nv2165.macro load_args_nv21 ofmt
46 load_args_nv1266 load_args_nv12 \ofmt
47.endm67.endm
48 68
49.macro load_args_yuv420p69.macro load_args_yuv420p ofmt
50 ldr x13, [sp] // srcV70 ldr x13, [sp] // srcV
51 ldr w14, [sp, #8] // linesizeV71 ldr w14, [sp, #8] // linesizeV
52 ldr x8, [sp, #16] // table72 ldr x8, [sp, #16] // table
@@ -54,7 +74,12 @@ · 1 unmodified line
54 ld1 {v1.1d}, [x8]74 ld1 {v1.1d}, [x8]
55 dup v0.8h, w1075 dup v0.8h, w10
56 dup v3.8h, w976 dup v3.8h, w9
77.ifc \ofmt,gbrp
78 load_dst1_dst2 40, 48, 56, 64
79 sub w3, w3, w0 // w3 = linesize - width (padding)
80.else
57 sub w3, w3, w0, lsl #2 // w3 = linesize - width * 4 (padding)81 sub w3, w3, w0, lsl #2 // w3 = linesize - width * 4 (padding)
82.endif
58 sub w5, w5, w0 // w5 = linesizeY - width (paddingY)83 sub w5, w5, w0 // w5 = linesizeY - width (paddingY)
59 sub w7, w7, w0, lsr #1 // w7 = linesizeU - width / 2 (paddingU)84 sub w7, w7, w0, lsr #1 // w7 = linesizeU - width / 2 (paddingU)
60 sub w14, w14, w0, lsr #1 // w14 = linesizeV - width / 2 (paddingV)85 sub w14, w14, w0, lsr #1 // w14 = linesizeV - width / 2 (paddingV)
@@ -62,7 +87,7 @@ · 1 unmodified line
62 neg w11, w1187 neg w11, w11
63.endm88.endm
64 89
65.macro load_args_yuv422p90.macro load_args_yuv422p ofmt
66 ldr x13, [sp] // srcV91 ldr x13, [sp] // srcV
67 ldr w14, [sp, #8] // linesizeV92 ldr w14, [sp, #8] // linesizeV
68 ldr x8, [sp, #16] // table93 ldr x8, [sp, #16] // table
@@ -70,7 +95,12 @@ · 1 unmodified line
70 ld1 {v1.1d}, [x8]95 ld1 {v1.1d}, [x8]
71 dup v0.8h, w1096 dup v0.8h, w10
72 dup v3.8h, w997 dup v3.8h, w9
98.ifc \ofmt,gbrp
99 load_dst1_dst2 40, 48, 56, 64
100 sub w3, w3, w0 // w3 = linesize - width (padding)
101.else
73 sub w3, w3, w0, lsl #2 // w3 = linesize - width * 4 (padding)102 sub w3, w3, w0, lsl #2 // w3 = linesize - width * 4 (padding)
103.endif
74 sub w5, w5, w0 // w5 = linesizeY - width (paddingY)104 sub w5, w5, w0 // w5 = linesizeY - width (paddingY)
75 sub w7, w7, w0, lsr #1 // w7 = linesizeU - width / 2 (paddingU)105 sub w7, w7, w0, lsr #1 // w7 = linesizeU - width / 2 (paddingU)
76 sub w14, w14, w0, lsr #1 // w14 = linesizeV - width / 2 (paddingV)106 sub w14, w14, w0, lsr #1 // w14 = linesizeV - width / 2 (paddingV)
@@ -100,9 +130,9 @@ · 23 unmodified lines
100.endm130.endm
101 131
102.macro increment_nv12132.macro increment_nv12
103 ands w15, w1, #1133 ands w17, w1, #1
104 csel w16, w7, w11, ne // incC = (h & 1) ? paddincC : -width134 csel w17, w7, w11, ne // incC = (h & 1) ? paddincC : -width
105 add x6, x6, w16, sxtw // srcC += incC135 add x6, x6, w17, sxtw // srcC += incC
106.endm136.endm
107 137
108.macro increment_nv21138.macro increment_nv21
@@ -110,10 +140,10 @@ · 1 unmodified line
110.endm140.endm
111 141
112.macro increment_yuv420p142.macro increment_yuv420p
113 ands w15, w1, #1143 ands w17, w1, #1
114 csel w16, w7, w11, ne // incU = (h & 1) ? paddincU : -width/2144 csel w17, w7, w11, ne // incU = (h & 1) ? paddincU : -width/2
145 add x6, x6, w17, sxtw // srcU += incU
115 csel w17, w14, w11, ne // incV = (h & 1) ? paddincV : -width/2146 csel w17, w14, w11, ne // incV = (h & 1) ? paddincV : -width/2
116 add x6, x6, w16, sxtw // srcU += incU
117 add x13, x13, w17, sxtw // srcV += incV147 add x13, x13, w17, sxtw // srcV += incV
118.endm148.endm
119 149
@@ -122,7 +152,7 @@ · 2 unmodified lines
122 add x13, x13, w14, sxtw // srcV += incV152 add x13, x13, w14, sxtw // srcV += incV
123.endm153.endm
124 154
125.macro compute_rgba r1 g1 b1 a1 r2 g2 b2 a2155.macro compute_rgb r1 g1 b1 r2 g2 b2
126 add v20.8h, v26.8h, v20.8h // Y1 + R1156 add v20.8h, v26.8h, v20.8h // Y1 + R1
127 add v21.8h, v27.8h, v21.8h // Y2 + R2157 add v21.8h, v27.8h, v21.8h // Y2 + R2
128 add v22.8h, v26.8h, v22.8h // Y1 + G1158 add v22.8h, v26.8h, v22.8h // Y1 + G1
@@ -135,13 +165,18 @@ · 6 unmodified lines
135 sqrshrun \g2, v23.8h, #1 // clip_u8((Y2 + G1) >> 1)165 sqrshrun \g2, v23.8h, #1 // clip_u8((Y2 + G1) >> 1)
136 sqrshrun \b1, v24.8h, #1 // clip_u8((Y1 + B1) >> 1)166 sqrshrun \b1, v24.8h, #1 // clip_u8((Y1 + B1) >> 1)
137 sqrshrun \b2, v25.8h, #1 // clip_u8((Y2 + B1) >> 1)167 sqrshrun \b2, v25.8h, #1 // clip_u8((Y2 + B1) >> 1)
168.endm
169
170.macro compute_rgba r1 g1 b1 a1 r2 g2 b2 a2
171 compute_rgb \r1, \g1, \b1, \r2, \g2, \b2
138 movi \a1, #255172 movi \a1, #255
139 movi \a2, #255173 movi \a2, #255
140.endm174.endm
141 175
142.macro declare_func ifmt ofmt176.macro declare_func ifmt ofmt
143function ff_\ifmt\()_to_\ofmt\()_neon, export=1177function ff_\ifmt\()_to_\ofmt\()_neon, export=1
144 load_args_\ifmt178 load_args_\ifmt \ofmt
179
145 mov w9, w1180 mov w9, w1
1461:1811:
147 mov w8, w0 // w8 = width182 mov w8, w0 // w8 = width
@@ -185,11 +220,22 @@ function ff_\ifmt\()_to_\ofmt\()_neon, export=1 · 37 unmodified lines
185 compute_rgba v6.8b,v5.8b,v4.8b,v7.8b, v18.8b,v17.8b,v16.8b,v19.8b220 compute_rgba v6.8b,v5.8b,v4.8b,v7.8b, v18.8b,v17.8b,v16.8b,v19.8b
186.endif221.endif
187 222
223.ifc \ofmt,gbrp
224 compute_rgb v18.8b,v4.8b,v6.8b, v19.8b,v5.8b,v7.8b
225 st1 { v4.8b, v5.8b }, [x2], #16
226 st1 { v6.8b, v7.8b }, [x10], #16
227 st1 { v18.8b, v19.8b }, [x15], #16
228.else
188 st4 { v4.8b, v5.8b, v6.8b, v7.8b}, [x2], #32229 st4 { v4.8b, v5.8b, v6.8b, v7.8b}, [x2], #32
189 st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [x2], #32230 st4 {v16.8b,v17.8b,v18.8b,v19.8b}, [x2], #32
231.endif
190 subs w8, w8, #16 // width -= 16232 subs w8, w8, #16 // width -= 16
191 b.gt 2b233 b.gt 2b
192 add x2, x2, w3, sxtw // dst += padding234 add x2, x2, w3, sxtw // dst += padding
235.ifc \ofmt,gbrp
236 add x10, x10, w12, sxtw // dst1 += padding1
237 add x15, x15, w16, sxtw // dst2 += padding2
238.endif
193 add x4, x4, w5, sxtw // srcY += paddingY239 add x4, x4, w5, sxtw // srcY += paddingY
194 increment_\ifmt240 increment_\ifmt
195 subs w1, w1, #1 // height -= 1241 subs w1, w1, #1 // height -= 1
@@ -204,6 +250,7 @@ endfunc · 8 unmodified lines
204 declare_func \ifmt, rgba250 declare_func \ifmt, rgba
205 declare_func \ifmt, abgr251 declare_func \ifmt, abgr
206 declare_func \ifmt, bgra252 declare_func \ifmt, bgra
253 declare_func \ifmt, gbrp
207.endm254.endm
208 255
209declare_rgb_funcs nv12256declare_rgb_funcs nv12

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