6e6143a635ddba792065604d709cd628e930f0a8
[ffmpeg.git] / libswscale / arm / yuv2rgb_neon.S
1 /*
2  * Copyright (c) 2015 Matthieu Bouron <matthieu.bouron stupeflix.com>
3  * Copyright (c) 2015 Clément Bœsch <clement stupeflix.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include "libavutil/arm/asm.S"
23
24
25 .macro compute_premult half_u1, half_u2, half_v1, half_v2
26     vmov                d2, \half_u1                                   @ copy left q14 to left q1
27     vmov                d3, \half_u1                                   @ copy left q14 to right q1
28     vmov                d4, \half_u2                                   @ copy right q14 to left q2
29     vmov                d5, \half_u2                                   @ copy right q14 to right q2
30
31     vmov                d6, \half_v1                                   @ copy left q15 to left q3
32     vmov                d7, \half_v1                                   @ copy left q15 to right q3
33     vmov                d8, \half_v2                                   @ copy right q15 to left q4
34     vmov                d9, \half_v2                                   @ copy right q15 to right q4
35
36     vzip.16             d2, d3                                         @ U1U1U2U2U3U3U4U4
37     vzip.16             d4, d5                                         @ U5U5U6U6U7U7U8U8
38
39     vzip.16             d6, d7                                         @ V1V1V2V2V3V3V4V4
40     vzip.16             d8, d9                                         @ V5V5V6V6V7V7V8V8
41
42     vmul.s16            q8,  q3, d1[0]                                 @  V * v2r             (left,  red)
43     vmul.s16            q9,  q4, d1[0]                                 @  V * v2r             (right, red)
44     vmul.s16            q10, q1, d1[1]                                 @  U * u2g
45     vmul.s16            q11, q2, d1[1]                                 @  U * u2g
46     vmla.s16            q10, q3, d1[2]                                 @  U * u2g + V * v2g   (left,  green)
47     vmla.s16            q11, q4, d1[2]                                 @  U * u2g + V * v2g   (right, green)
48     vmul.s16            q12, q1, d1[3]                                 @  U * u2b             (left,  blue)
49     vmul.s16            q13, q2, d1[3]                                 @  U * u2b             (right, blue)
50 .endm
51
52 .macro compute_color dst_comp1 dst_comp2 pre1 pre2
53     vadd.s16            q1, q14, \pre1
54     vadd.s16            q2, q15, \pre2
55     vqrshrun.s16        \dst_comp1, q1, #6
56     vqrshrun.s16        \dst_comp2, q2, #6
57 .endm
58
59 .macro compute_rgba r1 r2 g1 g2 b1 b2 a1 a2
60     compute_color       \r1, \r2, q8,  q9
61     compute_color       \g1, \g2, q10, q11
62     compute_color       \b1, \b2, q12, q13
63     vmov.u8             \a1, #255
64     vmov.u8             \a2, #255
65 .endm
66
67 .macro compute_16px dst y0 y1 ofmt
68     vmovl.u8            q14, \y0                                       @ 8px of y
69     vmovl.u8            q15, \y1                                       @ 8px of y
70
71     vdup.16             q5, r9                                         @ q5  = y_offset
72     vmov                d14, d0                                        @ q7  = y_coeff
73     vmov                d15, d0                                        @ q7  = y_coeff
74
75     vsub.s16            q14, q5
76     vsub.s16            q15, q5
77
78     vmul.s16            q14, q7                                        @ q14 = (srcY - y_offset) * y_coeff (left)
79     vmul.s16            q15, q7                                        @ q15 = (srcY - y_offset) * y_coeff (right)
80
81
82 .ifc \ofmt,argb
83     compute_rgba        d7, d11, d8, d12, d9, d13, d6, d10
84 .endif
85
86 .ifc \ofmt,rgba
87     compute_rgba        d6, d10, d7, d11, d8, d12, d9, d13
88 .endif
89
90 .ifc \ofmt,abgr
91     compute_rgba        d9, d13, d8, d12, d7, d11, d6, d10
92 .endif
93
94 .ifc \ofmt,bgra
95     compute_rgba        d8, d12, d7, d11, d6, d10, d9, d13
96 .endif
97     vst4.8              {q3, q4}, [\dst,:128]!
98     vst4.8              {q5, q6}, [\dst,:128]!
99
100 .endm
101
102 .macro process_1l_16px ofmt
103     compute_premult     d28, d29, d30, d31
104     vld1.8              {q7}, [r4]!
105     compute_16px        r2, d14, d15, \ofmt
106 .endm
107
108 .macro process_2l_16px ofmt
109     compute_premult     d28, d29, d30, d31
110
111     vld1.8              {q7}, [r4]!                                    @ first line of luma
112     compute_16px        r2, d14, d15, \ofmt
113
114     vld1.8              {q7}, [r12]!                                   @ second line of luma
115     compute_16px        r11, d14, d15, \ofmt
116 .endm
117
118 .macro load_args_nvx
119     push                {r4-r12, lr}
120     vpush               {q4-q7}
121     ldr                 r4, [sp, #104]                                 @ r4  = srcY
122     ldr                 r5, [sp, #108]                                 @ r5  = linesizeY
123     ldr                 r6, [sp, #112]                                 @ r6  = srcC
124     ldr                 r7, [sp, #116]                                 @ r7  = linesizeC
125     ldr                 r8, [sp, #120]                                 @ r8  = table
126     ldr                 r9, [sp, #124]                                 @ r9  = y_offset
127     ldr                 r10,[sp, #128]                                 @ r10 = y_coeff
128     vdup.16             d0, r10                                        @ d0  = y_coeff
129     vld1.16             {d1}, [r8]                                     @ d1  = *table
130     add                 r11, r2, r3                                    @ r11 = dst + linesize (dst2)
131     add                 r12, r4, r5                                    @ r12 = srcY + linesizeY (srcY2)
132     lsl                 r3, r3, #1
133     lsl                 r5, r5, #1
134     lsl                 r8, r0, #2
135     sub                 r3, r3, r8                                     @ r3 = linesize  * 2 - width * 4 (padding)
136     sub                 r5, r5, r0                                     @ r5 = linesizeY * 2 - width     (paddingY)
137     sub                 r7, r7, r0                                     @ r7 = linesizeC     - width     (paddingC)
138 .endm
139
140 .macro load_args_yuv420p
141     push                {r4-r12, lr}
142     vpush               {q4-q7}
143     ldr                 r4, [sp, #104]                                 @ r4  = srcY
144     ldr                 r5, [sp, #108]                                 @ r5  = linesizeY
145     ldr                 r6, [sp, #112]                                 @ r6  = srcU
146     ldr                 r8, [sp, #128]                                 @ r8  = table
147     ldr                 r9, [sp, #132]                                 @ r9  = y_offset
148     ldr                 r10,[sp, #136]                                 @ r10 = y_coeff
149     vdup.16             d0, r10                                        @ d0  = y_coeff
150     vld1.16             {d1}, [r8]                                     @ d1  = *table
151     add                 r11, r2, r3                                    @ r11 = dst + linesize (dst2)
152     add                 r12, r4, r5                                    @ r12 = srcY + linesizeY (srcY2)
153     lsl                 r3, r3, #1
154     lsl                 r5, r5, #1
155     lsl                 r8, r0, #2
156     sub                 r3, r3, r8                                     @ r3 = linesize  * 2 - width * 4 (padding)
157     sub                 r5, r5, r0                                     @ r5 = linesizeY * 2 - width     (paddingY)
158     ldr                 r10,[sp, #120]                                 @ r10 = srcV
159 .endm
160
161 .macro load_args_yuv422p
162     push                {r4-r12, lr}
163     vpush               {q4-q7}
164     ldr                 r4, [sp, #104]                                 @ r4  = srcY
165     ldr                 r5, [sp, #108]                                 @ r5  = linesizeY
166     ldr                 r6, [sp, #112]                                 @ r6  = srcU
167     ldr                 r7, [sp, #116]                                 @ r7  = linesizeU
168     ldr                 r12,[sp, #124]                                 @ r12 = linesizeV
169     ldr                 r8, [sp, #128]                                 @ r8  = table
170     ldr                 r9, [sp, #132]                                 @ r9  = y_offset
171     ldr                 r10,[sp, #136]                                 @ r10 = y_coeff
172     vdup.16             d0, r10                                        @ d0  = y_coeff
173     vld1.16             {d1}, [r8]                                     @ d1  = *table
174     add                 r11, r2, r3                                    @ r11 = dst + linesize (dst2)
175     lsl                 r8, r0, #2
176     sub                 r3, r3, r8                                     @ r3  = linesize  - width * 4 (padding)
177     sub                 r5, r5, r0                                     @ r5  = linesizeY - width     (paddingY)
178     sub                 r7, r7, r0, lsr #1                             @ r7  = linesizeU - width / 2 (paddingU)
179     sub                 r12,r12,r0, lsr #1                             @ r12 = linesizeV - width / 2 (paddingV)
180     ldr                 r10,[sp, #120]                                 @ r10 = srcV
181 .endm
182
183 .macro declare_func ifmt ofmt
184 function ff_\ifmt\()_to_\ofmt\()_neon, export=1
185
186 .ifc \ifmt,nv12
187     load_args_nvx
188 .endif
189
190 .ifc \ifmt,nv21
191     load_args_nvx
192 .endif
193
194 .ifc \ifmt,yuv420p
195     load_args_yuv420p
196 .endif
197
198
199 .ifc \ifmt,yuv422p
200     load_args_yuv422p
201 .endif
202
203 1:
204     mov                 r8, r0                                         @ r8 = width
205 2:
206     pld [r6, #64*3]
207     pld [r4, #64*3]
208
209     vmov.i8             d10, #128
210
211 .ifc \ifmt,nv12
212     pld [r12, #64*3]
213
214     vld2.8              {d2, d3}, [r6]!                                @ q1: interleaved chroma line
215     vsubl.u8            q14, d2, d10                                   @ q14 = U - 128
216     vsubl.u8            q15, d3, d10                                   @ q15 = V - 128
217
218     process_2l_16px \ofmt
219 .endif
220
221 .ifc \ifmt,nv21
222     pld [r12, #64*3]
223
224     vld2.8              {d2, d3}, [r6]!                                @ q1: interleaved chroma line
225     vsubl.u8            q14, d3, d10                                   @ q14 = U - 128
226     vsubl.u8            q15, d2, d10                                   @ q15 = V - 128
227
228     process_2l_16px \ofmt
229 .endif
230
231 .ifc \ifmt,yuv420p
232     pld [r10, #64*3]
233     pld [r12, #64*3]
234
235     vld1.8              d2, [r6]!                                      @ d2: chroma red line
236     vld1.8              d3, [r10]!                                     @ d3: chroma blue line
237     vsubl.u8            q14, d2, d10                                   @ q14 = U - 128
238     vsubl.u8            q15, d3, d10                                   @ q15 = V - 128
239
240     process_2l_16px \ofmt
241 .endif
242
243 .ifc \ifmt,yuv422p
244     pld [r10, #64*3]
245
246     vld1.8              d2, [r6]!                                      @ d2: chroma red line
247     vld1.8              d3, [r10]!                                     @ d3: chroma blue line
248     vsubl.u8            q14, d2, d10                                   @ q14 = U - 128
249     vsubl.u8            q15, d3, d10                                   @ q15 = V - 128
250
251     process_1l_16px \ofmt
252 .endif
253
254     subs                r8, r8, #16                                    @ width -= 16
255     bgt                 2b
256
257     add                 r2, r2, r3                                     @ dst   += padding
258     add                 r4, r4, r5                                     @ srcY  += paddingY
259
260 .ifc \ifmt,nv12
261     add                 r11, r11, r3                                   @ dst2  += padding
262     add                 r12, r12, r5                                   @ srcY2 += paddingY
263
264     add                 r6, r6, r7                                     @ srcC  += paddingC
265
266     subs                r1, r1, #2                                     @ height -= 2
267 .endif
268
269 .ifc \ifmt,nv21
270     add                 r11, r11, r3                                   @ dst2  += padding
271     add                 r12, r12, r5                                   @ srcY2 += paddingY
272
273     add                 r6, r6, r7                                     @ srcC  += paddingC
274     subs                r1, r1, #2                                     @ height -= 2
275 .endif
276
277 .ifc \ifmt,yuv420p
278     add                 r11, r11, r3                                   @ dst2  += padding
279     add                 r12, r12, r5                                   @ srcY2 += paddingY
280
281     ldr                 r7, [sp, #116]                                 @ r7     = linesizeU
282     sub                 r7, r7, r0, lsr #1                             @ r7     = linesizeU - width / 2 (paddingU)
283     add                 r6, r6, r7                                     @ srcU  += paddingU
284
285     ldr                 r7, [sp, #124]                                 @ r7     = linesizeV
286     sub                 r7, r7, r0, lsr #1                             @ r7     = linesizeV - width / 2 (paddingV)
287     add                 r10, r10, r7                                   @ srcV  += paddingV
288
289     subs                r1, r1, #2                                     @ height -= 2
290 .endif
291
292 .ifc \ifmt,yuv422p
293     add                 r6, r6, r7                                     @ srcU  += paddingU
294     add                 r10,r10,r12                                    @ srcV  += paddingV
295
296     subs                r1, r1, #1                                     @ height -= 1
297 .endif
298
299     bgt                 1b
300
301     vpop                {q4-q7}
302     pop                 {r4-r12, lr}
303     mov                 pc, lr
304 endfunc
305 .endm
306
307 .macro declare_rgb_funcs ifmt
308     declare_func \ifmt, argb
309     declare_func \ifmt, rgba
310     declare_func \ifmt, abgr
311     declare_func \ifmt, bgra
312 .endm
313
314 declare_rgb_funcs nv12
315 declare_rgb_funcs nv21
316 declare_rgb_funcs yuv420p
317 declare_rgb_funcs yuv422p