1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Copyright (c) 2016 Clément Bœsch <clement stupeflix.com>
3cabdff1aSopenharmony_ci *
4cabdff1aSopenharmony_ci * This file is part of FFmpeg.
5cabdff1aSopenharmony_ci *
6cabdff1aSopenharmony_ci * FFmpeg is free software; you can redistribute it and/or
7cabdff1aSopenharmony_ci * modify it under the terms of the GNU Lesser General Public
8cabdff1aSopenharmony_ci * License as published by the Free Software Foundation; either
9cabdff1aSopenharmony_ci * version 2.1 of the License, or (at your option) any later version.
10cabdff1aSopenharmony_ci *
11cabdff1aSopenharmony_ci * FFmpeg is distributed in the hope that it will be useful,
12cabdff1aSopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of
13cabdff1aSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14cabdff1aSopenharmony_ci * Lesser General Public License for more details.
15cabdff1aSopenharmony_ci *
16cabdff1aSopenharmony_ci * You should have received a copy of the GNU Lesser General Public
17cabdff1aSopenharmony_ci * License along with FFmpeg; if not, write to the Free Software
18cabdff1aSopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19cabdff1aSopenharmony_ci */
20cabdff1aSopenharmony_ci
21cabdff1aSopenharmony_ci#include "libavutil/aarch64/asm.S"
22cabdff1aSopenharmony_ci
23cabdff1aSopenharmony_cifunction ff_yuv2planeX_8_neon, export=1
24cabdff1aSopenharmony_ci        ld1                 {v0.8B}, [x5]                   // load 8x8-bit dither
25cabdff1aSopenharmony_ci        cbz                 w6, 1f                          // check if offsetting present
26cabdff1aSopenharmony_ci        ext                 v0.8B, v0.8B, v0.8B, #3         // honor offsetting which can be 0 or 3 only
27cabdff1aSopenharmony_ci1:      uxtl                v0.8H, v0.8B                    // extend dither to 16-bit
28cabdff1aSopenharmony_ci        ushll               v1.4S, v0.4H, #12               // extend dither to 32-bit with left shift by 12 (part 1)
29cabdff1aSopenharmony_ci        ushll2              v2.4S, v0.8H, #12               // extend dither to 32-bit with left shift by 12 (part 2)
30cabdff1aSopenharmony_ci        mov                 x7, #0                          // i = 0
31cabdff1aSopenharmony_ci2:      mov                 v3.16B, v1.16B                  // initialize accumulator part 1 with dithering value
32cabdff1aSopenharmony_ci        mov                 v4.16B, v2.16B                  // initialize accumulator part 2 with dithering value
33cabdff1aSopenharmony_ci        mov                 w8, w1                          // tmpfilterSize = filterSize
34cabdff1aSopenharmony_ci        mov                 x9, x2                          // srcp    = src
35cabdff1aSopenharmony_ci        mov                 x10, x0                         // filterp = filter
36cabdff1aSopenharmony_ci3:      ldp                 x11, x12, [x9], #16             // get 2 pointers: src[j] and src[j+1]
37cabdff1aSopenharmony_ci        add                 x11, x11, x7, lsl #1            // &src[j  ][i]
38cabdff1aSopenharmony_ci        add                 x12, x12, x7, lsl #1            // &src[j+1][i]
39cabdff1aSopenharmony_ci        ld1                 {v5.8H}, [x11]                  // read 8x16-bit @ src[j  ][i + {0..7}]: A,B,C,D,E,F,G,H
40cabdff1aSopenharmony_ci        ld1                 {v6.8H}, [x12]                  // read 8x16-bit @ src[j+1][i + {0..7}]: I,J,K,L,M,N,O,P
41cabdff1aSopenharmony_ci        ld1r                {v7.8H}, [x10], #2              // read 1x16-bit coeff X at filter[j  ] and duplicate across lanes
42cabdff1aSopenharmony_ci        ld1r                {v16.8H}, [x10], #2             // read 1x16-bit coeff Y at filter[j+1] and duplicate across lanes
43cabdff1aSopenharmony_ci        smlal               v3.4S, v5.4H, v7.4H             // val0 += {A,B,C,D} * X
44cabdff1aSopenharmony_ci        smlal2              v4.4S, v5.8H, v7.8H             // val1 += {E,F,G,H} * X
45cabdff1aSopenharmony_ci        smlal               v3.4S, v6.4H, v16.4H            // val0 += {I,J,K,L} * Y
46cabdff1aSopenharmony_ci        smlal2              v4.4S, v6.8H, v16.8H            // val1 += {M,N,O,P} * Y
47cabdff1aSopenharmony_ci        subs                w8, w8, #2                      // tmpfilterSize -= 2
48cabdff1aSopenharmony_ci        b.gt                3b                              // loop until filterSize consumed
49cabdff1aSopenharmony_ci
50cabdff1aSopenharmony_ci        sqshrun             v3.4h, v3.4s, #16               // clip16(val0>>16)
51cabdff1aSopenharmony_ci        sqshrun2            v3.8h, v4.4s, #16               // clip16(val1>>16)
52cabdff1aSopenharmony_ci        uqshrn              v3.8b, v3.8h, #3                // clip8(val>>19)
53cabdff1aSopenharmony_ci        st1                 {v3.8b}, [x3], #8               // write to destination
54cabdff1aSopenharmony_ci        subs                w4, w4, #8                      // dstW -= 8
55cabdff1aSopenharmony_ci        add                 x7, x7, #8                      // i += 8
56cabdff1aSopenharmony_ci        b.gt                2b                              // loop until width consumed
57cabdff1aSopenharmony_ci        ret
58cabdff1aSopenharmony_ciendfunc
59