1cabdff1aSopenharmony_ci/*
2cabdff1aSopenharmony_ci * Copyright (c) 2015 Manojkumar Bhosale (Manojkumar.Bhosale@imgtec.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/mips/generic_macros_msa.h"
22cabdff1aSopenharmony_ci#include "libavcodec/mips/hevcdsp_mips.h"
23cabdff1aSopenharmony_ci
24cabdff1aSopenharmony_cistatic const int16_t gt8x8_cnst[16] __attribute__ ((aligned (64))) = {
25cabdff1aSopenharmony_ci    64, 64, 83, 36, 89, 50, 18, 75, 64, -64, 36, -83, 75, -89, -50, -18
26cabdff1aSopenharmony_ci};
27cabdff1aSopenharmony_ci
28cabdff1aSopenharmony_cistatic const int16_t gt16x16_cnst[64] __attribute__ ((aligned (64))) = {
29cabdff1aSopenharmony_ci    64, 83, 64, 36, 89, 75, 50, 18, 90, 80, 57, 25, 70, 87, 9, 43,
30cabdff1aSopenharmony_ci    64, 36, -64, -83, 75, -18, -89, -50, 87, 9, -80, -70, -43, 57, -25, -90,
31cabdff1aSopenharmony_ci    64, -36, -64, 83, 50, -89, 18, 75, 80, -70, -25, 90, -87, 9, 43, 57,
32cabdff1aSopenharmony_ci    64, -83, 64, -36, 18, -50, 75, -89, 70, -87, 90, -80, 9, -43, -57, 25
33cabdff1aSopenharmony_ci};
34cabdff1aSopenharmony_ci
35cabdff1aSopenharmony_cistatic const int16_t gt32x32_cnst0[256] __attribute__ ((aligned (64))) = {
36cabdff1aSopenharmony_ci    90, 90, 88, 85, 82, 78, 73, 67, 61, 54, 46, 38, 31, 22, 13, 4,
37cabdff1aSopenharmony_ci    90, 82, 67, 46, 22, -4, -31, -54, -73, -85, -90, -88, -78, -61, -38, -13,
38cabdff1aSopenharmony_ci    88, 67, 31, -13, -54, -82, -90, -78, -46, -4, 38, 73, 90, 85, 61, 22,
39cabdff1aSopenharmony_ci    85, 46, -13, -67, -90, -73, -22, 38, 82, 88, 54, -4, -61, -90, -78, -31,
40cabdff1aSopenharmony_ci    82, 22, -54, -90, -61, 13, 78, 85, 31, -46, -90, -67, 4, 73, 88, 38,
41cabdff1aSopenharmony_ci    78, -4, -82, -73, 13, 85, 67, -22, -88, -61, 31, 90, 54, -38, -90, -46,
42cabdff1aSopenharmony_ci    73, -31, -90, -22, 78, 67, -38, -90, -13, 82, 61, -46, -88, -4, 85, 54,
43cabdff1aSopenharmony_ci    67, -54, -78, 38, 85, -22, -90, 4, 90, 13, -88, -31, 82, 46, -73, -61,
44cabdff1aSopenharmony_ci    61, -73, -46, 82, 31, -88, -13, 90, -4, -90, 22, 85, -38, -78, 54, 67,
45cabdff1aSopenharmony_ci    54, -85, -4, 88, -46, -61, 82, 13, -90, 38, 67, -78, -22, 90, -31, -73,
46cabdff1aSopenharmony_ci    46, -90, 38, 54, -90, 31, 61, -88, 22, 67, -85, 13, 73, -82, 4, 78,
47cabdff1aSopenharmony_ci    38, -88, 73, -4, -67, 90, -46, -31, 85, -78, 13, 61, -90, 54, 22, -82,
48cabdff1aSopenharmony_ci    31, -78, 90, -61, 4, 54, -88, 82, -38, -22, 73, -90, 67, -13, -46, 85,
49cabdff1aSopenharmony_ci    22, -61, 85, -90, 73, -38, -4, 46, -78, 90, -82, 54, -13, -31, 67, -88,
50cabdff1aSopenharmony_ci    13, -38, 61, -78, 88, -90, 85, -73, 54, -31, 4, 22, -46, 67, -82, 90,
51cabdff1aSopenharmony_ci    4, -13, 22, -31, 38, -46, 54, -61, 67, -73, 78, -82, 85, -88, 90, -90
52cabdff1aSopenharmony_ci};
53cabdff1aSopenharmony_ci
54cabdff1aSopenharmony_cistatic const int16_t gt32x32_cnst1[64] __attribute__ ((aligned (64))) = {
55cabdff1aSopenharmony_ci    90, 87, 80, 70, 57, 43, 25, 9, 87, 57, 9, -43, -80, -90, -70, -25,
56cabdff1aSopenharmony_ci    80, 9, -70, -87, -25, 57, 90, 43, 70, -43, -87, 9, 90, 25, -80, -57,
57cabdff1aSopenharmony_ci    57, -80, -25, 90, -9, -87, 43, 70, 43, -90, 57, 25, -87, 70, 9, -80,
58cabdff1aSopenharmony_ci    25, -70, 90, -80, 43, 9, -57, 87, 9, -25, 43, -57, 70, -80, 87, -90
59cabdff1aSopenharmony_ci};
60cabdff1aSopenharmony_ci
61cabdff1aSopenharmony_cistatic const int16_t gt32x32_cnst2[16] __attribute__ ((aligned (64))) = {
62cabdff1aSopenharmony_ci    89, 75, 50, 18, 75, -18, -89, -50, 50, -89, 18, 75, 18, -50, 75, -89
63cabdff1aSopenharmony_ci};
64cabdff1aSopenharmony_ci
65cabdff1aSopenharmony_ci#define HEVC_IDCT4x4_COL(in_r0, in_l0, in_r1, in_l1,          \
66cabdff1aSopenharmony_ci                         sum0, sum1, sum2, sum3, shift)       \
67cabdff1aSopenharmony_ci{                                                             \
68cabdff1aSopenharmony_ci    v4i32 vec0, vec1, vec2, vec3, vec4, vec5;                 \
69cabdff1aSopenharmony_ci    v4i32 cnst64 = __msa_ldi_w(64);                           \
70cabdff1aSopenharmony_ci    v4i32 cnst83 = __msa_ldi_w(83);                           \
71cabdff1aSopenharmony_ci    v4i32 cnst36 = __msa_ldi_w(36);                           \
72cabdff1aSopenharmony_ci                                                              \
73cabdff1aSopenharmony_ci    DOTP_SH4_SW(in_r0, in_r1, in_l0, in_l1, cnst64, cnst64,   \
74cabdff1aSopenharmony_ci                cnst83, cnst36, vec0, vec2, vec1, vec3);      \
75cabdff1aSopenharmony_ci    DOTP_SH2_SW(in_l0, in_l1, cnst36, cnst83, vec4, vec5);    \
76cabdff1aSopenharmony_ci                                                              \
77cabdff1aSopenharmony_ci    sum0 = vec0 + vec2;                                       \
78cabdff1aSopenharmony_ci    sum1 = vec0 - vec2;                                       \
79cabdff1aSopenharmony_ci    sum3 = sum0;                                              \
80cabdff1aSopenharmony_ci    sum2 = sum1;                                              \
81cabdff1aSopenharmony_ci                                                              \
82cabdff1aSopenharmony_ci    vec1 += vec3;                                             \
83cabdff1aSopenharmony_ci    vec4 -= vec5;                                             \
84cabdff1aSopenharmony_ci                                                              \
85cabdff1aSopenharmony_ci    sum0 += vec1;                                             \
86cabdff1aSopenharmony_ci    sum1 += vec4;                                             \
87cabdff1aSopenharmony_ci    sum2 -= vec4;                                             \
88cabdff1aSopenharmony_ci    sum3 -= vec1;                                             \
89cabdff1aSopenharmony_ci                                                              \
90cabdff1aSopenharmony_ci    SRARI_W4_SW(sum0, sum1, sum2, sum3, shift);               \
91cabdff1aSopenharmony_ci    SAT_SW4_SW(sum0, sum1, sum2, sum3, 15);                   \
92cabdff1aSopenharmony_ci}
93cabdff1aSopenharmony_ci
94cabdff1aSopenharmony_ci#define HEVC_IDCT8x8_COL(in0, in1, in2, in3, in4, in5, in6, in7, shift)  \
95cabdff1aSopenharmony_ci{                                                                        \
96cabdff1aSopenharmony_ci    v8i16 src0_r, src1_r, src2_r, src3_r;                                \
97cabdff1aSopenharmony_ci    v8i16 src0_l, src1_l, src2_l, src3_l;                                \
98cabdff1aSopenharmony_ci    v8i16 filt0, filter0, filter1, filter2, filter3;                     \
99cabdff1aSopenharmony_ci    v4i32 temp0_r, temp1_r, temp2_r, temp3_r, temp4_r, temp5_r;          \
100cabdff1aSopenharmony_ci    v4i32 temp0_l, temp1_l, temp2_l, temp3_l, temp4_l, temp5_l;          \
101cabdff1aSopenharmony_ci    v4i32 sum0_r, sum1_r, sum2_r, sum3_r;                                \
102cabdff1aSopenharmony_ci    v4i32 sum0_l, sum1_l, sum2_l, sum3_l;                                \
103cabdff1aSopenharmony_ci                                                                         \
104cabdff1aSopenharmony_ci    ILVR_H4_SH(in4, in0, in6, in2, in5, in1, in3, in7,                   \
105cabdff1aSopenharmony_ci               src0_r, src1_r, src2_r, src3_r);                          \
106cabdff1aSopenharmony_ci    ILVL_H4_SH(in4, in0, in6, in2, in5, in1, in3, in7,                   \
107cabdff1aSopenharmony_ci               src0_l, src1_l, src2_l, src3_l);                          \
108cabdff1aSopenharmony_ci                                                                         \
109cabdff1aSopenharmony_ci    filt0 = LD_SH(filter);                                               \
110cabdff1aSopenharmony_ci    SPLATI_W4_SH(filt0, filter0, filter1, filter2, filter3);             \
111cabdff1aSopenharmony_ci    DOTP_SH4_SW(src0_r, src0_l, src1_r, src1_l, filter0, filter0,        \
112cabdff1aSopenharmony_ci                filter1, filter1, temp0_r, temp0_l, temp1_r, temp1_l);   \
113cabdff1aSopenharmony_ci                                                                         \
114cabdff1aSopenharmony_ci    BUTTERFLY_4(temp0_r, temp0_l, temp1_l, temp1_r, sum0_r, sum0_l,      \
115cabdff1aSopenharmony_ci                sum1_l, sum1_r);                                         \
116cabdff1aSopenharmony_ci    sum2_r = sum1_r;                                                     \
117cabdff1aSopenharmony_ci    sum2_l = sum1_l;                                                     \
118cabdff1aSopenharmony_ci    sum3_r = sum0_r;                                                     \
119cabdff1aSopenharmony_ci    sum3_l = sum0_l;                                                     \
120cabdff1aSopenharmony_ci                                                                         \
121cabdff1aSopenharmony_ci    DOTP_SH4_SW(src2_r, src2_l, src3_r, src3_l,  filter2, filter2,       \
122cabdff1aSopenharmony_ci                filter3, filter3, temp2_r, temp2_l, temp3_r, temp3_l);   \
123cabdff1aSopenharmony_ci                                                                         \
124cabdff1aSopenharmony_ci    temp2_r += temp3_r;                                                  \
125cabdff1aSopenharmony_ci    temp2_l += temp3_l;                                                  \
126cabdff1aSopenharmony_ci    sum0_r += temp2_r;                                                   \
127cabdff1aSopenharmony_ci    sum0_l += temp2_l;                                                   \
128cabdff1aSopenharmony_ci    sum3_r -= temp2_r;                                                   \
129cabdff1aSopenharmony_ci    sum3_l -= temp2_l;                                                   \
130cabdff1aSopenharmony_ci                                                                         \
131cabdff1aSopenharmony_ci    SRARI_W4_SW(sum0_r, sum0_l, sum3_r, sum3_l, shift);                  \
132cabdff1aSopenharmony_ci    SAT_SW4_SW(sum0_r, sum0_l, sum3_r, sum3_l, 15);                      \
133cabdff1aSopenharmony_ci    PCKEV_H2_SH(sum0_l, sum0_r, sum3_l, sum3_r, in0, in7);               \
134cabdff1aSopenharmony_ci    DOTP_SH4_SW(src2_r, src2_l, src3_r, src3_l,  filter3, filter3,       \
135cabdff1aSopenharmony_ci                filter2, filter2, temp4_r, temp4_l, temp5_r, temp5_l);   \
136cabdff1aSopenharmony_ci                                                                         \
137cabdff1aSopenharmony_ci    temp4_r -= temp5_r;                                                  \
138cabdff1aSopenharmony_ci    temp4_l -= temp5_l;                                                  \
139cabdff1aSopenharmony_ci    sum1_r += temp4_r;                                                   \
140cabdff1aSopenharmony_ci    sum1_l += temp4_l;                                                   \
141cabdff1aSopenharmony_ci    sum2_r -= temp4_r;                                                   \
142cabdff1aSopenharmony_ci    sum2_l -= temp4_l;                                                   \
143cabdff1aSopenharmony_ci                                                                         \
144cabdff1aSopenharmony_ci    SRARI_W4_SW(sum1_r, sum1_l, sum2_r, sum2_l, shift);                  \
145cabdff1aSopenharmony_ci    SAT_SW4_SW(sum1_r, sum1_l, sum2_r, sum2_l, 15);                      \
146cabdff1aSopenharmony_ci    PCKEV_H2_SH(sum1_l, sum1_r, sum2_l, sum2_r, in3, in4);               \
147cabdff1aSopenharmony_ci                                                                         \
148cabdff1aSopenharmony_ci    filt0 = LD_SH(filter + 8);                                           \
149cabdff1aSopenharmony_ci    SPLATI_W4_SH(filt0, filter0, filter1, filter2, filter3);             \
150cabdff1aSopenharmony_ci    DOTP_SH4_SW(src0_r, src0_l, src1_r, src1_l,  filter0, filter0,       \
151cabdff1aSopenharmony_ci                filter1, filter1, temp0_r, temp0_l, temp1_r, temp1_l);   \
152cabdff1aSopenharmony_ci                                                                         \
153cabdff1aSopenharmony_ci    BUTTERFLY_4(temp0_r, temp0_l, temp1_l, temp1_r, sum0_r, sum0_l,      \
154cabdff1aSopenharmony_ci                sum1_l, sum1_r);                                         \
155cabdff1aSopenharmony_ci    sum2_r = sum1_r;                                                     \
156cabdff1aSopenharmony_ci    sum2_l = sum1_l;                                                     \
157cabdff1aSopenharmony_ci    sum3_r = sum0_r;                                                     \
158cabdff1aSopenharmony_ci    sum3_l = sum0_l;                                                     \
159cabdff1aSopenharmony_ci                                                                         \
160cabdff1aSopenharmony_ci    DOTP_SH4_SW(src2_r, src2_l, src3_r, src3_l, filter2, filter2,        \
161cabdff1aSopenharmony_ci                filter3, filter3, temp2_r, temp2_l, temp3_r, temp3_l);   \
162cabdff1aSopenharmony_ci                                                                         \
163cabdff1aSopenharmony_ci    temp2_r += temp3_r;                                                  \
164cabdff1aSopenharmony_ci    temp2_l += temp3_l;                                                  \
165cabdff1aSopenharmony_ci    sum0_r += temp2_r;                                                   \
166cabdff1aSopenharmony_ci    sum0_l += temp2_l;                                                   \
167cabdff1aSopenharmony_ci    sum3_r -= temp2_r;                                                   \
168cabdff1aSopenharmony_ci    sum3_l -= temp2_l;                                                   \
169cabdff1aSopenharmony_ci                                                                         \
170cabdff1aSopenharmony_ci    SRARI_W4_SW(sum0_r, sum0_l, sum3_r, sum3_l, shift);                  \
171cabdff1aSopenharmony_ci    SAT_SW4_SW(sum0_r, sum0_l, sum3_r, sum3_l, 15);                      \
172cabdff1aSopenharmony_ci    PCKEV_H2_SH(sum0_l, sum0_r, sum3_l, sum3_r, in1, in6);               \
173cabdff1aSopenharmony_ci    DOTP_SH4_SW(src2_r, src2_l, src3_r, src3_l, filter3, filter3,        \
174cabdff1aSopenharmony_ci                filter2, filter2, temp4_r, temp4_l, temp5_r, temp5_l);   \
175cabdff1aSopenharmony_ci                                                                         \
176cabdff1aSopenharmony_ci    temp4_r -= temp5_r;                                                  \
177cabdff1aSopenharmony_ci    temp4_l -= temp5_l;                                                  \
178cabdff1aSopenharmony_ci    sum1_r -= temp4_r;                                                   \
179cabdff1aSopenharmony_ci    sum1_l -= temp4_l;                                                   \
180cabdff1aSopenharmony_ci    sum2_r += temp4_r;                                                   \
181cabdff1aSopenharmony_ci    sum2_l += temp4_l;                                                   \
182cabdff1aSopenharmony_ci                                                                         \
183cabdff1aSopenharmony_ci    SRARI_W4_SW(sum1_r, sum1_l, sum2_r, sum2_l, shift);                  \
184cabdff1aSopenharmony_ci    SAT_SW4_SW(sum1_r, sum1_l, sum2_r, sum2_l, 15);                      \
185cabdff1aSopenharmony_ci    PCKEV_H2_SH(sum1_l, sum1_r, sum2_l, sum2_r, in2, in5);               \
186cabdff1aSopenharmony_ci}
187cabdff1aSopenharmony_ci
188cabdff1aSopenharmony_ci#define HEVC_IDCT16x16_COL(src0_r, src1_r, src2_r, src3_r,                \
189cabdff1aSopenharmony_ci                           src4_r, src5_r, src6_r, src7_r,                \
190cabdff1aSopenharmony_ci                           src0_l, src1_l, src2_l, src3_l,                \
191cabdff1aSopenharmony_ci                           src4_l, src5_l, src6_l, src7_l, shift)         \
192cabdff1aSopenharmony_ci{                                                                         \
193cabdff1aSopenharmony_ci    int16_t *ptr0, *ptr1;                                                 \
194cabdff1aSopenharmony_ci    v8i16 filt0, filt1, dst0, dst1;                                       \
195cabdff1aSopenharmony_ci    v8i16 filter0, filter1, filter2, filter3;                             \
196cabdff1aSopenharmony_ci    v4i32 temp0_r, temp1_r, temp0_l, temp1_l;                             \
197cabdff1aSopenharmony_ci    v4i32 sum0_r, sum1_r, sum2_r, sum3_r, sum0_l, sum1_l, sum2_l;         \
198cabdff1aSopenharmony_ci    v4i32 sum3_l, res0_r, res1_r, res0_l, res1_l;                         \
199cabdff1aSopenharmony_ci                                                                          \
200cabdff1aSopenharmony_ci    ptr0 = (buf_ptr + 112);                                               \
201cabdff1aSopenharmony_ci    ptr1 = (buf_ptr + 128);                                               \
202cabdff1aSopenharmony_ci    k = -1;                                                               \
203cabdff1aSopenharmony_ci                                                                          \
204cabdff1aSopenharmony_ci    for (j = 0; j < 4; j++)                                               \
205cabdff1aSopenharmony_ci    {                                                                     \
206cabdff1aSopenharmony_ci        LD_SH2(filter, 8, filt0, filt1)                                   \
207cabdff1aSopenharmony_ci        filter += 16;                                                     \
208cabdff1aSopenharmony_ci        SPLATI_W2_SH(filt0, 0, filter0, filter1);                         \
209cabdff1aSopenharmony_ci        SPLATI_W2_SH(filt1, 0, filter2, filter3);                         \
210cabdff1aSopenharmony_ci        DOTP_SH4_SW(src0_r, src0_l, src4_r, src4_l,  filter0, filter0,    \
211cabdff1aSopenharmony_ci                    filter2, filter2, sum0_r, sum0_l, sum2_r, sum2_l);    \
212cabdff1aSopenharmony_ci        DOTP_SH2_SW(src7_r, src7_l, filter2, filter2, sum3_r, sum3_l);    \
213cabdff1aSopenharmony_ci        DPADD_SH4_SW(src1_r, src1_l, src5_r, src5_l,  filter1, filter1,   \
214cabdff1aSopenharmony_ci                     filter3, filter3, sum0_r, sum0_l, sum2_r, sum2_l);   \
215cabdff1aSopenharmony_ci        DPADD_SH2_SW(src6_r, src6_l, filter3, filter3, sum3_r, sum3_l);   \
216cabdff1aSopenharmony_ci                                                                          \
217cabdff1aSopenharmony_ci        sum1_r = sum0_r;                                                  \
218cabdff1aSopenharmony_ci        sum1_l = sum0_l;                                                  \
219cabdff1aSopenharmony_ci                                                                          \
220cabdff1aSopenharmony_ci        SPLATI_W2_SH(filt0, 2, filter0, filter1);                         \
221cabdff1aSopenharmony_ci        SPLATI_W2_SH(filt1, 2, filter2, filter3);                         \
222cabdff1aSopenharmony_ci        DOTP_SH2_SW(src2_r, src2_l, filter0, filter0, temp0_r, temp0_l);  \
223cabdff1aSopenharmony_ci        DPADD_SH2_SW(src6_r, src6_l, filter2, filter2, sum2_r, sum2_l);   \
224cabdff1aSopenharmony_ci        DOTP_SH2_SW(src5_r, src5_l, filter2, filter2, temp1_r, temp1_l);  \
225cabdff1aSopenharmony_ci                                                                          \
226cabdff1aSopenharmony_ci        sum0_r += temp0_r;                                                \
227cabdff1aSopenharmony_ci        sum0_l += temp0_l;                                                \
228cabdff1aSopenharmony_ci        sum1_r -= temp0_r;                                                \
229cabdff1aSopenharmony_ci        sum1_l -= temp0_l;                                                \
230cabdff1aSopenharmony_ci                                                                          \
231cabdff1aSopenharmony_ci        sum3_r = temp1_r - sum3_r;                                        \
232cabdff1aSopenharmony_ci        sum3_l = temp1_l - sum3_l;                                        \
233cabdff1aSopenharmony_ci                                                                          \
234cabdff1aSopenharmony_ci        DOTP_SH2_SW(src3_r, src3_l, filter1, filter1, temp0_r, temp0_l);  \
235cabdff1aSopenharmony_ci        DPADD_SH4_SW(src7_r, src7_l, src4_r, src4_l, filter3, filter3,    \
236cabdff1aSopenharmony_ci                     filter3, filter3, sum2_r, sum2_l, sum3_r, sum3_l);   \
237cabdff1aSopenharmony_ci                                                                          \
238cabdff1aSopenharmony_ci        sum0_r += temp0_r;                                                \
239cabdff1aSopenharmony_ci        sum0_l += temp0_l;                                                \
240cabdff1aSopenharmony_ci        sum1_r -= temp0_r;                                                \
241cabdff1aSopenharmony_ci        sum1_l -= temp0_l;                                                \
242cabdff1aSopenharmony_ci                                                                          \
243cabdff1aSopenharmony_ci        BUTTERFLY_4(sum0_r, sum0_l, sum2_l, sum2_r, res0_r, res0_l,       \
244cabdff1aSopenharmony_ci                    res1_l, res1_r);                                      \
245cabdff1aSopenharmony_ci        SRARI_W4_SW(res0_r, res0_l, res1_r, res1_l, shift);               \
246cabdff1aSopenharmony_ci        SAT_SW4_SW(res0_r, res0_l, res1_r, res1_l, 15);                   \
247cabdff1aSopenharmony_ci        PCKEV_H2_SH(res0_l, res0_r, res1_l, res1_r, dst0, dst1);          \
248cabdff1aSopenharmony_ci        ST_SH(dst0, buf_ptr);                                             \
249cabdff1aSopenharmony_ci        ST_SH(dst1, (buf_ptr + ((15 - (j * 2)) * 16)));                   \
250cabdff1aSopenharmony_ci                                                                          \
251cabdff1aSopenharmony_ci        BUTTERFLY_4(sum1_r, sum1_l, sum3_l, sum3_r, res0_r, res0_l,       \
252cabdff1aSopenharmony_ci                    res1_l, res1_r);                                      \
253cabdff1aSopenharmony_ci        SRARI_W4_SW(res0_r, res0_l, res1_r, res1_l, shift);               \
254cabdff1aSopenharmony_ci        SAT_SW4_SW(res0_r, res0_l, res1_r, res1_l, 15);                   \
255cabdff1aSopenharmony_ci        PCKEV_H2_SH(res0_l, res0_r, res1_l, res1_r, dst0, dst1);          \
256cabdff1aSopenharmony_ci        ST_SH(dst0, (ptr0 + (((j / 2 + j % 2) * 2 * k) * 16)));           \
257cabdff1aSopenharmony_ci        ST_SH(dst1, (ptr1 - (((j / 2 + j % 2) * 2 * k) * 16)));           \
258cabdff1aSopenharmony_ci                                                                          \
259cabdff1aSopenharmony_ci        k *= -1;                                                          \
260cabdff1aSopenharmony_ci        buf_ptr += 16;                                                    \
261cabdff1aSopenharmony_ci    }                                                                     \
262cabdff1aSopenharmony_ci}
263cabdff1aSopenharmony_ci
264cabdff1aSopenharmony_ci#define HEVC_EVEN16_CALC(input, sum0_r, sum0_l, load_idx, store_idx)  \
265cabdff1aSopenharmony_ci{                                                                     \
266cabdff1aSopenharmony_ci    LD_SW2(input + load_idx * 8, 4, tmp0_r, tmp0_l);                  \
267cabdff1aSopenharmony_ci    tmp1_r = sum0_r;                                                  \
268cabdff1aSopenharmony_ci    tmp1_l = sum0_l;                                                  \
269cabdff1aSopenharmony_ci    sum0_r += tmp0_r;                                                 \
270cabdff1aSopenharmony_ci    sum0_l += tmp0_l;                                                 \
271cabdff1aSopenharmony_ci    ST_SW2(sum0_r, sum0_l, (input + load_idx * 8), 4);                \
272cabdff1aSopenharmony_ci    tmp1_r -= tmp0_r;                                                 \
273cabdff1aSopenharmony_ci    tmp1_l -= tmp0_l;                                                 \
274cabdff1aSopenharmony_ci    ST_SW2(tmp1_r, tmp1_l, (input + store_idx * 8), 4);               \
275cabdff1aSopenharmony_ci}
276cabdff1aSopenharmony_ci
277cabdff1aSopenharmony_ci#define HEVC_IDCT_LUMA4x4_COL(in_r0, in_l0, in_r1, in_l1,     \
278cabdff1aSopenharmony_ci                              res0, res1, res2, res3, shift)  \
279cabdff1aSopenharmony_ci{                                                             \
280cabdff1aSopenharmony_ci    v4i32 vec0, vec1, vec2, vec3;                             \
281cabdff1aSopenharmony_ci    v4i32 cnst74 = __msa_ldi_w(74);                           \
282cabdff1aSopenharmony_ci    v4i32 cnst55 = __msa_ldi_w(55);                           \
283cabdff1aSopenharmony_ci    v4i32 cnst29 = __msa_ldi_w(29);                           \
284cabdff1aSopenharmony_ci                                                              \
285cabdff1aSopenharmony_ci    vec0 = in_r0 + in_r1;                                     \
286cabdff1aSopenharmony_ci    vec2 = in_r0 - in_l1;                                     \
287cabdff1aSopenharmony_ci    res0 = vec0 * cnst29;                                     \
288cabdff1aSopenharmony_ci    res1 = vec2 * cnst55;                                     \
289cabdff1aSopenharmony_ci    res2 = in_r0 - in_r1;                                     \
290cabdff1aSopenharmony_ci    vec1 = in_r1 + in_l1;                                     \
291cabdff1aSopenharmony_ci    res2 += in_l1;                                            \
292cabdff1aSopenharmony_ci    vec3 = in_l0 * cnst74;                                    \
293cabdff1aSopenharmony_ci    res3 = vec0 * cnst55;                                     \
294cabdff1aSopenharmony_ci                                                              \
295cabdff1aSopenharmony_ci    res0 += vec1 * cnst55;                                    \
296cabdff1aSopenharmony_ci    res1 -= vec1 * cnst29;                                    \
297cabdff1aSopenharmony_ci    res2 *= cnst74;                                           \
298cabdff1aSopenharmony_ci    res3 += vec2 * cnst29;                                    \
299cabdff1aSopenharmony_ci                                                              \
300cabdff1aSopenharmony_ci    res0 += vec3;                                             \
301cabdff1aSopenharmony_ci    res1 += vec3;                                             \
302cabdff1aSopenharmony_ci    res3 -= vec3;                                             \
303cabdff1aSopenharmony_ci                                                              \
304cabdff1aSopenharmony_ci    SRARI_W4_SW(res0, res1, res2, res3, shift);               \
305cabdff1aSopenharmony_ci    SAT_SW4_SW(res0, res1, res2, res3, 15);                   \
306cabdff1aSopenharmony_ci}
307cabdff1aSopenharmony_ci
308cabdff1aSopenharmony_cistatic void hevc_idct_4x4_msa(int16_t *coeffs)
309cabdff1aSopenharmony_ci{
310cabdff1aSopenharmony_ci    v8i16 in0, in1;
311cabdff1aSopenharmony_ci    v4i32 in_r0, in_l0, in_r1, in_l1;
312cabdff1aSopenharmony_ci    v4i32 sum0, sum1, sum2, sum3;
313cabdff1aSopenharmony_ci    v8i16 zeros = { 0 };
314cabdff1aSopenharmony_ci
315cabdff1aSopenharmony_ci    LD_SH2(coeffs, 8, in0, in1);
316cabdff1aSopenharmony_ci    ILVRL_H2_SW(zeros, in0, in_r0, in_l0);
317cabdff1aSopenharmony_ci    ILVRL_H2_SW(zeros, in1, in_r1, in_l1);
318cabdff1aSopenharmony_ci
319cabdff1aSopenharmony_ci    HEVC_IDCT4x4_COL(in_r0, in_l0, in_r1, in_l1, sum0, sum1, sum2, sum3, 7);
320cabdff1aSopenharmony_ci    TRANSPOSE4x4_SW_SW(sum0, sum1, sum2, sum3, in_r0, in_l0, in_r1, in_l1);
321cabdff1aSopenharmony_ci    HEVC_IDCT4x4_COL(in_r0, in_l0, in_r1, in_l1, sum0, sum1, sum2, sum3, 12);
322cabdff1aSopenharmony_ci
323cabdff1aSopenharmony_ci    /* Pack and transpose */
324cabdff1aSopenharmony_ci    PCKEV_H2_SH(sum2, sum0, sum3, sum1, in0, in1);
325cabdff1aSopenharmony_ci    ILVRL_H2_SW(in1, in0, sum0, sum1);
326cabdff1aSopenharmony_ci    ILVRL_W2_SH(sum1, sum0, in0, in1);
327cabdff1aSopenharmony_ci
328cabdff1aSopenharmony_ci    ST_SH2(in0, in1, coeffs, 8);
329cabdff1aSopenharmony_ci}
330cabdff1aSopenharmony_ci
331cabdff1aSopenharmony_cistatic void hevc_idct_8x8_msa(int16_t *coeffs)
332cabdff1aSopenharmony_ci{
333cabdff1aSopenharmony_ci    const int16_t *filter = &gt8x8_cnst[0];
334cabdff1aSopenharmony_ci    v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
335cabdff1aSopenharmony_ci
336cabdff1aSopenharmony_ci    LD_SH8(coeffs, 8, in0, in1, in2, in3, in4, in5, in6, in7);
337cabdff1aSopenharmony_ci    HEVC_IDCT8x8_COL(in0, in1, in2, in3, in4, in5, in6, in7, 7);
338cabdff1aSopenharmony_ci    TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
339cabdff1aSopenharmony_ci                       in0, in1, in2, in3, in4, in5, in6, in7);
340cabdff1aSopenharmony_ci    HEVC_IDCT8x8_COL(in0, in1, in2, in3, in4, in5, in6, in7, 12);
341cabdff1aSopenharmony_ci    TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
342cabdff1aSopenharmony_ci                       in0, in1, in2, in3, in4, in5, in6, in7);
343cabdff1aSopenharmony_ci    ST_SH8(in0, in1, in2, in3, in4, in5, in6, in7, coeffs, 8);
344cabdff1aSopenharmony_ci}
345cabdff1aSopenharmony_ci
346cabdff1aSopenharmony_cistatic void hevc_idct_16x16_msa(int16_t *coeffs)
347cabdff1aSopenharmony_ci{
348cabdff1aSopenharmony_ci    int16_t i, j, k;
349cabdff1aSopenharmony_ci    int16_t buf[256];
350cabdff1aSopenharmony_ci    int16_t *buf_ptr = &buf[0];
351cabdff1aSopenharmony_ci    int16_t *src = coeffs;
352cabdff1aSopenharmony_ci    const int16_t *filter = &gt16x16_cnst[0];
353cabdff1aSopenharmony_ci    v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
354cabdff1aSopenharmony_ci    v8i16 in8, in9, in10, in11, in12, in13, in14, in15;
355cabdff1aSopenharmony_ci    v8i16 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
356cabdff1aSopenharmony_ci    v8i16 src0_r, src1_r, src2_r, src3_r, src4_r, src5_r, src6_r, src7_r;
357cabdff1aSopenharmony_ci    v8i16 src0_l, src1_l, src2_l, src3_l, src4_l, src5_l, src6_l, src7_l;
358cabdff1aSopenharmony_ci
359cabdff1aSopenharmony_ci    for (i = 2; i--;) {
360cabdff1aSopenharmony_ci        LD_SH16(src, 16, in0, in1, in2, in3, in4, in5, in6, in7,
361cabdff1aSopenharmony_ci                in8, in9, in10, in11, in12, in13, in14, in15);
362cabdff1aSopenharmony_ci
363cabdff1aSopenharmony_ci        ILVR_H4_SH(in4, in0, in12, in8, in6, in2, in14, in10,
364cabdff1aSopenharmony_ci                   src0_r, src1_r, src2_r, src3_r);
365cabdff1aSopenharmony_ci        ILVR_H4_SH(in5, in1, in13, in9, in3, in7, in11, in15,
366cabdff1aSopenharmony_ci                   src4_r, src5_r, src6_r, src7_r);
367cabdff1aSopenharmony_ci        ILVL_H4_SH(in4, in0, in12, in8, in6, in2, in14, in10,
368cabdff1aSopenharmony_ci                   src0_l, src1_l, src2_l, src3_l);
369cabdff1aSopenharmony_ci        ILVL_H4_SH(in5, in1, in13, in9, in3, in7, in11, in15,
370cabdff1aSopenharmony_ci                   src4_l, src5_l, src6_l, src7_l);
371cabdff1aSopenharmony_ci        HEVC_IDCT16x16_COL(src0_r, src1_r, src2_r, src3_r, src4_r, src5_r,
372cabdff1aSopenharmony_ci                           src6_r, src7_r, src0_l, src1_l, src2_l, src3_l,
373cabdff1aSopenharmony_ci                           src4_l, src5_l, src6_l, src7_l, 7);
374cabdff1aSopenharmony_ci
375cabdff1aSopenharmony_ci        src += 8;
376cabdff1aSopenharmony_ci        buf_ptr = (&buf[0] + 8);
377cabdff1aSopenharmony_ci        filter = &gt16x16_cnst[0];
378cabdff1aSopenharmony_ci    }
379cabdff1aSopenharmony_ci
380cabdff1aSopenharmony_ci    src = &buf[0];
381cabdff1aSopenharmony_ci    buf_ptr = coeffs;
382cabdff1aSopenharmony_ci    filter = &gt16x16_cnst[0];
383cabdff1aSopenharmony_ci
384cabdff1aSopenharmony_ci    for (i = 2; i--;) {
385cabdff1aSopenharmony_ci        LD_SH16(src, 8, in0, in8, in1, in9, in2, in10, in3, in11,
386cabdff1aSopenharmony_ci                in4, in12, in5, in13, in6, in14, in7, in15);
387cabdff1aSopenharmony_ci        TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
388cabdff1aSopenharmony_ci                           in0, in1, in2, in3, in4, in5, in6, in7);
389cabdff1aSopenharmony_ci        TRANSPOSE8x8_SH_SH(in8, in9, in10, in11, in12, in13, in14, in15,
390cabdff1aSopenharmony_ci                           in8, in9, in10, in11, in12, in13, in14, in15);
391cabdff1aSopenharmony_ci        ILVR_H4_SH(in4, in0, in12, in8, in6, in2, in14, in10,
392cabdff1aSopenharmony_ci                   src0_r, src1_r, src2_r, src3_r);
393cabdff1aSopenharmony_ci        ILVR_H4_SH(in5, in1, in13, in9, in3, in7, in11, in15,
394cabdff1aSopenharmony_ci                   src4_r, src5_r, src6_r, src7_r);
395cabdff1aSopenharmony_ci        ILVL_H4_SH(in4, in0, in12, in8, in6, in2, in14, in10,
396cabdff1aSopenharmony_ci                   src0_l, src1_l, src2_l, src3_l);
397cabdff1aSopenharmony_ci        ILVL_H4_SH(in5, in1, in13, in9, in3, in7, in11, in15,
398cabdff1aSopenharmony_ci                   src4_l, src5_l, src6_l, src7_l);
399cabdff1aSopenharmony_ci        HEVC_IDCT16x16_COL(src0_r, src1_r, src2_r, src3_r, src4_r, src5_r,
400cabdff1aSopenharmony_ci                           src6_r, src7_r, src0_l, src1_l, src2_l, src3_l,
401cabdff1aSopenharmony_ci                           src4_l, src5_l, src6_l, src7_l, 12);
402cabdff1aSopenharmony_ci
403cabdff1aSopenharmony_ci        src += 128;
404cabdff1aSopenharmony_ci        buf_ptr = coeffs + 8;
405cabdff1aSopenharmony_ci        filter = &gt16x16_cnst[0];
406cabdff1aSopenharmony_ci    }
407cabdff1aSopenharmony_ci
408cabdff1aSopenharmony_ci    LD_SH8(coeffs, 16, in0, in1, in2, in3, in4, in5, in6, in7);
409cabdff1aSopenharmony_ci    TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
410cabdff1aSopenharmony_ci                       vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7);
411cabdff1aSopenharmony_ci    ST_SH8(vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, coeffs, 16);
412cabdff1aSopenharmony_ci
413cabdff1aSopenharmony_ci    LD_SH8((coeffs + 8), 16, in0, in1, in2, in3, in4, in5, in6, in7);
414cabdff1aSopenharmony_ci    TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
415cabdff1aSopenharmony_ci                       vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7);
416cabdff1aSopenharmony_ci    LD_SH8((coeffs + 128), 16, in8, in9, in10, in11, in12, in13, in14, in15);
417cabdff1aSopenharmony_ci    ST_SH8(vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, (coeffs + 128), 16);
418cabdff1aSopenharmony_ci    TRANSPOSE8x8_SH_SH(in8, in9, in10, in11, in12, in13, in14, in15,
419cabdff1aSopenharmony_ci                       vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7);
420cabdff1aSopenharmony_ci    ST_SH8(vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, (coeffs + 8), 16);
421cabdff1aSopenharmony_ci
422cabdff1aSopenharmony_ci    LD_SH8((coeffs + 136), 16, in0, in1, in2, in3, in4, in5, in6, in7);
423cabdff1aSopenharmony_ci    TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
424cabdff1aSopenharmony_ci                       vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7);
425cabdff1aSopenharmony_ci    ST_SH8(vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, (coeffs + 136), 16);
426cabdff1aSopenharmony_ci}
427cabdff1aSopenharmony_ci
428cabdff1aSopenharmony_cistatic void hevc_idct_8x32_column_msa(int16_t *coeffs, uint8_t buf_pitch,
429cabdff1aSopenharmony_ci                                      uint8_t round)
430cabdff1aSopenharmony_ci{
431cabdff1aSopenharmony_ci    uint8_t i;
432cabdff1aSopenharmony_ci    const int16_t *filter_ptr0 = &gt32x32_cnst0[0];
433cabdff1aSopenharmony_ci    const int16_t *filter_ptr1 = &gt32x32_cnst1[0];
434cabdff1aSopenharmony_ci    const int16_t *filter_ptr2 = &gt32x32_cnst2[0];
435cabdff1aSopenharmony_ci    const int16_t *filter_ptr3 = &gt8x8_cnst[0];
436cabdff1aSopenharmony_ci    int16_t *src0 = (coeffs + buf_pitch);
437cabdff1aSopenharmony_ci    int16_t *src1 = (coeffs + 2 * buf_pitch);
438cabdff1aSopenharmony_ci    int16_t *src2 = (coeffs + 4 * buf_pitch);
439cabdff1aSopenharmony_ci    int16_t *src3 = (coeffs);
440cabdff1aSopenharmony_ci    int32_t cnst0, cnst1;
441cabdff1aSopenharmony_ci    int32_t tmp_buf[8 * 32 + 15];
442cabdff1aSopenharmony_ci    int32_t *tmp_buf_ptr = tmp_buf + 15;
443cabdff1aSopenharmony_ci    v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
444cabdff1aSopenharmony_ci    v8i16 src0_r, src1_r, src2_r, src3_r, src4_r, src5_r, src6_r, src7_r;
445cabdff1aSopenharmony_ci    v8i16 src0_l, src1_l, src2_l, src3_l, src4_l, src5_l, src6_l, src7_l;
446cabdff1aSopenharmony_ci    v8i16 filt0, filter0, filter1, filter2, filter3;
447cabdff1aSopenharmony_ci    v4i32 sum0_r, sum0_l, sum1_r, sum1_l, tmp0_r, tmp0_l, tmp1_r, tmp1_l;
448cabdff1aSopenharmony_ci
449cabdff1aSopenharmony_ci    /* Align pointer to 64 byte boundary */
450cabdff1aSopenharmony_ci    tmp_buf_ptr = (int32_t *)(((uintptr_t) tmp_buf_ptr) & ~(uintptr_t) 63);
451cabdff1aSopenharmony_ci
452cabdff1aSopenharmony_ci    /* process coeff 4, 12, 20, 28 */
453cabdff1aSopenharmony_ci    LD_SH4(src2, 8 * buf_pitch, in0, in1, in2, in3);
454cabdff1aSopenharmony_ci    ILVR_H2_SH(in1, in0, in3, in2, src0_r, src1_r);
455cabdff1aSopenharmony_ci    ILVL_H2_SH(in1, in0, in3, in2, src0_l, src1_l);
456cabdff1aSopenharmony_ci
457cabdff1aSopenharmony_ci    LD_SH2(src3, 16 * buf_pitch, in4, in6);
458cabdff1aSopenharmony_ci    LD_SH2((src3 + 8 * buf_pitch), 16 * buf_pitch, in5, in7);
459cabdff1aSopenharmony_ci    ILVR_H2_SH(in6, in4, in7, in5, src2_r, src3_r);
460cabdff1aSopenharmony_ci    ILVL_H2_SH(in6, in4, in7, in5, src2_l, src3_l);
461cabdff1aSopenharmony_ci
462cabdff1aSopenharmony_ci    /* loop for all columns of constants */
463cabdff1aSopenharmony_ci    for (i = 0; i < 2; i++) {
464cabdff1aSopenharmony_ci        /* processing single column of constants */
465cabdff1aSopenharmony_ci        cnst0 = LW(filter_ptr2);
466cabdff1aSopenharmony_ci        cnst1 = LW(filter_ptr2 + 2);
467cabdff1aSopenharmony_ci
468cabdff1aSopenharmony_ci        filter0 = (v8i16) __msa_fill_w(cnst0);
469cabdff1aSopenharmony_ci        filter1 = (v8i16) __msa_fill_w(cnst1);
470cabdff1aSopenharmony_ci
471cabdff1aSopenharmony_ci        DOTP_SH2_SW(src0_r, src0_l, filter0, filter0, sum0_r, sum0_l);
472cabdff1aSopenharmony_ci        DPADD_SH2_SW(src1_r, src1_l, filter1, filter1, sum0_r, sum0_l);
473cabdff1aSopenharmony_ci        ST_SW2(sum0_r, sum0_l, (tmp_buf_ptr + 2 * i * 8), 4);
474cabdff1aSopenharmony_ci
475cabdff1aSopenharmony_ci        /* processing single column of constants */
476cabdff1aSopenharmony_ci        cnst0 = LW(filter_ptr2 + 4);
477cabdff1aSopenharmony_ci        cnst1 = LW(filter_ptr2 + 6);
478cabdff1aSopenharmony_ci
479cabdff1aSopenharmony_ci        filter0 = (v8i16) __msa_fill_w(cnst0);
480cabdff1aSopenharmony_ci        filter1 = (v8i16) __msa_fill_w(cnst1);
481cabdff1aSopenharmony_ci
482cabdff1aSopenharmony_ci        DOTP_SH2_SW(src0_r, src0_l, filter0, filter0, sum0_r, sum0_l);
483cabdff1aSopenharmony_ci        DPADD_SH2_SW(src1_r, src1_l, filter1, filter1, sum0_r, sum0_l);
484cabdff1aSopenharmony_ci        ST_SW2(sum0_r, sum0_l, (tmp_buf_ptr + (2 * i + 1) * 8), 4);
485cabdff1aSopenharmony_ci
486cabdff1aSopenharmony_ci        filter_ptr2 += 8;
487cabdff1aSopenharmony_ci    }
488cabdff1aSopenharmony_ci
489cabdff1aSopenharmony_ci    /* process coeff 0, 8, 16, 24 */
490cabdff1aSopenharmony_ci    /* loop for all columns of constants */
491cabdff1aSopenharmony_ci    for (i = 0; i < 2; i++) {
492cabdff1aSopenharmony_ci        /* processing first column of filter constants */
493cabdff1aSopenharmony_ci        cnst0 = LW(filter_ptr3);
494cabdff1aSopenharmony_ci        cnst1 = LW(filter_ptr3 + 2);
495cabdff1aSopenharmony_ci
496cabdff1aSopenharmony_ci        filter0 = (v8i16) __msa_fill_w(cnst0);
497cabdff1aSopenharmony_ci        filter1 = (v8i16) __msa_fill_w(cnst1);
498cabdff1aSopenharmony_ci
499cabdff1aSopenharmony_ci        DOTP_SH4_SW(src2_r, src2_l, src3_r, src3_l, filter0, filter0, filter1,
500cabdff1aSopenharmony_ci                    filter1, sum0_r, sum0_l, tmp1_r, tmp1_l);
501cabdff1aSopenharmony_ci
502cabdff1aSopenharmony_ci        sum1_r = sum0_r - tmp1_r;
503cabdff1aSopenharmony_ci        sum1_l = sum0_l - tmp1_l;
504cabdff1aSopenharmony_ci        sum0_r = sum0_r + tmp1_r;
505cabdff1aSopenharmony_ci        sum0_l = sum0_l + tmp1_l;
506cabdff1aSopenharmony_ci
507cabdff1aSopenharmony_ci        HEVC_EVEN16_CALC(tmp_buf_ptr, sum0_r, sum0_l, i, (7 - i));
508cabdff1aSopenharmony_ci        HEVC_EVEN16_CALC(tmp_buf_ptr, sum1_r, sum1_l, (3 - i), (4 + i));
509cabdff1aSopenharmony_ci
510cabdff1aSopenharmony_ci        filter_ptr3 += 8;
511cabdff1aSopenharmony_ci    }
512cabdff1aSopenharmony_ci
513cabdff1aSopenharmony_ci    /* process coeff 2 6 10 14 18 22 26 30 */
514cabdff1aSopenharmony_ci    LD_SH8(src1, 4 * buf_pitch, in0, in1, in2, in3, in4, in5, in6, in7);
515cabdff1aSopenharmony_ci    ILVR_H4_SH(in1, in0, in3, in2, in5, in4, in7, in6,
516cabdff1aSopenharmony_ci               src0_r, src1_r, src2_r, src3_r);
517cabdff1aSopenharmony_ci    ILVL_H4_SH(in1, in0, in3, in2, in5, in4, in7, in6,
518cabdff1aSopenharmony_ci               src0_l, src1_l, src2_l, src3_l);
519cabdff1aSopenharmony_ci
520cabdff1aSopenharmony_ci    /* loop for all columns of constants */
521cabdff1aSopenharmony_ci    for (i = 0; i < 8; i++) {
522cabdff1aSopenharmony_ci        /* processing single column of constants */
523cabdff1aSopenharmony_ci        filt0 = LD_SH(filter_ptr1);
524cabdff1aSopenharmony_ci        SPLATI_W4_SH(filt0, filter0, filter1, filter2, filter3);
525cabdff1aSopenharmony_ci        DOTP_SH2_SW(src0_r, src0_l, filter0, filter0, sum0_r, sum0_l);
526cabdff1aSopenharmony_ci        DPADD_SH4_SW(src1_r, src1_l, src2_r, src2_l, filter1, filter1, filter2,
527cabdff1aSopenharmony_ci                     filter2, sum0_r, sum0_l, sum0_r, sum0_l);
528cabdff1aSopenharmony_ci        DPADD_SH2_SW(src3_r, src3_l, filter3, filter3, sum0_r, sum0_l);
529cabdff1aSopenharmony_ci
530cabdff1aSopenharmony_ci        LD_SW2(tmp_buf_ptr + i * 8, 4, tmp0_r, tmp0_l);
531cabdff1aSopenharmony_ci        tmp1_r = tmp0_r;
532cabdff1aSopenharmony_ci        tmp1_l = tmp0_l;
533cabdff1aSopenharmony_ci        tmp0_r += sum0_r;
534cabdff1aSopenharmony_ci        tmp0_l += sum0_l;
535cabdff1aSopenharmony_ci        ST_SW2(tmp0_r, tmp0_l, (tmp_buf_ptr + i * 8), 4);
536cabdff1aSopenharmony_ci        tmp1_r -= sum0_r;
537cabdff1aSopenharmony_ci        tmp1_l -= sum0_l;
538cabdff1aSopenharmony_ci        ST_SW2(tmp1_r, tmp1_l, (tmp_buf_ptr + (15 - i) * 8), 4);
539cabdff1aSopenharmony_ci
540cabdff1aSopenharmony_ci        filter_ptr1 += 8;
541cabdff1aSopenharmony_ci    }
542cabdff1aSopenharmony_ci
543cabdff1aSopenharmony_ci    /* process coeff 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 */
544cabdff1aSopenharmony_ci    LD_SH8(src0, 2 * buf_pitch, in0, in1, in2, in3, in4, in5, in6, in7);
545cabdff1aSopenharmony_ci    src0 += 16 * buf_pitch;
546cabdff1aSopenharmony_ci    ILVR_H4_SH(in1, in0, in3, in2, in5, in4, in7, in6,
547cabdff1aSopenharmony_ci               src0_r, src1_r, src2_r, src3_r);
548cabdff1aSopenharmony_ci    ILVL_H4_SH(in1, in0, in3, in2, in5, in4, in7, in6,
549cabdff1aSopenharmony_ci               src0_l, src1_l, src2_l, src3_l);
550cabdff1aSopenharmony_ci
551cabdff1aSopenharmony_ci    LD_SH8(src0, 2 * buf_pitch, in0, in1, in2, in3, in4, in5, in6, in7);
552cabdff1aSopenharmony_ci    ILVR_H4_SH(in1, in0, in3, in2, in5, in4, in7, in6,
553cabdff1aSopenharmony_ci               src4_r, src5_r, src6_r, src7_r);
554cabdff1aSopenharmony_ci    ILVL_H4_SH(in1, in0, in3, in2, in5, in4, in7, in6,
555cabdff1aSopenharmony_ci               src4_l, src5_l, src6_l, src7_l);
556cabdff1aSopenharmony_ci
557cabdff1aSopenharmony_ci    /* loop for all columns of filter constants */
558cabdff1aSopenharmony_ci    for (i = 0; i < 16; i++) {
559cabdff1aSopenharmony_ci        /* processing single column of constants */
560cabdff1aSopenharmony_ci        filt0 = LD_SH(filter_ptr0);
561cabdff1aSopenharmony_ci        SPLATI_W4_SH(filt0, filter0, filter1, filter2, filter3);
562cabdff1aSopenharmony_ci        DOTP_SH2_SW(src0_r, src0_l, filter0, filter0, sum0_r, sum0_l);
563cabdff1aSopenharmony_ci        DPADD_SH4_SW(src1_r, src1_l, src2_r, src2_l, filter1, filter1, filter2,
564cabdff1aSopenharmony_ci                     filter2, sum0_r, sum0_l, sum0_r, sum0_l);
565cabdff1aSopenharmony_ci        DPADD_SH2_SW(src3_r, src3_l, filter3, filter3, sum0_r, sum0_l);
566cabdff1aSopenharmony_ci
567cabdff1aSopenharmony_ci        tmp1_r = sum0_r;
568cabdff1aSopenharmony_ci        tmp1_l = sum0_l;
569cabdff1aSopenharmony_ci
570cabdff1aSopenharmony_ci        filt0 = LD_SH(filter_ptr0 + 8);
571cabdff1aSopenharmony_ci        SPLATI_W4_SH(filt0, filter0, filter1, filter2, filter3);
572cabdff1aSopenharmony_ci        DOTP_SH2_SW(src4_r, src4_l, filter0, filter0, sum0_r, sum0_l);
573cabdff1aSopenharmony_ci        DPADD_SH4_SW(src5_r, src5_l, src6_r, src6_l, filter1, filter1, filter2,
574cabdff1aSopenharmony_ci                     filter2, sum0_r, sum0_l, sum0_r, sum0_l);
575cabdff1aSopenharmony_ci        DPADD_SH2_SW(src7_r, src7_l, filter3, filter3, sum0_r, sum0_l);
576cabdff1aSopenharmony_ci
577cabdff1aSopenharmony_ci        sum0_r += tmp1_r;
578cabdff1aSopenharmony_ci        sum0_l += tmp1_l;
579cabdff1aSopenharmony_ci
580cabdff1aSopenharmony_ci        LD_SW2(tmp_buf_ptr + i * 8, 4, tmp0_r, tmp0_l);
581cabdff1aSopenharmony_ci        tmp1_r = tmp0_r;
582cabdff1aSopenharmony_ci        tmp1_l = tmp0_l;
583cabdff1aSopenharmony_ci        tmp0_r += sum0_r;
584cabdff1aSopenharmony_ci        tmp0_l += sum0_l;
585cabdff1aSopenharmony_ci        sum1_r = __msa_fill_w(round);
586cabdff1aSopenharmony_ci        SRAR_W2_SW(tmp0_r, tmp0_l, sum1_r);
587cabdff1aSopenharmony_ci        SAT_SW2_SW(tmp0_r, tmp0_l, 15);
588cabdff1aSopenharmony_ci        in0 = __msa_pckev_h((v8i16) tmp0_l, (v8i16) tmp0_r);
589cabdff1aSopenharmony_ci        ST_SH(in0, (coeffs + i * buf_pitch));
590cabdff1aSopenharmony_ci        tmp1_r -= sum0_r;
591cabdff1aSopenharmony_ci        tmp1_l -= sum0_l;
592cabdff1aSopenharmony_ci        SRAR_W2_SW(tmp1_r, tmp1_l, sum1_r);
593cabdff1aSopenharmony_ci        SAT_SW2_SW(tmp1_r, tmp1_l, 15);
594cabdff1aSopenharmony_ci        in0 = __msa_pckev_h((v8i16) tmp1_l, (v8i16) tmp1_r);
595cabdff1aSopenharmony_ci        ST_SH(in0, (coeffs + (31 - i) * buf_pitch));
596cabdff1aSopenharmony_ci
597cabdff1aSopenharmony_ci        filter_ptr0 += 16;
598cabdff1aSopenharmony_ci    }
599cabdff1aSopenharmony_ci}
600cabdff1aSopenharmony_ci
601cabdff1aSopenharmony_cistatic void hevc_idct_transpose_32x8_to_8x32(int16_t *coeffs, int16_t *tmp_buf)
602cabdff1aSopenharmony_ci{
603cabdff1aSopenharmony_ci    uint8_t i;
604cabdff1aSopenharmony_ci    v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
605cabdff1aSopenharmony_ci
606cabdff1aSopenharmony_ci    for (i = 0; i < 4; i++) {
607cabdff1aSopenharmony_ci        LD_SH8(coeffs + i * 8, 32, in0, in1, in2, in3, in4, in5, in6, in7);
608cabdff1aSopenharmony_ci        TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
609cabdff1aSopenharmony_ci                           in0, in1, in2, in3, in4, in5, in6, in7);
610cabdff1aSopenharmony_ci        ST_SH8(in0, in1, in2, in3, in4, in5, in6, in7, tmp_buf + i * 8 * 8, 8);
611cabdff1aSopenharmony_ci    }
612cabdff1aSopenharmony_ci}
613cabdff1aSopenharmony_ci
614cabdff1aSopenharmony_cistatic void hevc_idct_transpose_8x32_to_32x8(int16_t *tmp_buf, int16_t *coeffs)
615cabdff1aSopenharmony_ci{
616cabdff1aSopenharmony_ci    uint8_t i;
617cabdff1aSopenharmony_ci    v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
618cabdff1aSopenharmony_ci
619cabdff1aSopenharmony_ci    for (i = 0; i < 4; i++) {
620cabdff1aSopenharmony_ci        LD_SH8(tmp_buf + i * 8 * 8, 8, in0, in1, in2, in3, in4, in5, in6, in7);
621cabdff1aSopenharmony_ci        TRANSPOSE8x8_SH_SH(in0, in1, in2, in3, in4, in5, in6, in7,
622cabdff1aSopenharmony_ci                           in0, in1, in2, in3, in4, in5, in6, in7);
623cabdff1aSopenharmony_ci        ST_SH8(in0, in1, in2, in3, in4, in5, in6, in7, coeffs + i * 8, 32);
624cabdff1aSopenharmony_ci    }
625cabdff1aSopenharmony_ci}
626cabdff1aSopenharmony_ci
627cabdff1aSopenharmony_cistatic void hevc_idct_32x32_msa(int16_t *coeffs)
628cabdff1aSopenharmony_ci{
629cabdff1aSopenharmony_ci    uint8_t row_cnt, col_cnt;
630cabdff1aSopenharmony_ci    int16_t *src = coeffs;
631cabdff1aSopenharmony_ci    int16_t tmp_buf[8 * 32 + 31];
632cabdff1aSopenharmony_ci    int16_t *tmp_buf_ptr = tmp_buf + 31;
633cabdff1aSopenharmony_ci    uint8_t round;
634cabdff1aSopenharmony_ci    uint8_t buf_pitch;
635cabdff1aSopenharmony_ci
636cabdff1aSopenharmony_ci    /* Align pointer to 64 byte boundary */
637cabdff1aSopenharmony_ci    tmp_buf_ptr = (int16_t *)(((uintptr_t) tmp_buf_ptr) & ~(uintptr_t) 63);
638cabdff1aSopenharmony_ci
639cabdff1aSopenharmony_ci    /* column transform */
640cabdff1aSopenharmony_ci    round = 7;
641cabdff1aSopenharmony_ci    buf_pitch = 32;
642cabdff1aSopenharmony_ci    for (col_cnt = 0; col_cnt < 4; col_cnt++) {
643cabdff1aSopenharmony_ci        /* process 8x32 blocks */
644cabdff1aSopenharmony_ci        hevc_idct_8x32_column_msa((coeffs + col_cnt * 8), buf_pitch, round);
645cabdff1aSopenharmony_ci    }
646cabdff1aSopenharmony_ci
647cabdff1aSopenharmony_ci    /* row transform */
648cabdff1aSopenharmony_ci    round = 12;
649cabdff1aSopenharmony_ci    buf_pitch = 8;
650cabdff1aSopenharmony_ci    for (row_cnt = 0; row_cnt < 4; row_cnt++) {
651cabdff1aSopenharmony_ci        /* process 32x8 blocks */
652cabdff1aSopenharmony_ci        src = (coeffs + 32 * 8 * row_cnt);
653cabdff1aSopenharmony_ci
654cabdff1aSopenharmony_ci        hevc_idct_transpose_32x8_to_8x32(src, tmp_buf_ptr);
655cabdff1aSopenharmony_ci        hevc_idct_8x32_column_msa(tmp_buf_ptr, buf_pitch, round);
656cabdff1aSopenharmony_ci        hevc_idct_transpose_8x32_to_32x8(tmp_buf_ptr, src);
657cabdff1aSopenharmony_ci    }
658cabdff1aSopenharmony_ci}
659cabdff1aSopenharmony_ci
660cabdff1aSopenharmony_cistatic void hevc_idct_dc_4x4_msa(int16_t *coeffs)
661cabdff1aSopenharmony_ci{
662cabdff1aSopenharmony_ci    int32_t val;
663cabdff1aSopenharmony_ci    v8i16 dst;
664cabdff1aSopenharmony_ci
665cabdff1aSopenharmony_ci    val = (coeffs[0] + 1) >> 1;
666cabdff1aSopenharmony_ci    val = (val + 32) >> 6;
667cabdff1aSopenharmony_ci    dst = __msa_fill_h(val);
668cabdff1aSopenharmony_ci
669cabdff1aSopenharmony_ci    ST_SH2(dst, dst, coeffs, 8);
670cabdff1aSopenharmony_ci}
671cabdff1aSopenharmony_ci
672cabdff1aSopenharmony_cistatic void hevc_idct_dc_8x8_msa(int16_t *coeffs)
673cabdff1aSopenharmony_ci{
674cabdff1aSopenharmony_ci    int32_t val;
675cabdff1aSopenharmony_ci    v8i16 dst;
676cabdff1aSopenharmony_ci
677cabdff1aSopenharmony_ci    val = (coeffs[0] + 1) >> 1;
678cabdff1aSopenharmony_ci    val = (val + 32) >> 6;
679cabdff1aSopenharmony_ci    dst = __msa_fill_h(val);
680cabdff1aSopenharmony_ci
681cabdff1aSopenharmony_ci    ST_SH8(dst, dst, dst, dst, dst, dst, dst, dst, coeffs, 8);
682cabdff1aSopenharmony_ci}
683cabdff1aSopenharmony_ci
684cabdff1aSopenharmony_cistatic void hevc_idct_dc_16x16_msa(int16_t *coeffs)
685cabdff1aSopenharmony_ci{
686cabdff1aSopenharmony_ci    uint8_t loop;
687cabdff1aSopenharmony_ci    int32_t val;
688cabdff1aSopenharmony_ci    v8i16 dst;
689cabdff1aSopenharmony_ci
690cabdff1aSopenharmony_ci    val = (coeffs[0] + 1) >> 1;
691cabdff1aSopenharmony_ci    val = (val + 32) >> 6;
692cabdff1aSopenharmony_ci    dst = __msa_fill_h(val);
693cabdff1aSopenharmony_ci
694cabdff1aSopenharmony_ci    for (loop = 4; loop--;) {
695cabdff1aSopenharmony_ci        ST_SH8(dst, dst, dst, dst, dst, dst, dst, dst, coeffs, 8);
696cabdff1aSopenharmony_ci        coeffs += 8 * 8;
697cabdff1aSopenharmony_ci    }
698cabdff1aSopenharmony_ci}
699cabdff1aSopenharmony_ci
700cabdff1aSopenharmony_cistatic void hevc_idct_dc_32x32_msa(int16_t *coeffs)
701cabdff1aSopenharmony_ci{
702cabdff1aSopenharmony_ci    uint8_t loop;
703cabdff1aSopenharmony_ci    int32_t val;
704cabdff1aSopenharmony_ci    v8i16 dst;
705cabdff1aSopenharmony_ci
706cabdff1aSopenharmony_ci    val = (coeffs[0] + 1) >> 1;
707cabdff1aSopenharmony_ci    val = (val + 32) >> 6;
708cabdff1aSopenharmony_ci    dst = __msa_fill_h(val);
709cabdff1aSopenharmony_ci
710cabdff1aSopenharmony_ci    for (loop = 16; loop--;) {
711cabdff1aSopenharmony_ci        ST_SH8(dst, dst, dst, dst, dst, dst, dst, dst, coeffs, 8);
712cabdff1aSopenharmony_ci        coeffs += 8 * 8;
713cabdff1aSopenharmony_ci    }
714cabdff1aSopenharmony_ci}
715cabdff1aSopenharmony_ci
716cabdff1aSopenharmony_cistatic void hevc_addblk_4x4_msa(int16_t *coeffs, uint8_t *dst, int32_t stride)
717cabdff1aSopenharmony_ci{
718cabdff1aSopenharmony_ci    uint32_t dst0, dst1, dst2, dst3;
719cabdff1aSopenharmony_ci    v8i16 dst_r0, dst_l0, in0, in1;
720cabdff1aSopenharmony_ci    v4i32 dst_vec = { 0 };
721cabdff1aSopenharmony_ci    v16u8 zeros = { 0 };
722cabdff1aSopenharmony_ci
723cabdff1aSopenharmony_ci    LD_SH2(coeffs, 8, in0, in1);
724cabdff1aSopenharmony_ci    LW4(dst, stride, dst0, dst1, dst2, dst3);
725cabdff1aSopenharmony_ci    INSERT_W4_SW(dst0, dst1, dst2, dst3, dst_vec);
726cabdff1aSopenharmony_ci    ILVRL_B2_SH(zeros, dst_vec, dst_r0, dst_l0);
727cabdff1aSopenharmony_ci    ADD2(dst_r0, in0, dst_l0, in1, dst_r0, dst_l0);
728cabdff1aSopenharmony_ci    CLIP_SH2_0_255(dst_r0, dst_l0);
729cabdff1aSopenharmony_ci    dst_vec = (v4i32) __msa_pckev_b((v16i8) dst_l0, (v16i8) dst_r0);
730cabdff1aSopenharmony_ci    ST_W4(dst_vec, 0, 1, 2, 3, dst, stride);
731cabdff1aSopenharmony_ci}
732cabdff1aSopenharmony_ci
733cabdff1aSopenharmony_cistatic void hevc_addblk_8x8_msa(int16_t *coeffs, uint8_t *dst, int32_t stride)
734cabdff1aSopenharmony_ci{
735cabdff1aSopenharmony_ci    uint8_t *temp_dst = dst;
736cabdff1aSopenharmony_ci    uint64_t dst0, dst1, dst2, dst3;
737cabdff1aSopenharmony_ci    v2i64 dst_vec0 = { 0 };
738cabdff1aSopenharmony_ci    v2i64 dst_vec1 = { 0 };
739cabdff1aSopenharmony_ci    v8i16 dst_r0, dst_l0, dst_r1, dst_l1;
740cabdff1aSopenharmony_ci    v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
741cabdff1aSopenharmony_ci    v16u8 zeros = { 0 };
742cabdff1aSopenharmony_ci
743cabdff1aSopenharmony_ci    LD_SH8(coeffs, 8, in0, in1, in2, in3, in4, in5, in6, in7);
744cabdff1aSopenharmony_ci    LD4(temp_dst, stride, dst0, dst1, dst2, dst3);
745cabdff1aSopenharmony_ci    temp_dst += (4 * stride);
746cabdff1aSopenharmony_ci
747cabdff1aSopenharmony_ci    INSERT_D2_SD(dst0, dst1, dst_vec0);
748cabdff1aSopenharmony_ci    INSERT_D2_SD(dst2, dst3, dst_vec1);
749cabdff1aSopenharmony_ci    ILVRL_B2_SH(zeros, dst_vec0, dst_r0, dst_l0);
750cabdff1aSopenharmony_ci    ILVRL_B2_SH(zeros, dst_vec1, dst_r1, dst_l1);
751cabdff1aSopenharmony_ci    ADD4(dst_r0, in0, dst_l0, in1, dst_r1, in2, dst_l1, in3,
752cabdff1aSopenharmony_ci         dst_r0, dst_l0, dst_r1, dst_l1);
753cabdff1aSopenharmony_ci    CLIP_SH4_0_255(dst_r0, dst_l0, dst_r1, dst_l1);
754cabdff1aSopenharmony_ci    PCKEV_B2_SH(dst_l0, dst_r0, dst_l1, dst_r1, dst_r0, dst_r1);
755cabdff1aSopenharmony_ci    ST_D4(dst_r0, dst_r1, 0, 1, 0, 1, dst, stride);
756cabdff1aSopenharmony_ci
757cabdff1aSopenharmony_ci    LD4(temp_dst, stride, dst0, dst1, dst2, dst3);
758cabdff1aSopenharmony_ci    INSERT_D2_SD(dst0, dst1, dst_vec0);
759cabdff1aSopenharmony_ci    INSERT_D2_SD(dst2, dst3, dst_vec1);
760cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst_vec0, dst_r0, dst_l0);
761cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst_vec1, dst_r1, dst_l1);
762cabdff1aSopenharmony_ci    ADD4(dst_r0, in4, dst_l0, in5, dst_r1, in6, dst_l1, in7,
763cabdff1aSopenharmony_ci         dst_r0, dst_l0, dst_r1, dst_l1);
764cabdff1aSopenharmony_ci    CLIP_SH4_0_255(dst_r0, dst_l0, dst_r1, dst_l1);
765cabdff1aSopenharmony_ci    PCKEV_B2_SH(dst_l0, dst_r0, dst_l1, dst_r1, dst_r0, dst_r1);
766cabdff1aSopenharmony_ci    ST_D4(dst_r0, dst_r1, 0, 1, 0, 1, dst + 4 * stride, stride);
767cabdff1aSopenharmony_ci}
768cabdff1aSopenharmony_ci
769cabdff1aSopenharmony_cistatic void hevc_addblk_16x16_msa(int16_t *coeffs, uint8_t *dst, int32_t stride)
770cabdff1aSopenharmony_ci{
771cabdff1aSopenharmony_ci    uint8_t loop_cnt;
772cabdff1aSopenharmony_ci    uint8_t *temp_dst = dst;
773cabdff1aSopenharmony_ci    v16u8 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
774cabdff1aSopenharmony_ci    v8i16 dst_r0, dst_l0, dst_r1, dst_l1, dst_r2, dst_l2, dst_r3, dst_l3;
775cabdff1aSopenharmony_ci    v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
776cabdff1aSopenharmony_ci
777cabdff1aSopenharmony_ci    /* Pre-load for next iteration */
778cabdff1aSopenharmony_ci    LD_UB4(temp_dst, stride, dst4, dst5, dst6, dst7);
779cabdff1aSopenharmony_ci    temp_dst += (4 * stride);
780cabdff1aSopenharmony_ci    LD_SH4(coeffs, 16, in0, in2, in4, in6);
781cabdff1aSopenharmony_ci    LD_SH4((coeffs + 8), 16, in1, in3, in5, in7);
782cabdff1aSopenharmony_ci    coeffs += 64;
783cabdff1aSopenharmony_ci
784cabdff1aSopenharmony_ci    for (loop_cnt = 3; loop_cnt--;) {
785cabdff1aSopenharmony_ci        UNPCK_UB_SH(dst4, dst_r0, dst_l0);
786cabdff1aSopenharmony_ci        UNPCK_UB_SH(dst5, dst_r1, dst_l1);
787cabdff1aSopenharmony_ci        UNPCK_UB_SH(dst6, dst_r2, dst_l2);
788cabdff1aSopenharmony_ci        UNPCK_UB_SH(dst7, dst_r3, dst_l3);
789cabdff1aSopenharmony_ci
790cabdff1aSopenharmony_ci        dst_r0 += in0;
791cabdff1aSopenharmony_ci        dst_l0 += in1;
792cabdff1aSopenharmony_ci        dst_r1 += in2;
793cabdff1aSopenharmony_ci        dst_l1 += in3;
794cabdff1aSopenharmony_ci        dst_r2 += in4;
795cabdff1aSopenharmony_ci        dst_l2 += in5;
796cabdff1aSopenharmony_ci        dst_r3 += in6;
797cabdff1aSopenharmony_ci        dst_l3 += in7;
798cabdff1aSopenharmony_ci
799cabdff1aSopenharmony_ci        /* Pre-load for next iteration */
800cabdff1aSopenharmony_ci        LD_UB4(temp_dst, stride, dst4, dst5, dst6, dst7);
801cabdff1aSopenharmony_ci        temp_dst += (4 * stride);
802cabdff1aSopenharmony_ci        LD_SH4(coeffs, 16, in0, in2, in4, in6);
803cabdff1aSopenharmony_ci        LD_SH4((coeffs + 8), 16, in1, in3, in5, in7);
804cabdff1aSopenharmony_ci        coeffs += 64;
805cabdff1aSopenharmony_ci
806cabdff1aSopenharmony_ci        CLIP_SH8_0_255(dst_r0, dst_l0, dst_r1, dst_l1,
807cabdff1aSopenharmony_ci                       dst_r2, dst_l2, dst_r3, dst_l3);
808cabdff1aSopenharmony_ci
809cabdff1aSopenharmony_ci        PCKEV_B4_UB(dst_l0, dst_r0, dst_l1, dst_r1, dst_l2, dst_r2, dst_l3,
810cabdff1aSopenharmony_ci                    dst_r3, dst0, dst1, dst2, dst3);
811cabdff1aSopenharmony_ci        ST_UB4(dst0, dst1, dst2, dst3, dst, stride);
812cabdff1aSopenharmony_ci        dst += (4 * stride);
813cabdff1aSopenharmony_ci    }
814cabdff1aSopenharmony_ci
815cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst4, dst_r0, dst_l0);
816cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst5, dst_r1, dst_l1);
817cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst6, dst_r2, dst_l2);
818cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst7, dst_r3, dst_l3);
819cabdff1aSopenharmony_ci
820cabdff1aSopenharmony_ci    dst_r0 += in0;
821cabdff1aSopenharmony_ci    dst_l0 += in1;
822cabdff1aSopenharmony_ci    dst_r1 += in2;
823cabdff1aSopenharmony_ci    dst_l1 += in3;
824cabdff1aSopenharmony_ci    dst_r2 += in4;
825cabdff1aSopenharmony_ci    dst_l2 += in5;
826cabdff1aSopenharmony_ci    dst_r3 += in6;
827cabdff1aSopenharmony_ci    dst_l3 += in7;
828cabdff1aSopenharmony_ci
829cabdff1aSopenharmony_ci    CLIP_SH8_0_255(dst_r0, dst_l0, dst_r1, dst_l1,
830cabdff1aSopenharmony_ci                   dst_r2, dst_l2, dst_r3, dst_l3);
831cabdff1aSopenharmony_ci    PCKEV_B4_UB(dst_l0, dst_r0, dst_l1, dst_r1, dst_l2, dst_r2, dst_l3,
832cabdff1aSopenharmony_ci                dst_r3, dst0, dst1, dst2, dst3);
833cabdff1aSopenharmony_ci    ST_UB4(dst0, dst1, dst2, dst3, dst, stride);
834cabdff1aSopenharmony_ci}
835cabdff1aSopenharmony_ci
836cabdff1aSopenharmony_cistatic void hevc_addblk_32x32_msa(int16_t *coeffs, uint8_t *dst, int32_t stride)
837cabdff1aSopenharmony_ci{
838cabdff1aSopenharmony_ci    uint8_t loop_cnt;
839cabdff1aSopenharmony_ci    uint8_t *temp_dst = dst;
840cabdff1aSopenharmony_ci    v16u8 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
841cabdff1aSopenharmony_ci    v8i16 dst_r0, dst_l0, dst_r1, dst_l1, dst_r2, dst_l2, dst_r3, dst_l3;
842cabdff1aSopenharmony_ci    v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
843cabdff1aSopenharmony_ci
844cabdff1aSopenharmony_ci    /* Pre-load for next iteration */
845cabdff1aSopenharmony_ci    LD_UB2(temp_dst, 16, dst4, dst5);
846cabdff1aSopenharmony_ci    temp_dst += stride;
847cabdff1aSopenharmony_ci    LD_UB2(temp_dst, 16, dst6, dst7);
848cabdff1aSopenharmony_ci    temp_dst += stride;
849cabdff1aSopenharmony_ci    LD_SH4(coeffs, 16, in0, in2, in4, in6);
850cabdff1aSopenharmony_ci    LD_SH4((coeffs + 8), 16, in1, in3, in5, in7);
851cabdff1aSopenharmony_ci    coeffs += 64;
852cabdff1aSopenharmony_ci
853cabdff1aSopenharmony_ci    for (loop_cnt = 14; loop_cnt--;) {
854cabdff1aSopenharmony_ci        UNPCK_UB_SH(dst4, dst_r0, dst_l0);
855cabdff1aSopenharmony_ci        UNPCK_UB_SH(dst5, dst_r1, dst_l1);
856cabdff1aSopenharmony_ci        UNPCK_UB_SH(dst6, dst_r2, dst_l2);
857cabdff1aSopenharmony_ci        UNPCK_UB_SH(dst7, dst_r3, dst_l3);
858cabdff1aSopenharmony_ci
859cabdff1aSopenharmony_ci        dst_r0 += in0;
860cabdff1aSopenharmony_ci        dst_l0 += in1;
861cabdff1aSopenharmony_ci        dst_r1 += in2;
862cabdff1aSopenharmony_ci        dst_l1 += in3;
863cabdff1aSopenharmony_ci        dst_r2 += in4;
864cabdff1aSopenharmony_ci        dst_l2 += in5;
865cabdff1aSopenharmony_ci        dst_r3 += in6;
866cabdff1aSopenharmony_ci        dst_l3 += in7;
867cabdff1aSopenharmony_ci
868cabdff1aSopenharmony_ci        /* Pre-load for next iteration */
869cabdff1aSopenharmony_ci        LD_UB2(temp_dst, 16, dst4, dst5);
870cabdff1aSopenharmony_ci        temp_dst += stride;
871cabdff1aSopenharmony_ci        LD_UB2(temp_dst, 16, dst6, dst7);
872cabdff1aSopenharmony_ci        temp_dst += stride;
873cabdff1aSopenharmony_ci        LD_SH4(coeffs, 16, in0, in2, in4, in6);
874cabdff1aSopenharmony_ci        LD_SH4((coeffs + 8), 16, in1, in3, in5, in7);
875cabdff1aSopenharmony_ci        coeffs += 64;
876cabdff1aSopenharmony_ci
877cabdff1aSopenharmony_ci        CLIP_SH8_0_255(dst_r0, dst_l0, dst_r1, dst_l1,
878cabdff1aSopenharmony_ci                       dst_r2, dst_l2, dst_r3, dst_l3);
879cabdff1aSopenharmony_ci        PCKEV_B4_UB(dst_l0, dst_r0, dst_l1, dst_r1, dst_l2, dst_r2, dst_l3,
880cabdff1aSopenharmony_ci                    dst_r3, dst0, dst1, dst2, dst3);
881cabdff1aSopenharmony_ci        ST_UB2(dst0, dst1, dst, 16);
882cabdff1aSopenharmony_ci        dst += stride;
883cabdff1aSopenharmony_ci        ST_UB2(dst2, dst3, dst, 16);
884cabdff1aSopenharmony_ci        dst += stride;
885cabdff1aSopenharmony_ci    }
886cabdff1aSopenharmony_ci
887cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst4, dst_r0, dst_l0);
888cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst5, dst_r1, dst_l1);
889cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst6, dst_r2, dst_l2);
890cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst7, dst_r3, dst_l3);
891cabdff1aSopenharmony_ci
892cabdff1aSopenharmony_ci    dst_r0 += in0;
893cabdff1aSopenharmony_ci    dst_l0 += in1;
894cabdff1aSopenharmony_ci    dst_r1 += in2;
895cabdff1aSopenharmony_ci    dst_l1 += in3;
896cabdff1aSopenharmony_ci    dst_r2 += in4;
897cabdff1aSopenharmony_ci    dst_l2 += in5;
898cabdff1aSopenharmony_ci    dst_r3 += in6;
899cabdff1aSopenharmony_ci    dst_l3 += in7;
900cabdff1aSopenharmony_ci
901cabdff1aSopenharmony_ci    /* Pre-load for next iteration */
902cabdff1aSopenharmony_ci    LD_UB2(temp_dst, 16, dst4, dst5);
903cabdff1aSopenharmony_ci    temp_dst += stride;
904cabdff1aSopenharmony_ci    LD_UB2(temp_dst, 16, dst6, dst7);
905cabdff1aSopenharmony_ci    temp_dst += stride;
906cabdff1aSopenharmony_ci    LD_SH4(coeffs, 16, in0, in2, in4, in6);
907cabdff1aSopenharmony_ci    LD_SH4((coeffs + 8), 16, in1, in3, in5, in7);
908cabdff1aSopenharmony_ci
909cabdff1aSopenharmony_ci    CLIP_SH8_0_255(dst_r0, dst_l0, dst_r1, dst_l1,
910cabdff1aSopenharmony_ci                   dst_r2, dst_l2, dst_r3, dst_l3);
911cabdff1aSopenharmony_ci    PCKEV_B4_UB(dst_l0, dst_r0, dst_l1, dst_r1, dst_l2, dst_r2, dst_l3,
912cabdff1aSopenharmony_ci                dst_r3, dst0, dst1, dst2, dst3);
913cabdff1aSopenharmony_ci    ST_UB2(dst0, dst1, dst, 16);
914cabdff1aSopenharmony_ci    dst += stride;
915cabdff1aSopenharmony_ci    ST_UB2(dst2, dst3, dst, 16);
916cabdff1aSopenharmony_ci    dst += stride;
917cabdff1aSopenharmony_ci
918cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst4, dst_r0, dst_l0);
919cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst5, dst_r1, dst_l1);
920cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst6, dst_r2, dst_l2);
921cabdff1aSopenharmony_ci    UNPCK_UB_SH(dst7, dst_r3, dst_l3);
922cabdff1aSopenharmony_ci
923cabdff1aSopenharmony_ci    dst_r0 += in0;
924cabdff1aSopenharmony_ci    dst_l0 += in1;
925cabdff1aSopenharmony_ci    dst_r1 += in2;
926cabdff1aSopenharmony_ci    dst_l1 += in3;
927cabdff1aSopenharmony_ci    dst_r2 += in4;
928cabdff1aSopenharmony_ci    dst_l2 += in5;
929cabdff1aSopenharmony_ci    dst_r3 += in6;
930cabdff1aSopenharmony_ci    dst_l3 += in7;
931cabdff1aSopenharmony_ci
932cabdff1aSopenharmony_ci    CLIP_SH8_0_255(dst_r0, dst_l0, dst_r1, dst_l1,
933cabdff1aSopenharmony_ci                   dst_r2, dst_l2, dst_r3, dst_l3);
934cabdff1aSopenharmony_ci    PCKEV_B4_UB(dst_l0, dst_r0, dst_l1, dst_r1, dst_l2, dst_r2, dst_l3,
935cabdff1aSopenharmony_ci                dst_r3, dst0, dst1, dst2, dst3);
936cabdff1aSopenharmony_ci    ST_UB2(dst0, dst1, dst, 16);
937cabdff1aSopenharmony_ci    dst += stride;
938cabdff1aSopenharmony_ci    ST_UB2(dst2, dst3, dst, 16);
939cabdff1aSopenharmony_ci}
940cabdff1aSopenharmony_ci
941cabdff1aSopenharmony_cistatic void hevc_idct_luma_4x4_msa(int16_t *coeffs)
942cabdff1aSopenharmony_ci{
943cabdff1aSopenharmony_ci    v8i16 in0, in1, dst0, dst1;
944cabdff1aSopenharmony_ci    v4i32 in_r0, in_l0, in_r1, in_l1, res0, res1, res2, res3;
945cabdff1aSopenharmony_ci
946cabdff1aSopenharmony_ci    LD_SH2(coeffs, 8, in0, in1);
947cabdff1aSopenharmony_ci    UNPCK_SH_SW(in0, in_r0, in_l0);
948cabdff1aSopenharmony_ci    UNPCK_SH_SW(in1, in_r1, in_l1);
949cabdff1aSopenharmony_ci    HEVC_IDCT_LUMA4x4_COL(in_r0, in_l0, in_r1, in_l1, res0, res1, res2, res3,
950cabdff1aSopenharmony_ci                          7);
951cabdff1aSopenharmony_ci    TRANSPOSE4x4_SW_SW(res0, res1, res2, res3, in_r0, in_l0, in_r1, in_l1);
952cabdff1aSopenharmony_ci    HEVC_IDCT_LUMA4x4_COL(in_r0, in_l0, in_r1, in_l1, res0, res1, res2, res3,
953cabdff1aSopenharmony_ci                          12);
954cabdff1aSopenharmony_ci
955cabdff1aSopenharmony_ci    /* Pack and transpose */
956cabdff1aSopenharmony_ci    PCKEV_H2_SH(res2, res0, res3, res1, dst0, dst1);
957cabdff1aSopenharmony_ci    ILVRL_H2_SW(dst1, dst0, res0, res1);
958cabdff1aSopenharmony_ci    ILVRL_W2_SH(res1, res0, dst0, dst1);
959cabdff1aSopenharmony_ci
960cabdff1aSopenharmony_ci    ST_SH2(dst0, dst1, coeffs, 8);
961cabdff1aSopenharmony_ci}
962cabdff1aSopenharmony_ci
963cabdff1aSopenharmony_civoid ff_hevc_idct_4x4_msa(int16_t *coeffs, int col_limit)
964cabdff1aSopenharmony_ci{
965cabdff1aSopenharmony_ci    hevc_idct_4x4_msa(coeffs);
966cabdff1aSopenharmony_ci}
967cabdff1aSopenharmony_ci
968cabdff1aSopenharmony_civoid ff_hevc_idct_8x8_msa(int16_t *coeffs, int col_limit)
969cabdff1aSopenharmony_ci{
970cabdff1aSopenharmony_ci    hevc_idct_8x8_msa(coeffs);
971cabdff1aSopenharmony_ci}
972cabdff1aSopenharmony_ci
973cabdff1aSopenharmony_civoid ff_hevc_idct_16x16_msa(int16_t *coeffs, int col_limit)
974cabdff1aSopenharmony_ci{
975cabdff1aSopenharmony_ci    hevc_idct_16x16_msa(coeffs);
976cabdff1aSopenharmony_ci}
977cabdff1aSopenharmony_ci
978cabdff1aSopenharmony_civoid ff_hevc_idct_32x32_msa(int16_t *coeffs, int col_limit)
979cabdff1aSopenharmony_ci{
980cabdff1aSopenharmony_ci    hevc_idct_32x32_msa(coeffs);
981cabdff1aSopenharmony_ci}
982cabdff1aSopenharmony_ci
983cabdff1aSopenharmony_civoid ff_hevc_addblk_4x4_msa(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
984cabdff1aSopenharmony_ci{
985cabdff1aSopenharmony_ci    hevc_addblk_4x4_msa(coeffs, dst, stride);
986cabdff1aSopenharmony_ci}
987cabdff1aSopenharmony_ci
988cabdff1aSopenharmony_civoid ff_hevc_addblk_8x8_msa(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
989cabdff1aSopenharmony_ci{
990cabdff1aSopenharmony_ci    hevc_addblk_8x8_msa(coeffs, dst, stride);
991cabdff1aSopenharmony_ci}
992cabdff1aSopenharmony_ci
993cabdff1aSopenharmony_civoid ff_hevc_addblk_16x16_msa(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
994cabdff1aSopenharmony_ci{
995cabdff1aSopenharmony_ci    hevc_addblk_16x16_msa(coeffs, dst, stride);
996cabdff1aSopenharmony_ci}
997cabdff1aSopenharmony_ci
998cabdff1aSopenharmony_civoid ff_hevc_addblk_32x32_msa(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
999cabdff1aSopenharmony_ci{
1000cabdff1aSopenharmony_ci    hevc_addblk_32x32_msa(coeffs, dst, stride);
1001cabdff1aSopenharmony_ci}
1002cabdff1aSopenharmony_ci
1003cabdff1aSopenharmony_civoid ff_hevc_idct_dc_4x4_msa(int16_t *coeffs)
1004cabdff1aSopenharmony_ci{
1005cabdff1aSopenharmony_ci    hevc_idct_dc_4x4_msa(coeffs);
1006cabdff1aSopenharmony_ci}
1007cabdff1aSopenharmony_ci
1008cabdff1aSopenharmony_civoid ff_hevc_idct_dc_8x8_msa(int16_t *coeffs)
1009cabdff1aSopenharmony_ci{
1010cabdff1aSopenharmony_ci    hevc_idct_dc_8x8_msa(coeffs);
1011cabdff1aSopenharmony_ci}
1012cabdff1aSopenharmony_ci
1013cabdff1aSopenharmony_civoid ff_hevc_idct_dc_16x16_msa(int16_t *coeffs)
1014cabdff1aSopenharmony_ci{
1015cabdff1aSopenharmony_ci    hevc_idct_dc_16x16_msa(coeffs);
1016cabdff1aSopenharmony_ci}
1017cabdff1aSopenharmony_ci
1018cabdff1aSopenharmony_civoid ff_hevc_idct_dc_32x32_msa(int16_t *coeffs)
1019cabdff1aSopenharmony_ci{
1020cabdff1aSopenharmony_ci    hevc_idct_dc_32x32_msa(coeffs);
1021cabdff1aSopenharmony_ci}
1022cabdff1aSopenharmony_ci
1023cabdff1aSopenharmony_civoid ff_hevc_idct_luma_4x4_msa(int16_t *coeffs)
1024cabdff1aSopenharmony_ci{
1025cabdff1aSopenharmony_ci    hevc_idct_luma_4x4_msa(coeffs);
1026cabdff1aSopenharmony_ci}
1027