History

swscale/aarch64/rgb2rgb: add neon implementation for rgb24toyv12

A55 A76 rgb24toyv12_16_200_c: 36890.6 17275.5 rgb24toyv12_16_200_neon: 12460.1 ( 2.96x) 5360.8 ( 3.22x) rgb24toyv12_128_60_c: 83205.1 39884.8 rgb24toyv12_128_60_neon: 27468.4 ( 3.03x) 13552.5 ( 2.94x) rgb24toyv12_512_16_c: 88111.6 42346.8 rgb24toyv12_512_16_neon: 29126.6 ( 3.03x) 14411.2 ( 2.94x) rgb24toyv12_1920_4_c: 82068.1 39620.0 rgb24toyv12_1920_4_neon: 27011.6 ( 3.04x) 13492.2 ( 2.94x)

Ramiro Polla committed 2 years ago

Commit c0666d81 parent caaec2e2 files · +164 −0Browse files

Unified · Split

2 files
  1. libswscale/aarch64/rgb2rgb.c +4 −0
  2. libswscale/aarch64/rgb2rgb_neon.S +160 −0
libswscale/aarch64/rgb2rgb.c+4−0
@@ -27,6 +27,9 @@ · 26 unmodified lines
27#include "libswscale/swscale.h"27#include "libswscale/swscale.h"
28#include "libswscale/swscale_internal.h"28#include "libswscale/swscale_internal.h"
29 29
30void ff_rgb24toyv12_neon(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
31 uint8_t *vdst, int width, int height, int lumStride,
32 int chromStride, int srcStride, int32_t *rgb2yuv);
30void ff_interleave_bytes_neon(const uint8_t *src1, const uint8_t *src2,33void ff_interleave_bytes_neon(const uint8_t *src1, const uint8_t *src2,
31 uint8_t *dest, int width, int height,34 uint8_t *dest, int width, int height,
32 int src1Stride, int src2Stride, int dstStride);35 int src1Stride, int src2Stride, int dstStride);
@@ -39,6 +42,7 @@ av_cold void rgb2rgb_init_aarch64(void) · 6 unmodified lines
39 int cpu_flags = av_get_cpu_flags();42 int cpu_flags = av_get_cpu_flags();
40 43
41 if (have_neon(cpu_flags)) {44 if (have_neon(cpu_flags)) {
45 ff_rgb24toyv12 = ff_rgb24toyv12_neon;
42 interleaveBytes = ff_interleave_bytes_neon;46 interleaveBytes = ff_interleave_bytes_neon;
43 deinterleaveBytes = ff_deinterleave_bytes_neon;47 deinterleaveBytes = ff_deinterleave_bytes_neon;
44 }48 }
libswscale/aarch64/rgb2rgb_neon.S+160−0
@@ -1,5 +1,6 @@
1/*1/*
2 * Copyright (c) 2020 Martin Storsjo2 * Copyright (c) 2020 Martin Storsjo
3 * Copyright (c) 2024 Ramiro Polla
3 *4 *
4 * This file is part of FFmpeg.5 * This file is part of FFmpeg.
5 *6 *
@@ -20,6 +21,165 @@ · 14 unmodified lines
20 21
21#include "libavutil/aarch64/asm.S"22#include "libavutil/aarch64/asm.S"
22 23
24#define RGB2YUV_COEFFS 16*4+16*32
25#define BY v0.h[0]
26#define GY v0.h[1]
27#define RY v0.h[2]
28#define BU v1.h[0]
29#define GU v1.h[1]
30#define RU v1.h[2]
31#define BV v2.h[0]
32#define GV v2.h[1]
33#define RV v2.h[2]
34#define Y_OFFSET v22
35#define UV_OFFSET v23
36
37// convert rgb to 16-bit y, u, or v
38// uses v3 and v4
39.macro rgbconv16 dst, b, g, r, bc, gc, rc
40 smull v3.4s, \b\().4h, \bc
41 smlal v3.4s, \g\().4h, \gc
42 smlal v3.4s, \r\().4h, \rc
43 smull2 v4.4s, \b\().8h, \bc
44 smlal2 v4.4s, \g\().8h, \gc
45 smlal2 v4.4s, \r\().8h, \rc // v3:v4 = b * bc + g * gc + r * rc (32-bit)
46 shrn \dst\().4h, v3.4s, #7
47 shrn2 \dst\().8h, v4.4s, #7 // dst = b * bc + g * gc + r * rc (16-bit)
48.endm
49
50// void ff_rgb24toyv12_neon(const uint8_t *src, uint8_t *ydst, uint8_t *udst,
51// uint8_t *vdst, int width, int height, int lumStride,
52// int chromStride, int srcStride, int32_t *rgb2yuv);
53function ff_rgb24toyv12_neon, export=1
54// x0 const uint8_t *src
55// x1 uint8_t *ydst
56// x2 uint8_t *udst
57// x3 uint8_t *vdst
58// w4 int width
59// w5 int height
60// w6 int lumStride
61// w7 int chromStride
62 ldrsw x14, [sp]
63 ldr x15, [sp, #8]
64// x14 int srcStride
65// x15 int32_t *rgb2yuv
66
67 // extend width and stride parameters
68 uxtw x4, w4
69 sxtw x6, w6
70 sxtw x7, w7
71
72 // src1 = x0
73 // src2 = x10
74 add x10, x0, x14 // x10 = src + srcStride
75 lsl x14, x14, #1 // srcStride *= 2
76 add x11, x4, x4, lsl #1 // x11 = 3 * width
77 sub x14, x14, x11 // srcPadding = (2 * srcStride) - (3 * width)
78
79 // ydst1 = x1
80 // ydst2 = x11
81 add x11, x1, x6 // x11 = ydst + lumStride
82 lsl x6, x6, #1 // lumStride *= 2
83 sub x6, x6, x4 // lumPadding = (2 * lumStride) - width
84
85 sub x7, x7, x4, lsr #1 // chromPadding = chromStride - (width / 2)
86
87 // load rgb2yuv coefficients into v0, v1, and v2
88 add x15, x15, #RGB2YUV_COEFFS
89 ld1 {v0.8h-v2.8h}, [x15] // load 24 values
90
91 // load offset constants
92 movi Y_OFFSET.8h, #0x10, lsl #8
93 movi UV_OFFSET.8h, #0x80, lsl #8
94
951:
96 mov w15, w4 // w15 = width
97
982:
99 // load first line
100 ld3 {v26.16b, v27.16b, v28.16b}, [x0], #48
101
102 // widen first line to 16-bit
103 uxtl v16.8h, v26.8b // v16 = B11
104 uxtl v17.8h, v27.8b // v17 = G11
105 uxtl v18.8h, v28.8b // v18 = R11
106 uxtl2 v19.8h, v26.16b // v19 = B12
107 uxtl2 v20.8h, v27.16b // v20 = G12
108 uxtl2 v21.8h, v28.16b // v21 = R12
109
110 // calculate Y values for first line
111 rgbconv16 v24, v16, v17, v18, BY, GY, RY // v24 = Y11
112 rgbconv16 v25, v19, v20, v21, BY, GY, RY // v25 = Y12
113
114 // load second line
115 ld3 {v26.16b, v27.16b, v28.16b}, [x10], #48
116
117 // pairwise add and save rgb values to calculate average
118 addp v5.8h, v16.8h, v19.8h
119 addp v6.8h, v17.8h, v20.8h
120 addp v7.8h, v18.8h, v21.8h
121
122 // widen second line to 16-bit
123 uxtl v16.8h, v26.8b // v16 = B21
124 uxtl v17.8h, v27.8b // v17 = G21
125 uxtl v18.8h, v28.8b // v18 = R21
126 uxtl2 v19.8h, v26.16b // v19 = B22
127 uxtl2 v20.8h, v27.16b // v20 = G22
128 uxtl2 v21.8h, v28.16b // v21 = R22
129
130 // calculate Y values for second line
131 rgbconv16 v26, v16, v17, v18, BY, GY, RY // v26 = Y21
132 rgbconv16 v27, v19, v20, v21, BY, GY, RY // v27 = Y22
133
134 // pairwise add rgb values to calculate average
135 addp v16.8h, v16.8h, v19.8h
136 addp v17.8h, v17.8h, v20.8h
137 addp v18.8h, v18.8h, v21.8h
138
139 // calculate average
140 add v16.8h, v16.8h, v5.8h
141 add v17.8h, v17.8h, v6.8h
142 add v18.8h, v18.8h, v7.8h
143 ushr v16.8h, v16.8h, #2
144 ushr v17.8h, v17.8h, #2
145 ushr v18.8h, v18.8h, #2
146
147 // calculate U and V values
148 rgbconv16 v28, v16, v17, v18, BU, GU, RU // v28 = U
149 rgbconv16 v29, v16, v17, v18, BV, GV, RV // v29 = V
150
151 // add offsets and narrow all values
152 addhn v24.8b, v24.8h, Y_OFFSET.8h
153 addhn v25.8b, v25.8h, Y_OFFSET.8h
154 addhn v26.8b, v26.8h, Y_OFFSET.8h
155 addhn v27.8b, v27.8h, Y_OFFSET.8h
156 addhn v28.8b, v28.8h, UV_OFFSET.8h
157 addhn v29.8b, v29.8h, UV_OFFSET.8h
158
159 subs w15, w15, #16
160
161 // store output
162 st1 {v24.8b, v25.8b}, [x1], #16 // store ydst1
163 st1 {v26.8b, v27.8b}, [x11], #16 // store ydst2
164 st1 {v28.8b}, [x2], #8 // store udst
165 st1 {v29.8b}, [x3], #8 // store vdst
166
167 b.gt 2b
168
169 subs w5, w5, #2
170
171 // row += 2
172 add x0, x0, x14 // src1 += srcPadding
173 add x10, x10, x14 // src2 += srcPadding
174 add x1, x1, x6 // ydst1 += lumPadding
175 add x11, x11, x6 // ydst2 += lumPadding
176 add x2, x2, x7 // udst += chromPadding
177 add x3, x3, x7 // vdst += chromPadding
178 b.gt 1b
179
180 ret
181endfunc
182
23// void ff_interleave_bytes_neon(const uint8_t *src1, const uint8_t *src2,183// void ff_interleave_bytes_neon(const uint8_t *src1, const uint8_t *src2,
24// uint8_t *dest, int width, int height,184// uint8_t *dest, int width, int height,
25// int src1Stride, int src2Stride, int dstStride);185// int src1Stride, int src2Stride, int dstStride);

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