FFmpeg
hevc_mc_biw_msa.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2017 Manojkumar Bhosale (Manojkumar.Bhosale@imgtec.com)
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
24 
25 static const uint8_t ff_hevc_mask_arr[16 * 2] __attribute__((aligned(0x40))) = {
26  /* 8 width cases */
27  0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
28  0, 1, 1, 2, 2, 3, 3, 4, 16, 17, 17, 18, 18, 19, 19, 20
29 };
30 
31 #define HEVC_BIW_RND_CLIP2(in0, in1, vec0, vec1, wgt, rnd, offset, \
32  out0, out1) \
33 { \
34  v4i32 out0_r, out1_r, out0_l, out1_l; \
35  \
36  ILVR_H2_SW(in0, vec0, in1, vec1, out0_r, out1_r); \
37  ILVL_H2_SW(in0, vec0, in1, vec1, out0_l, out1_l); \
38  \
39  out0_r = __msa_dpadd_s_w(offset, (v8i16) out0_r, (v8i16) wgt); \
40  out1_r = __msa_dpadd_s_w(offset, (v8i16) out1_r, (v8i16) wgt); \
41  out0_l = __msa_dpadd_s_w(offset, (v8i16) out0_l, (v8i16) wgt); \
42  out1_l = __msa_dpadd_s_w(offset, (v8i16) out1_l, (v8i16) wgt); \
43  \
44  SRAR_W4_SW(out0_r, out1_r, out0_l, out1_l, rnd); \
45  PCKEV_H2_SH(out0_l, out0_r, out1_l, out1_r, out0, out1); \
46  CLIP_SH2_0_255(out0, out1); \
47 }
48 
49 #define HEVC_BIW_RND_CLIP4(in0, in1, in2, in3, vec0, vec1, vec2, vec3, \
50  wgt, rnd, offset, out0, out1, out2, out3) \
51 { \
52  HEVC_BIW_RND_CLIP2(in0, in1, vec0, vec1, wgt, rnd, offset, out0, out1); \
53  HEVC_BIW_RND_CLIP2(in2, in3, vec2, vec3, wgt, rnd, offset, out2, out3); \
54 }
55 
56 #define HEVC_BIW_RND_CLIP2_MAX_SATU(in0, in1, vec0, vec1, wgt, rnd, \
57  offset, out0, out1) \
58 { \
59  v4i32 out0_r, out1_r, out0_l, out1_l; \
60  \
61  ILVR_H2_SW(in0, vec0, in1, vec1, out0_r, out1_r); \
62  ILVL_H2_SW(in0, vec0, in1, vec1, out0_l, out1_l); \
63  out0_r = __msa_dpadd_s_w(offset, (v8i16) out0_r, (v8i16) wgt); \
64  out1_r = __msa_dpadd_s_w(offset, (v8i16) out1_r, (v8i16) wgt); \
65  out0_l = __msa_dpadd_s_w(offset, (v8i16) out0_l, (v8i16) wgt); \
66  out1_l = __msa_dpadd_s_w(offset, (v8i16) out1_l, (v8i16) wgt); \
67  SRAR_W4_SW(out0_r, out1_r, out0_l, out1_l, rnd); \
68  PCKEV_H2_SH(out0_l, out0_r, out1_l, out1_r, out0, out1); \
69  CLIP_SH2_0_255(out0, out1); \
70 }
71 
72 #define HEVC_BIW_RND_CLIP4_MAX_SATU(in0, in1, in2, in3, vec0, vec1, vec2, \
73  vec3, wgt, rnd, offset, out0, out1, \
74  out2, out3) \
75 { \
76  HEVC_BIW_RND_CLIP2_MAX_SATU(in0, in1, vec0, vec1, wgt, rnd, offset, \
77  out0, out1); \
78  HEVC_BIW_RND_CLIP2_MAX_SATU(in2, in3, vec2, vec3, wgt, rnd, offset, \
79  out2, out3); \
80 }
81 
82 static void hevc_biwgt_copy_4w_msa(const uint8_t *src0_ptr,
83  int32_t src_stride,
84  const int16_t *src1_ptr,
85  int32_t src2_stride,
86  uint8_t *dst,
87  int32_t dst_stride,
89  int32_t weight0,
90  int32_t weight1,
91  int32_t offset0,
92  int32_t offset1,
93  int32_t rnd_val)
94 {
95  uint32_t loop_cnt, tp0, tp1, tp2, tp3;
96  uint64_t tpd0, tpd1, tpd2, tpd3;
98  v16u8 out0, out1;
99  v16i8 zero = { 0 };
100  v16i8 src0 = { 0 }, src1 = { 0 };
101  v8i16 in0 = { 0 }, in1 = { 0 }, in2 = { 0 }, in3 = { 0 };
102  v8i16 dst0, dst1, dst2, dst3, weight_vec;
103  v4i32 dst0_r, dst0_l, offset_vec, rnd_vec;
104 
105  offset = (offset0 + offset1) << rnd_val;
106  weight0 = weight0 & 0x0000FFFF;
107  weight = weight0 | (weight1 << 16);
108 
109  offset_vec = __msa_fill_w(offset);
110  weight_vec = (v8i16) __msa_fill_w(weight);
111  rnd_vec = __msa_fill_w(rnd_val + 1);
112 
113  if (2 == height) {
114  LW2(src0_ptr, src_stride, tp0, tp1);
115  INSERT_W2_SB(tp0, tp1, src0);
116  LD2(src1_ptr, src2_stride, tpd0, tpd1);
117  INSERT_D2_SH(tpd0, tpd1, in0);
118 
119  dst0 = (v8i16) __msa_ilvr_b(zero, src0);
120  dst0 <<= 6;
121 
122  ILVRL_H2_SW(dst0, in0, dst0_r, dst0_l);
123  dst0_r = __msa_dpadd_s_w(offset_vec, (v8i16) dst0_r, weight_vec);
124  dst0_l = __msa_dpadd_s_w(offset_vec, (v8i16) dst0_l, weight_vec);
125  SRAR_W2_SW(dst0_r, dst0_l, rnd_vec);
126  dst0 = (v8i16) __msa_pckev_h((v8i16) dst0_l, (v8i16) dst0_r);
127  CLIP_SH_0_255(dst0);
128  out0 = (v16u8) __msa_pckev_b((v16i8) dst0, (v16i8) dst0);
129  ST_W2(out0, 0, 1, dst, dst_stride);
130  } else if (4 == height) {
131  LW4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
132  INSERT_W4_SB(tp0, tp1, tp2, tp3, src0);
133  LD4(src1_ptr, src2_stride, tpd0, tpd1, tpd2, tpd3);
134  INSERT_D2_SH(tpd0, tpd1, in0);
135  INSERT_D2_SH(tpd2, tpd3, in1);
136  ILVRL_B2_SH(zero, src0, dst0, dst1);
137  SLLI_2V(dst0, dst1, 6);
138  HEVC_BIW_RND_CLIP2_MAX_SATU(dst0, dst1, in0, in1, weight_vec, rnd_vec,
139  offset_vec, dst0, dst1);
140  out0 = (v16u8) __msa_pckev_b((v16i8) dst1, (v16i8) dst0);
141  ST_W4(out0, 0, 1, 2, 3, dst, dst_stride);
142  } else if (0 == height % 8) {
143  for (loop_cnt = (height >> 3); loop_cnt--;) {
144  LW4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
145  src0_ptr += 4 * src_stride;
146  INSERT_W4_SB(tp0, tp1, tp2, tp3, src0);
147  LW4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
148  src0_ptr += 4 * src_stride;
149  INSERT_W4_SB(tp0, tp1, tp2, tp3, src1);
150  LD4(src1_ptr, src2_stride, tpd0, tpd1, tpd2, tpd3);
151  src1_ptr += (4 * src2_stride);
152  INSERT_D2_SH(tpd0, tpd1, in0);
153  INSERT_D2_SH(tpd2, tpd3, in1);
154  LD4(src1_ptr, src2_stride, tpd0, tpd1, tpd2, tpd3);
155  src1_ptr += (4 * src2_stride);
156  INSERT_D2_SH(tpd0, tpd1, in2);
157  INSERT_D2_SH(tpd2, tpd3, in3);
158  ILVRL_B2_SH(zero, src0, dst0, dst1);
159  ILVRL_B2_SH(zero, src1, dst2, dst3);
160  SLLI_4V(dst0, dst1, dst2, dst3, 6);
161  HEVC_BIW_RND_CLIP4_MAX_SATU(dst0, dst1, dst2, dst3, in0, in1, in2,
162  in3, weight_vec, rnd_vec, offset_vec,
163  dst0, dst1, dst2, dst3);
164  PCKEV_B2_UB(dst1, dst0, dst3, dst2, out0, out1);
165  ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
166  dst += (8 * dst_stride);
167  }
168  }
169 }
170 
171 static void hevc_biwgt_copy_6w_msa(const uint8_t *src0_ptr,
172  int32_t src_stride,
173  const int16_t *src1_ptr,
174  int32_t src2_stride,
175  uint8_t *dst,
176  int32_t dst_stride,
177  int32_t height,
178  int32_t weight0,
179  int32_t weight1,
180  int32_t offset0,
181  int32_t offset1,
182  int32_t rnd_val)
183 {
184  uint32_t loop_cnt;
186  uint64_t tp0, tp1, tp2, tp3;
187  v16u8 out0, out1;
188  v16i8 zero = { 0 };
189  v16i8 src0 = { 0 }, src1 = { 0 };
190  v8i16 in0, in1, in2, in3;
191  v8i16 dst0, dst1, dst2, dst3;
192  v4i32 offset_vec, weight_vec, rnd_vec;
193 
194  offset = (offset0 + offset1) << rnd_val;
195  weight0 = weight0 & 0x0000FFFF;
196  weight = weight0 | (weight1 << 16);
197 
198  weight_vec = __msa_fill_w(weight);
199  offset_vec = __msa_fill_w(offset);
200  rnd_vec = __msa_fill_w(rnd_val + 1);
201 
202  for (loop_cnt = (height >> 2); loop_cnt--;) {
203  LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
204  src0_ptr += (4 * src_stride);
205  INSERT_D2_SB(tp0, tp1, src0);
206  INSERT_D2_SB(tp2, tp3, src1);
207  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
208  src1_ptr += (4 * src2_stride);
209  ILVRL_B2_SH(zero, src0, dst0, dst1);
210  ILVRL_B2_SH(zero, src1, dst2, dst3);
211  SLLI_4V(dst0, dst1, dst2, dst3, 6);
212  HEVC_BIW_RND_CLIP4_MAX_SATU(dst0, dst1, dst2, dst3,
213  in0, in1, in2, in3,
214  weight_vec, rnd_vec, offset_vec,
215  dst0, dst1, dst2, dst3);
216  PCKEV_B2_UB(dst1, dst0, dst3, dst2, out0, out1);
217  ST_W2(out0, 0, 2, dst, dst_stride);
218  ST_H2(out0, 2, 6, dst + 4, dst_stride);
219  ST_W2(out1, 0, 2, dst + 2 * dst_stride, dst_stride);
220  ST_H2(out1, 2, 6, dst + 2 * dst_stride + 4, dst_stride);
221  dst += (4 * dst_stride);
222  }
223 }
224 
225 static void hevc_biwgt_copy_8w_msa(const uint8_t *src0_ptr,
226  int32_t src_stride,
227  const int16_t *src1_ptr,
228  int32_t src2_stride,
229  uint8_t *dst,
230  int32_t dst_stride,
231  int32_t height,
232  int32_t weight0,
233  int32_t weight1,
234  int32_t offset0,
235  int32_t offset1,
236  int32_t rnd_val)
237 {
238  uint64_t tp0, tp1, tp2, tp3;
240  v16u8 out0, out1, out2;
241  v16i8 zero = { 0 };
242  v16i8 src0 = { 0 }, src1 = { 0 }, src2 = { 0 };
243  v8i16 in0, in1, in2, in3, in4, in5;
244  v8i16 dst0, dst1, dst2, dst3, dst4, dst5;
245  v4i32 offset_vec, weight_vec, rnd_vec;
246 
247  offset = (offset0 + offset1) << rnd_val;
248  weight0 = weight0 & 0x0000FFFF;
249  weight = weight0 | (weight1 << 16);
250 
251  offset_vec = __msa_fill_w(offset);
252  weight_vec = __msa_fill_w(weight);
253  rnd_vec = __msa_fill_w(rnd_val + 1);
254 
255  if (2 == height) {
256  LD2(src0_ptr, src_stride, tp0, tp1);
257  INSERT_D2_SB(tp0, tp1, src0);
258  LD_SH2(src1_ptr, src2_stride, in0, in1);
259  ILVRL_B2_SH(zero, src0, dst0, dst1);
260  SLLI_2V(dst0, dst1, 6);
261 
262  HEVC_BIW_RND_CLIP2(dst0, dst1, in0, in1,
263  weight_vec, rnd_vec, offset_vec,
264  dst0, dst1);
265 
266  out0 = (v16u8) __msa_pckev_b((v16i8) dst1, (v16i8) dst0);
267  ST_D2(out0, 0, 1, dst, dst_stride);
268  } else if (6 == height) {
269  LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
270  src0_ptr += 4 * src_stride;
271  INSERT_D2_SB(tp0, tp1, src0);
272  INSERT_D2_SB(tp2, tp3, src1);
273  LD2(src0_ptr, src_stride, tp0, tp1);
274  INSERT_D2_SB(tp0, tp1, src2);
275  ILVRL_B2_SH(zero, src0, dst0, dst1);
276  ILVRL_B2_SH(zero, src1, dst2, dst3);
277  ILVRL_B2_SH(zero, src2, dst4, dst5);
278  LD_SH6(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5);
279  SLLI_4V(dst0, dst1, dst2, dst3, 6);
280  SLLI_2V(dst4, dst5, 6);
281  HEVC_BIW_RND_CLIP4_MAX_SATU(dst0, dst1, dst2, dst3, in0, in1, in2, in3,
282  weight_vec, rnd_vec, offset_vec, dst0, dst1,
283  dst2, dst3);
284  HEVC_BIW_RND_CLIP2_MAX_SATU(dst4, dst5, in4, in5, weight_vec, rnd_vec,
285  offset_vec, dst4, dst5);
286  PCKEV_B3_UB(dst1, dst0, dst3, dst2, dst5, dst4, out0, out1, out2);
287  ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
288  ST_D2(out2, 0, 1, dst + 4 * dst_stride, dst_stride);
289  } else if (0 == height % 4) {
290  uint32_t loop_cnt;
291 
292  for (loop_cnt = (height >> 2); loop_cnt--;) {
293  LD4(src0_ptr, src_stride, tp0, tp1, tp2, tp3);
294  src0_ptr += (4 * src_stride);
295  INSERT_D2_SB(tp0, tp1, src0);
296  INSERT_D2_SB(tp2, tp3, src1);
297  ILVRL_B2_SH(zero, src0, dst0, dst1);
298  ILVRL_B2_SH(zero, src1, dst2, dst3);
299  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
300  src1_ptr += (4 * src2_stride);
301 
302  SLLI_4V(dst0, dst1, dst2, dst3, 6);
303  HEVC_BIW_RND_CLIP4_MAX_SATU(dst0, dst1, dst2, dst3, in0, in1, in2,
304  in3, weight_vec, rnd_vec, offset_vec,
305  dst0, dst1, dst2, dst3);
306  PCKEV_B2_UB(dst1, dst0, dst3, dst2, out0, out1);
307  ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
308  dst += (4 * dst_stride);
309  }
310  }
311 }
312 
313 static void hevc_biwgt_copy_12w_msa(const uint8_t *src0_ptr,
314  int32_t src_stride,
315  const int16_t *src1_ptr,
316  int32_t src2_stride,
317  uint8_t *dst,
318  int32_t dst_stride,
319  int32_t height,
320  int32_t weight0,
321  int32_t weight1,
322  int32_t offset0,
323  int32_t offset1,
324  int32_t rnd_val)
325 {
326  uint32_t loop_cnt;
328  v16i8 zero = { 0 };
329  v16u8 out0, out1, out2;
330  v16i8 src0, src1, src2, src3;
331  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
332  v8i16 dst0, dst1, dst2, dst3, dst4, dst5;
333  v4i32 offset_vec, weight_vec, rnd_vec;
334 
335  offset = (offset0 + offset1) << rnd_val;
336  weight0 = weight0 & 0x0000FFFF;
337  weight = weight0 | (weight1 << 16);
338 
339  offset_vec = __msa_fill_w(offset);
340  weight_vec = __msa_fill_w(weight);
341  rnd_vec = __msa_fill_w(rnd_val + 1);
342 
343  for (loop_cnt = (16 >> 2); loop_cnt--;) {
344  LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
345  src0_ptr += (4 * src_stride);
346  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
347  LD_SH4(src1_ptr + 8, src2_stride, in4, in5, in6, in7);
348  src1_ptr += (4 * src2_stride);
349 
350  ILVR_D2_SH(in5, in4, in7, in6, in4, in5);
351  ILVR_B4_SH(zero, src0, zero, src1, zero, src2, zero, src3,
352  dst0, dst1, dst2, dst3);
353 
354  SLLI_4V(dst0, dst1, dst2, dst3, 6);
355  ILVL_W2_SB(src1, src0, src3, src2, src0, src1);
356  ILVR_B2_SH(zero, src0, zero, src1, dst4, dst5);
357 
358  dst4 <<= 6;
359  dst5 <<= 6;
360  HEVC_BIW_RND_CLIP4_MAX_SATU(dst0, dst1, dst2, dst3, in0, in1, in2, in3,
361  weight_vec, rnd_vec, offset_vec, dst0, dst1,
362  dst2, dst3);
363  HEVC_BIW_RND_CLIP2_MAX_SATU(dst4, dst5, in4, in5, weight_vec, rnd_vec,
364  offset_vec, dst4, dst5);
365  PCKEV_B3_UB(dst1, dst0, dst3, dst2, dst5, dst4, out0, out1, out2);
366  ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
367  ST_W4(out2, 0, 1, 2, 3, dst + 8, dst_stride);
368  dst += (4 * dst_stride);
369  }
370 }
371 
372 static void hevc_biwgt_copy_16w_msa(const uint8_t *src0_ptr,
373  int32_t src_stride,
374  const int16_t *src1_ptr,
375  int32_t src2_stride,
376  uint8_t *dst,
377  int32_t dst_stride,
378  int32_t height,
379  int32_t weight0,
380  int32_t weight1,
381  int32_t offset0,
382  int32_t offset1,
383  int32_t rnd_val)
384 {
385  uint32_t loop_cnt;
387  v16u8 out0, out1, out2, out3;
388  v16i8 zero = { 0 };
389  v16i8 src0, src1, src2, src3;
390  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
391  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
392  v4i32 offset_vec, weight_vec, rnd_vec;
393 
394  offset = (offset0 + offset1) << rnd_val;
395  weight0 = weight0 & 0x0000FFFF;
396  weight = weight0 | (weight1 << 16);
397 
398  offset_vec = __msa_fill_w(offset);
399  weight_vec = __msa_fill_w(weight);
400  rnd_vec = __msa_fill_w(rnd_val + 1);
401 
402  for (loop_cnt = (height >> 2); loop_cnt--;) {
403  LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
404  src0_ptr += (4 * src_stride);
405  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
406  LD_SH4(src1_ptr + 8, src2_stride, in4, in5, in6, in7);
407  src1_ptr += (4 * src2_stride);
408  ILVR_B4_SH(zero, src0, zero, src1, zero, src2, zero, src3, tmp0, tmp1,
409  tmp2, tmp3);
410  ILVL_B4_SH(zero, src0, zero, src1, zero, src2, zero, src3, tmp4, tmp5,
411  tmp6, tmp7);
412  SLLI_4V(tmp0, tmp1, tmp2, tmp3, 6);
413  SLLI_4V(tmp4, tmp5, tmp6, tmp7, 6);
414  HEVC_BIW_RND_CLIP4_MAX_SATU(tmp0, tmp1, tmp4, tmp5, in0, in1, in4, in5,
415  weight_vec, rnd_vec, offset_vec, tmp0, tmp1,
416  tmp4, tmp5);
417  HEVC_BIW_RND_CLIP4_MAX_SATU(tmp2, tmp3, tmp6, tmp7, in2, in3, in6, in7,
418  weight_vec, rnd_vec, offset_vec, tmp2, tmp3,
419  tmp6, tmp7);
420  PCKEV_B2_UB(tmp4, tmp0, tmp5, tmp1, out0, out1);
421  PCKEV_B2_UB(tmp6, tmp2, tmp7, tmp3, out2, out3);
422  ST_UB4(out0, out1, out2, out3, dst, dst_stride);
423  dst += (4 * dst_stride);
424  }
425 }
426 
427 static void hevc_biwgt_copy_24w_msa(const uint8_t *src0_ptr,
428  int32_t src_stride,
429  const int16_t *src1_ptr,
430  int32_t src2_stride,
431  uint8_t *dst,
432  int32_t dst_stride,
433  int32_t height,
434  int32_t weight0,
435  int32_t weight1,
436  int32_t offset0,
437  int32_t offset1,
438  int32_t rnd_val)
439 {
440  uint32_t loop_cnt;
442  v16u8 out0, out1, out2, out3, out4, out5;
443  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, zero = { 0 };
444  v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7, dst8, dst9, dst10;
445  v8i16 in0, in1, in2, in3, in4, in5, in6, in7, in8, in9, in10, in11, dst11;
446  v4i32 offset_vec, weight_vec, rnd_vec;
447 
448  offset = (offset0 + offset1) << rnd_val;
449  weight0 = weight0 & 0x0000FFFF;
450  weight = weight0 | (weight1 << 16);
451 
452  offset_vec = __msa_fill_w(offset);
453  weight_vec = __msa_fill_w(weight);
454  rnd_vec = __msa_fill_w(rnd_val + 1);
455 
456  for (loop_cnt = 8; loop_cnt--;) {
457  LD_SB4(src0_ptr, src_stride, src0, src1, src4, src5);
458  LD_SB4(src0_ptr + 16, src_stride, src2, src3, src6, src7);
459  src0_ptr += (4 * src_stride);
460  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
461  LD_SH4(src1_ptr + 8, src2_stride, in4, in5, in6, in7);
462  LD_SH4(src1_ptr + 16, src2_stride, in8, in9, in10, in11);
463  src1_ptr += (4 * src2_stride);
464 
465  ILVRL_B2_SH(zero, src0, dst0, dst1);
466  ILVRL_B2_SH(zero, src1, dst2, dst3);
467  ILVR_B2_SH(zero, src2, zero, src3, dst4, dst5);
468  ILVRL_B2_SH(zero, src4, dst6, dst7);
469  ILVRL_B2_SH(zero, src5, dst8, dst9);
470  ILVR_B2_SH(zero, src6, zero, src7, dst10, dst11);
471  SLLI_4V(dst0, dst1, dst2, dst3, 6);
472  SLLI_4V(dst4, dst5, dst6, dst7, 6);
473  SLLI_4V(dst8, dst9, dst10, dst11, 6);
474  HEVC_BIW_RND_CLIP4_MAX_SATU(dst0, dst1, dst2, dst3, in0, in4, in1, in5,
475  weight_vec, rnd_vec, offset_vec, dst0, dst1,
476  dst2, dst3);
477  HEVC_BIW_RND_CLIP4_MAX_SATU(dst4, dst5, dst6, dst7, in8, in9, in2, in6,
478  weight_vec, rnd_vec, offset_vec, dst4, dst5,
479  dst6, dst7);
480  HEVC_BIW_RND_CLIP4_MAX_SATU(dst8, dst9, dst10, dst11, in3, in7, in10,
481  in11, weight_vec, rnd_vec, offset_vec,
482  dst8, dst9, dst10, dst11);
483  PCKEV_B3_UB(dst1, dst0, dst3, dst2, dst5, dst4, out0, out1, out2);
484  PCKEV_B3_UB(dst7, dst6, dst9, dst8, dst11, dst10, out3, out4, out5);
485  ST_UB4(out0, out1, out3, out4, dst, dst_stride);
486  ST_D4(out2, out5, 0, 1, 0, 1, dst + 16, dst_stride);
487  dst += (4 * dst_stride);
488  }
489 }
490 
491 static void hevc_biwgt_copy_32w_msa(const uint8_t *src0_ptr,
492  int32_t src_stride,
493  const int16_t *src1_ptr,
494  int32_t src2_stride,
495  uint8_t *dst,
496  int32_t dst_stride,
497  int32_t height,
498  int32_t weight0,
499  int32_t weight1,
500  int32_t offset0,
501  int32_t offset1,
502  int32_t rnd_val)
503 {
504  uint32_t loop_cnt;
506  v16u8 out0, out1, out2, out3;
507  v16i8 zero = { 0 };
508  v16i8 src0, src1, src2, src3;
509  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
510  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
511  v4i32 offset_vec, weight_vec, rnd_vec;
512 
513  offset = (offset0 + offset1) << rnd_val;
514  weight0 = weight0 & 0x0000FFFF;
515  weight = weight0 | (weight1 << 16);
516 
517  offset_vec = __msa_fill_w(offset);
518  weight_vec = __msa_fill_w(weight);
519  rnd_vec = __msa_fill_w(rnd_val + 1);
520 
521  for (loop_cnt = (height >> 1); loop_cnt--;) {
522  LD_SB2(src0_ptr, 16, src0, src1);
523  src0_ptr += src_stride;
524  LD_SB2(src0_ptr, 16, src2, src3);
525  src0_ptr += src_stride;
526  LD_SH4(src1_ptr, 8, in0, in1, in2, in3);
527  src1_ptr += src2_stride;
528  LD_SH4(src1_ptr, 8, in4, in5, in6, in7);
529  src1_ptr += src2_stride;
530 
531  ILVRL_B2_SH(zero, src0, tmp0, tmp4);
532  ILVRL_B2_SH(zero, src1, tmp1, tmp5);
533  ILVRL_B2_SH(zero, src2, tmp2, tmp6);
534  ILVRL_B2_SH(zero, src3, tmp3, tmp7);
535  SLLI_4V(tmp0, tmp1, tmp2, tmp3, 6);
536  SLLI_4V(tmp4, tmp5, tmp6, tmp7, 6);
537  HEVC_BIW_RND_CLIP4_MAX_SATU(tmp0, tmp4, tmp1, tmp5, in0, in1, in2, in3,
538  weight_vec, rnd_vec, offset_vec, tmp0, tmp4,
539  tmp1, tmp5);
540  HEVC_BIW_RND_CLIP4_MAX_SATU(tmp2, tmp6, tmp3, tmp7, in4, in5, in6, in7,
541  weight_vec, rnd_vec, offset_vec, tmp2, tmp6,
542  tmp3, tmp7);
543  PCKEV_B2_UB(tmp4, tmp0, tmp5, tmp1, out0, out1);
544  PCKEV_B2_UB(tmp6, tmp2, tmp7, tmp3, out2, out3);
545  ST_UB2(out0, out1, dst, 16);
546  dst += dst_stride;
547  ST_UB2(out2, out3, dst, 16);
548  dst += dst_stride;
549  }
550 }
551 
552 static void hevc_biwgt_copy_48w_msa(const uint8_t *src0_ptr,
553  int32_t src_stride,
554  const int16_t *src1_ptr,
555  int32_t src2_stride,
556  uint8_t *dst,
557  int32_t dst_stride,
558  int32_t height,
559  int32_t weight0,
560  int32_t weight1,
561  int32_t offset0,
562  int32_t offset1,
563  int32_t rnd_val)
564 {
565  uint32_t loop_cnt;
567  v16u8 out0, out1, out2;
568  v16i8 src0, src1, src2;
569  v16i8 zero = { 0 };
570  v8i16 dst0, dst1, dst2, dst3, dst4, dst5, in0, in1, in2, in3, in4, in5;
571  v4i32 offset_vec, weight_vec, rnd_vec;
572 
573  offset = (offset0 + offset1) << rnd_val;
574  weight0 = weight0 & 0x0000FFFF;
575  weight = weight0 | (weight1 << 16);
576 
577  offset_vec = __msa_fill_w(offset);
578  weight_vec = __msa_fill_w(weight);
579  rnd_vec = __msa_fill_w(rnd_val + 1);
580 
581  for (loop_cnt = 64; loop_cnt--;) {
582  LD_SB3(src0_ptr, 16, src0, src1, src2);
583  src0_ptr += src_stride;
584  LD_SH6(src1_ptr, 8, in0, in1, in2, in3, in4, in5);
585  src1_ptr += src2_stride;
586 
587  ILVRL_B2_SH(zero, src0, dst0, dst1);
588  ILVRL_B2_SH(zero, src1, dst2, dst3);
589  ILVRL_B2_SH(zero, src2, dst4, dst5);
590  SLLI_4V(dst0, dst1, dst2, dst3, 6);
591  SLLI_2V(dst4, dst5, 6);
592  HEVC_BIW_RND_CLIP4_MAX_SATU(dst0, dst1, dst2, dst3, in0, in1, in2, in3,
593  weight_vec, rnd_vec, offset_vec, dst0, dst1,
594  dst2, dst3);
595  HEVC_BIW_RND_CLIP2_MAX_SATU(dst4, dst5, in4, in5, weight_vec, rnd_vec,
596  offset_vec, dst4, dst5);
597  PCKEV_B3_UB(dst1, dst0, dst3, dst2, dst5, dst4, out0, out1, out2);
598  ST_UB2(out0, out1, dst, 16);
599  ST_UB(out2, dst + 32);
600  dst += dst_stride;
601  }
602 }
603 
604 static void hevc_biwgt_copy_64w_msa(const uint8_t *src0_ptr,
605  int32_t src_stride,
606  const int16_t *src1_ptr,
607  int32_t src2_stride,
608  uint8_t *dst,
609  int32_t dst_stride,
610  int32_t height,
611  int32_t weight0,
612  int32_t weight1,
613  int32_t offset0,
614  int32_t offset1,
615  int32_t rnd_val)
616 {
617  uint32_t loop_cnt;
619  v16u8 out0, out1, out2, out3;
620  v16i8 zero = { 0 };
621  v16i8 src0, src1, src2, src3;
622  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
623  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
624  v4i32 offset_vec, weight_vec, rnd_vec;
625 
626  offset = (offset0 + offset1) << rnd_val;
627  weight0 = weight0 & 0x0000FFFF;
628  weight = weight0 | (weight1 << 16);
629 
630  offset_vec = __msa_fill_w(offset);
631  weight_vec = __msa_fill_w(weight);
632  rnd_vec = __msa_fill_w(rnd_val + 1);
633 
634  for (loop_cnt = height; loop_cnt--;) {
635  LD_SB4(src0_ptr, 16, src0, src1, src2, src3);
636  src0_ptr += src_stride;
637  LD_SH8(src1_ptr, 8, in0, in1, in2, in3, in4, in5, in6, in7);
638  src1_ptr += src2_stride;
639 
640  ILVR_B4_SH(zero, src0, zero, src1, zero, src2, zero, src3, tmp0, tmp1,
641  tmp2, tmp3);
642  ILVL_B4_SH(zero, src0, zero, src1, zero, src2, zero, src3, tmp4, tmp5,
643  tmp6, tmp7);
644  SLLI_4V(tmp0, tmp1, tmp2, tmp3, 6);
645  SLLI_4V(tmp4, tmp5, tmp6, tmp7, 6);
646  HEVC_BIW_RND_CLIP4_MAX_SATU(tmp0, tmp4, tmp1, tmp5, in0, in1, in2, in3,
647  weight_vec, rnd_vec, offset_vec, tmp0, tmp4,
648  tmp1, tmp5);
649  HEVC_BIW_RND_CLIP4_MAX_SATU(tmp2, tmp6, tmp3, tmp7, in4, in5, in6, in7,
650  weight_vec, rnd_vec, offset_vec, tmp2, tmp6,
651  tmp3, tmp7);
652  PCKEV_B2_UB(tmp4, tmp0, tmp5, tmp1, out0, out1);
653  PCKEV_B2_UB(tmp6, tmp2, tmp7, tmp3, out2, out3);
654  ST_UB4(out0, out1, out2, out3, dst, 16);
655  dst += dst_stride;
656  }
657 }
658 
659 static void hevc_hz_biwgt_8t_4w_msa(const uint8_t *src0_ptr,
660  int32_t src_stride,
661  const int16_t *src1_ptr,
662  int32_t src2_stride,
663  uint8_t *dst,
664  int32_t dst_stride,
665  const int8_t *filter,
666  int32_t height,
667  int32_t weight0,
668  int32_t weight1,
669  int32_t offset0,
670  int32_t offset1,
671  int32_t rnd_val)
672 {
673  uint32_t loop_cnt;
674  int32_t offset, weight, constant;
675  v8i16 filt0, filt1, filt2, filt3;
676  v16i8 src0, src1, src2, src3;
677  v16i8 mask1, mask2, mask3;
678  v16i8 vec0, vec1, vec2, vec3;
679  v8i16 dst0, dst1;
680  v8i16 in0, in1, in2, in3;
681  v8i16 filter_vec, out0, out1;
682  v4i32 weight_vec, offset_vec, rnd_vec;
683  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[16]);
684 
685  src0_ptr -= 3;
686  filter_vec = LD_SH(filter);
687  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
688 
689  mask1 = mask0 + 2;
690  mask2 = mask0 + 4;
691  mask3 = mask0 + 6;
692 
693  offset = (offset0 + offset1) << rnd_val;
694  weight0 = weight0 & 0x0000FFFF;
695  weight = weight0 | (weight1 << 16);
696  constant = 128 * weight1;
697  constant <<= 6;
698  offset += constant;
699 
700  offset_vec = __msa_fill_w(offset);
701  weight_vec = __msa_fill_w(weight);
702  rnd_vec = __msa_fill_w(rnd_val + 1);
703 
704  for (loop_cnt = (height >> 2); loop_cnt--;) {
705  LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
706  src0_ptr += (4 * src_stride);
707  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
708  src1_ptr += (4 * src2_stride);
709  ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
710  XORI_B4_128_SB(src0, src1, src2, src3);
711 
712  VSHF_B4_SB(src0, src1, mask0, mask1, mask2, mask3,
713  vec0, vec1, vec2, vec3);
714  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
715  filt3);
716  VSHF_B4_SB(src2, src3, mask0, mask1, mask2, mask3,
717  vec0, vec1, vec2, vec3);
718  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
719  filt3);
720 
721  HEVC_BIW_RND_CLIP2(dst0, dst1, in0, in1,
722  weight_vec, rnd_vec, offset_vec,
723  out0, out1);
724 
725  out0 = (v8i16) __msa_pckev_b((v16i8) out1, (v16i8) out0);
726  ST_W4(out0, 0, 1, 2, 3, dst, dst_stride);
727  dst += (4 * dst_stride);
728  }
729 }
730 
731 static void hevc_hz_biwgt_8t_8w_msa(const uint8_t *src0_ptr,
732  int32_t src_stride,
733  const int16_t *src1_ptr,
734  int32_t src2_stride,
735  uint8_t *dst,
736  int32_t dst_stride,
737  const int8_t *filter,
738  int32_t height,
739  int32_t weight0,
740  int32_t weight1,
741  int32_t offset0,
742  int32_t offset1,
743  int32_t rnd_val)
744 {
745  uint32_t loop_cnt;
746  int32_t offset, weight, constant;
747  v8i16 filt0, filt1, filt2, filt3;
748  v16i8 src0, src1, src2, src3;
749  v16i8 mask1, mask2, mask3;
750  v16i8 vec0, vec1, vec2, vec3;
751  v8i16 dst0, dst1, dst2, dst3;
752  v8i16 in0, in1, in2, in3;
753  v8i16 filter_vec, out0, out1, out2, out3;
754  v4i32 weight_vec, offset_vec, rnd_vec;
755  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
756 
757  src0_ptr -= 3;
758  offset = (offset0 + offset1) << rnd_val;
759  weight0 = weight0 & 0x0000FFFF;
760  weight = weight0 | (weight1 << 16);
761  constant = 128 * weight1;
762  constant <<= 6;
763  offset += constant;
764 
765  offset_vec = __msa_fill_w(offset);
766  weight_vec = __msa_fill_w(weight);
767  rnd_vec = __msa_fill_w(rnd_val + 1);
768 
769  filter_vec = LD_SH(filter);
770  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
771 
772  mask1 = mask0 + 2;
773  mask2 = mask0 + 4;
774  mask3 = mask0 + 6;
775 
776  for (loop_cnt = (height >> 2); loop_cnt--;) {
777  LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
778  src0_ptr += (4 * src_stride);
779  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
780  src1_ptr += (4 * src2_stride);
781  XORI_B4_128_SB(src0, src1, src2, src3);
782 
783  VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3,
784  vec0, vec1, vec2, vec3);
785  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
786  filt3);
787  VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3,
788  vec0, vec1, vec2, vec3);
789  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
790  filt3);
791  VSHF_B4_SB(src2, src2, mask0, mask1, mask2, mask3,
792  vec0, vec1, vec2, vec3);
793  dst2 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
794  filt3);
795  VSHF_B4_SB(src3, src3, mask0, mask1, mask2, mask3,
796  vec0, vec1, vec2, vec3);
797  dst3 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
798  filt3);
799 
800  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
801  in0, in1, in2, in3,
802  weight_vec, rnd_vec, offset_vec,
803  out0, out1, out2, out3);
804 
805  PCKEV_B2_SH(out1, out0, out3, out2, out0, out1);
806  ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
807  dst += (4 * dst_stride);
808  }
809 }
810 
811 static void hevc_hz_biwgt_8t_12w_msa(const uint8_t *src0_ptr,
812  int32_t src_stride,
813  const int16_t *src1_ptr,
814  int32_t src2_stride,
815  uint8_t *dst,
816  int32_t dst_stride,
817  const int8_t *filter,
818  int32_t height,
819  int32_t weight0,
820  int32_t weight1,
821  int32_t offset0,
822  int32_t offset1,
823  int32_t rnd_val)
824 {
825  uint32_t loop_cnt;
826  int32_t offset, weight, constant;
827  v16i8 src0, src1, src2, src3, vec0, vec1, vec2, vec3;
828  v16i8 mask0, mask1, mask2, mask3, mask4, mask5, mask6, mask7;
829  v8i16 filt0, filt1, filt2, filt3, out0, out1, out2, out3;
830  v8i16 dst0, dst1, dst2, dst3, in0, in1, in2, in3, filter_vec;
831  v4i32 weight_vec, offset_vec, rnd_vec;
832 
833  src0_ptr -= 3;
834 
835  weight0 = weight0 & 0x0000FFFF;
836  weight = weight0 | (weight1 << 16);
837  constant = 128 * weight1;
838  constant <<= 6;
839  offset = (offset0 + offset1) << rnd_val;
840  offset += constant;
841 
842  offset_vec = __msa_fill_w(offset);
843  weight_vec = __msa_fill_w(weight);
844  rnd_vec = __msa_fill_w(rnd_val + 1);
845 
846  filter_vec = LD_SH(filter);
847  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
848 
849  mask0 = LD_SB(&ff_hevc_mask_arr[0]);
850  mask1 = mask0 + 2;
851  mask2 = mask0 + 4;
852  mask3 = mask0 + 6;
853  mask4 = LD_SB(&ff_hevc_mask_arr[16]);
854  mask5 = mask4 + 2;
855  mask6 = mask4 + 4;
856  mask7 = mask4 + 6;
857 
858  for (loop_cnt = 4; loop_cnt--;) {
859  LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
860  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
861  XORI_B4_128_SB(src0, src1, src2, src3);
862  VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3, vec0, vec1, vec2,
863  vec3);
864  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
865  filt3);
866  VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3, vec0, vec1, vec2,
867  vec3);
868  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
869  filt3);
870  VSHF_B4_SB(src2, src2, mask0, mask1, mask2, mask3, vec0, vec1, vec2,
871  vec3);
872  dst2 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
873  filt3);
874  VSHF_B4_SB(src3, src3, mask0, mask1, mask2, mask3, vec0, vec1, vec2,
875  vec3);
876  dst3 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
877  filt3);
878  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3, in0, in1, in2, in3,
879  weight_vec, rnd_vec, offset_vec, out0, out1, out2,
880  out3);
881  PCKEV_B2_SH(out1, out0, out3, out2, out0, out1);
882  ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
883 
884  LD_SB4(src0_ptr + 8, src_stride, src0, src1, src2, src3);
885  src0_ptr += (4 * src_stride);
886  LD_SH4(src1_ptr + 8, src2_stride, in0, in1, in2, in3);
887  src1_ptr += (4 * src2_stride);
888  ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
889  XORI_B4_128_SB(src0, src1, src2, src3);
890  VSHF_B4_SB(src0, src1, mask4, mask5, mask6, mask7, vec0, vec1, vec2,
891  vec3);
892  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
893  filt3);
894  VSHF_B4_SB(src2, src3, mask4, mask5, mask6, mask7, vec0, vec1, vec2,
895  vec3);
896  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
897  filt3);
898  HEVC_BIW_RND_CLIP2(dst0, dst1, in0, in1, weight_vec, rnd_vec,
899  offset_vec, out0, out1);
900  out0 = (v8i16) __msa_pckev_b((v16i8) out1, (v16i8) out0);
901  ST_W4(out0, 0, 1, 2, 3, dst + 8, dst_stride);
902  dst += (4 * dst_stride);
903  }
904 }
905 
906 static void hevc_hz_biwgt_8t_16w_msa(const uint8_t *src0_ptr,
907  int32_t src_stride,
908  const int16_t *src1_ptr,
909  int32_t src2_stride,
910  uint8_t *dst,
911  int32_t dst_stride,
912  const int8_t *filter,
913  int32_t height,
914  int32_t weight0,
915  int32_t weight1,
916  int32_t offset0,
917  int32_t offset1,
918  int32_t rnd_val)
919 {
920  uint32_t loop_cnt;
921  int32_t offset, weight, constant;
922  v16i8 src0, src1, src2, src3;
923  v8i16 in0, in1, in2, in3;
924  v8i16 filt0, filt1, filt2, filt3;
925  v16i8 mask1, mask2, mask3;
926  v8i16 filter_vec, out0, out1, out2, out3;
927  v16i8 vec0, vec1, vec2, vec3;
928  v8i16 dst0, dst1, dst2, dst3;
929  v4i32 weight_vec, offset_vec, rnd_vec;
930  v16i8 mask0 = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8 };
931 
932  src0_ptr -= 3;
933  offset = (offset0 + offset1) << rnd_val;
934  weight0 = weight0 & 0x0000FFFF;
935  weight = weight0 | (weight1 << 16);
936  constant = 128 * weight1;
937  constant <<= 6;
938  offset += constant;
939 
940  offset_vec = __msa_fill_w(offset);
941  weight_vec = __msa_fill_w(weight);
942  rnd_vec = __msa_fill_w(rnd_val + 1);
943 
944  filter_vec = LD_SH(filter);
945  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
946 
947  mask1 = mask0 + 2;
948  mask2 = mask0 + 4;
949  mask3 = mask0 + 6;
950 
951  for (loop_cnt = (height >> 1); loop_cnt--;) {
952  LD_SB2(src0_ptr, 8, src0, src1);
953  src0_ptr += src_stride;
954  LD_SB2(src0_ptr, 8, src2, src3);
955  src0_ptr += src_stride;
956  LD_SH2(src1_ptr, 8, in0, in1);
957  src1_ptr += src2_stride;
958  LD_SH2(src1_ptr, 8, in2, in3);
959  src1_ptr += src2_stride;
960  XORI_B4_128_SB(src0, src1, src2, src3);
961 
962  VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3,
963  vec0, vec1, vec2, vec3);
964  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
965  filt3);
966  VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3,
967  vec0, vec1, vec2, vec3);
968  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
969  filt3);
970  VSHF_B4_SB(src2, src2, mask0, mask1, mask2, mask3,
971  vec0, vec1, vec2, vec3);
972  dst2 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
973  filt3);
974  VSHF_B4_SB(src3, src3, mask0, mask1, mask2, mask3,
975  vec0, vec1, vec2, vec3);
976  dst3 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
977  filt3);
978 
979  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
980  in0, in1, in2, in3,
981  weight_vec, rnd_vec, offset_vec,
982  out0, out1, out2, out3);
983 
984  PCKEV_B2_SH(out1, out0, out3, out2, out0, out1);
985  ST_SH2(out0, out1, dst, dst_stride);
986  dst += (2 * dst_stride);
987  }
988 }
989 
990 static void hevc_hz_biwgt_8t_24w_msa(const uint8_t *src0_ptr,
991  int32_t src_stride,
992  const int16_t *src1_ptr,
993  int32_t src2_stride,
994  uint8_t *dst,
995  int32_t dst_stride,
996  const int8_t *filter,
997  int32_t height,
998  int32_t weight0,
999  int32_t weight1,
1000  int32_t offset0,
1001  int32_t offset1,
1002  int32_t rnd_val)
1003 {
1004  uint32_t loop_cnt;
1005  uint64_t dst_val0;
1006  int32_t offset, weight, constant;
1007  v16i8 src0, src1;
1008  v8i16 in0, in1, in2;
1009  v8i16 filt0, filt1, filt2, filt3;
1010  v16i8 mask1, mask2, mask3, mask4, mask5, mask6, mask7;
1011  v16i8 vec0, vec1, vec2, vec3;
1012  v8i16 dst0, dst1, dst2;
1013  v4i32 dst2_r, dst2_l;
1014  v8i16 filter_vec, out0, out1, out2;
1015  v4i32 weight_vec, offset_vec, rnd_vec;
1016  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
1017 
1018  src0_ptr = src0_ptr - 3;
1019  offset = (offset0 + offset1) << rnd_val;
1020  weight0 = weight0 & 0x0000FFFF;
1021  weight = weight0 | (weight1 << 16);
1022  constant = 128 * weight1;
1023  constant <<= 6;
1024  offset += constant;
1025 
1026  offset_vec = __msa_fill_w(offset);
1027  weight_vec = __msa_fill_w(weight);
1028  rnd_vec = __msa_fill_w(rnd_val + 1);
1029 
1030  filter_vec = LD_SH(filter);
1031  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
1032 
1033  mask1 = mask0 + 2;
1034  mask2 = mask0 + 4;
1035  mask3 = mask0 + 6;
1036  mask4 = mask0 + 8;
1037  mask5 = mask0 + 10;
1038  mask6 = mask0 + 12;
1039  mask7 = mask0 + 14;
1040 
1041  LD_SB2(src0_ptr, 16, src0, src1);
1042  src0_ptr += src_stride;
1043  LD_SH2(src1_ptr, 8, in0, in1);
1044  in2 = LD_SH(src1_ptr + 16);
1045  src1_ptr += src2_stride;
1047 
1048  for (loop_cnt = 31; loop_cnt--;) {
1049  VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3,
1050  vec0, vec1, vec2, vec3);
1051  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1052  filt3);
1053  VSHF_B4_SB(src0, src1, mask4, mask5, mask6, mask7,
1054  vec0, vec1, vec2, vec3);
1055  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1056  filt3);
1057  VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3,
1058  vec0, vec1, vec2, vec3);
1059  dst2 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1060  filt3);
1061 
1062  HEVC_BIW_RND_CLIP2(dst0, dst1, in0, in1,
1063  weight_vec, rnd_vec, offset_vec,
1064  out0, out1);
1065 
1066  ILVRL_H2_SW(dst2, in2, dst2_r, dst2_l);
1067  dst2_r = __msa_dpadd_s_w(offset_vec, (v8i16) dst2_r,
1068  (v8i16) weight_vec);
1069  dst2_l = __msa_dpadd_s_w(offset_vec, (v8i16) dst2_l,
1070  (v8i16) weight_vec);
1071  SRAR_W2_SW(dst2_r, dst2_l, rnd_vec);
1072  out2 = __msa_pckev_h((v8i16) dst2_l, (v8i16) dst2_r);
1073  CLIP_SH_0_255(out2);
1074 
1075  LD_SB2(src0_ptr, 16, src0, src1);
1076  src0_ptr += src_stride;
1077  LD_SH2(src1_ptr, 8, in0, in1);
1078  in2 = LD_SH(src1_ptr + 16);
1079  src1_ptr += src2_stride;
1081  PCKEV_B2_SH(out1, out0, out2, out2, out0, out2);
1082  dst_val0 = __msa_copy_u_d((v2i64) out2, 0);
1083  ST_SH(out0, dst);
1084  SD(dst_val0, dst + 16);
1085  dst += dst_stride;
1086  }
1087 
1088  VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3, vec0, vec1, vec2, vec3);
1089  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1090  filt3);
1091  VSHF_B4_SB(src0, src1, mask4, mask5, mask6, mask7, vec0, vec1, vec2, vec3);
1092  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1093  filt3);
1094  VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3, vec0, vec1, vec2, vec3);
1095  dst2 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1096  filt3);
1097  HEVC_BIW_RND_CLIP2(dst0, dst1, in0, in1, weight_vec, rnd_vec, offset_vec,
1098  out0, out1);
1099  ILVRL_H2_SW(dst2, in2, dst2_r, dst2_l);
1100  dst2_r = __msa_dpadd_s_w(offset_vec, (v8i16) dst2_r, (v8i16) weight_vec);
1101  dst2_l = __msa_dpadd_s_w(offset_vec, (v8i16) dst2_l, (v8i16) weight_vec);
1102  SRAR_W2_SW(dst2_r, dst2_l, rnd_vec);
1103  out2 = __msa_pckev_h((v8i16) dst2_l, (v8i16) dst2_r);
1104  CLIP_SH_0_255(out2);
1105  PCKEV_B2_SH(out1, out0, out2, out2, out0, out2);
1106  dst_val0 = __msa_copy_u_d((v2i64) out2, 0);
1107  ST_SH(out0, dst);
1108  SD(dst_val0, dst + 16);
1109  dst += dst_stride;
1110 }
1111 
1112 static void hevc_hz_biwgt_8t_32w_msa(const uint8_t *src0_ptr,
1113  int32_t src_stride,
1114  const int16_t *src1_ptr,
1115  int32_t src2_stride,
1116  uint8_t *dst,
1117  int32_t dst_stride,
1118  const int8_t *filter,
1119  int32_t height,
1120  int32_t weight0,
1121  int32_t weight1,
1122  int32_t offset0,
1123  int32_t offset1,
1124  int32_t rnd_val)
1125 {
1126  uint32_t loop_cnt;
1127  int32_t offset, weight, constant;
1128  v16i8 src0, src1, src2;
1129  v8i16 in0, in1, in2, in3;
1130  v8i16 filt0, filt1, filt2, filt3;
1131  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
1132  v16i8 mask1, mask2, mask3, mask4, mask5, mask6, mask7;
1133  v16i8 vec0, vec1, vec2, vec3;
1134  v8i16 dst0, dst1, dst2, dst3;
1135  v8i16 filter_vec, out0, out1, out2, out3;
1136  v4i32 weight_vec, offset_vec, rnd_vec;
1137 
1138  src0_ptr -= 3;
1139  offset = (offset0 + offset1) << rnd_val;
1140  weight0 = weight0 & 0x0000FFFF;
1141  weight = weight0 | (weight1 << 16);
1142  constant = 128 * weight1;
1143  constant <<= 6;
1144  offset += constant;
1145 
1146  offset_vec = __msa_fill_w(offset);
1147  weight_vec = __msa_fill_w(weight);
1148  rnd_vec = __msa_fill_w(rnd_val + 1);
1149 
1150  filter_vec = LD_SH(filter);
1151  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
1152 
1153  mask1 = mask0 + 2;
1154  mask2 = mask0 + 4;
1155  mask3 = mask0 + 6;
1156  mask4 = mask0 + 8;
1157  mask5 = mask0 + 10;
1158  mask6 = mask0 + 12;
1159  mask7 = mask0 + 14;
1160 
1161  for (loop_cnt = height; loop_cnt--;) {
1162  LD_SB2(src0_ptr, 16, src0, src1);
1163  src2 = LD_SB(src0_ptr + 24);
1164  src0_ptr += src_stride;
1165  LD_SH4(src1_ptr, 8, in0, in1, in2, in3);
1166  src1_ptr += src2_stride;
1167 
1169 
1170  VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3,
1171  vec0, vec1, vec2, vec3);
1172  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1173  filt3);
1174  VSHF_B4_SB(src0, src1, mask4, mask5, mask6, mask7,
1175  vec0, vec1, vec2, vec3);
1176  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1177  filt3);
1178  VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3,
1179  vec0, vec1, vec2, vec3);
1180  dst2 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1181  filt3);
1182  VSHF_B4_SB(src2, src2, mask0, mask1, mask2, mask3,
1183  vec0, vec1, vec2, vec3);
1184  dst3 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1185  filt3);
1186 
1187  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
1188  in0, in1, in2, in3,
1189  weight_vec, rnd_vec, offset_vec,
1190  out0, out1, out2, out3);
1191 
1192  PCKEV_B2_SH(out1, out0, out3, out2, out0, out1);
1193  ST_SH2(out0, out1, dst, 16);
1194  dst += dst_stride;
1195  }
1196 }
1197 
1198 static void hevc_hz_biwgt_8t_48w_msa(const uint8_t *src0_ptr,
1199  int32_t src_stride,
1200  const int16_t *src1_ptr,
1201  int32_t src2_stride,
1202  uint8_t *dst,
1203  int32_t dst_stride,
1204  const int8_t *filter,
1205  int32_t height,
1206  int32_t weight0,
1207  int32_t weight1,
1208  int32_t offset0,
1209  int32_t offset1,
1210  int32_t rnd_val)
1211 {
1212  uint32_t loop_cnt;
1213  int32_t offset, weight, constant;
1214  v16i8 src0, src1, src2, src3, src4;
1215  v8i16 in0, in1, in2, in3;
1216  v8i16 filt0, filt1, filt2, filt3;
1217  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
1218  v16i8 mask1, mask2, mask3, mask4, mask5, mask6, mask7;
1219  v16i8 vec0, vec1, vec2, vec3;
1220  v8i16 dst0, dst1, dst2, dst3;
1221  v8i16 filter_vec, out0, out1, out2, out3;
1222  v4i32 weight_vec, offset_vec, rnd_vec;
1223 
1224  src0_ptr -= 3;
1225  offset = (offset0 + offset1) << rnd_val;
1226  weight0 = weight0 & 0x0000FFFF;
1227  weight = weight0 | (weight1 << 16);
1228  constant = 128 * weight1;
1229  constant <<= 6;
1230  offset += constant;
1231 
1232  offset_vec = __msa_fill_w(offset);
1233  weight_vec = __msa_fill_w(weight);
1234  rnd_vec = __msa_fill_w(rnd_val + 1);
1235 
1236  filter_vec = LD_SH(filter);
1237  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
1238 
1239  mask1 = mask0 + 2;
1240  mask2 = mask0 + 4;
1241  mask3 = mask0 + 6;
1242  mask4 = mask0 + 8;
1243  mask5 = mask0 + 10;
1244  mask6 = mask0 + 12;
1245  mask7 = mask0 + 14;
1246 
1247  for (loop_cnt = 64; loop_cnt--;) {
1248  LD_SB2(src0_ptr, 16, src0, src1);
1249  src2 = LD_SB(src0_ptr + 24);
1250  LD_SH4(src1_ptr, 8, in0, in1, in2, in3);
1252  LD_SB2(src0_ptr + 32, 8, src3, src4);
1253  src0_ptr += src_stride;
1254  XORI_B2_128_SB(src3, src4);
1255 
1256  VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3,
1257  vec0, vec1, vec2, vec3);
1258  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1259  filt3);
1260  VSHF_B4_SB(src0, src1, mask4, mask5, mask6, mask7,
1261  vec0, vec1, vec2, vec3);
1262  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1263  filt3);
1264  VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3,
1265  vec0, vec1, vec2, vec3);
1266  dst2 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1267  filt3);
1268  VSHF_B4_SB(src2, src2, mask0, mask1, mask2, mask3,
1269  vec0, vec1, vec2, vec3);
1270  dst3 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1271  filt3);
1272 
1273  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3, in0, in1, in2, in3,
1274  weight_vec, rnd_vec, offset_vec,
1275  out0, out1, out2, out3);
1276 
1277  PCKEV_B2_SH(out1, out0, out3, out2, out0, out1);
1278  ST_SH2(out0, out1, dst, 16);
1279 
1280  LD_SH2(src1_ptr + 32, 8, in2, in3);
1281  src1_ptr += src2_stride;
1282 
1283  VSHF_B4_SB(src3, src3, mask0, mask1, mask2, mask3,
1284  vec0, vec1, vec2, vec3);
1285  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1286  filt3);
1287  VSHF_B4_SB(src4, src4, mask0, mask1, mask2, mask3,
1288  vec0, vec1, vec2, vec3);
1289  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1290  filt3);
1291 
1292  HEVC_BIW_RND_CLIP2(dst0, dst1, in2, in3,
1293  weight_vec, rnd_vec, offset_vec,
1294  out0, out1);
1295 
1296  out0 = (v8i16) __msa_pckev_b((v16i8) out1, (v16i8) out0);
1297  ST_SH(out0, dst + 32);
1298  dst += dst_stride;
1299  }
1300 }
1301 
1302 static void hevc_hz_biwgt_8t_64w_msa(const uint8_t *src0_ptr,
1303  int32_t src_stride,
1304  const int16_t *src1_ptr,
1305  int32_t src2_stride,
1306  uint8_t *dst,
1307  int32_t dst_stride,
1308  const int8_t *filter,
1309  int32_t height,
1310  int32_t weight0,
1311  int32_t weight1,
1312  int32_t offset0,
1313  int32_t offset1,
1314  int32_t rnd_val)
1315 {
1316  const uint8_t *src0_ptr_tmp;
1317  uint8_t *dst_tmp;
1318  const int16_t *src1_ptr_tmp;
1319  uint32_t loop_cnt, cnt;
1320  int32_t offset, weight, constant;
1321  v16i8 src0, src1, src2;
1322  v8i16 in0, in1, in2, in3;
1323  v8i16 filt0, filt1, filt2, filt3;
1324  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
1325  v16i8 mask1, mask2, mask3, mask4, mask5, mask6, mask7;
1326  v16i8 vec0, vec1, vec2, vec3;
1327  v8i16 dst0, dst1, dst2, dst3;
1328  v8i16 filter_vec, out0, out1, out2, out3;
1329  v4i32 weight_vec, offset_vec, rnd_vec;
1330 
1331  src0_ptr -= 3;
1332  offset = (offset0 + offset1) << rnd_val;
1333  weight0 = weight0 & 0x0000FFFF;
1334  weight = weight0 | (weight1 << 16);
1335  constant = 128 * weight1;
1336  constant <<= 6;
1337  offset += constant;
1338 
1339  offset_vec = __msa_fill_w(offset);
1340  weight_vec = __msa_fill_w(weight);
1341  rnd_vec = __msa_fill_w(rnd_val + 1);
1342 
1343  filter_vec = LD_SH(filter);
1344  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
1345 
1346  mask1 = mask0 + 2;
1347  mask2 = mask0 + 4;
1348  mask3 = mask0 + 6;
1349  mask4 = mask0 + 8;
1350  mask5 = mask0 + 10;
1351  mask6 = mask0 + 12;
1352  mask7 = mask0 + 14;
1353 
1354  for (loop_cnt = height; loop_cnt--;) {
1355  src0_ptr_tmp = src0_ptr;
1356  dst_tmp = dst;
1357  src1_ptr_tmp = src1_ptr;
1358 
1359  for (cnt = 2; cnt--;) {
1360  LD_SB2(src0_ptr_tmp, 16, src0, src1);
1361  src2 = LD_SB(src0_ptr_tmp + 24);
1362  src0_ptr_tmp += 32;
1363  LD_SH4(src1_ptr_tmp, 8, in0, in1, in2, in3);
1364  src1_ptr_tmp += 32;
1366 
1367  VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3,
1368  vec0, vec1, vec2, vec3);
1369  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1,
1370  filt2, filt3);
1371  VSHF_B4_SB(src0, src1, mask4, mask5, mask6, mask7,
1372  vec0, vec1, vec2, vec3);
1373  dst1 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1,
1374  filt2, filt3);
1375  VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3,
1376  vec0, vec1, vec2, vec3);
1377  dst2 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1,
1378  filt2, filt3);
1379  VSHF_B4_SB(src2, src2, mask0, mask1, mask2, mask3,
1380  vec0, vec1, vec2, vec3);
1381  dst3 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1,
1382  filt2, filt3);
1383 
1384  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
1385  in0, in1, in2, in3,
1386  weight_vec, rnd_vec, offset_vec,
1387  out0, out1, out2, out3);
1388 
1389  PCKEV_B2_SH(out1, out0, out3, out2, out0, out1);
1390  ST_SH2(out0, out1, dst_tmp, 16);
1391  dst_tmp += 32;
1392  }
1393 
1394  src0_ptr += src_stride;
1395  src1_ptr += src2_stride;
1396  dst += dst_stride;
1397 
1398  }
1399 }
1400 
1401 static void hevc_vt_biwgt_8t_4w_msa(const uint8_t *src0_ptr,
1402  int32_t src_stride,
1403  const int16_t *src1_ptr,
1404  int32_t src2_stride,
1405  uint8_t *dst,
1406  int32_t dst_stride,
1407  const int8_t *filter,
1408  int32_t height,
1409  int32_t weight0,
1410  int32_t weight1,
1411  int32_t offset0,
1412  int32_t offset1,
1413  int32_t rnd_val)
1414 {
1415  uint32_t loop_cnt;
1417  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
1418  v16i8 src11, src12, src13, src14;
1419  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
1420  v16i8 src10_r, src32_r, src54_r, src76_r, src98_r;
1421  v16i8 src21_r, src43_r, src65_r, src87_r, src109_r;
1422  v16i8 src1110_r, src1211_r, src1312_r, src1413_r;
1423  v16i8 src2110, src4332, src6554, src8776, src10998;
1424  v16i8 src12111110, src14131312;
1425  v8i16 dst10, dst32, dst54, dst76;
1426  v8i16 filt0, filt1, filt2, filt3;
1427  v8i16 filter_vec, out0, out1, out2, out3;
1428  v4i32 weight_vec, weight1_vec, offset_vec, rnd_vec, const_vec;
1429 
1430  src0_ptr -= (3 * src_stride);
1431  offset = (offset0 + offset1) << rnd_val;
1432  weight0 = weight0 & 0x0000FFFF;
1433  weight = weight0 | (weight1 << 16);
1434 
1435  const_vec = __msa_ldi_w(128);
1436  const_vec <<= 6;
1437  offset_vec = __msa_fill_w(offset);
1438  weight_vec = __msa_fill_w(weight);
1439  rnd_vec = __msa_fill_w(rnd_val + 1);
1440  weight1_vec = __msa_fill_w(weight1);
1441  offset_vec += const_vec * weight1_vec;
1442 
1443  filter_vec = LD_SH(filter);
1444  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
1445 
1446  LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
1447  src0_ptr += (7 * src_stride);
1448 
1449  ILVR_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
1450  src10_r, src32_r, src54_r, src21_r);
1451  ILVR_B2_SB(src4, src3, src6, src5, src43_r, src65_r);
1452  ILVR_D3_SB(src21_r, src10_r, src43_r, src32_r, src65_r, src54_r,
1453  src2110, src4332, src6554);
1454  XORI_B3_128_SB(src2110, src4332, src6554);
1455 
1456  for (loop_cnt = (height >> 3); loop_cnt--;) {
1457  LD_SB8(src0_ptr, src_stride,
1458  src7, src8, src9, src10, src11, src12, src13, src14);
1459  src0_ptr += (8 * src_stride);
1460  LD_SH8(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5, in6, in7);
1461  src1_ptr += (8 * src2_stride);
1462 
1463  ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
1464  ILVR_D2_SH(in5, in4, in7, in6, in2, in3);
1465  ILVR_B4_SB(src7, src6, src8, src7, src9, src8, src10, src9,
1466  src76_r, src87_r, src98_r, src109_r);
1467  ILVR_B4_SB(src11, src10, src12, src11, src13, src12, src14, src13,
1468  src1110_r, src1211_r, src1312_r, src1413_r);
1469  ILVR_D4_SB(src87_r, src76_r, src109_r, src98_r, src1211_r, src1110_r,
1470  src1413_r, src1312_r,
1471  src8776, src10998, src12111110, src14131312);
1472  XORI_B4_128_SB(src8776, src10998, src12111110, src14131312);
1473 
1474  DOTP_SB4_SH(src2110, src4332, src6554, src8776, filt0, filt0, filt0,
1475  filt0, dst10, dst32, dst54, dst76);
1476  DPADD_SB4_SH(src4332, src6554, src8776, src10998, filt1, filt1, filt1,
1477  filt1, dst10, dst32, dst54, dst76);
1478  DPADD_SB4_SH(src6554, src8776, src10998, src12111110, filt2, filt2,
1479  filt2, filt2, dst10, dst32, dst54, dst76);
1480  DPADD_SB4_SH(src8776, src10998, src12111110, src14131312, filt3, filt3,
1481  filt3, filt3, dst10, dst32, dst54, dst76);
1482 
1483  HEVC_BIW_RND_CLIP4(dst10, dst32, dst54, dst76,
1484  in0, in1, in2, in3,
1485  weight_vec, rnd_vec, offset_vec,
1486  out0, out1, out2, out3);
1487 
1488  PCKEV_B2_SH(out1, out0, out3, out2, out0, out1);
1489  ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
1490  dst += (8 * dst_stride);
1491 
1492  src2110 = src10998;
1493  src4332 = src12111110;
1494  src6554 = src14131312;
1495  src6 = src14;
1496  }
1497 }
1498 
1499 static void hevc_vt_biwgt_8t_8w_msa(const uint8_t *src0_ptr,
1500  int32_t src_stride,
1501  const int16_t *src1_ptr,
1502  int32_t src2_stride,
1503  uint8_t *dst,
1504  int32_t dst_stride,
1505  const int8_t *filter,
1506  int32_t height,
1507  int32_t weight0,
1508  int32_t weight1,
1509  int32_t offset0,
1510  int32_t offset1,
1511  int32_t rnd_val)
1512 {
1513  uint32_t loop_cnt;
1515  v16i8 src0, src1, src2, src3, src4, src5;
1516  v16i8 src6, src7, src8, src9, src10;
1517  v8i16 in0, in1, in2, in3;
1518  v16i8 src10_r, src32_r, src54_r, src76_r, src98_r;
1519  v16i8 src21_r, src43_r, src65_r, src87_r, src109_r;
1520  v8i16 tmp0, tmp1, tmp2, tmp3;
1521  v8i16 filt0, filt1, filt2, filt3;
1522  v8i16 filter_vec, out0, out1, out2, out3;
1523  v4i32 weight_vec, weight1_vec, offset_vec, rnd_vec, const_vec;
1524 
1525  src0_ptr -= (3 * src_stride);
1526  offset = (offset0 + offset1) << rnd_val;
1527  weight0 = weight0 & 0x0000FFFF;
1528  weight = weight0 | (weight1 << 16);
1529 
1530  const_vec = __msa_ldi_w(128);
1531  const_vec <<= 6;
1532  offset_vec = __msa_fill_w(offset);
1533  weight_vec = __msa_fill_w(weight);
1534  rnd_vec = __msa_fill_w(rnd_val + 1);
1535  weight1_vec = __msa_fill_w(weight1);
1536  offset_vec += const_vec * weight1_vec;
1537 
1538  filter_vec = LD_SH(filter);
1539  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
1540 
1541  LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
1542  src0_ptr += (7 * src_stride);
1543  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
1544 
1545  ILVR_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
1546  src10_r, src32_r, src54_r, src21_r);
1547  ILVR_B2_SB(src4, src3, src6, src5, src43_r, src65_r);
1548 
1549  for (loop_cnt = (height >> 2); loop_cnt--;) {
1550  LD_SB4(src0_ptr, src_stride, src7, src8, src9, src10);
1551  src0_ptr += (4 * src_stride);
1552  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
1553  src1_ptr += (4 * src2_stride);
1554 
1555  XORI_B4_128_SB(src7, src8, src9, src10);
1556  ILVR_B4_SB(src7, src6, src8, src7, src9, src8, src10, src9,
1557  src76_r, src87_r, src98_r, src109_r);
1558 
1559  DOTP_SB4_SH(src10_r, src21_r, src32_r, src43_r, filt0, filt0, filt0,
1560  filt0, tmp0, tmp1, tmp2, tmp3);
1561  DPADD_SB4_SH(src32_r, src43_r, src54_r, src65_r, filt1, filt1, filt1,
1562  filt1, tmp0, tmp1, tmp2, tmp3);
1563  DPADD_SB4_SH(src54_r, src65_r, src76_r, src87_r, filt2, filt2, filt2,
1564  filt2, tmp0, tmp1, tmp2, tmp3);
1565  DPADD_SB4_SH(src76_r, src87_r, src98_r, src109_r, filt3, filt3, filt3,
1566  filt3, tmp0, tmp1, tmp2, tmp3);
1567 
1568  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp2, tmp3,
1569  in0, in1, in2, in3,
1570  weight_vec, rnd_vec, offset_vec,
1571  out0, out1, out2, out3);
1572 
1573  PCKEV_B2_SH(out1, out0, out3, out2, out0, out1);
1574  ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
1575  dst += (4 * dst_stride);
1576 
1577  src10_r = src54_r;
1578  src32_r = src76_r;
1579  src54_r = src98_r;
1580  src21_r = src65_r;
1581  src43_r = src87_r;
1582  src65_r = src109_r;
1583  src6 = src10;
1584  }
1585 }
1586 
1587 static void hevc_vt_biwgt_8t_12w_msa(const uint8_t *src0_ptr,
1588  int32_t src_stride,
1589  const int16_t *src1_ptr,
1590  int32_t src2_stride,
1591  uint8_t *dst,
1592  int32_t dst_stride,
1593  const int8_t *filter,
1594  int32_t height,
1595  int32_t weight0,
1596  int32_t weight1,
1597  int32_t offset0,
1598  int32_t offset1,
1599  int32_t rnd_val)
1600 {
1601  uint32_t loop_cnt;
1603  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
1604  v8i16 in0, in1, in2, in3;
1605  v16i8 src10_r, src32_r, src54_r, src76_r;
1606  v16i8 src21_r, src43_r, src65_r, src87_r;
1607  v8i16 tmp0, tmp1, tmp2;
1608  v16i8 src10_l, src32_l, src54_l, src76_l;
1609  v16i8 src21_l, src43_l, src65_l, src87_l;
1610  v16i8 src2110, src4332, src6554, src8776;
1611  v8i16 filt0, filt1, filt2, filt3;
1612  v8i16 out0, out1, out2, filter_vec;
1613  v4i32 dst2_r, dst2_l;
1614  v4i32 weight_vec, weight1_vec, offset_vec, rnd_vec, const_vec;
1615 
1616  src0_ptr -= (3 * src_stride);
1617  offset = (offset0 + offset1) << rnd_val;
1618  weight0 = weight0 & 0x0000FFFF;
1619  weight = weight0 | (weight1 << 16);
1620 
1621  const_vec = __msa_ldi_w(128);
1622  const_vec <<= 6;
1623  offset_vec = __msa_fill_w(offset);
1624  weight_vec = __msa_fill_w(weight);
1625  rnd_vec = __msa_fill_w(rnd_val + 1);
1626  weight1_vec = __msa_fill_w(weight1);
1627  offset_vec += const_vec * weight1_vec;
1628 
1629  filter_vec = LD_SH(filter);
1630  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
1631 
1632  LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
1633  src0_ptr += (7 * src_stride);
1634  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
1635 
1636  ILVR_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
1637  src10_r, src32_r, src54_r, src21_r);
1638  ILVR_B2_SB(src4, src3, src6, src5, src43_r, src65_r);
1639  ILVL_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
1640  src10_l, src32_l, src54_l, src21_l);
1641  ILVL_B2_SB(src4, src3, src6, src5, src43_l, src65_l);
1642  ILVR_D3_SB(src21_l, src10_l, src43_l, src32_l, src65_l, src54_l,
1643  src2110, src4332, src6554);
1644 
1645  for (loop_cnt = 8; loop_cnt--;) {
1646  LD_SB2(src0_ptr, src_stride, src7, src8);
1647  src0_ptr += (2 * src_stride);
1648  LD_SH2(src1_ptr, src2_stride, in0, in1);
1649  LD_SH2((src1_ptr + 8), src2_stride, in2, in3);
1650  src1_ptr += (2 * src2_stride);
1651  in2 = (v8i16) __msa_ilvr_d((v2i64) in3, (v2i64) in2);
1652  XORI_B2_128_SB(src7, src8);
1653 
1654  ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
1655  ILVL_B2_SB(src7, src6, src8, src7, src76_l, src87_l);
1656  src8776 = (v16i8) __msa_ilvr_d((v2i64) src87_l, (v2i64) src76_l);
1657 
1658  DOTP_SB3_SH(src10_r, src21_r, src2110, filt0, filt0, filt0,
1659  tmp0, tmp1, tmp2);
1660  DPADD_SB2_SH(src32_r, src43_r, filt1, filt1, tmp0, tmp1);
1661  tmp2 = __msa_dpadd_s_h(tmp2, src4332, (v16i8) filt1);
1662  DPADD_SB2_SH(src54_r, src65_r, filt2, filt2, tmp0, tmp1);
1663  tmp2 = __msa_dpadd_s_h(tmp2, src6554, (v16i8) filt2);
1664  DPADD_SB2_SH(src76_r, src87_r, filt3, filt3, tmp0, tmp1);
1665  tmp2 = __msa_dpadd_s_h(tmp2, src8776, (v16i8) filt3);
1666 
1667  HEVC_BIW_RND_CLIP2(tmp0, tmp1, in0, in1,
1668  weight_vec, rnd_vec, offset_vec,
1669  out0, out1);
1670 
1671  ILVRL_H2_SW(tmp2, in2, dst2_r, dst2_l);
1672  dst2_r = __msa_dpadd_s_w(offset_vec, (v8i16) dst2_r,
1673  (v8i16) weight_vec);
1674  dst2_l = __msa_dpadd_s_w(offset_vec, (v8i16) dst2_l,
1675  (v8i16) weight_vec);
1676  SRAR_W2_SW(dst2_r, dst2_l, rnd_vec);
1677  out2 = __msa_pckev_h((v8i16) dst2_l, (v8i16) dst2_r);
1678  CLIP_SH_0_255(out2);
1679  PCKEV_B2_SH(out1, out0, out2, out2, out0, out2);
1680  ST_D2(out0, 0, 1, dst, dst_stride);
1681  ST_W2(out2, 0, 1, dst + 8, dst_stride);
1682  dst += (2 * dst_stride);
1683 
1684  src10_r = src32_r;
1685  src32_r = src54_r;
1686  src54_r = src76_r;
1687  src21_r = src43_r;
1688  src43_r = src65_r;
1689  src65_r = src87_r;
1690  src2110 = src4332;
1691  src4332 = src6554;
1692  src6554 = src8776;
1693  src6 = src8;
1694  }
1695 }
1696 
1697 static void hevc_vt_biwgt_8t_16multx2mult_msa(const uint8_t *src0_ptr,
1698  int32_t src_stride,
1699  const int16_t *src1_ptr,
1700  int32_t src2_stride,
1701  uint8_t *dst,
1702  int32_t dst_stride,
1703  const int8_t *filter,
1704  int32_t height,
1705  int32_t weight0,
1706  int32_t weight1,
1707  int32_t offset0,
1708  int32_t offset1,
1709  int32_t rnd_val,
1710  int32_t width)
1711 {
1712  const uint8_t *src0_ptr_tmp;
1713  const int16_t *src1_ptr_tmp;
1714  uint8_t *dst_tmp;
1715  uint32_t loop_cnt, cnt;
1717  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
1718  v8i16 in0, in1, in2, in3;
1719  v16i8 src10_r, src32_r, src54_r, src76_r;
1720  v16i8 src21_r, src43_r, src65_r, src87_r;
1721  v16i8 src10_l, src32_l, src54_l, src76_l;
1722  v16i8 src21_l, src43_l, src65_l, src87_l;
1723  v8i16 tmp0, tmp1, tmp2, tmp3;
1724  v8i16 filt0, filt1, filt2, filt3;
1725  v8i16 filter_vec;
1726  v8i16 out0, out1, out2, out3;
1727  v4i32 weight_vec, weight1_vec, offset_vec, rnd_vec, const_vec;
1728 
1729  src0_ptr -= (3 * src_stride);
1730 
1731  offset = (offset0 + offset1) << rnd_val;
1732  weight0 = weight0 & 0x0000FFFF;
1733  weight = weight0 | (weight1 << 16);
1734 
1735  const_vec = __msa_ldi_w(128);
1736  const_vec <<= 6;
1737  offset_vec = __msa_fill_w(offset);
1738  weight_vec = __msa_fill_w(weight);
1739  rnd_vec = __msa_fill_w(rnd_val + 1);
1740  weight1_vec = __msa_fill_w(weight1);
1741  offset_vec += const_vec * weight1_vec;
1742 
1743  filter_vec = LD_SH(filter);
1744  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
1745 
1746  for (cnt = (width >> 4); cnt--;) {
1747  src0_ptr_tmp = src0_ptr;
1748  src1_ptr_tmp = src1_ptr;
1749  dst_tmp = dst;
1750 
1751  LD_SB7(src0_ptr_tmp, src_stride,
1752  src0, src1, src2, src3, src4, src5, src6);
1753  src0_ptr_tmp += (7 * src_stride);
1754 
1755  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
1756  ILVR_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
1757  src10_r, src32_r, src54_r, src21_r);
1758  ILVR_B2_SB(src4, src3, src6, src5, src43_r, src65_r);
1759  ILVL_B4_SB(src1, src0, src3, src2, src5, src4, src2, src1,
1760  src10_l, src32_l, src54_l, src21_l);
1761  ILVL_B2_SB(src4, src3, src6, src5, src43_l, src65_l);
1762 
1763  for (loop_cnt = (height >> 1); loop_cnt--;) {
1764  LD_SB2(src0_ptr_tmp, src_stride, src7, src8);
1765  src0_ptr_tmp += (2 * src_stride);
1766  LD_SH2(src1_ptr_tmp, src2_stride, in0, in1);
1767  LD_SH2((src1_ptr_tmp + 8), src2_stride, in2, in3);
1768  src1_ptr_tmp += (2 * src2_stride);
1769 
1770  XORI_B2_128_SB(src7, src8);
1771  ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
1772  ILVL_B2_SB(src7, src6, src8, src7, src76_l, src87_l);
1773 
1774  DOTP_SB4_SH(src10_r, src21_r, src10_l, src21_l, filt0, filt0,
1775  filt0, filt0, tmp0, tmp1, tmp2, tmp3);
1776  DPADD_SB4_SH(src32_r, src43_r, src32_l, src43_l, filt1, filt1,
1777  filt1, filt1, tmp0, tmp1, tmp2, tmp3);
1778  DPADD_SB4_SH(src54_r, src65_r, src54_l, src65_l, filt2, filt2,
1779  filt2, filt2, tmp0, tmp1, tmp2, tmp3);
1780  DPADD_SB4_SH(src76_r, src87_r, src76_l, src87_l, filt3, filt3,
1781  filt3, filt3, tmp0, tmp1, tmp2, tmp3);
1782 
1783  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp2, tmp3,
1784  in0, in1, in2, in3,
1785  weight_vec, rnd_vec, offset_vec,
1786  out0, out1, out2, out3);
1787 
1788  PCKEV_B2_SH(out2, out0, out3, out1, out0, out1);
1789  ST_SH2(out0, out1, dst_tmp, dst_stride);
1790  dst_tmp += (2 * dst_stride);
1791 
1792  src10_r = src32_r;
1793  src32_r = src54_r;
1794  src54_r = src76_r;
1795  src21_r = src43_r;
1796  src43_r = src65_r;
1797  src65_r = src87_r;
1798  src10_l = src32_l;
1799  src32_l = src54_l;
1800  src54_l = src76_l;
1801  src21_l = src43_l;
1802  src43_l = src65_l;
1803  src65_l = src87_l;
1804  src6 = src8;
1805  }
1806 
1807  src0_ptr += 16;
1808  src1_ptr += 16;
1809  dst += 16;
1810  }
1811 }
1812 
1813 static void hevc_vt_biwgt_8t_16w_msa(const uint8_t *src0_ptr,
1814  int32_t src_stride,
1815  const int16_t *src1_ptr,
1816  int32_t src2_stride,
1817  uint8_t *dst,
1818  int32_t dst_stride,
1819  const int8_t *filter,
1820  int32_t height,
1821  int32_t weight0,
1822  int32_t weight1,
1823  int32_t offset0,
1824  int32_t offset1,
1825  int32_t rnd_val)
1826 {
1827  hevc_vt_biwgt_8t_16multx2mult_msa(src0_ptr, src_stride,
1828  src1_ptr, src2_stride,
1829  dst, dst_stride, filter, height,
1830  weight0, weight1, offset0, offset1,
1831  rnd_val, 16);
1832 }
1833 
1834 static void hevc_vt_biwgt_8t_24w_msa(const uint8_t *src0_ptr,
1835  int32_t src_stride,
1836  const int16_t *src1_ptr,
1837  int32_t src2_stride,
1838  uint8_t *dst,
1839  int32_t dst_stride,
1840  const int8_t *filter,
1841  int32_t height,
1842  int32_t weight0,
1843  int32_t weight1,
1844  int32_t offset0,
1845  int32_t offset1,
1846  int32_t rnd_val)
1847 {
1848  hevc_vt_biwgt_8t_16multx2mult_msa(src0_ptr, src_stride,
1849  src1_ptr, src2_stride,
1850  dst, dst_stride, filter, height,
1851  weight0, weight1, offset0, offset1,
1852  rnd_val, 16);
1853  hevc_vt_biwgt_8t_8w_msa(src0_ptr + 16, src_stride,
1854  src1_ptr + 16, src2_stride,
1855  dst + 16, dst_stride, filter, height,
1856  weight0, weight1, offset0, offset1, rnd_val);
1857 }
1858 
1859 static void hevc_vt_biwgt_8t_32w_msa(const uint8_t *src0_ptr,
1860  int32_t src_stride,
1861  const int16_t *src1_ptr,
1862  int32_t src2_stride,
1863  uint8_t *dst,
1864  int32_t dst_stride,
1865  const int8_t *filter,
1866  int32_t height,
1867  int32_t weight0,
1868  int32_t weight1,
1869  int32_t offset0,
1870  int32_t offset1,
1871  int32_t rnd_val)
1872 {
1873  hevc_vt_biwgt_8t_16multx2mult_msa(src0_ptr, src_stride,
1874  src1_ptr, src2_stride,
1875  dst, dst_stride, filter, height,
1876  weight0, weight1, offset0, offset1,
1877  rnd_val, 32);
1878 }
1879 
1880 static void hevc_vt_biwgt_8t_48w_msa(const uint8_t *src0_ptr,
1881  int32_t src_stride,
1882  const int16_t *src1_ptr,
1883  int32_t src2_stride,
1884  uint8_t *dst,
1885  int32_t dst_stride,
1886  const int8_t *filter,
1887  int32_t height,
1888  int32_t weight0,
1889  int32_t weight1,
1890  int32_t offset0,
1891  int32_t offset1,
1892  int32_t rnd_val)
1893 {
1894  hevc_vt_biwgt_8t_16multx2mult_msa(src0_ptr, src_stride,
1895  src1_ptr, src2_stride,
1896  dst, dst_stride, filter, height,
1897  weight0, weight1, offset0, offset1,
1898  rnd_val, 48);
1899 }
1900 
1901 static void hevc_vt_biwgt_8t_64w_msa(const uint8_t *src0_ptr,
1902  int32_t src_stride,
1903  const int16_t *src1_ptr,
1904  int32_t src2_stride,
1905  uint8_t *dst,
1906  int32_t dst_stride,
1907  const int8_t *filter,
1908  int32_t height,
1909  int32_t weight0,
1910  int32_t weight1,
1911  int32_t offset0,
1912  int32_t offset1,
1913  int32_t rnd_val)
1914 {
1915  hevc_vt_biwgt_8t_16multx2mult_msa(src0_ptr, src_stride,
1916  src1_ptr, src2_stride,
1917  dst, dst_stride, filter, height,
1918  weight0, weight1, offset0, offset1,
1919  rnd_val, 64);
1920 }
1921 
1922 static void hevc_hv_biwgt_8t_4w_msa(const uint8_t *src0_ptr,
1923  int32_t src_stride,
1924  const int16_t *src1_ptr,
1925  int32_t src2_stride,
1926  uint8_t *dst,
1927  int32_t dst_stride,
1928  const int8_t *filter_x,
1929  const int8_t *filter_y,
1930  int32_t height,
1931  int32_t weight0,
1932  int32_t weight1,
1933  int32_t offset0,
1934  int32_t offset1,
1935  int32_t rnd_val)
1936 {
1937  uint32_t loop_cnt;
1938  uint64_t tp0, tp1;
1940  v16u8 out;
1941  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
1942  v8i16 in0 = { 0 }, in1 = { 0 };
1943  v8i16 filt0, filt1, filt2, filt3;
1944  v8i16 filt_h0, filt_h1, filt_h2, filt_h3;
1945  v16i8 mask1, mask2, mask3;
1946  v8i16 filter_vec, weight_vec;
1947  v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
1948  v16i8 vec8, vec9, vec10, vec11, vec12, vec13, vec14, vec15;
1949  v8i16 dst30, dst41, dst52, dst63, dst66, dst87;
1950  v8i16 tmp0, tmp1, tmp2, tmp3;
1951  v8i16 dst10, dst32, dst54, dst76;
1952  v8i16 dst21, dst43, dst65, dst97, dst108, dst109, dst98;
1953  v4i32 offset_vec, rnd_vec, const_vec, dst0, dst1, dst2, dst3;
1954  v16i8 mask0 = LD_SB(ff_hevc_mask_arr + 16);
1955 
1956  src0_ptr -= ((3 * src_stride) + 3);
1957 
1958  filter_vec = LD_SH(filter_x);
1959  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
1960 
1961  filter_vec = LD_SH(filter_y);
1962  UNPCK_R_SB_SH(filter_vec, filter_vec);
1963 
1964  SPLATI_W4_SH(filter_vec, filt_h0, filt_h1, filt_h2, filt_h3);
1965 
1966  mask1 = mask0 + 2;
1967  mask2 = mask0 + 4;
1968  mask3 = mask0 + 6;
1969 
1970  offset = (offset0 + offset1) << rnd_val;
1971  weight0 = weight0 & 0x0000FFFF;
1972  weight = weight0 | (weight1 << 16);
1973 
1974  const_vec = __msa_fill_w((128 * weight1));
1975  const_vec <<= 6;
1976  offset_vec = __msa_fill_w(offset);
1977  rnd_vec = __msa_fill_w(rnd_val + 1);
1978  offset_vec += const_vec;
1979  weight_vec = (v8i16) __msa_fill_w(weight);
1980 
1981  LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
1982  src0_ptr += (7 * src_stride);
1983 
1984  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
1985 
1986  VSHF_B4_SB(src0, src3, mask0, mask1, mask2, mask3, vec0, vec1, vec2, vec3);
1987  VSHF_B4_SB(src1, src4, mask0, mask1, mask2, mask3, vec4, vec5, vec6, vec7);
1988  VSHF_B4_SB(src2, src5, mask0, mask1, mask2, mask3,
1989  vec8, vec9, vec10, vec11);
1990  VSHF_B4_SB(src3, src6, mask0, mask1, mask2, mask3,
1991  vec12, vec13, vec14, vec15);
1992 
1993  dst30 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
1994  filt3);
1995  dst41 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
1996  filt3);
1997  dst52 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
1998  filt3);
1999  dst63 = HEVC_FILT_8TAP_SH(vec12, vec13, vec14, vec15, filt0, filt1, filt2,
2000  filt3);
2001 
2002  ILVRL_H2_SH(dst41, dst30, dst10, dst43);
2003  ILVRL_H2_SH(dst52, dst41, dst21, dst54);
2004  ILVRL_H2_SH(dst63, dst52, dst32, dst65);
2005 
2006  dst66 = (v8i16) __msa_splati_d((v2i64) dst63, 1);
2007 
2008  for (loop_cnt = height >> 2; loop_cnt--;) {
2009  LD_SB4(src0_ptr, src_stride, src7, src8, src9, src10);
2010  src0_ptr += (4 * src_stride);
2011  XORI_B4_128_SB(src7, src8, src9, src10);
2012 
2013  LD2(src1_ptr, src2_stride, tp0, tp1);
2014  INSERT_D2_SH(tp0, tp1, in0);
2015  src1_ptr += (2 * src2_stride);
2016  LD2(src1_ptr, src2_stride, tp0, tp1);
2017  INSERT_D2_SH(tp0, tp1, in1);
2018  src1_ptr += (2 * src2_stride);
2019 
2020  VSHF_B4_SB(src7, src9, mask0, mask1, mask2, mask3,
2021  vec0, vec1, vec2, vec3);
2022  VSHF_B4_SB(src8, src10, mask0, mask1, mask2, mask3,
2023  vec4, vec5, vec6, vec7);
2024  dst97 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
2025  filt3);
2026  dst108 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
2027  filt3);
2028 
2029  dst76 = __msa_ilvr_h(dst97, dst66);
2030  ILVRL_H2_SH(dst108, dst97, dst87, dst109);
2031  dst66 = (v8i16) __msa_splati_d((v2i64) dst97, 1);
2032  dst98 = __msa_ilvr_h(dst66, dst108);
2033 
2034  dst0 = HEVC_FILT_8TAP(dst10, dst32, dst54, dst76, filt_h0, filt_h1,
2035  filt_h2, filt_h3);
2036  dst1 = HEVC_FILT_8TAP(dst21, dst43, dst65, dst87, filt_h0, filt_h1,
2037  filt_h2, filt_h3);
2038  dst2 = HEVC_FILT_8TAP(dst32, dst54, dst76, dst98, filt_h0, filt_h1,
2039  filt_h2, filt_h3);
2040  dst3 = HEVC_FILT_8TAP(dst43, dst65, dst87, dst109, filt_h0, filt_h1,
2041  filt_h2, filt_h3);
2042  SRA_4V(dst0, dst1, dst2, dst3, 6);
2043  PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp1, tmp3);
2044  ILVRL_H2_SH(tmp1, in0, tmp0, tmp1);
2045  ILVRL_H2_SH(tmp3, in1, tmp2, tmp3);
2046  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
2047  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
2048  dst2 = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
2049  dst3 = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
2050  SRAR_W4_SW(dst0, dst1, dst2, dst3, rnd_vec);
2051  CLIP_SW4_0_255(dst0, dst1, dst2, dst3);
2052  PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp0, tmp1);
2053  out = (v16u8) __msa_pckev_b((v16i8) tmp1, (v16i8) tmp0);
2054  ST_W4(out, 0, 1, 2, 3, dst, dst_stride);
2055  dst += (4 * dst_stride);
2056 
2057  dst10 = dst54;
2058  dst32 = dst76;
2059  dst54 = dst98;
2060  dst21 = dst65;
2061  dst43 = dst87;
2062  dst65 = dst109;
2063  dst66 = (v8i16) __msa_splati_d((v2i64) dst108, 1);
2064  }
2065 }
2066 
2067 static void hevc_hv_biwgt_8t_8multx2mult_msa(const uint8_t *src0_ptr,
2068  int32_t src_stride,
2069  const int16_t *src1_ptr,
2070  int32_t src2_stride,
2071  uint8_t *dst,
2072  int32_t dst_stride,
2073  const int8_t *filter_x,
2074  const int8_t *filter_y,
2075  int32_t height,
2076  int32_t weight0,
2077  int32_t weight1,
2078  int32_t offset0,
2079  int32_t offset1,
2080  int32_t rnd_val,
2081  int32_t width8mult)
2082 {
2083  uint32_t loop_cnt, cnt;
2085  const uint8_t *src0_ptr_tmp;
2086  const int16_t *src1_ptr_tmp;
2087  uint8_t *dst_tmp;
2088  v16u8 out;
2089  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
2090  v8i16 in0, in1;
2091  v8i16 filt0, filt1, filt2, filt3;
2092  v8i16 filt_h0, filt_h1, filt_h2, filt_h3;
2093  v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
2094  v16i8 mask1, mask2, mask3;
2095  v8i16 filter_vec, weight_vec;
2096  v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
2097  v16i8 vec8, vec9, vec10, vec11, vec12, vec13, vec14, vec15;
2098  v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7, dst8;
2099  v4i32 dst0_r, dst0_l, dst1_r, dst1_l;
2100  v8i16 tmp0, tmp1, tmp2, tmp3;
2101  v8i16 dst10_r, dst32_r, dst54_r, dst76_r;
2102  v8i16 dst10_l, dst32_l, dst54_l, dst76_l;
2103  v8i16 dst21_r, dst43_r, dst65_r, dst87_r;
2104  v8i16 dst21_l, dst43_l, dst65_l, dst87_l;
2105  v4i32 offset_vec, rnd_vec, const_vec;
2106 
2107  src0_ptr -= ((3 * src_stride) + 3);
2108 
2109  offset = (offset0 + offset1) << rnd_val;
2110  weight0 = weight0 & 0x0000FFFF;
2111  weight = weight0 | (weight1 << 16);
2112 
2113  const_vec = __msa_fill_w((128 * weight1));
2114  const_vec <<= 6;
2115  offset_vec = __msa_fill_w(offset);
2116  rnd_vec = __msa_fill_w(rnd_val + 1);
2117  offset_vec += const_vec;
2118  weight_vec = (v8i16) __msa_fill_w(weight);
2119 
2120  filter_vec = LD_SH(filter_x);
2121  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
2122 
2123  filter_vec = LD_SH(filter_y);
2124  UNPCK_R_SB_SH(filter_vec, filter_vec);
2125 
2126  SPLATI_W4_SH(filter_vec, filt_h0, filt_h1, filt_h2, filt_h3);
2127 
2128  mask1 = mask0 + 2;
2129  mask2 = mask0 + 4;
2130  mask3 = mask0 + 6;
2131 
2132  for (cnt = width8mult; cnt--;) {
2133  src0_ptr_tmp = src0_ptr;
2134  src1_ptr_tmp = src1_ptr;
2135  dst_tmp = dst;
2136 
2137  LD_SB7(src0_ptr_tmp, src_stride,
2138  src0, src1, src2, src3, src4, src5, src6);
2139  src0_ptr_tmp += (7 * src_stride);
2140 
2141  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
2142 
2143  /* row 0 row 1 row 2 row 3 */
2144  VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3,
2145  vec0, vec1, vec2, vec3);
2146  VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3,
2147  vec4, vec5, vec6, vec7);
2148  VSHF_B4_SB(src2, src2, mask0, mask1, mask2, mask3,
2149  vec8, vec9, vec10, vec11);
2150  VSHF_B4_SB(src3, src3, mask0, mask1, mask2, mask3,
2151  vec12, vec13, vec14, vec15);
2152 
2153  dst0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
2154  filt3);
2155  dst1 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
2156  filt3);
2157  dst2 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
2158  filt3);
2159  dst3 = HEVC_FILT_8TAP_SH(vec12, vec13, vec14, vec15, filt0, filt1,
2160  filt2, filt3);
2161 
2162  /* row 4 row 5 row 6 */
2163  VSHF_B4_SB(src4, src4, mask0, mask1, mask2, mask3,
2164  vec0, vec1, vec2, vec3);
2165  VSHF_B4_SB(src5, src5, mask0, mask1, mask2, mask3,
2166  vec4, vec5, vec6, vec7);
2167  VSHF_B4_SB(src6, src6, mask0, mask1, mask2, mask3,
2168  vec8, vec9, vec10, vec11);
2169 
2170  dst4 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
2171  filt3);
2172  dst5 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
2173  filt3);
2174  dst6 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
2175  filt3);
2176 
2177  for (loop_cnt = height >> 1; loop_cnt--;) {
2178  LD_SB2(src0_ptr_tmp, src_stride, src7, src8);
2179  XORI_B2_128_SB(src7, src8);
2180  src0_ptr_tmp += 2 * src_stride;
2181 
2182  LD_SH2(src1_ptr_tmp, src2_stride, in0, in1);
2183  src1_ptr_tmp += (2 * src2_stride);
2184 
2185  ILVR_H4_SH(dst1, dst0, dst3, dst2, dst5, dst4, dst2, dst1, dst10_r,
2186  dst32_r, dst54_r, dst21_r);
2187  ILVL_H4_SH(dst1, dst0, dst3, dst2, dst5, dst4, dst2, dst1, dst10_l,
2188  dst32_l, dst54_l, dst21_l);
2189  ILVR_H2_SH(dst4, dst3, dst6, dst5, dst43_r, dst65_r);
2190  ILVL_H2_SH(dst4, dst3, dst6, dst5, dst43_l, dst65_l);
2191 
2192  VSHF_B4_SB(src7, src7, mask0, mask1, mask2, mask3,
2193  vec0, vec1, vec2, vec3);
2194  dst7 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1,
2195  filt2, filt3);
2196 
2197  ILVRL_H2_SH(dst7, dst6, dst76_r, dst76_l);
2198  dst0_r = HEVC_FILT_8TAP(dst10_r, dst32_r, dst54_r, dst76_r,
2199  filt_h0, filt_h1, filt_h2, filt_h3);
2200  dst0_l = HEVC_FILT_8TAP(dst10_l, dst32_l, dst54_l, dst76_l,
2201  filt_h0, filt_h1, filt_h2, filt_h3);
2202 
2203  dst0_r >>= 6;
2204  dst0_l >>= 6;
2205 
2206  /* row 8 */
2207  VSHF_B4_SB(src8, src8, mask0, mask1, mask2, mask3,
2208  vec0, vec1, vec2, vec3);
2209  dst8 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1,
2210  filt2, filt3);
2211 
2212  ILVRL_H2_SH(dst8, dst7, dst87_r, dst87_l);
2213  dst1_r = HEVC_FILT_8TAP(dst21_r, dst43_r, dst65_r, dst87_r,
2214  filt_h0, filt_h1, filt_h2, filt_h3);
2215  dst1_l = HEVC_FILT_8TAP(dst21_l, dst43_l, dst65_l, dst87_l,
2216  filt_h0, filt_h1, filt_h2, filt_h3);
2217 
2218  dst1_r >>= 6;
2219  dst1_l >>= 6;
2220 
2221  PCKEV_H2_SH(dst0_l, dst0_r, dst1_l, dst1_r, tmp1, tmp3);
2222  ILVRL_H2_SH(tmp1, in0, tmp0, tmp1);
2223  ILVRL_H2_SH(tmp3, in1, tmp2, tmp3);
2224  dst0_r = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
2225  dst0_l = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
2226  dst1_r = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
2227  dst1_l = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
2228  SRAR_W4_SW(dst0_l, dst0_r, dst1_l, dst1_r, rnd_vec);
2229  CLIP_SW4_0_255(dst0_l, dst0_r, dst1_l, dst1_r);
2230  PCKEV_H2_SH(dst0_l, dst0_r, dst1_l, dst1_r, tmp0, tmp1);
2231  out = (v16u8) __msa_pckev_b((v16i8) tmp1, (v16i8) tmp0);
2232  ST_D2(out, 0, 1, dst_tmp, dst_stride);
2233  dst_tmp += (2 * dst_stride);
2234 
2235  dst0 = dst2;
2236  dst1 = dst3;
2237  dst2 = dst4;
2238  dst3 = dst5;
2239  dst4 = dst6;
2240  dst5 = dst7;
2241  dst6 = dst8;
2242  }
2243 
2244  src0_ptr += 8;
2245  src1_ptr += 8;
2246  dst += 8;
2247  }
2248 }
2249 
2250 static void hevc_hv_biwgt_8t_8w_msa(const uint8_t *src0_ptr,
2251  int32_t src_stride,
2252  const int16_t *src1_ptr,
2253  int32_t src2_stride,
2254  uint8_t *dst,
2255  int32_t dst_stride,
2256  const int8_t *filter_x,
2257  const int8_t *filter_y,
2258  int32_t height,
2259  int32_t weight0,
2260  int32_t weight1,
2261  int32_t offset0,
2262  int32_t offset1,
2263  int32_t rnd_val)
2264 {
2265  hevc_hv_biwgt_8t_8multx2mult_msa(src0_ptr, src_stride,
2266  src1_ptr, src2_stride,
2267  dst, dst_stride, filter_x, filter_y,
2268  height, weight0, weight1, offset0,
2269  offset1, rnd_val, 1);
2270 }
2271 
2272 static void hevc_hv_biwgt_8t_12w_msa(const uint8_t *src0_ptr,
2273  int32_t src_stride,
2274  const int16_t *src1_ptr,
2275  int32_t src2_stride,
2276  uint8_t *dst,
2277  int32_t dst_stride,
2278  const int8_t *filter_x,
2279  const int8_t *filter_y,
2280  int32_t height,
2281  int32_t weight0,
2282  int32_t weight1,
2283  int32_t offset0,
2284  int32_t offset1,
2285  int32_t rnd_val)
2286 {
2287  uint32_t loop_cnt;
2288  const uint8_t *src0_ptr_tmp;
2289  uint8_t *dst_tmp;
2290  const int16_t *src1_ptr_tmp;
2292  uint64_t tp0, tp1;
2293  v16u8 out;
2294  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
2295  v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
2296  v16i8 vec8, vec9, vec10, vec11, vec12, vec13, vec14, vec15;
2297  v16i8 mask0, mask1, mask2, mask3, mask4, mask5, mask6, mask7;
2298  v8i16 in0 = { 0 }, in1 = { 0 };
2299  v8i16 filter_vec, weight_vec, tmp0, tmp1, tmp2, tmp3;
2300  v8i16 filt0, filt1, filt2, filt3, filt_h0, filt_h1, filt_h2, filt_h3;
2301  v8i16 dsth0, dsth1, dsth2, dsth3, dsth4, dsth5, dsth6, dsth7, dsth8;
2302  v8i16 dst10_r, dst32_r, dst54_r, dst76_r, dst21_r, dst43_r, dst65_r;
2303  v8i16 dst10_l, dst32_l, dst54_l, dst76_l, dst21_l, dst43_l, dst65_l;
2304  v8i16 dst30, dst41, dst52, dst63, dst66, dst87, dst10, dst32, dst54, dst76;
2305  v8i16 dst21, dst43, dst65, dst97, dst108, dst109, dst98, dst87_r, dst87_l;
2306  v4i32 offset_vec, rnd_vec, const_vec, dst0, dst1, dst2, dst3;
2307 
2308  src0_ptr -= ((3 * src_stride) + 3);
2309 
2310  offset = (offset0 + offset1) << rnd_val;
2311  weight0 = weight0 & 0x0000FFFF;
2312  weight = weight0 | (weight1 << 16);
2313 
2314  const_vec = __msa_fill_w((128 * weight1));
2315  const_vec <<= 6;
2316  offset_vec = __msa_fill_w(offset);
2317  rnd_vec = __msa_fill_w(rnd_val + 1);
2318  offset_vec += const_vec;
2319  weight_vec = (v8i16) __msa_fill_w(weight);
2320 
2321  filter_vec = LD_SH(filter_x);
2322  SPLATI_H4_SH(filter_vec, 0, 1, 2, 3, filt0, filt1, filt2, filt3);
2323 
2324  filter_vec = LD_SH(filter_y);
2325  UNPCK_R_SB_SH(filter_vec, filter_vec);
2326 
2327  SPLATI_W4_SH(filter_vec, filt_h0, filt_h1, filt_h2, filt_h3);
2328 
2329  mask0 = LD_SB(ff_hevc_mask_arr);
2330  mask1 = mask0 + 2;
2331  mask2 = mask0 + 4;
2332  mask3 = mask0 + 6;
2333 
2334  src0_ptr_tmp = src0_ptr;
2335  src1_ptr_tmp = src1_ptr;
2336  dst_tmp = dst;
2337 
2338  LD_SB7(src0_ptr_tmp, src_stride, src0, src1, src2, src3, src4, src5, src6);
2339  src0_ptr_tmp += (7 * src_stride);
2340  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
2341 
2342  VSHF_B4_SB(src0, src0, mask0, mask1, mask2, mask3, vec0, vec1, vec2, vec3);
2343  VSHF_B4_SB(src1, src1, mask0, mask1, mask2, mask3, vec4, vec5, vec6, vec7);
2344  VSHF_B4_SB(src2, src2, mask0, mask1, mask2, mask3, vec8, vec9, vec10,
2345  vec11);
2346  VSHF_B4_SB(src3, src3, mask0, mask1, mask2, mask3, vec12, vec13, vec14,
2347  vec15);
2348  dsth0 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
2349  filt3);
2350  dsth1 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
2351  filt3);
2352  dsth2 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
2353  filt3);
2354  dsth3 = HEVC_FILT_8TAP_SH(vec12, vec13, vec14, vec15, filt0, filt1,
2355  filt2, filt3);
2356  VSHF_B4_SB(src4, src4, mask0, mask1, mask2, mask3, vec0, vec1, vec2, vec3);
2357  VSHF_B4_SB(src5, src5, mask0, mask1, mask2, mask3, vec4, vec5, vec6, vec7);
2358  VSHF_B4_SB(src6, src6, mask0, mask1, mask2, mask3, vec8, vec9, vec10,
2359  vec11);
2360  dsth4 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
2361  filt3);
2362  dsth5 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
2363  filt3);
2364  dsth6 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
2365  filt3);
2366 
2367  for (loop_cnt = 8; loop_cnt--;) {
2368  LD_SB2(src0_ptr_tmp, src_stride, src7, src8);
2369  src0_ptr_tmp += (2 * src_stride);
2370  XORI_B2_128_SB(src7, src8);
2371 
2372  LD_SH2(src1_ptr_tmp, src2_stride, in0, in1);
2373  src1_ptr_tmp += (2 * src2_stride);
2374 
2375  ILVR_H4_SH(dsth1, dsth0, dsth3, dsth2, dsth5, dsth4, dsth2, dsth1,
2376  dst10_r, dst32_r, dst54_r, dst21_r);
2377  ILVL_H4_SH(dsth1, dsth0, dsth3, dsth2, dsth5, dsth4, dsth2, dsth1,
2378  dst10_l, dst32_l, dst54_l, dst21_l);
2379  ILVR_H2_SH(dsth4, dsth3, dsth6, dsth5, dst43_r, dst65_r);
2380  ILVL_H2_SH(dsth4, dsth3, dsth6, dsth5, dst43_l, dst65_l);
2381 
2382  VSHF_B4_SB(src7, src7, mask0, mask1, mask2, mask3, vec0, vec1, vec2,
2383  vec3);
2384  dsth7 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
2385  filt3);
2386 
2387  ILVRL_H2_SH(dsth7, dsth6, dst76_r, dst76_l);
2388  dst0 = HEVC_FILT_8TAP(dst10_r, dst32_r, dst54_r, dst76_r, filt_h0,
2389  filt_h1, filt_h2, filt_h3);
2390  dst1 = HEVC_FILT_8TAP(dst10_l, dst32_l, dst54_l, dst76_l, filt_h0,
2391  filt_h1, filt_h2, filt_h3);
2392  dst0 >>= 6;
2393  dst1 >>= 6;
2394 
2395  VSHF_B4_SB(src8, src8, mask0, mask1, mask2, mask3, vec0, vec1, vec2,
2396  vec3);
2397  dsth8 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
2398  filt3);
2399 
2400  ILVRL_H2_SH(dsth8, dsth7, dst87_r, dst87_l);
2401  dst2 = HEVC_FILT_8TAP(dst21_r, dst43_r, dst65_r, dst87_r, filt_h0,
2402  filt_h1, filt_h2, filt_h3);
2403  dst3 = HEVC_FILT_8TAP(dst21_l, dst43_l, dst65_l, dst87_l, filt_h0,
2404  filt_h1, filt_h2, filt_h3);
2405  dst2 >>= 6;
2406  dst3 >>= 6;
2407 
2408  PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp1, tmp3);
2409  ILVRL_H2_SH(tmp1, in0, tmp0, tmp1);
2410  ILVRL_H2_SH(tmp3, in1, tmp2, tmp3);
2411  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
2412  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
2413  dst2 = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
2414  dst3 = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
2415  SRAR_W4_SW(dst1, dst0, dst3, dst2, rnd_vec);
2416  CLIP_SW4_0_255(dst1, dst0, dst3, dst2);
2417  PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp0, tmp1);
2418  out = (v16u8) __msa_pckev_b((v16i8) tmp1, (v16i8) tmp0);
2419  ST_D2(out, 0, 1, dst_tmp, dst_stride);
2420  dst_tmp += (2 * dst_stride);
2421 
2422  dsth0 = dsth2;
2423  dsth1 = dsth3;
2424  dsth2 = dsth4;
2425  dsth3 = dsth5;
2426  dsth4 = dsth6;
2427  dsth5 = dsth7;
2428  dsth6 = dsth8;
2429  }
2430 
2431  src0_ptr += 8;
2432  src1_ptr += 8;
2433  dst += 8;
2434 
2435  mask4 = LD_SB(ff_hevc_mask_arr + 16);
2436  mask5 = mask4 + 2;
2437  mask6 = mask4 + 4;
2438  mask7 = mask4 + 6;
2439 
2440  LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
2441  src0_ptr += (7 * src_stride);
2442  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
2443 
2444  VSHF_B4_SB(src0, src3, mask4, mask5, mask6, mask7, vec0, vec1, vec2, vec3);
2445  VSHF_B4_SB(src1, src4, mask4, mask5, mask6, mask7, vec4, vec5, vec6, vec7);
2446  VSHF_B4_SB(src2, src5, mask4, mask5, mask6, mask7, vec8, vec9, vec10,
2447  vec11);
2448  VSHF_B4_SB(src3, src6, mask4, mask5, mask6, mask7, vec12, vec13, vec14,
2449  vec15);
2450  dst30 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
2451  filt3);
2452  dst41 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
2453  filt3);
2454  dst52 = HEVC_FILT_8TAP_SH(vec8, vec9, vec10, vec11, filt0, filt1, filt2,
2455  filt3);
2456  dst63 = HEVC_FILT_8TAP_SH(vec12, vec13, vec14, vec15, filt0, filt1, filt2,
2457  filt3);
2458  ILVRL_H2_SH(dst41, dst30, dst10, dst43);
2459  ILVRL_H2_SH(dst52, dst41, dst21, dst54);
2460  ILVRL_H2_SH(dst63, dst52, dst32, dst65);
2461 
2462  dst66 = (v8i16) __msa_splati_d((v2i64) dst63, 1);
2463 
2464  for (loop_cnt = 4; loop_cnt--;) {
2465  LD_SB4(src0_ptr, src_stride, src7, src8, src9, src10);
2466  src0_ptr += (4 * src_stride);
2467  XORI_B4_128_SB(src7, src8, src9, src10);
2468 
2469  LD2(src1_ptr, src2_stride, tp0, tp1);
2470  INSERT_D2_SH(tp0, tp1, in0);
2471  src1_ptr += (2 * src2_stride);
2472  LD2(src1_ptr, src2_stride, tp0, tp1);
2473  INSERT_D2_SH(tp0, tp1, in1);
2474  src1_ptr += (2 * src2_stride);
2475 
2476  VSHF_B4_SB(src7, src9, mask4, mask5, mask6, mask7, vec0, vec1, vec2,
2477  vec3);
2478  VSHF_B4_SB(src8, src10, mask4, mask5, mask6, mask7, vec4, vec5, vec6,
2479  vec7);
2480  dst97 = HEVC_FILT_8TAP_SH(vec0, vec1, vec2, vec3, filt0, filt1, filt2,
2481  filt3);
2482  dst108 = HEVC_FILT_8TAP_SH(vec4, vec5, vec6, vec7, filt0, filt1, filt2,
2483  filt3);
2484 
2485  dst76 = __msa_ilvr_h(dst97, dst66);
2486  ILVRL_H2_SH(dst108, dst97, dst87, dst109);
2487  dst66 = (v8i16) __msa_splati_d((v2i64) dst97, 1);
2488  dst98 = __msa_ilvr_h(dst66, dst108);
2489 
2490  dst0 = HEVC_FILT_8TAP(dst10, dst32, dst54, dst76, filt_h0, filt_h1,
2491  filt_h2, filt_h3);
2492  dst1 = HEVC_FILT_8TAP(dst21, dst43, dst65, dst87, filt_h0, filt_h1,
2493  filt_h2, filt_h3);
2494  dst2 = HEVC_FILT_8TAP(dst32, dst54, dst76, dst98, filt_h0, filt_h1,
2495  filt_h2, filt_h3);
2496  dst3 = HEVC_FILT_8TAP(dst43, dst65, dst87, dst109, filt_h0, filt_h1,
2497  filt_h2, filt_h3);
2498  SRA_4V(dst0, dst1, dst2, dst3, 6);
2499  PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp1, tmp3);
2500  ILVRL_H2_SH(tmp1, in0, tmp0, tmp1);
2501  ILVRL_H2_SH(tmp3, in1, tmp2, tmp3);
2502  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
2503  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
2504  dst2 = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
2505  dst3 = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
2506  SRAR_W4_SW(dst0, dst1, dst2, dst3, rnd_vec);
2507  CLIP_SW4_0_255(dst0, dst1, dst2, dst3);
2508  PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp0, tmp1);
2509  out = (v16u8) __msa_pckev_b((v16i8) tmp1, (v16i8) tmp0);
2510  ST_W4(out, 0, 1, 2, 3, dst, dst_stride);
2511  dst += (4 * dst_stride);
2512 
2513  dst10 = dst54;
2514  dst32 = dst76;
2515  dst54 = dst98;
2516  dst21 = dst65;
2517  dst43 = dst87;
2518  dst65 = dst109;
2519  dst66 = (v8i16) __msa_splati_d((v2i64) dst108, 1);
2520  }
2521 }
2522 
2523 static void hevc_hv_biwgt_8t_16w_msa(const uint8_t *src0_ptr,
2524  int32_t src_stride,
2525  const int16_t *src1_ptr,
2526  int32_t src2_stride,
2527  uint8_t *dst,
2528  int32_t dst_stride,
2529  const int8_t *filter_x,
2530  const int8_t *filter_y,
2531  int32_t height,
2532  int32_t weight0,
2533  int32_t weight1,
2534  int32_t offset0,
2535  int32_t offset1,
2536  int32_t rnd_val)
2537 {
2538  hevc_hv_biwgt_8t_8multx2mult_msa(src0_ptr, src_stride,
2539  src1_ptr, src2_stride,
2540  dst, dst_stride, filter_x, filter_y,
2541  height, weight0, weight1, offset0,
2542  offset1, rnd_val, 2);
2543 }
2544 
2545 static void hevc_hv_biwgt_8t_24w_msa(const uint8_t *src0_ptr,
2546  int32_t src_stride,
2547  const int16_t *src1_ptr,
2548  int32_t src2_stride,
2549  uint8_t *dst,
2550  int32_t dst_stride,
2551  const int8_t *filter_x,
2552  const int8_t *filter_y,
2553  int32_t height,
2554  int32_t weight0,
2555  int32_t weight1,
2556  int32_t offset0,
2557  int32_t offset1,
2558  int32_t rnd_val)
2559 {
2560  hevc_hv_biwgt_8t_8multx2mult_msa(src0_ptr, src_stride,
2561  src1_ptr, src2_stride,
2562  dst, dst_stride, filter_x, filter_y,
2563  height, weight0, weight1, offset0,
2564  offset1, rnd_val, 3);
2565 }
2566 
2567 static void hevc_hv_biwgt_8t_32w_msa(const uint8_t *src0_ptr,
2568  int32_t src_stride,
2569  const int16_t *src1_ptr,
2570  int32_t src2_stride,
2571  uint8_t *dst,
2572  int32_t dst_stride,
2573  const int8_t *filter_x,
2574  const int8_t *filter_y,
2575  int32_t height,
2576  int32_t weight0,
2577  int32_t weight1,
2578  int32_t offset0,
2579  int32_t offset1,
2580  int32_t rnd_val)
2581 {
2582  hevc_hv_biwgt_8t_8multx2mult_msa(src0_ptr, src_stride,
2583  src1_ptr, src2_stride,
2584  dst, dst_stride, filter_x, filter_y,
2585  height, weight0, weight1, offset0,
2586  offset1, rnd_val, 4);
2587 }
2588 
2589 static void hevc_hv_biwgt_8t_48w_msa(const uint8_t *src0_ptr,
2590  int32_t src_stride,
2591  const int16_t *src1_ptr,
2592  int32_t src2_stride,
2593  uint8_t *dst,
2594  int32_t dst_stride,
2595  const int8_t *filter_x,
2596  const int8_t *filter_y,
2597  int32_t height,
2598  int32_t weight0,
2599  int32_t weight1,
2600  int32_t offset0,
2601  int32_t offset1,
2602  int32_t rnd_val)
2603 {
2604  hevc_hv_biwgt_8t_8multx2mult_msa(src0_ptr, src_stride,
2605  src1_ptr, src2_stride,
2606  dst, dst_stride, filter_x, filter_y,
2607  height, weight0, weight1, offset0,
2608  offset1, rnd_val, 6);
2609 }
2610 
2611 static void hevc_hv_biwgt_8t_64w_msa(const uint8_t *src0_ptr,
2612  int32_t src_stride,
2613  const int16_t *src1_ptr,
2614  int32_t src2_stride,
2615  uint8_t *dst,
2616  int32_t dst_stride,
2617  const int8_t *filter_x,
2618  const int8_t *filter_y,
2619  int32_t height,
2620  int32_t weight0,
2621  int32_t weight1,
2622  int32_t offset0,
2623  int32_t offset1,
2624  int32_t rnd_val)
2625 {
2626  hevc_hv_biwgt_8t_8multx2mult_msa(src0_ptr, src_stride,
2627  src1_ptr, src2_stride,
2628  dst, dst_stride, filter_x, filter_y,
2629  height, weight0, weight1, offset0,
2630  offset1, rnd_val, 8);
2631 }
2632 
2633 static void hevc_hz_biwgt_4t_4x2_msa(const uint8_t *src0_ptr,
2634  int32_t src_stride,
2635  const int16_t *src1_ptr,
2636  int32_t src2_stride,
2637  uint8_t *dst,
2638  int32_t dst_stride,
2639  const int8_t *filter,
2640  int32_t weight0,
2641  int32_t weight1,
2642  int32_t offset0,
2643  int32_t offset1,
2644  int32_t rnd_val)
2645 {
2646  int32_t offset, weight, constant;
2647  v8i16 filt0, filt1;
2648  v16i8 src0, src1;
2649  v8i16 in0, in1;
2650  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[16]);
2651  v16i8 mask1, vec0, vec1;
2652  v8i16 dst0;
2653  v4i32 dst0_r, dst0_l;
2654  v8i16 out0, filter_vec;
2655  v4i32 weight_vec, offset_vec, rnd_vec;
2656 
2657  src0_ptr -= 1;
2658 
2659  filter_vec = LD_SH(filter);
2660  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
2661 
2662  mask1 = mask0 + 2;
2663 
2664  offset = (offset0 + offset1) << rnd_val;
2665  weight0 = weight0 & 0x0000FFFF;
2666  weight = weight0 | (weight1 << 16);
2667  constant = 128 * weight1;
2668  constant <<= 6;
2669  offset += constant;
2670 
2671  offset_vec = __msa_fill_w(offset);
2672  weight_vec = __msa_fill_w(weight);
2673  rnd_vec = __msa_fill_w(rnd_val + 1);
2674 
2675  LD_SB2(src0_ptr, src_stride, src0, src1);
2676  LD_SH2(src1_ptr, src2_stride, in0, in1);
2677  in0 = (v8i16) __msa_ilvr_d((v2i64) in1, (v2i64) in0);
2679 
2680  VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, vec0, vec1);
2681  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2682 
2683  ILVRL_H2_SW(dst0, in0, dst0_r, dst0_l);
2684  dst0_r = __msa_dpadd_s_w(offset_vec, (v8i16) dst0_r, (v8i16) weight_vec);
2685  dst0_l = __msa_dpadd_s_w(offset_vec, (v8i16) dst0_l, (v8i16) weight_vec);
2686  SRAR_W2_SW(dst0_r, dst0_l, rnd_vec);
2687  out0 = __msa_pckev_h((v8i16) dst0_l, (v8i16) dst0_r);
2688  CLIP_SH_0_255(out0);
2689  out0 = (v8i16) __msa_pckev_b((v16i8) out0, (v16i8) out0);
2690  ST_W2(out0, 0, 1, dst, dst_stride);
2691 }
2692 
2693 static void hevc_hz_biwgt_4t_4x4_msa(const uint8_t *src0_ptr,
2694  int32_t src_stride,
2695  const int16_t *src1_ptr,
2696  int32_t src2_stride,
2697  uint8_t *dst,
2698  int32_t dst_stride,
2699  const int8_t *filter,
2700  int32_t weight0,
2701  int32_t weight1,
2702  int32_t offset0,
2703  int32_t offset1,
2704  int32_t rnd_val)
2705 {
2706  int32_t offset, weight, constant;
2707  v8i16 filt0, filt1;
2708  v16i8 src0, src1, src2, src3;
2709  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[16]);
2710  v16i8 mask1;
2711  v8i16 dst0, dst1;
2712  v16i8 vec0, vec1;
2713  v8i16 in0, in1, in2, in3;
2714  v8i16 filter_vec;
2715  v4i32 weight_vec, offset_vec, rnd_vec;
2716 
2717  src0_ptr -= 1;
2718 
2719  /* rearranging filter */
2720  filter_vec = LD_SH(filter);
2721  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
2722 
2723  mask1 = mask0 + 2;
2724 
2725  offset = (offset0 + offset1) << rnd_val;
2726  weight0 = weight0 & 0x0000FFFF;
2727  weight = weight0 | (weight1 << 16);
2728  constant = 128 * weight1;
2729  constant <<= 6;
2730  offset += constant;
2731 
2732  offset_vec = __msa_fill_w(offset);
2733  weight_vec = __msa_fill_w(weight);
2734  rnd_vec = __msa_fill_w(rnd_val + 1);
2735 
2736  LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
2737  XORI_B4_128_SB(src0, src1, src2, src3);
2738  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
2739  ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
2740 
2741  VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, vec0, vec1);
2742  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2743  VSHF_B2_SB(src2, src3, src2, src3, mask0, mask1, vec0, vec1);
2744  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2745  HEVC_BIW_RND_CLIP2(dst0, dst1, in0, in1,
2746  weight_vec, rnd_vec, offset_vec,
2747  dst0, dst1);
2748 
2749  dst0 = (v8i16) __msa_pckev_b((v16i8) dst1, (v16i8) dst0);
2750  ST_W4(dst0, 0, 1, 2, 3, dst, dst_stride);
2751 }
2752 
2753 static void hevc_hz_biwgt_4t_4x8multiple_msa(const uint8_t *src0_ptr,
2754  int32_t src_stride,
2755  const int16_t *src1_ptr,
2756  int32_t src2_stride,
2757  uint8_t *dst,
2758  int32_t dst_stride,
2759  const int8_t *filter,
2760  int32_t height,
2761  int32_t weight0,
2762  int32_t weight1,
2763  int32_t offset0,
2764  int32_t offset1,
2765  int32_t rnd_val)
2766 {
2767  uint32_t loop_cnt;
2768  int32_t weight, offset, constant;
2769  v8i16 filt0, filt1;
2770  v16i8 src0, src1, src2, src3, src4, src5, src6, src7;
2771  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[16]);
2772  v16i8 mask1;
2773  v16i8 vec0, vec1;
2774  v8i16 dst0, dst1, dst2, dst3;
2775  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
2776  v8i16 filter_vec;
2777  v4i32 weight_vec, offset_vec, rnd_vec;
2778 
2779  src0_ptr -= 1;
2780 
2781  filter_vec = LD_SH(filter);
2782  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
2783 
2784  offset = (offset0 + offset1) << rnd_val;
2785  weight0 = weight0 & 0x0000FFFF;
2786  weight = weight0 | (weight1 << 16);
2787  constant = 128 * weight1;
2788  constant <<= 6;
2789  offset += constant;
2790 
2791  offset_vec = __msa_fill_w(offset);
2792  weight_vec = __msa_fill_w(weight);
2793  rnd_vec = __msa_fill_w(rnd_val + 1);
2794 
2795  mask1 = mask0 + 2;
2796 
2797  for (loop_cnt = (height >> 3); loop_cnt--;) {
2798  LD_SB8(src0_ptr, src_stride,
2799  src0, src1, src2, src3, src4, src5, src6, src7);
2800  src0_ptr += (8 * src_stride);
2801  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
2802  src1_ptr += (4 * src2_stride);
2803  LD_SH4(src1_ptr, src2_stride, in4, in5, in6, in7);
2804  src1_ptr += (4 * src2_stride);
2805  ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
2806  ILVR_D2_SH(in5, in4, in7, in6, in2, in3);
2807  XORI_B8_128_SB(src0, src1, src2, src3, src4, src5, src6, src7);
2808 
2809  VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, vec0, vec1);
2810  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2811  VSHF_B2_SB(src2, src3, src2, src3, mask0, mask1, vec0, vec1);
2812  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2813  VSHF_B2_SB(src4, src5, src4, src5, mask0, mask1, vec0, vec1);
2814  dst2 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2815  VSHF_B2_SB(src6, src7, src6, src7, mask0, mask1, vec0, vec1);
2816  dst3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2817  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
2818  in0, in1, in2, in3,
2819  weight_vec, rnd_vec, offset_vec,
2820  dst0, dst1, dst2, dst3);
2821 
2822  PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
2823  ST_W8(dst0, dst1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
2824  dst += (8 * dst_stride);
2825  }
2826 }
2827 
2828 static void hevc_hz_biwgt_4t_4w_msa(const uint8_t *src0_ptr,
2829  int32_t src_stride,
2830  const int16_t *src1_ptr,
2831  int32_t src2_stride,
2832  uint8_t *dst,
2833  int32_t dst_stride,
2834  const int8_t *filter,
2835  int32_t height,
2836  int32_t weight0,
2837  int32_t weight1,
2838  int32_t offset0,
2839  int32_t offset1,
2840  int32_t rnd_val)
2841 {
2842  if (2 == height) {
2843  hevc_hz_biwgt_4t_4x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
2844  dst, dst_stride, filter,
2845  weight0, weight1, offset0, offset1, rnd_val);
2846  } else if (4 == height) {
2847  hevc_hz_biwgt_4t_4x4_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
2848  dst, dst_stride, filter,
2849  weight0, weight1, offset0, offset1, rnd_val);
2850  } else if (0 == (height % 8)) {
2851  hevc_hz_biwgt_4t_4x8multiple_msa(src0_ptr, src_stride,
2852  src1_ptr, src2_stride,
2853  dst, dst_stride, filter, height,
2854  weight0, weight1, offset0, offset1,
2855  rnd_val);
2856  }
2857 }
2858 
2859 static void hevc_hz_biwgt_4t_6w_msa(const uint8_t *src0_ptr,
2860  int32_t src_stride,
2861  const int16_t *src1_ptr,
2862  int32_t src2_stride,
2863  uint8_t *dst,
2864  int32_t dst_stride,
2865  const int8_t *filter,
2866  int32_t height,
2867  int32_t weight0,
2868  int32_t weight1,
2869  int32_t offset0,
2870  int32_t offset1,
2871  int32_t rnd_val)
2872 {
2873  uint32_t loop_cnt;
2874  int32_t offset, weight, constant;
2875  v8i16 filt0, filt1;
2876  v16i8 src0, src1, src2, src3;
2877  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
2878  v16i8 mask1;
2879  v16i8 vec0, vec1;
2880  v8i16 in0, in1, in2, in3;
2881  v8i16 dst0, dst1, dst2, dst3;
2882  v8i16 filter_vec;
2883  v4i32 weight_vec, offset_vec, rnd_vec;
2884 
2885  src0_ptr -= 1;
2886 
2887  filter_vec = LD_SH(filter);
2888  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
2889 
2890  offset = (offset0 + offset1) << rnd_val;
2891  weight0 = weight0 & 0x0000FFFF;
2892  weight = weight0 | (weight1 << 16);
2893  constant = 128 * weight1;
2894  constant <<= 6;
2895  offset += constant;
2896 
2897  offset_vec = __msa_fill_w(offset);
2898  weight_vec = __msa_fill_w(weight);
2899  rnd_vec = __msa_fill_w(rnd_val + 1);
2900 
2901  mask1 = mask0 + 2;
2902 
2903  for (loop_cnt = 2; loop_cnt--;) {
2904  LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
2905  src0_ptr += (4 * src_stride);
2906  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
2907  src1_ptr += (4 * src2_stride);
2908  XORI_B4_128_SB(src0, src1, src2, src3);
2909 
2910  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
2911  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2912  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec0, vec1);
2913  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2914  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec0, vec1);
2915  dst2 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2916  VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
2917  dst3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2918 
2919  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
2920  in0, in1, in2, in3,
2921  weight_vec, rnd_vec, offset_vec,
2922  dst0, dst1, dst2, dst3);
2923 
2924  PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
2925  ST_W2(dst0, 0, 2, dst, dst_stride);
2926  ST_H2(dst0, 2, 6, dst + 4, dst_stride);
2927  ST_W2(dst1, 0, 2, dst + 2 * dst_stride, dst_stride);
2928  ST_H2(dst1, 2, 6, dst + 2 * dst_stride + 4, dst_stride);
2929  dst += (4 * dst_stride);
2930  }
2931 }
2932 
2933 static void hevc_hz_biwgt_4t_8x2_msa(const uint8_t *src0_ptr,
2934  int32_t src_stride,
2935  const int16_t *src1_ptr,
2936  int32_t src2_stride,
2937  uint8_t *dst,
2938  int32_t dst_stride,
2939  const int8_t *filter,
2940  int32_t weight0,
2941  int32_t weight1,
2942  int32_t offset0,
2943  int32_t offset1,
2944  int32_t rnd_val)
2945 {
2946  int32_t offset, weight, constant;
2947  v8i16 filt0, filt1;
2948  v16i8 src0, src1;
2949  v8i16 in0, in1;
2950  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
2951  v16i8 mask1, vec0, vec1;
2952  v8i16 dst0, dst1;
2953  v8i16 filter_vec;
2954  v4i32 weight_vec, offset_vec, rnd_vec;
2955 
2956  src0_ptr -= 1;
2957 
2958  filter_vec = LD_SH(filter);
2959  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
2960 
2961  offset = (offset0 + offset1) << rnd_val;
2962  weight0 = weight0 & 0x0000FFFF;
2963  weight = weight0 | (weight1 << 16);
2964  constant = 128 * weight1;
2965  constant <<= 6;
2966  offset += constant;
2967 
2968  offset_vec = __msa_fill_w(offset);
2969  weight_vec = __msa_fill_w(weight);
2970  rnd_vec = __msa_fill_w(rnd_val + 1);
2971 
2972  mask1 = mask0 + 2;
2973 
2974  LD_SB2(src0_ptr, src_stride, src0, src1);
2975  LD_SH2(src1_ptr, src2_stride, in0, in1);
2977  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
2978  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2979  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec0, vec1);
2980  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
2981  HEVC_BIW_RND_CLIP2(dst0, dst1, in0, in1,
2982  weight_vec, rnd_vec, offset_vec,
2983  dst0, dst1);
2984 
2985  dst0 = (v8i16) __msa_pckev_b((v16i8) dst1, (v16i8) dst0);
2986  ST_D2(dst0, 0, 1, dst, dst_stride);
2987 }
2988 
2989 static void hevc_hz_biwgt_4t_8x6_msa(const uint8_t *src0_ptr,
2990  int32_t src_stride,
2991  const int16_t *src1_ptr,
2992  int32_t src2_stride,
2993  uint8_t *dst,
2994  int32_t dst_stride,
2995  const int8_t *filter,
2996  int32_t weight0,
2997  int32_t weight1,
2998  int32_t offset0,
2999  int32_t offset1,
3000  int32_t rnd_val)
3001 {
3002  int32_t weight, offset, constant;
3003  v8i16 filt0, filt1;
3004  v16i8 src0, src1, src2, src3, src4, src5;
3005  v8i16 in0, in1, in2, in3, in4, in5;
3006  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
3007  v16i8 mask1;
3008  v16i8 vec0, vec1;
3009  v8i16 dst0, dst1, dst2, dst3, dst4, dst5;
3010  v8i16 filter_vec;
3011  v4i32 weight_vec, offset_vec, rnd_vec;
3012 
3013  src0_ptr -= 1;
3014 
3015  filter_vec = LD_SH(filter);
3016  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3017 
3018  offset = (offset0 + offset1) << rnd_val;
3019  weight0 = weight0 & 0x0000FFFF;
3020  weight = weight0 | (weight1 << 16);
3021  constant = 128 * weight1;
3022  constant <<= 6;
3023  offset += constant;
3024 
3025  offset_vec = __msa_fill_w(offset);
3026  weight_vec = __msa_fill_w(weight);
3027  rnd_vec = __msa_fill_w(rnd_val + 1);
3028 
3029  mask1 = mask0 + 2;
3030 
3031  LD_SB6(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5);
3032 
3033  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
3034  src1_ptr += (4 * src2_stride);
3035  LD_SH2(src1_ptr, src2_stride, in4, in5);
3036  XORI_B6_128_SB(src0, src1, src2, src3, src4, src5);
3037  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
3038  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3039  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec0, vec1);
3040  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3041  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec0, vec1);
3042  dst2 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3043  VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
3044  dst3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3045  VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec0, vec1);
3046  dst4 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3047  VSHF_B2_SB(src5, src5, src5, src5, mask0, mask1, vec0, vec1);
3048  dst5 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3049  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
3050  in0, in1, in2, in3,
3051  weight_vec, rnd_vec, offset_vec,
3052  dst0, dst1, dst2, dst3);
3053  HEVC_BIW_RND_CLIP2(dst4, dst5, in4, in5,
3054  weight_vec, rnd_vec, offset_vec,
3055  dst4, dst5);
3056 
3057  PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
3058  dst3 = (v8i16) __msa_pckev_b((v16i8) dst5, (v16i8) dst4);
3059  ST_D4(dst0, dst1, 0, 1, 0, 1, dst, dst_stride);
3060  ST_D2(dst3, 0, 1, dst + 4 * dst_stride, dst_stride);
3061 }
3062 
3063 static void hevc_hz_biwgt_4t_8x4multiple_msa(const uint8_t *src0_ptr,
3064  int32_t src_stride,
3065  const int16_t *src1_ptr,
3066  int32_t src2_stride,
3067  uint8_t *dst,
3068  int32_t dst_stride,
3069  const int8_t *filter,
3070  int32_t height,
3071  int32_t weight0,
3072  int32_t weight1,
3073  int32_t offset0,
3074  int32_t offset1,
3075  int32_t rnd_val)
3076 {
3077  uint32_t loop_cnt;
3078  int32_t offset, weight, constant;
3079  v8i16 filt0, filt1;
3080  v16i8 src0, src1, src2, src3;
3081  v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
3082  v16i8 mask1;
3083  v16i8 vec0, vec1;
3084  v8i16 in0, in1, in2, in3;
3085  v8i16 dst0, dst1, dst2, dst3;
3086  v8i16 filter_vec;
3087  v4i32 weight_vec, offset_vec, rnd_vec;
3088 
3089  src0_ptr -= 1;
3090 
3091  filter_vec = LD_SH(filter);
3092  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3093 
3094  offset = (offset0 + offset1) << rnd_val;
3095  weight0 = weight0 & 0x0000FFFF;
3096  weight = weight0 | (weight1 << 16);
3097  constant = 128 * weight1;
3098  constant <<= 6;
3099  offset += constant;
3100 
3101  offset_vec = __msa_fill_w(offset);
3102  weight_vec = __msa_fill_w(weight);
3103  rnd_vec = __msa_fill_w(rnd_val + 1);
3104 
3105  mask1 = mask0 + 2;
3106 
3107  for (loop_cnt = (height >> 2); loop_cnt--;) {
3108  LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
3109  src0_ptr += (4 * src_stride);
3110  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
3111  src1_ptr += (4 * src2_stride);
3112  XORI_B4_128_SB(src0, src1, src2, src3);
3113 
3114  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
3115  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3116  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec0, vec1);
3117  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3118  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec0, vec1);
3119  dst2 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3120  VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
3121  dst3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3122  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
3123  in0, in1, in2, in3,
3124  weight_vec, rnd_vec, offset_vec,
3125  dst0, dst1, dst2, dst3);
3126 
3127  PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
3128  ST_D4(dst0, dst1, 0, 1, 0, 1, dst, dst_stride);
3129  dst += (4 * dst_stride);
3130  }
3131 }
3132 
3133 static void hevc_hz_biwgt_4t_8w_msa(const uint8_t *src0_ptr,
3134  int32_t src_stride,
3135  const int16_t *src1_ptr,
3136  int32_t src2_stride,
3137  uint8_t *dst,
3138  int32_t dst_stride,
3139  const int8_t *filter,
3140  int32_t height,
3141  int32_t weight0,
3142  int32_t weight1,
3143  int32_t offset0,
3144  int32_t offset1,
3145  int32_t rnd_val)
3146 {
3147  if (2 == height) {
3148  hevc_hz_biwgt_4t_8x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
3149  dst, dst_stride, filter,
3150  weight0, weight1, offset0, offset1, rnd_val);
3151  } else if (6 == height) {
3152  hevc_hz_biwgt_4t_8x6_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
3153  dst, dst_stride, filter,
3154  weight0, weight1, offset0, offset1, rnd_val);
3155  } else if (0 == (height % 4)) {
3156  hevc_hz_biwgt_4t_8x4multiple_msa(src0_ptr, src_stride,
3157  src1_ptr, src2_stride,
3158  dst, dst_stride, filter, height,
3159  weight0, weight1, offset0, offset1,
3160  rnd_val);
3161  }
3162 }
3163 
3164 static void hevc_hz_biwgt_4t_12w_msa(const uint8_t *src0_ptr,
3165  int32_t src_stride,
3166  const int16_t *src1_ptr,
3167  int32_t src2_stride,
3168  uint8_t *dst,
3169  int32_t dst_stride,
3170  const int8_t *filter,
3171  int32_t height,
3172  int32_t weight0,
3173  int32_t weight1,
3174  int32_t offset0,
3175  int32_t offset1,
3176  int32_t rnd_val)
3177 {
3178  uint32_t loop_cnt;
3179  int32_t offset, weight, constant;
3180  v8i16 filt0, filt1;
3181  v16i8 src0, src1, src2, src3;
3182  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
3183  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
3184  v16i8 mask2 = {
3185  8, 9, 9, 10, 10, 11, 11, 12, 24, 25, 25, 26, 26, 27, 27, 28
3186  };
3187  v16i8 mask1, mask3;
3188  v16i8 vec0, vec1;
3189  v8i16 dst0, dst1, dst2, dst3, dst4, dst5;
3190  v8i16 filter_vec;
3191  v4i32 weight_vec, offset_vec, rnd_vec;
3192 
3193  src0_ptr -= 1;
3194 
3195  filter_vec = LD_SH(filter);
3196  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3197 
3198  offset = (offset0 + offset1) << rnd_val;
3199  weight0 = weight0 & 0x0000FFFF;
3200  weight = weight0 | (weight1 << 16);
3201  constant = 128 * weight1;
3202  constant <<= 6;
3203  offset += constant;
3204 
3205  offset_vec = __msa_fill_w(offset);
3206  weight_vec = __msa_fill_w(weight);
3207  rnd_vec = __msa_fill_w(rnd_val + 1);
3208 
3209  mask1 = mask0 + 2;
3210  mask3 = mask2 + 2;
3211 
3212  for (loop_cnt = 4; loop_cnt--;) {
3213  LD_SB4(src0_ptr, src_stride, src0, src1, src2, src3);
3214  src0_ptr += (4 * src_stride);
3215  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
3216  LD_SH4(src1_ptr + 8, src2_stride, in4, in5, in6, in7);
3217  src1_ptr += (4 * src2_stride);
3218  ILVR_D2_SH(in5, in4, in7, in6, in4, in5);
3219  XORI_B4_128_SB(src0, src1, src2, src3);
3220 
3221  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
3222  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3223  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec0, vec1);
3224  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3225  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec0, vec1);
3226  dst2 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3227  VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
3228  dst3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3229  VSHF_B2_SB(src0, src1, src0, src1, mask2, mask3, vec0, vec1);
3230  dst4 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3231  VSHF_B2_SB(src2, src3, src2, src3, mask2, mask3, vec0, vec1);
3232  dst5 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3233 
3234  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
3235  in0, in1, in2, in3,
3236  weight_vec, rnd_vec, offset_vec,
3237  dst0, dst1, dst2, dst3);
3238  HEVC_BIW_RND_CLIP2(dst4, dst5, in4, in5,
3239  weight_vec, rnd_vec, offset_vec,
3240  dst4, dst5);
3241 
3242  PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
3243  dst3 = (v8i16) __msa_pckev_b((v16i8) dst5, (v16i8) dst4);
3244  ST_D4(dst0, dst1, 0, 1, 0, 1, dst, dst_stride);
3245  ST_W4(dst3, 0, 1, 2, 3, dst + 8, dst_stride);
3246  dst += (4 * dst_stride);
3247  }
3248 }
3249 
3250 static void hevc_hz_biwgt_4t_16w_msa(const uint8_t *src0_ptr,
3251  int32_t src_stride,
3252  const int16_t *src1_ptr,
3253  int32_t src2_stride,
3254  uint8_t *dst,
3255  int32_t dst_stride,
3256  const int8_t *filter,
3257  int32_t height,
3258  int32_t weight0,
3259  int32_t weight1,
3260  int32_t offset0,
3261  int32_t offset1,
3262  int32_t rnd_val)
3263 {
3264  uint32_t loop_cnt;
3265  int32_t offset, weight, constant;
3266  v16i8 src0, src1, src2, src3, src4, src5, src6, src7;
3267  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
3268  v8i16 filt0, filt1;
3269  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
3270  v16i8 mask1;
3271  v8i16 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
3272  v16i8 vec0, vec1;
3273  v8i16 filter_vec;
3274  v4i32 weight_vec, offset_vec, rnd_vec;
3275 
3276  src0_ptr -= 1;
3277 
3278  filter_vec = LD_SH(filter);
3279  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3280 
3281  offset = (offset0 + offset1) << rnd_val;
3282  weight0 = weight0 & 0x0000FFFF;
3283  weight = weight0 | (weight1 << 16);
3284  constant = 128 * weight1;
3285  constant <<= 6;
3286  offset += constant;
3287 
3288  offset_vec = __msa_fill_w(offset);
3289  weight_vec = __msa_fill_w(weight);
3290  rnd_vec = __msa_fill_w(rnd_val + 1);
3291 
3292  mask1 = mask0 + 2;
3293 
3294  for (loop_cnt = (height >> 2); loop_cnt--;) {
3295  LD_SB4(src0_ptr, src_stride, src0, src2, src4, src6);
3296  LD_SB4(src0_ptr + 8, src_stride, src1, src3, src5, src7);
3297  src0_ptr += (4 * src_stride);
3298  LD_SH4(src1_ptr, src2_stride, in0, in2, in4, in6);
3299  LD_SH4(src1_ptr + 8, src2_stride, in1, in3, in5, in7);
3300  src1_ptr += (4 * src2_stride);
3301  XORI_B8_128_SB(src0, src1, src2, src3, src4, src5, src6, src7);
3302 
3303  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
3304  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3305  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec0, vec1);
3306  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3307  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec0, vec1);
3308  dst2 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3309  VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
3310  dst3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3311  VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec0, vec1);
3312  dst4 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3313  VSHF_B2_SB(src5, src5, src5, src5, mask0, mask1, vec0, vec1);
3314  dst5 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3315  VSHF_B2_SB(src6, src6, src6, src6, mask0, mask1, vec0, vec1);
3316  dst6 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3317  VSHF_B2_SB(src7, src7, src7, src7, mask0, mask1, vec0, vec1);
3318  dst7 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3319  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
3320  in0, in1, in2, in3,
3321  weight_vec, rnd_vec, offset_vec,
3322  dst0, dst1, dst2, dst3);
3323 
3324  PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
3325  ST_SH2(dst0, dst1, dst, dst_stride);
3326  dst += (2 * dst_stride);
3327 
3328  HEVC_BIW_RND_CLIP4(dst4, dst5, dst6, dst7,
3329  in4, in5, in6, in7,
3330  weight_vec, rnd_vec, offset_vec,
3331  dst0, dst1, dst2, dst3);
3332 
3333  PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
3334  ST_SH2(dst0, dst1, dst, dst_stride);
3335  dst += (2 * dst_stride);
3336  }
3337 }
3338 
3339 static void hevc_hz_biwgt_4t_24w_msa(const uint8_t *src0_ptr,
3340  int32_t src_stride,
3341  const int16_t *src1_ptr,
3342  int32_t src2_stride,
3343  uint8_t *dst,
3344  int32_t dst_stride,
3345  const int8_t *filter,
3346  int32_t height,
3347  int32_t weight0,
3348  int32_t weight1,
3349  int32_t offset0,
3350  int32_t offset1,
3351  int32_t rnd_val)
3352 {
3353  uint32_t loop_cnt;
3354  int32_t offset, weight, constant;
3355  v16i8 src0, src1, src2, src3;
3356  v8i16 filt0, filt1;
3357  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
3358  v16i8 mask1, mask2, mask3;
3359  v16i8 vec0, vec1;
3360  v8i16 dst0, dst1, dst2, dst3;
3361  v8i16 in0, in1, in2, in3, in4, in5;
3362  v8i16 filter_vec;
3363  v4i32 weight_vec, offset_vec, rnd_vec;
3364 
3365  src0_ptr -= 1;
3366 
3367  filter_vec = LD_SH(filter);
3368  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3369 
3370  offset = (offset0 + offset1) << rnd_val;
3371  weight0 = weight0 & 0x0000FFFF;
3372  weight = weight0 | (weight1 << 16);
3373  constant = 128 * weight1;
3374  constant <<= 6;
3375  offset += constant;
3376 
3377  offset_vec = __msa_fill_w(offset);
3378  weight_vec = __msa_fill_w(weight);
3379  rnd_vec = __msa_fill_w(rnd_val + 1);
3380 
3381  mask1 = mask0 + 2;
3382  mask2 = mask0 + 8;
3383  mask3 = mask0 + 10;
3384 
3385  for (loop_cnt = 16; loop_cnt--;) {
3386  LD_SB2(src0_ptr, src_stride, src0, src2);
3387  LD_SB2(src0_ptr + 16, src_stride, src1, src3);
3388  src0_ptr += (2 * src_stride);
3389  LD_SH2(src1_ptr, src2_stride, in0, in2);
3390  LD_SH2(src1_ptr + 8, src2_stride, in1, in3);
3391  LD_SH2(src1_ptr + 16, src2_stride, in4, in5);
3392  src1_ptr += (2 * src2_stride);
3393  XORI_B4_128_SB(src0, src1, src2, src3);
3394 
3395  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
3396  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3397  VSHF_B2_SB(src0, src1, src0, src1, mask2, mask3, vec0, vec1);
3398  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3399  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec0, vec1);
3400  dst2 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3401  VSHF_B2_SB(src2, src3, src2, src3, mask2, mask3, vec0, vec1);
3402  dst3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3403  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
3404  in0, in1, in2, in3,
3405  weight_vec, rnd_vec, offset_vec,
3406  dst0, dst1, dst2, dst3);
3407 
3408  PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
3409  ST_SH2(dst0, dst1, dst, dst_stride);
3410 
3411  /* 8 width */
3412  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec0, vec1);
3413  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3414  VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
3415  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3416  HEVC_BIW_RND_CLIP2(dst0, dst1, in4, in5,
3417  weight_vec, rnd_vec, offset_vec,
3418  dst0, dst1);
3419 
3420  dst0 = (v8i16) __msa_pckev_b((v16i8) dst1, (v16i8) dst0);
3421  ST_D2(dst0, 0, 1, (dst + 16), dst_stride);
3422  dst += (2 * dst_stride);
3423  }
3424 }
3425 
3426 static void hevc_hz_biwgt_4t_32w_msa(const uint8_t *src0_ptr,
3427  int32_t src_stride,
3428  const int16_t *src1_ptr,
3429  int32_t src2_stride,
3430  uint8_t *dst,
3431  int32_t dst_stride,
3432  const int8_t *filter,
3433  int32_t height,
3434  int32_t weight0,
3435  int32_t weight1,
3436  int32_t offset0,
3437  int32_t offset1,
3438  int32_t rnd_val)
3439 {
3440  uint32_t loop_cnt;
3441  int32_t offset, weight, constant;
3442  v16i8 src0, src1, src2;
3443  v8i16 filt0, filt1;
3444  v16i8 mask0 = LD_SB(&ff_hevc_mask_arr[0]);
3445  v16i8 mask1, mask2, mask3;
3446  v8i16 dst0, dst1, dst2, dst3;
3447  v16i8 vec0, vec1;
3448  v8i16 in0, in1, in2, in3;
3449  v8i16 filter_vec;
3450  v4i32 weight_vec, offset_vec, rnd_vec;
3451 
3452  src0_ptr -= 1;
3453 
3454  filter_vec = LD_SH(filter);
3455  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3456 
3457  offset = (offset0 + offset1) << rnd_val;
3458  weight0 = weight0 & 0x0000FFFF;
3459  weight = weight0 | (weight1 << 16);
3460  constant = 128 * weight1;
3461  constant <<= 6;
3462  offset += constant;
3463 
3464  offset_vec = __msa_fill_w(offset);
3465  weight_vec = __msa_fill_w(weight);
3466  rnd_vec = __msa_fill_w(rnd_val + 1);
3467 
3468  mask1 = mask0 + 2;
3469  mask2 = mask0 + 8;
3470  mask3 = mask0 + 10;
3471 
3472  for (loop_cnt = height; loop_cnt--;) {
3473  LD_SB2(src0_ptr, 16, src0, src1);
3474  src2 = LD_SB(src0_ptr + 24);
3475  src0_ptr += src_stride;
3476  LD_SH4(src1_ptr, 8, in0, in1, in2, in3);
3477  src1_ptr += src2_stride;
3479 
3480  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
3481  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3482  VSHF_B2_SB(src0, src1, src0, src1, mask2, mask3, vec0, vec1);
3483  dst1 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3484  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec0, vec1);
3485  dst2 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3486  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec0, vec1);
3487  dst3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
3488  HEVC_BIW_RND_CLIP4(dst0, dst1, dst2, dst3,
3489  in0, in1, in2, in3,
3490  weight_vec, rnd_vec, offset_vec,
3491  dst0, dst1, dst2, dst3);
3492 
3493  PCKEV_B2_SH(dst1, dst0, dst3, dst2, dst0, dst1);
3494  ST_SH2(dst0, dst1, dst, 16);
3495  dst += dst_stride;
3496  }
3497 }
3498 
3499 static void hevc_vt_biwgt_4t_4x2_msa(const uint8_t *src0_ptr,
3500  int32_t src_stride,
3501  const int16_t *src1_ptr,
3502  int32_t src2_stride,
3503  uint8_t *dst,
3504  int32_t dst_stride,
3505  const int8_t *filter,
3506  int32_t weight0,
3507  int32_t weight1,
3508  int32_t offset0,
3509  int32_t offset1,
3510  int32_t rnd_val)
3511 {
3512  int32_t weight, offset, constant;
3513  v16i8 src0, src1, src2, src3, src4;
3514  v8i16 in0, in1, dst10;
3515  v16i8 src10_r, src32_r, src21_r, src43_r, src2110, src4332;
3516  v4i32 dst10_r, dst10_l;
3517  v8i16 filt0, filt1;
3518  v8i16 filter_vec, out;
3519  v4i32 weight_vec, offset_vec, rnd_vec;
3520 
3521  src0_ptr -= src_stride;
3522 
3523  offset = (offset0 + offset1) << rnd_val;
3524  weight0 = weight0 & 0x0000FFFF;
3525  weight = weight0 | (weight1 << 16);
3526  constant = 128 * weight1;
3527  constant <<= 6;
3528  offset += constant;
3529 
3530  offset_vec = __msa_fill_w(offset);
3531  weight_vec = __msa_fill_w(weight);
3532  rnd_vec = __msa_fill_w(rnd_val + 1);
3533 
3534  filter_vec = LD_SH(filter);
3535  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3536 
3537  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
3538  src0_ptr += (3 * src_stride);
3539  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
3540  src2110 = (v16i8) __msa_ilvr_d((v2i64) src21_r, (v2i64) src10_r);
3541  src2110 = (v16i8) __msa_xori_b((v16u8) src2110, 128);
3542  LD_SB2(src0_ptr, src_stride, src3, src4);
3543  src0_ptr += (2 * src_stride);
3544  LD_SH2(src1_ptr, src2_stride, in0, in1);
3545  src1_ptr += (2 * src2_stride);
3546 
3547  in0 = (v8i16) __msa_ilvr_d((v2i64) in1, (v2i64) in0);
3548  ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
3549  src4332 = (v16i8) __msa_ilvr_d((v2i64) src43_r, (v2i64) src32_r);
3550  src4332 = (v16i8) __msa_xori_b((v16u8) src4332, 128);
3551 
3552  dst10 = HEVC_FILT_4TAP_SH(src2110, src4332, filt0, filt1);
3553 
3554  ILVRL_H2_SW(dst10, in0, dst10_r, dst10_l);
3555  dst10_r = __msa_dpadd_s_w(offset_vec, (v8i16) dst10_r, (v8i16) weight_vec);
3556  dst10_l = __msa_dpadd_s_w(offset_vec, (v8i16) dst10_l, (v8i16) weight_vec);
3557  SRAR_W2_SW(dst10_r, dst10_l, rnd_vec);
3558  out = __msa_pckev_h((v8i16) dst10_l, (v8i16) dst10_r);
3559  CLIP_SH_0_255(out);
3560  out = (v8i16) __msa_pckev_b((v16i8) out, (v16i8) out);
3561  ST_W2(out, 0, 1, dst, dst_stride);
3562 }
3563 
3564 static void hevc_vt_biwgt_4t_4x4_msa(const uint8_t *src0_ptr,
3565  int32_t src_stride,
3566  const int16_t *src1_ptr,
3567  int32_t src2_stride,
3568  uint8_t *dst,
3569  int32_t dst_stride,
3570  const int8_t *filter,
3571  int32_t weight0,
3572  int32_t weight1,
3573  int32_t offset0,
3574  int32_t offset1,
3575  int32_t rnd_val)
3576 {
3577  int32_t weight, offset, constant;
3578  v16i8 src0, src1, src2, src3, src4, src5, src6;
3579  v8i16 in0, in1, in2, in3;
3580  v16i8 src10_r, src32_r, src54_r, src21_r, src43_r, src65_r;
3581  v16i8 src2110, src4332, src6554;
3582  v8i16 dst10, dst32;
3583  v8i16 filt0, filt1;
3584  v8i16 filter_vec;
3585  v4i32 weight_vec, offset_vec, rnd_vec;
3586 
3587  src0_ptr -= src_stride;
3588 
3589  offset = (offset0 + offset1) << rnd_val;
3590  weight0 = weight0 & 0x0000FFFF;
3591  weight = weight0 | (weight1 << 16);
3592  constant = 128 * weight1;
3593  constant <<= 6;
3594  offset += constant;
3595 
3596  offset_vec = __msa_fill_w(offset);
3597  weight_vec = __msa_fill_w(weight);
3598  rnd_vec = __msa_fill_w(rnd_val + 1);
3599 
3600  filter_vec = LD_SH(filter);
3601  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3602 
3603  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
3604  src0_ptr += (3 * src_stride);
3605  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
3606  src2110 = (v16i8) __msa_ilvr_d((v2i64) src21_r, (v2i64) src10_r);
3607  src2110 = (v16i8) __msa_xori_b((v16u8) src2110, 128);
3608 
3609  LD_SB4(src0_ptr, src_stride, src3, src4, src5, src6);
3610  src0_ptr += (4 * src_stride);
3611  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
3612  src1_ptr += (4 * src2_stride);
3613  ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
3614  ILVR_B4_SB(src3, src2, src4, src3, src5, src4, src6, src5,
3615  src32_r, src43_r, src54_r, src65_r);
3616  ILVR_D2_SB(src43_r, src32_r, src65_r, src54_r, src4332, src6554);
3617  XORI_B2_128_SB(src4332, src6554);
3618 
3619  dst10 = HEVC_FILT_4TAP_SH(src2110, src4332, filt0, filt1);
3620  dst32 = HEVC_FILT_4TAP_SH(src4332, src6554, filt0, filt1);
3621 
3622  HEVC_BIW_RND_CLIP2(dst10, dst32, in0, in1,
3623  weight_vec, rnd_vec, offset_vec,
3624  dst10, dst32);
3625 
3626  dst10 = (v8i16) __msa_pckev_b((v16i8) dst32, (v16i8) dst10);
3627  ST_W4(dst10, 0, 1, 2, 3, dst, dst_stride);
3628  dst += (4 * dst_stride);
3629 }
3630 
3631 static void hevc_vt_biwgt_4t_4x8multiple_msa(const uint8_t *src0_ptr,
3632  int32_t src_stride,
3633  const int16_t *src1_ptr,
3634  int32_t src2_stride,
3635  uint8_t *dst,
3636  int32_t dst_stride,
3637  const int8_t *filter,
3638  int32_t height,
3639  int32_t weight0,
3640  int32_t weight1,
3641  int32_t offset0,
3642  int32_t offset1,
3643  int32_t rnd_val)
3644 {
3645  uint32_t loop_cnt;
3646  int32_t weight, offset, constant;
3647  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9;
3648  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
3649  v16i8 src10_r, src32_r, src54_r, src76_r, src98_r;
3650  v16i8 src21_r, src43_r, src65_r, src87_r, src109_r;
3651  v16i8 src2110, src4332, src6554, src8776;
3652  v8i16 dst10, dst32, dst54, dst76;
3653  v8i16 filt0, filt1;
3654  v8i16 filter_vec;
3655  v4i32 weight_vec, offset_vec, rnd_vec;
3656 
3657  src0_ptr -= src_stride;
3658 
3659  offset = (offset0 + offset1) << rnd_val;
3660  weight0 = weight0 & 0x0000FFFF;
3661  weight = weight0 | (weight1 << 16);
3662  constant = 128 * weight1;
3663  constant <<= 6;
3664  offset += constant;
3665 
3666  offset_vec = __msa_fill_w(offset);
3667  weight_vec = __msa_fill_w(weight);
3668  rnd_vec = __msa_fill_w(rnd_val + 1);
3669 
3670  filter_vec = LD_SH(filter);
3671  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3672 
3673  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
3674  src0_ptr += (3 * src_stride);
3675  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
3676  src2110 = (v16i8) __msa_ilvr_d((v2i64) src21_r, (v2i64) src10_r);
3677  src2110 = (v16i8) __msa_xori_b((v16u8) src2110, 128);
3678 
3679  for (loop_cnt = (height >> 3); loop_cnt--;) {
3680  LD_SB6(src0_ptr, src_stride, src3, src4, src5, src6, src7, src8);
3681  src0_ptr += (6 * src_stride);
3682  LD_SH8(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5, in6, in7);
3683  src1_ptr += (8 * src2_stride);
3684 
3685  ILVR_D2_SH(in1, in0, in3, in2, in0, in1);
3686  ILVR_D2_SH(in5, in4, in7, in6, in2, in3);
3687 
3688  ILVR_B4_SB(src3, src2, src4, src3, src5, src4, src6, src5,
3689  src32_r, src43_r, src54_r, src65_r);
3690  ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
3691  ILVR_D3_SB(src43_r, src32_r, src65_r, src54_r, src87_r, src76_r,
3692  src4332, src6554, src8776);
3693  XORI_B3_128_SB(src4332, src6554, src8776);
3694 
3695  dst10 = HEVC_FILT_4TAP_SH(src2110, src4332, filt0, filt1);
3696  dst32 = HEVC_FILT_4TAP_SH(src4332, src6554, filt0, filt1);
3697  dst54 = HEVC_FILT_4TAP_SH(src6554, src8776, filt0, filt1);
3698 
3699  LD_SB2(src0_ptr, src_stride, src9, src2);
3700  src0_ptr += (2 * src_stride);
3701  ILVR_B2_SB(src9, src8, src2, src9, src98_r, src109_r);
3702  src2110 = (v16i8) __msa_ilvr_d((v2i64) src109_r, (v2i64) src98_r);
3703  src2110 = (v16i8) __msa_xori_b((v16u8) src2110, 128);
3704 
3705  dst76 = HEVC_FILT_4TAP_SH(src8776, src2110, filt0, filt1);
3706  HEVC_BIW_RND_CLIP4(dst10, dst32, dst54, dst76,
3707  in0, in1, in2, in3,
3708  weight_vec, rnd_vec, offset_vec,
3709  dst10, dst32, dst54, dst76);
3710 
3711  PCKEV_B2_SH(dst32, dst10, dst76, dst54, dst10, dst32);
3712  ST_W8(dst10, dst32, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
3713  dst += (8 * dst_stride);
3714  }
3715 }
3716 
3717 static void hevc_vt_biwgt_4t_4w_msa(const uint8_t *src0_ptr,
3718  int32_t src_stride,
3719  const int16_t *src1_ptr,
3720  int32_t src2_stride,
3721  uint8_t *dst,
3722  int32_t dst_stride,
3723  const int8_t *filter,
3724  int32_t height,
3725  int32_t weight0,
3726  int32_t weight1,
3727  int32_t offset0,
3728  int32_t offset1,
3729  int32_t rnd_val)
3730 {
3731  if (2 == height) {
3732  hevc_vt_biwgt_4t_4x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
3733  dst, dst_stride, filter,
3734  weight0, weight1, offset0, offset1, rnd_val);
3735  } else if (4 == height) {
3736  hevc_vt_biwgt_4t_4x4_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
3737  dst, dst_stride, filter,
3738  weight0, weight1, offset0, offset1, rnd_val);
3739  } else if (0 == (height % 8)) {
3740  hevc_vt_biwgt_4t_4x8multiple_msa(src0_ptr, src_stride,
3741  src1_ptr, src2_stride,
3742  dst, dst_stride, filter, height,
3743  weight0, weight1, offset0, offset1,
3744  rnd_val);
3745  }
3746 }
3747 
3748 static void hevc_vt_biwgt_4t_6w_msa(const uint8_t *src0_ptr,
3749  int32_t src_stride,
3750  const int16_t *src1_ptr,
3751  int32_t src2_stride,
3752  uint8_t *dst,
3753  int32_t dst_stride,
3754  const int8_t *filter,
3755  int32_t height,
3756  int32_t weight0,
3757  int32_t weight1,
3758  int32_t offset0,
3759  int32_t offset1,
3760  int32_t rnd_val)
3761 {
3762  uint32_t loop_cnt;
3763  int32_t offset, weight, constant;
3764  v16i8 src0, src1, src2, src3, src4;
3765  v8i16 in0, in1, in2, in3;
3766  v16i8 src10_r, src32_r, src21_r, src43_r;
3767  v8i16 tmp0, tmp1, tmp2, tmp3;
3768  v8i16 filt0, filt1;
3769  v8i16 filter_vec;
3770  v4i32 weight_vec, offset_vec, rnd_vec;
3771 
3772  src0_ptr -= src_stride;
3773 
3774  offset = (offset0 + offset1) << rnd_val;
3775  weight0 = weight0 & 0x0000FFFF;
3776  weight = weight0 | (weight1 << 16);
3777  constant = 128 * weight1;
3778  constant <<= 6;
3779  offset += constant;
3780 
3781  offset_vec = __msa_fill_w(offset);
3782  weight_vec = __msa_fill_w(weight);
3783  rnd_vec = __msa_fill_w(rnd_val + 1);
3784 
3785  filter_vec = LD_SH(filter);
3786  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3787 
3788  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
3789  src0_ptr += (3 * src_stride);
3791  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
3792 
3793  for (loop_cnt = (height >> 2); loop_cnt--;) {
3794  LD_SB2(src0_ptr, src_stride, src3, src4);
3795  src0_ptr += (2 * src_stride);
3796  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
3797  src1_ptr += (4 * src2_stride);
3798  XORI_B2_128_SB(src3, src4);
3799  ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
3800 
3801  tmp0 = HEVC_FILT_4TAP_SH(src10_r, src32_r, filt0, filt1);
3802  tmp1 = HEVC_FILT_4TAP_SH(src21_r, src43_r, filt0, filt1);
3803 
3804  LD_SB2(src0_ptr, src_stride, src1, src2);
3805  src0_ptr += (2 * src_stride);
3807  ILVR_B2_SB(src1, src4, src2, src1, src10_r, src21_r);
3808 
3809  tmp2 = HEVC_FILT_4TAP_SH(src32_r, src10_r, filt0, filt1);
3810  tmp3 = HEVC_FILT_4TAP_SH(src43_r, src21_r, filt0, filt1);
3811  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp2, tmp3,
3812  in0, in1, in2, in3,
3813  weight_vec, rnd_vec, offset_vec,
3814  tmp0, tmp1, tmp2, tmp3);
3815 
3816  PCKEV_B2_SH(tmp1, tmp0, tmp3, tmp2, tmp0, tmp1);
3817  ST_W2(tmp0, 0, 2, dst, dst_stride);
3818  ST_H2(tmp0, 2, 6, dst + 4, dst_stride);
3819  ST_W2(tmp1, 0, 2, dst + 2 * dst_stride, dst_stride);
3820  ST_H2(tmp1, 2, 6, dst + 2 * dst_stride + 4, dst_stride);
3821  dst += (4 * dst_stride);
3822  }
3823 }
3824 
3825 static void hevc_vt_biwgt_4t_8x2_msa(const uint8_t *src0_ptr,
3826  int32_t src_stride,
3827  const int16_t *src1_ptr,
3828  int32_t src2_stride,
3829  uint8_t *dst,
3830  int32_t dst_stride,
3831  const int8_t *filter,
3832  int32_t weight0,
3833  int32_t weight1,
3834  int32_t offset0,
3835  int32_t offset1,
3836  int32_t rnd_val)
3837 {
3838  int32_t offset, weight, constant;
3839  v16i8 src0, src1, src2, src3, src4;
3840  v8i16 in0, in1, tmp0, tmp1;
3841  v16i8 src10_r, src32_r, src21_r, src43_r;
3842  v8i16 filt0, filt1;
3843  v8i16 filter_vec;
3844  v4i32 weight_vec, offset_vec, rnd_vec;
3845 
3846  src0_ptr -= src_stride;
3847 
3848  offset = (offset0 + offset1) << rnd_val;
3849  weight0 = weight0 & 0x0000FFFF;
3850  weight = weight0 | (weight1 << 16);
3851  constant = 128 * weight1;
3852  constant <<= 6;
3853  offset += constant;
3854 
3855  offset_vec = __msa_fill_w(offset);
3856  weight_vec = __msa_fill_w(weight);
3857  rnd_vec = __msa_fill_w(rnd_val + 1);
3858 
3859  filter_vec = LD_SH(filter);
3860  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3861 
3862  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
3863  src0_ptr += (3 * src_stride);
3865  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
3866 
3867  LD_SB2(src0_ptr, src_stride, src3, src4);
3868  LD_SH2(src1_ptr, src2_stride, in0, in1);
3869  XORI_B2_128_SB(src3, src4);
3870  ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
3871 
3872  tmp0 = HEVC_FILT_4TAP_SH(src10_r, src32_r, filt0, filt1);
3873  tmp1 = HEVC_FILT_4TAP_SH(src21_r, src43_r, filt0, filt1);
3874  HEVC_BIW_RND_CLIP2(tmp0, tmp1, in0, in1,
3875  weight_vec, rnd_vec, offset_vec,
3876  tmp0, tmp1);
3877 
3878  tmp0 = (v8i16) __msa_pckev_b((v16i8) tmp1, (v16i8) tmp0);
3879  ST_D2(tmp0, 0, 1, dst, dst_stride);
3880 }
3881 
3882 static void hevc_vt_biwgt_4t_8x6_msa(const uint8_t *src0_ptr,
3883  int32_t src_stride,
3884  const int16_t *src1_ptr,
3885  int32_t src2_stride,
3886  uint8_t *dst,
3887  int32_t dst_stride,
3888  const int8_t *filter,
3889  int32_t weight0,
3890  int32_t weight1,
3891  int32_t offset0,
3892  int32_t offset1,
3893  int32_t rnd_val)
3894 {
3895  int32_t offset, weight, constant;
3896  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
3897  v8i16 in0, in1, in2, in3, in4, in5;
3898  v16i8 src10_r, src32_r, src54_r, src76_r;
3899  v16i8 src21_r, src43_r, src65_r, src87_r;
3900  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
3901  v8i16 filt0, filt1;
3902  v8i16 filter_vec;
3903  v4i32 weight_vec, offset_vec, rnd_vec;
3904 
3905  src0_ptr -= src_stride;
3906 
3907  offset = (offset0 + offset1) << rnd_val;
3908  weight0 = weight0 & 0x0000FFFF;
3909  weight = weight0 | (weight1 << 16);
3910  constant = 128 * weight1;
3911  constant <<= 6;
3912  offset += constant;
3913 
3914  offset_vec = __msa_fill_w(offset);
3915  weight_vec = __msa_fill_w(weight);
3916  rnd_vec = __msa_fill_w(rnd_val + 1);
3917 
3918  filter_vec = LD_SH(filter);
3919  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3920 
3921  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
3922  src0_ptr += (3 * src_stride);
3924  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
3925 
3926  LD_SB6(src0_ptr, src_stride, src3, src4, src5, src6, src7, src8);
3927  LD_SH6(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5);
3928  XORI_B6_128_SB(src3, src4, src5, src6, src7, src8);
3929  ILVR_B4_SB(src3, src2, src4, src3, src5, src4, src6, src5,
3930  src32_r, src43_r, src54_r, src65_r);
3931  ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
3932 
3933  tmp0 = HEVC_FILT_4TAP_SH(src10_r, src32_r, filt0, filt1);
3934  tmp1 = HEVC_FILT_4TAP_SH(src21_r, src43_r, filt0, filt1);
3935  tmp2 = HEVC_FILT_4TAP_SH(src32_r, src54_r, filt0, filt1);
3936  tmp3 = HEVC_FILT_4TAP_SH(src43_r, src65_r, filt0, filt1);
3937  tmp4 = HEVC_FILT_4TAP_SH(src54_r, src76_r, filt0, filt1);
3938  tmp5 = HEVC_FILT_4TAP_SH(src65_r, src87_r, filt0, filt1);
3939  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp2, tmp3,
3940  in0, in1, in2, in3,
3941  weight_vec, rnd_vec, offset_vec,
3942  tmp0, tmp1, tmp2, tmp3);
3943  HEVC_BIW_RND_CLIP2(tmp4, tmp5, in4, in5,
3944  weight_vec, rnd_vec, offset_vec,
3945  tmp4, tmp5);
3946 
3947  PCKEV_B2_SH(tmp1, tmp0, tmp3, tmp2, tmp0, tmp1);
3948  tmp3 = (v8i16) __msa_pckev_b((v16i8) tmp5, (v16i8) tmp4);
3949  ST_D4(tmp0, tmp1, 0, 1, 0, 1, dst, dst_stride);
3950  ST_D2(tmp3, 0, 1, dst + 4 * dst_stride, dst_stride);
3951 }
3952 
3953 static void hevc_vt_biwgt_4t_8x4multiple_msa(const uint8_t *src0_ptr,
3954  int32_t src_stride,
3955  const int16_t *src1_ptr,
3956  int32_t src2_stride,
3957  uint8_t *dst,
3958  int32_t dst_stride,
3959  const int8_t *filter,
3960  int32_t height,
3961  int32_t weight0,
3962  int32_t weight1,
3963  int32_t offset0,
3964  int32_t offset1,
3965  int32_t rnd_val)
3966 {
3967  uint32_t loop_cnt;
3968  int32_t offset, weight, constant;
3969  v16i8 src0, src1, src2, src3, src4;
3970  v8i16 in0, in1, in2, in3;
3971  v16i8 src10_r, src32_r, src21_r, src43_r;
3972  v8i16 tmp0, tmp1, tmp2, tmp3;
3973  v8i16 filt0, filt1;
3974  v8i16 filter_vec;
3975  v4i32 weight_vec, offset_vec, rnd_vec;
3976 
3977  src0_ptr -= src_stride;
3978 
3979  offset = (offset0 + offset1) << rnd_val;
3980  weight0 = weight0 & 0x0000FFFF;
3981  weight = weight0 | (weight1 << 16);
3982  constant = 128 * weight1;
3983  constant <<= 6;
3984  offset += constant;
3985 
3986  offset_vec = __msa_fill_w(offset);
3987  weight_vec = __msa_fill_w(weight);
3988  rnd_vec = __msa_fill_w(rnd_val + 1);
3989 
3990  filter_vec = LD_SH(filter);
3991  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
3992 
3993  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
3994  src0_ptr += (3 * src_stride);
3996  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
3997 
3998  for (loop_cnt = (height >> 2); loop_cnt--;) {
3999  LD_SB2(src0_ptr, src_stride, src3, src4);
4000  src0_ptr += (2 * src_stride);
4001  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
4002  src1_ptr += (4 * src2_stride);
4003  XORI_B2_128_SB(src3, src4);
4004  ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
4005 
4006  tmp0 = HEVC_FILT_4TAP_SH(src10_r, src32_r, filt0, filt1);
4007  tmp1 = HEVC_FILT_4TAP_SH(src21_r, src43_r, filt0, filt1);
4008 
4009  LD_SB2(src0_ptr, src_stride, src1, src2);
4010  src0_ptr += (2 * src_stride);
4012  ILVR_B2_SB(src1, src4, src2, src1, src10_r, src21_r);
4013 
4014  tmp2 = HEVC_FILT_4TAP_SH(src32_r, src10_r, filt0, filt1);
4015  tmp3 = HEVC_FILT_4TAP_SH(src43_r, src21_r, filt0, filt1);
4016  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp2, tmp3,
4017  in0, in1, in2, in3,
4018  weight_vec, rnd_vec, offset_vec,
4019  tmp0, tmp1, tmp2, tmp3);
4020 
4021  PCKEV_B2_SH(tmp1, tmp0, tmp3, tmp2, tmp0, tmp1);
4022  ST_D4(tmp0, tmp1, 0, 1, 0, 1, dst, dst_stride);
4023  dst += (4 * dst_stride);
4024  }
4025 }
4026 
4027 static void hevc_vt_biwgt_4t_8w_msa(const uint8_t *src0_ptr,
4028  int32_t src_stride,
4029  const int16_t *src1_ptr,
4030  int32_t src2_stride,
4031  uint8_t *dst,
4032  int32_t dst_stride,
4033  const int8_t *filter,
4034  int32_t height,
4035  int32_t weight0,
4036  int32_t weight1,
4037  int32_t offset0,
4038  int32_t offset1,
4039  int32_t rnd_val)
4040 {
4041  if (2 == height) {
4042  hevc_vt_biwgt_4t_8x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
4043  dst, dst_stride, filter,
4044  weight0, weight1, offset0, offset1, rnd_val);
4045  } else if (6 == height) {
4046  hevc_vt_biwgt_4t_8x6_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
4047  dst, dst_stride, filter,
4048  weight0, weight1, offset0, offset1, rnd_val);
4049  } else {
4050  hevc_vt_biwgt_4t_8x4multiple_msa(src0_ptr, src_stride,
4051  src1_ptr, src2_stride,
4052  dst, dst_stride, filter, height,
4053  weight0, weight1, offset0, offset1,
4054  rnd_val);
4055  }
4056 }
4057 
4058 static void hevc_vt_biwgt_4t_12w_msa(const uint8_t *src0_ptr,
4059  int32_t src_stride,
4060  const int16_t *src1_ptr,
4061  int32_t src2_stride,
4062  uint8_t *dst,
4063  int32_t dst_stride,
4064  const int8_t *filter,
4065  int32_t height,
4066  int32_t weight0,
4067  int32_t weight1,
4068  int32_t offset0,
4069  int32_t offset1,
4070  int32_t rnd_val)
4071 {
4072  uint32_t loop_cnt;
4073  int32_t offset, weight, constant;
4074  v16i8 src0, src1, src2, src3, src4, src5;
4075  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
4076  v16i8 src10_r, src32_r, src21_r, src43_r;
4077  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
4078  v16i8 src10_l, src32_l, src54_l, src21_l, src43_l, src65_l;
4079  v16i8 src2110, src4332;
4080  v8i16 filt0, filt1;
4081  v8i16 filter_vec;
4082  v4i32 weight_vec, offset_vec, rnd_vec;
4083 
4084  src0_ptr -= (1 * src_stride);
4085 
4086  offset = (offset0 + offset1) << rnd_val;
4087  weight0 = weight0 & 0x0000FFFF;
4088  weight = weight0 | (weight1 << 16);
4089  constant = 128 * weight1;
4090  constant <<= 6;
4091  offset += constant;
4092 
4093  offset_vec = __msa_fill_w(offset);
4094  weight_vec = __msa_fill_w(weight);
4095  rnd_vec = __msa_fill_w(rnd_val + 1);
4096 
4097  filter_vec = LD_SH(filter);
4098  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
4099 
4100  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
4101  src0_ptr += (3 * src_stride);
4103  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
4104  ILVL_B2_SB(src1, src0, src2, src1, src10_l, src21_l);
4105  src2110 = (v16i8) __msa_ilvr_d((v2i64) src21_l, (v2i64) src10_l);
4106 
4107  for (loop_cnt = (height >> 2); loop_cnt--;) {
4108  LD_SB2(src0_ptr, src_stride, src3, src4);
4109  src0_ptr += (2 * src_stride);
4110  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
4111  LD_SH4(src1_ptr + 8, src2_stride, in4, in5, in6, in7);
4112  src1_ptr += (4 * src2_stride);
4113  ILVR_D2_SH(in5, in4, in7, in6, in4, in5);
4114  XORI_B2_128_SB(src3, src4);
4115 
4116  ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
4117  ILVL_B2_SB(src3, src2, src4, src3, src32_l, src43_l);
4118  src4332 = (v16i8) __msa_ilvr_d((v2i64) src43_l, (v2i64) src32_l);
4119 
4120  tmp0 = HEVC_FILT_4TAP_SH(src10_r, src32_r, filt0, filt1);
4121  tmp1 = HEVC_FILT_4TAP_SH(src21_r, src43_r, filt0, filt1);
4122  tmp4 = HEVC_FILT_4TAP_SH(src2110, src4332, filt0, filt1);
4123 
4124  LD_SB2(src0_ptr, src_stride, src5, src2);
4125  src0_ptr += (2 * src_stride);
4126  XORI_B2_128_SB(src5, src2);
4127  ILVR_B2_SB(src5, src4, src2, src5, src10_r, src21_r);
4128  ILVL_B2_SB(src5, src4, src2, src5, src54_l, src65_l);
4129  src2110 = (v16i8) __msa_ilvr_d((v2i64) src65_l, (v2i64) src54_l);
4130 
4131  tmp2 = HEVC_FILT_4TAP_SH(src32_r, src10_r, filt0, filt1);
4132  tmp3 = HEVC_FILT_4TAP_SH(src43_r, src21_r, filt0, filt1);
4133  tmp5 = HEVC_FILT_4TAP_SH(src4332, src2110, filt0, filt1);
4134  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp2, tmp3,
4135  in0, in1, in2, in3,
4136  weight_vec, rnd_vec, offset_vec,
4137  tmp0, tmp1, tmp2, tmp3);
4138  HEVC_BIW_RND_CLIP2(tmp4, tmp5, in4, in5,
4139  weight_vec, rnd_vec, offset_vec,
4140  tmp4, tmp5);
4141 
4142  PCKEV_B2_SH(tmp1, tmp0, tmp3, tmp2, tmp0, tmp1);
4143  tmp2 = (v8i16) __msa_pckev_b((v16i8) tmp5, (v16i8) tmp4);
4144  ST_D4(tmp0, tmp1, 0, 1, 0, 1, dst, dst_stride);
4145  ST_W4(tmp2, 0, 1, 2, 3, dst + 8, dst_stride);
4146  dst += (4 * dst_stride);
4147  }
4148 }
4149 
4150 static void hevc_vt_biwgt_4t_16w_msa(const uint8_t *src0_ptr,
4151  int32_t src_stride,
4152  const int16_t *src1_ptr,
4153  int32_t src2_stride,
4154  uint8_t *dst,
4155  int32_t dst_stride,
4156  const int8_t *filter,
4157  int32_t height,
4158  int32_t weight0,
4159  int32_t weight1,
4160  int32_t offset0,
4161  int32_t offset1,
4162  int32_t rnd_val)
4163 {
4164  uint32_t loop_cnt;
4165  int32_t offset, weight, constant;
4166  v16i8 src0, src1, src2, src3, src4, src5;
4167  v8i16 in0, in1, in2, in3;
4168  v16i8 src10_r, src32_r, src21_r, src43_r;
4169  v16i8 src10_l, src32_l, src21_l, src43_l;
4170  v8i16 tmp0, tmp1, tmp2, tmp3;
4171  v8i16 filt0, filt1;
4172  v8i16 filter_vec;
4173  v4i32 weight_vec, offset_vec, rnd_vec;
4174 
4175  src0_ptr -= src_stride;
4176 
4177  offset = (offset0 + offset1) << rnd_val;
4178  weight0 = weight0 & 0x0000FFFF;
4179  weight = weight0 | (weight1 << 16);
4180  constant = 128 * weight1;
4181  constant <<= 6;
4182  offset += constant;
4183 
4184  offset_vec = __msa_fill_w(offset);
4185  weight_vec = __msa_fill_w(weight);
4186  rnd_vec = __msa_fill_w(rnd_val + 1);
4187 
4188  filter_vec = LD_SH(filter);
4189  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
4190 
4191  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
4192  src0_ptr += (3 * src_stride);
4194  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
4195  ILVL_B2_SB(src1, src0, src2, src1, src10_l, src21_l);
4196 
4197  for (loop_cnt = (height >> 2); loop_cnt--;) {
4198  LD_SB2(src0_ptr, src_stride, src3, src4);
4199  src0_ptr += (2 * src_stride);
4200  LD_SH2(src1_ptr, src2_stride, in0, in1);
4201  LD_SH2(src1_ptr + 8, src2_stride, in2, in3);
4202  src1_ptr += (2 * src2_stride);
4203  XORI_B2_128_SB(src3, src4);
4204  ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
4205  ILVL_B2_SB(src3, src2, src4, src3, src32_l, src43_l);
4206 
4207  tmp0 = HEVC_FILT_4TAP_SH(src10_r, src32_r, filt0, filt1);
4208  tmp1 = HEVC_FILT_4TAP_SH(src21_r, src43_r, filt0, filt1);
4209  tmp2 = HEVC_FILT_4TAP_SH(src10_l, src32_l, filt0, filt1);
4210  tmp3 = HEVC_FILT_4TAP_SH(src21_l, src43_l, filt0, filt1);
4211 
4212  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp2, tmp3,
4213  in0, in1, in2, in3,
4214  weight_vec, rnd_vec, offset_vec,
4215  tmp0, tmp1, tmp2, tmp3);
4216  PCKEV_B2_SH(tmp2, tmp0, tmp3, tmp1, tmp0, tmp1);
4217  ST_SH2(tmp0, tmp1, dst, dst_stride);
4218  dst += (2 * dst_stride);
4219  LD_SB2(src0_ptr, src_stride, src5, src2);
4220  src0_ptr += (2 * src_stride);
4221 
4222  LD_SH2(src1_ptr, src2_stride, in0, in1);
4223  LD_SH2(src1_ptr + 8, src2_stride, in2, in3);
4224  src1_ptr += (2 * src2_stride);
4225  XORI_B2_128_SB(src5, src2);
4226  ILVR_B2_SB(src5, src4, src2, src5, src10_r, src21_r);
4227  ILVL_B2_SB(src5, src4, src2, src5, src10_l, src21_l);
4228 
4229  tmp0 = HEVC_FILT_4TAP_SH(src32_r, src10_r, filt0, filt1);
4230  tmp1 = HEVC_FILT_4TAP_SH(src43_r, src21_r, filt0, filt1);
4231  tmp2 = HEVC_FILT_4TAP_SH(src32_l, src10_l, filt0, filt1);
4232  tmp3 = HEVC_FILT_4TAP_SH(src43_l, src21_l, filt0, filt1);
4233  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp2, tmp3,
4234  in0, in1, in2, in3,
4235  weight_vec, rnd_vec, offset_vec,
4236  tmp0, tmp1, tmp2, tmp3);
4237 
4238  PCKEV_B2_SH(tmp2, tmp0, tmp3, tmp1, tmp0, tmp1);
4239  ST_SH2(tmp0, tmp1, dst, dst_stride);
4240  dst += (2 * dst_stride);
4241  }
4242 }
4243 
4244 static void hevc_vt_biwgt_4t_24w_msa(const uint8_t *src0_ptr,
4245  int32_t src_stride,
4246  const int16_t *src1_ptr,
4247  int32_t src2_stride,
4248  uint8_t *dst,
4249  int32_t dst_stride,
4250  const int8_t *filter,
4251  int32_t height,
4252  int32_t weight0,
4253  int32_t weight1,
4254  int32_t offset0,
4255  int32_t offset1,
4256  int32_t rnd_val)
4257 {
4258  uint32_t loop_cnt;
4259  int32_t offset, weight, constant;
4260  v16i8 src0, src1, src2, src3, src4, src5;
4261  v16i8 src6, src7, src8, src9, src10, src11;
4262  v8i16 in0, in1, in2, in3, in4, in5;
4263  v16i8 src10_r, src32_r, src76_r, src98_r;
4264  v16i8 src10_l, src32_l, src21_l, src43_l;
4265  v16i8 src21_r, src43_r, src87_r, src109_r;
4266  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
4267  v8i16 filt0, filt1;
4268  v8i16 filter_vec;
4269  v4i32 weight_vec, offset_vec, rnd_vec;
4270 
4271  src0_ptr -= src_stride;
4272 
4273  offset = (offset0 + offset1) << rnd_val;
4274  weight0 = weight0 & 0x0000FFFF;
4275  weight = weight0 | (weight1 << 16);
4276  constant = 128 * weight1;
4277  constant <<= 6;
4278  offset += constant;
4279 
4280  offset_vec = __msa_fill_w(offset);
4281  weight_vec = __msa_fill_w(weight);
4282  rnd_vec = __msa_fill_w(rnd_val + 1);
4283 
4284  filter_vec = LD_SH(filter);
4285  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
4286 
4287  /* 16width */
4288  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
4290  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
4291  ILVL_B2_SB(src1, src0, src2, src1, src10_l, src21_l);
4292  /* 8width */
4293  LD_SB3(src0_ptr + 16, src_stride, src6, src7, src8);
4294  src0_ptr += (3 * src_stride);
4295  XORI_B3_128_SB(src6, src7, src8);
4296  ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
4297 
4298  for (loop_cnt = (height >> 2); loop_cnt--;) {
4299  /* 16width */
4300  LD_SB2(src0_ptr, src_stride, src3, src4);
4301  LD_SH2(src1_ptr, src2_stride, in0, in1);
4302  LD_SH2(src1_ptr + 8, src2_stride, in2, in3);
4303  XORI_B2_128_SB(src3, src4);
4304  ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
4305  ILVL_B2_SB(src3, src2, src4, src3, src32_l, src43_l);
4306 
4307  /* 8width */
4308  LD_SB2(src0_ptr + 16, src_stride, src9, src10);
4309  src0_ptr += (2 * src_stride);
4310  LD_SH2(src1_ptr + 16, src2_stride, in4, in5);
4311  src1_ptr += (2 * src2_stride);
4312  XORI_B2_128_SB(src9, src10);
4313  ILVR_B2_SB(src9, src8, src10, src9, src98_r, src109_r);
4314  /* 16width */
4315  tmp0 = HEVC_FILT_4TAP_SH(src10_r, src32_r, filt0, filt1);
4316  tmp4 = HEVC_FILT_4TAP_SH(src10_l, src32_l, filt0, filt1);
4317  tmp1 = HEVC_FILT_4TAP_SH(src21_r, src43_r, filt0, filt1);
4318  tmp5 = HEVC_FILT_4TAP_SH(src21_l, src43_l, filt0, filt1);
4319  /* 8width */
4320  tmp2 = HEVC_FILT_4TAP_SH(src76_r, src98_r, filt0, filt1);
4321  tmp3 = HEVC_FILT_4TAP_SH(src87_r, src109_r, filt0, filt1);
4322  /* 16width */
4323  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp4, tmp5,
4324  in0, in1, in2, in3,
4325  weight_vec, rnd_vec, offset_vec,
4326  tmp0, tmp1, tmp4, tmp5);
4327  /* 8width */
4328  HEVC_BIW_RND_CLIP2(tmp2, tmp3, in4, in5,
4329  weight_vec, rnd_vec, offset_vec,
4330  tmp2, tmp3);
4331  /* 16width */
4332  PCKEV_B2_SH(tmp4, tmp0, tmp5, tmp1, tmp0, tmp1);
4333  /* 8width */
4334  tmp2 = (v8i16) __msa_pckev_b((v16i8) tmp3, (v16i8) tmp2);
4335  ST_SH2(tmp0, tmp1, dst, dst_stride);
4336  ST_D2(tmp2, 0, 1, dst + 16, dst_stride);
4337  dst += (2 * dst_stride);
4338 
4339  /* 16width */
4340  LD_SB2(src0_ptr, src_stride, src5, src2);
4341  LD_SH2(src1_ptr, src2_stride, in0, in1);
4342  LD_SH2(src1_ptr + 8, src2_stride, in2, in3);
4343  XORI_B2_128_SB(src5, src2);
4344  ILVR_B2_SB(src5, src4, src2, src5, src10_r, src21_r);
4345  ILVL_B2_SB(src5, src4, src2, src5, src10_l, src21_l);
4346  /* 8width */
4347  LD_SB2(src0_ptr + 16, src_stride, src11, src8);
4348  src0_ptr += (2 * src_stride);
4349  LD_SH2(src1_ptr + 16, src2_stride, in4, in5);
4350  src1_ptr += (2 * src2_stride);
4351  XORI_B2_128_SB(src11, src8);
4352  ILVR_B2_SB(src11, src10, src8, src11, src76_r, src87_r);
4353  /* 16width */
4354  tmp0 = HEVC_FILT_4TAP_SH(src32_r, src10_r, filt0, filt1);
4355  tmp4 = HEVC_FILT_4TAP_SH(src32_l, src10_l, filt0, filt1);
4356  tmp1 = HEVC_FILT_4TAP_SH(src43_r, src21_r, filt0, filt1);
4357  tmp5 = HEVC_FILT_4TAP_SH(src43_l, src21_l, filt0, filt1);
4358  /* 8width */
4359  tmp2 = HEVC_FILT_4TAP_SH(src98_r, src76_r, filt0, filt1);
4360  tmp3 = HEVC_FILT_4TAP_SH(src109_r, src87_r, filt0, filt1);
4361  /* 16width */
4362  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp4, tmp5,
4363  in0, in1, in2, in3,
4364  weight_vec, rnd_vec, offset_vec,
4365  tmp0, tmp1, tmp4, tmp5);
4366  /* 8width */
4367  HEVC_BIW_RND_CLIP2(tmp2, tmp3, in4, in5,
4368  weight_vec, rnd_vec, offset_vec,
4369  tmp2, tmp3);
4370  /* 16width */
4371  PCKEV_B2_SH(tmp4, tmp0, tmp5, tmp1, tmp0, tmp1);
4372 
4373  /* 8width */
4374  tmp2 = (v8i16) __msa_pckev_b((v16i8) tmp3, (v16i8) tmp2);
4375  ST_SH2(tmp0, tmp1, dst, dst_stride);
4376  ST_D2(tmp2, 0, 1, dst + 16, dst_stride);
4377  dst += (2 * dst_stride);
4378  }
4379 }
4380 
4381 static void hevc_vt_biwgt_4t_32w_msa(const uint8_t *src0_ptr,
4382  int32_t src_stride,
4383  const int16_t *src1_ptr,
4384  int32_t src2_stride,
4385  uint8_t *dst,
4386  int32_t dst_stride,
4387  const int8_t *filter,
4388  int32_t height,
4389  int32_t weight0,
4390  int32_t weight1,
4391  int32_t offset0,
4392  int32_t offset1,
4393  int32_t rnd_val)
4394 {
4395  uint32_t loop_cnt;
4396  uint8_t *dst_tmp = dst + 16;
4397  int32_t offset, weight, constant;
4398  v16i8 src0, src1, src2, src3, src4, src6, src7, src8, src9, src10;
4399  v8i16 in0, in1, in2, in3, in4, in5, in6, in7;
4400  v16i8 src10_r, src32_r, src76_r, src98_r;
4401  v16i8 src21_r, src43_r, src87_r, src109_r;
4402  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
4403  v16i8 src10_l, src32_l, src76_l, src98_l;
4404  v16i8 src21_l, src43_l, src87_l, src109_l;
4405  v8i16 filt0, filt1;
4406  v8i16 filter_vec;
4407  v4i32 weight_vec, offset_vec, rnd_vec;
4408 
4409  src0_ptr -= src_stride;
4410 
4411  offset = (offset0 + offset1) << rnd_val;
4412  weight0 = weight0 & 0x0000FFFF;
4413  weight = weight0 | (weight1 << 16);
4414  constant = 128 * weight1;
4415  constant <<= 6;
4416  offset += constant;
4417 
4418  offset_vec = __msa_fill_w(offset);
4419  weight_vec = __msa_fill_w(weight);
4420  rnd_vec = __msa_fill_w(rnd_val + 1);
4421 
4422  filter_vec = LD_SH(filter);
4423  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
4424 
4425  /* 16width */
4426  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
4428  ILVR_B2_SB(src1, src0, src2, src1, src10_r, src21_r);
4429  ILVL_B2_SB(src1, src0, src2, src1, src10_l, src21_l);
4430  /* next 16width */
4431  LD_SB3(src0_ptr + 16, src_stride, src6, src7, src8);
4432  src0_ptr += (3 * src_stride);
4433  XORI_B3_128_SB(src6, src7, src8);
4434  ILVR_B2_SB(src7, src6, src8, src7, src76_r, src87_r);
4435  ILVL_B2_SB(src7, src6, src8, src7, src76_l, src87_l);
4436 
4437  for (loop_cnt = (height >> 1); loop_cnt--;) {
4438  /* 16width */
4439  LD_SB2(src0_ptr, src_stride, src3, src4);
4440  LD_SH2(src1_ptr, src2_stride, in0, in1);
4441  LD_SH2(src1_ptr + 8, src2_stride, in2, in3);
4442  XORI_B2_128_SB(src3, src4);
4443  ILVR_B2_SB(src3, src2, src4, src3, src32_r, src43_r);
4444  ILVL_B2_SB(src3, src2, src4, src3, src32_l, src43_l);
4445 
4446  /* 16width */
4447  tmp0 = HEVC_FILT_4TAP_SH(src10_r, src32_r, filt0, filt1);
4448  tmp4 = HEVC_FILT_4TAP_SH(src10_l, src32_l, filt0, filt1);
4449  tmp1 = HEVC_FILT_4TAP_SH(src21_r, src43_r, filt0, filt1);
4450  tmp5 = HEVC_FILT_4TAP_SH(src21_l, src43_l, filt0, filt1);
4451  /* 16width */
4452  HEVC_BIW_RND_CLIP4(tmp0, tmp1, tmp4, tmp5,
4453  in0, in1, in2, in3,
4454  weight_vec, rnd_vec, offset_vec,
4455  tmp0, tmp1, tmp4, tmp5);
4456  /* 16width */
4457  PCKEV_B2_SH(tmp4, tmp0, tmp5, tmp1, tmp0, tmp1);
4458  ST_SH2(tmp0, tmp1, dst, dst_stride);
4459  dst += (2 * dst_stride);
4460 
4461  src10_r = src32_r;
4462  src21_r = src43_r;
4463  src10_l = src32_l;
4464  src21_l = src43_l;
4465  src2 = src4;
4466 
4467  /* next 16width */
4468  LD_SB2(src0_ptr + 16, src_stride, src9, src10);
4469  src0_ptr += (2 * src_stride);
4470  LD_SH2(src1_ptr + 16, src2_stride, in4, in5);
4471  LD_SH2(src1_ptr + 24, src2_stride, in6, in7);
4472  src1_ptr += (2 * src2_stride);
4473  XORI_B2_128_SB(src9, src10);
4474  ILVR_B2_SB(src9, src8, src10, src9, src98_r, src109_r);
4475  ILVL_B2_SB(src9, src8, src10, src9, src98_l, src109_l);
4476  /* next 16width */
4477  tmp2 = HEVC_FILT_4TAP_SH(src76_r, src98_r, filt0, filt1);
4478  tmp6 = HEVC_FILT_4TAP_SH(src76_l, src98_l, filt0, filt1);
4479  tmp3 = HEVC_FILT_4TAP_SH(src87_r, src109_r, filt0, filt1);
4480  tmp7 = HEVC_FILT_4TAP_SH(src87_l, src109_l, filt0, filt1);
4481  /* next 16width */
4482  HEVC_BIW_RND_CLIP4(tmp2, tmp3, tmp6, tmp7,
4483  in4, in5, in6, in7,
4484  weight_vec, rnd_vec, offset_vec,
4485  tmp2, tmp3, tmp6, tmp7);
4486 
4487  /* next 16width */
4488  PCKEV_B2_SH(tmp6, tmp2, tmp7, tmp3, tmp2, tmp3);
4489  ST_SH2(tmp2, tmp3, dst_tmp, dst_stride);
4490  dst_tmp += (2 * dst_stride);
4491 
4492  src76_r = src98_r;
4493  src87_r = src109_r;
4494  src76_l = src98_l;
4495  src87_l = src109_l;
4496  src8 = src10;
4497  }
4498 }
4499 
4500 static void hevc_hv_biwgt_4t_4x2_msa(const uint8_t *src0_ptr,
4501  int32_t src_stride,
4502  const int16_t *src1_ptr,
4503  int32_t src2_stride,
4504  uint8_t *dst,
4505  int32_t dst_stride,
4506  const int8_t *filter_x,
4507  const int8_t *filter_y,
4508  int32_t weight0,
4509  int32_t weight1,
4510  int32_t offset0,
4511  int32_t offset1,
4512  int32_t rnd_val)
4513 {
4514  uint64_t tp0, tp1;
4516  v8i16 in0 = { 0 };
4517  v16u8 out;
4518  v16i8 src0, src1, src2, src3, src4;
4519  v8i16 filt0, filt1;
4520  v8i16 filt_h0, filt_h1;
4521  v16i8 mask0 = LD_SB(ff_hevc_mask_arr + 16);
4522  v16i8 mask1;
4523  v8i16 filter_vec, tmp, weight_vec;
4524  v16i8 vec0, vec1, vec2, vec3, vec4, vec5;
4525  v8i16 dst20, dst31, dst42, dst10, dst32, dst21, dst43, tmp0, tmp1;
4526  v4i32 dst0, dst1, offset_vec, rnd_vec, const_vec;
4527 
4528  src0_ptr -= (src_stride + 1);
4529 
4530  filter_vec = LD_SH(filter_x);
4531  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
4532 
4533  filter_vec = LD_SH(filter_y);
4534  UNPCK_R_SB_SH(filter_vec, filter_vec);
4535 
4536  SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
4537 
4538  mask1 = mask0 + 2;
4539 
4540  offset = (offset0 + offset1) << rnd_val;
4541  weight0 = weight0 & 0x0000FFFF;
4542  weight = weight0 | (weight1 << 16);
4543 
4544  const_vec = __msa_fill_w((128 * weight1));
4545  const_vec <<= 6;
4546  offset_vec = __msa_fill_w(offset);
4547  weight_vec = (v8i16) __msa_fill_w(weight);
4548  rnd_vec = __msa_fill_w(rnd_val + 1);
4549  offset_vec += const_vec;
4550 
4551  LD_SB5(src0_ptr, src_stride, src0, src1, src2, src3, src4);
4552  XORI_B5_128_SB(src0, src1, src2, src3, src4);
4553 
4554  VSHF_B2_SB(src0, src2, src0, src2, mask0, mask1, vec0, vec1);
4555  VSHF_B2_SB(src1, src3, src1, src3, mask0, mask1, vec2, vec3);
4556  VSHF_B2_SB(src2, src4, src2, src4, mask0, mask1, vec4, vec5);
4557 
4558  dst20 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
4559  dst31 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
4560  dst42 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
4561 
4562  ILVRL_H2_SH(dst31, dst20, dst10, dst32);
4563  ILVRL_H2_SH(dst42, dst31, dst21, dst43);
4564 
4565  dst0 = HEVC_FILT_4TAP(dst10, dst32, filt_h0, filt_h1);
4566  dst1 = HEVC_FILT_4TAP(dst21, dst43, filt_h0, filt_h1);
4567  dst0 >>= 6;
4568  dst1 >>= 6;
4569  dst0 = (v4i32) __msa_pckev_h((v8i16) dst1, (v8i16) dst0);
4570 
4571  LD2(src1_ptr, src2_stride, tp0, tp1);
4572  INSERT_D2_SH(tp0, tp1, in0);
4573 
4574  ILVRL_H2_SH(dst0, in0, tmp0, tmp1);
4575  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
4576  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
4577  SRAR_W2_SW(dst0, dst1, rnd_vec);
4578  tmp = __msa_pckev_h((v8i16) dst1, (v8i16) dst0);
4579  CLIP_SH_0_255(tmp);
4580  out = (v16u8) __msa_pckev_b((v16i8) tmp, (v16i8) tmp);
4581  ST_W2(out, 0, 1, dst, dst_stride);
4582 }
4583 
4584 static void hevc_hv_biwgt_4t_4x4_msa(const uint8_t *src0_ptr,
4585  int32_t src_stride,
4586  const int16_t *src1_ptr,
4587  int32_t src2_stride,
4588  uint8_t *dst,
4589  int32_t dst_stride,
4590  const int8_t *filter_x,
4591  const int8_t *filter_y,
4592  int32_t weight0,
4593  int32_t weight1,
4594  int32_t offset0,
4595  int32_t offset1,
4596  int32_t rnd_val)
4597 {
4598  uint64_t tp0, tp1;
4600  v16u8 out;
4601  v8i16 in0 = { 0 }, in1 = { 0 };
4602  v16i8 src0, src1, src2, src3, src4, src5, src6;
4603  v8i16 filt0, filt1;
4604  v8i16 filt_h0, filt_h1;
4605  v16i8 mask0 = LD_SB(ff_hevc_mask_arr + 16);
4606  v16i8 mask1;
4607  v8i16 filter_vec, weight_vec;
4608  v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
4609  v8i16 tmp0, tmp1, tmp2, tmp3;
4610  v8i16 dst30, dst41, dst52, dst63;
4611  v8i16 dst10, dst32, dst54, dst21, dst43, dst65;
4612  v4i32 offset_vec, rnd_vec, const_vec;
4613  v4i32 dst0, dst1, dst2, dst3;
4614 
4615  src0_ptr -= (src_stride + 1);
4616 
4617  filter_vec = LD_SH(filter_x);
4618  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
4619 
4620  filter_vec = LD_SH(filter_y);
4621  UNPCK_R_SB_SH(filter_vec, filter_vec);
4622 
4623  SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
4624 
4625  mask1 = mask0 + 2;
4626 
4627  offset = (offset0 + offset1) << rnd_val;
4628  weight0 = weight0 & 0x0000FFFF;
4629  weight = weight0 | (weight1 << 16);
4630 
4631  const_vec = __msa_fill_w((128 * weight1));
4632  const_vec <<= 6;
4633  offset_vec = __msa_fill_w(offset);
4634  weight_vec = (v8i16) __msa_fill_w(weight);
4635  rnd_vec = __msa_fill_w(rnd_val + 1);
4636  offset_vec += const_vec;
4637 
4638  LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
4639  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
4640 
4641  VSHF_B2_SB(src0, src3, src0, src3, mask0, mask1, vec0, vec1);
4642  VSHF_B2_SB(src1, src4, src1, src4, mask0, mask1, vec2, vec3);
4643  VSHF_B2_SB(src2, src5, src2, src5, mask0, mask1, vec4, vec5);
4644  VSHF_B2_SB(src3, src6, src3, src6, mask0, mask1, vec6, vec7);
4645 
4646  dst30 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
4647  dst41 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
4648  dst52 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
4649  dst63 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
4650 
4651  ILVRL_H2_SH(dst41, dst30, dst10, dst43);
4652  ILVRL_H2_SH(dst52, dst41, dst21, dst54);
4653  ILVRL_H2_SH(dst63, dst52, dst32, dst65);
4654  dst0 = HEVC_FILT_4TAP(dst10, dst32, filt_h0, filt_h1);
4655  dst1 = HEVC_FILT_4TAP(dst21, dst43, filt_h0, filt_h1);
4656  dst2 = HEVC_FILT_4TAP(dst32, dst54, filt_h0, filt_h1);
4657  dst3 = HEVC_FILT_4TAP(dst43, dst65, filt_h0, filt_h1);
4658  SRA_4V(dst0, dst1, dst2, dst3, 6);
4659  PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp1, tmp3);
4660 
4661  LD2(src1_ptr, src2_stride, tp0, tp1);
4662  INSERT_D2_SH(tp0, tp1, in0);
4663  src1_ptr += (2 * src2_stride);
4664  LD2(src1_ptr, src2_stride, tp0, tp1);
4665  INSERT_D2_SH(tp0, tp1, in1);
4666 
4667  ILVRL_H2_SH(tmp1, in0, tmp0, tmp1);
4668  ILVRL_H2_SH(tmp3, in1, tmp2, tmp3);
4669 
4670  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
4671  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
4672  dst2 = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
4673  dst3 = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
4674  SRAR_W4_SW(dst0, dst1, dst2, dst3, rnd_vec);
4675  PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp0, tmp1);
4676  CLIP_SH2_0_255(tmp0, tmp1);
4677  out = (v16u8) __msa_pckev_b((v16i8) tmp1, (v16i8) tmp0);
4678  ST_W4(out, 0, 1, 2, 3, dst, dst_stride);
4679 }
4680 
4681 static void hevc_hv_biwgt_4t_4multx8mult_msa(const uint8_t *src0_ptr,
4682  int32_t src_stride,
4683  const int16_t *src1_ptr,
4684  int32_t src2_stride,
4685  uint8_t *dst,
4686  int32_t dst_stride,
4687  const int8_t *filter_x,
4688  const int8_t *filter_y,
4689  int32_t height,
4690  int32_t weight0,
4691  int32_t weight1,
4692  int32_t offset0,
4693  int32_t offset1,
4694  int32_t rnd_val)
4695 {
4696  uint32_t loop_cnt;
4697  uint64_t tp0, tp1;
4699  v16u8 out0, out1;
4700  v8i16 in0 = { 0 }, in1 = { 0 }, in2 = { 0 }, in3 = { 0 };
4701  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
4702  v8i16 filt0, filt1;
4703  v8i16 filt_h0, filt_h1;
4704  v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
4705  v16i8 mask0 = LD_SB(ff_hevc_mask_arr + 16);
4706  v16i8 mask1;
4707  v8i16 filter_vec, weight_vec;
4708  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
4709  v8i16 dst10, dst21, dst22, dst73, dst84, dst95, dst106;
4710  v8i16 dst10_r, dst32_r, dst54_r, dst76_r;
4711  v8i16 dst21_r, dst43_r, dst65_r, dst87_r;
4712  v8i16 dst98_r, dst109_r;
4713  v4i32 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
4714  v4i32 offset_vec, rnd_vec, const_vec;
4715 
4716  src0_ptr -= (src_stride + 1);
4717 
4718  filter_vec = LD_SH(filter_x);
4719  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
4720 
4721  filter_vec = LD_SH(filter_y);
4722  UNPCK_R_SB_SH(filter_vec, filter_vec);
4723 
4724  SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
4725 
4726  mask1 = mask0 + 2;
4727 
4728  offset = (offset0 + offset1) << rnd_val;
4729  weight0 = weight0 & 0x0000FFFF;
4730  weight = weight0 | (weight1 << 16);
4731 
4732  const_vec = __msa_fill_w((128 * weight1));
4733  const_vec <<= 6;
4734  offset_vec = __msa_fill_w(offset);
4735  weight_vec = (v8i16) __msa_fill_w(weight);
4736  rnd_vec = __msa_fill_w(rnd_val + 1);
4737  offset_vec += const_vec;
4738 
4739  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
4740  src0_ptr += (3 * src_stride);
4742 
4743  VSHF_B2_SB(src0, src1, src0, src1, mask0, mask1, vec0, vec1);
4744  VSHF_B2_SB(src1, src2, src1, src2, mask0, mask1, vec2, vec3);
4745  dst10 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
4746  dst21 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
4747  ILVRL_H2_SH(dst21, dst10, dst10_r, dst21_r);
4748  dst22 = (v8i16) __msa_splati_d((v2i64) dst21, 1);
4749 
4750  for (loop_cnt = height >> 3; loop_cnt--;) {
4751  LD_SB8(src0_ptr, src_stride,
4752  src3, src4, src5, src6, src7, src8, src9, src10);
4753  src0_ptr += (8 * src_stride);
4754  XORI_B8_128_SB(src3, src4, src5, src6, src7, src8, src9, src10);
4755  VSHF_B2_SB(src3, src7, src3, src7, mask0, mask1, vec0, vec1);
4756  VSHF_B2_SB(src4, src8, src4, src8, mask0, mask1, vec2, vec3);
4757  VSHF_B2_SB(src5, src9, src5, src9, mask0, mask1, vec4, vec5);
4758  VSHF_B2_SB(src6, src10, src6, src10, mask0, mask1, vec6, vec7);
4759 
4760  dst73 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
4761  dst84 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
4762  dst95 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
4763  dst106 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
4764 
4765  dst32_r = __msa_ilvr_h(dst73, dst22);
4766  ILVRL_H2_SH(dst84, dst73, dst43_r, dst87_r);
4767  ILVRL_H2_SH(dst95, dst84, dst54_r, dst98_r);
4768  ILVRL_H2_SH(dst106, dst95, dst65_r, dst109_r);
4769  dst22 = (v8i16) __msa_splati_d((v2i64) dst73, 1);
4770  dst76_r = __msa_ilvr_h(dst22, dst106);
4771 
4772  LD2(src1_ptr, src2_stride, tp0, tp1);
4773  src1_ptr += 2 * src2_stride;
4774  INSERT_D2_SH(tp0, tp1, in0);
4775  LD2(src1_ptr, src2_stride, tp0, tp1);
4776  src1_ptr += 2 * src2_stride;
4777  INSERT_D2_SH(tp0, tp1, in1);
4778 
4779  LD2(src1_ptr, src2_stride, tp0, tp1);
4780  src1_ptr += 2 * src2_stride;
4781  INSERT_D2_SH(tp0, tp1, in2);
4782  LD2(src1_ptr, src2_stride, tp0, tp1);
4783  src1_ptr += 2 * src2_stride;
4784  INSERT_D2_SH(tp0, tp1, in3);
4785 
4786  dst0 = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
4787  dst1 = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
4788  dst2 = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
4789  dst3 = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
4790  dst4 = HEVC_FILT_4TAP(dst54_r, dst76_r, filt_h0, filt_h1);
4791  dst5 = HEVC_FILT_4TAP(dst65_r, dst87_r, filt_h0, filt_h1);
4792  dst6 = HEVC_FILT_4TAP(dst76_r, dst98_r, filt_h0, filt_h1);
4793  dst7 = HEVC_FILT_4TAP(dst87_r, dst109_r, filt_h0, filt_h1);
4794  SRA_4V(dst0, dst1, dst2, dst3, 6);
4795  SRA_4V(dst4, dst5, dst6, dst7, 6);
4796  PCKEV_H4_SW(dst1, dst0, dst3, dst2, dst5, dst4, dst7, dst6, dst0, dst1,
4797  dst2, dst3);
4798  ILVRL_H2_SH(dst0, in0, tmp0, tmp1);
4799  ILVRL_H2_SH(dst1, in1, tmp2, tmp3);
4800  ILVRL_H2_SH(dst2, in2, tmp4, tmp5);
4801  ILVRL_H2_SH(dst3, in3, tmp6, tmp7);
4802  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
4803  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
4804  dst2 = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
4805  dst3 = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
4806  dst4 = __msa_dpadd_s_w(offset_vec, tmp4, weight_vec);
4807  dst5 = __msa_dpadd_s_w(offset_vec, tmp5, weight_vec);
4808  dst6 = __msa_dpadd_s_w(offset_vec, tmp6, weight_vec);
4809  dst7 = __msa_dpadd_s_w(offset_vec, tmp7, weight_vec);
4810  SRAR_W4_SW(dst0, dst1, dst2, dst3, rnd_vec);
4811  SRAR_W4_SW(dst4, dst5, dst6, dst7, rnd_vec);
4812  PCKEV_H4_SH(dst1, dst0, dst3, dst2, dst5, dst4, dst7, dst6, tmp0, tmp1,
4813  tmp2, tmp3);
4814  CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
4815  PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
4816  ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
4817  dst += (8 * dst_stride);
4818 
4819  dst10_r = dst98_r;
4820  dst21_r = dst109_r;
4821  dst22 = (v8i16) __msa_splati_d((v2i64) dst106, 1);
4822  }
4823 }
4824 
4825 static void hevc_hv_biwgt_4t_4w_msa(const uint8_t *src0_ptr,
4826  int32_t src_stride,
4827  const int16_t *src1_ptr,
4828  int32_t src2_stride,
4829  uint8_t *dst,
4830  int32_t dst_stride,
4831  const int8_t *filter_x,
4832  const int8_t *filter_y,
4833  int32_t height,
4834  int32_t weight0,
4835  int32_t weight1,
4836  int32_t offset0,
4837  int32_t offset1,
4838  int32_t rnd_val)
4839 {
4840  if (2 == height) {
4841  hevc_hv_biwgt_4t_4x2_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
4842  dst, dst_stride, filter_x, filter_y,
4843  weight0, weight1, offset0, offset1, rnd_val);
4844  } else if (4 == height) {
4845  hevc_hv_biwgt_4t_4x4_msa(src0_ptr, src_stride, src1_ptr, src2_stride,
4846  dst, dst_stride, filter_x, filter_y,
4847  weight0, weight1, offset0, offset1, rnd_val);
4848  } else if (0 == (height % 8)) {
4849  hevc_hv_biwgt_4t_4multx8mult_msa(src0_ptr, src_stride,
4850  src1_ptr, src2_stride,
4851  dst, dst_stride, filter_x, filter_y,
4852  height, weight0, weight1,
4853  offset0, offset1, rnd_val);
4854  }
4855 }
4856 
4857 static void hevc_hv_biwgt_4t_6w_msa(const uint8_t *src0_ptr,
4858  int32_t src_stride,
4859  const int16_t *src1_ptr,
4860  int32_t src2_stride,
4861  uint8_t *dst,
4862  int32_t dst_stride,
4863  const int8_t *filter_x,
4864  const int8_t *filter_y,
4865  int32_t height,
4866  int32_t weight0,
4867  int32_t weight1,
4868  int32_t offset0,
4869  int32_t offset1,
4870  int32_t rnd_val)
4871 {
4872  uint32_t tpw0, tpw1, tpw2, tpw3;
4873  uint64_t tp0, tp1;
4875  v16u8 out0, out1, out2;
4876  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
4877  v8i16 in0 = { 0 }, in1 = { 0 }, in2 = { 0 }, in3 = { 0 };
4878  v8i16 in4 = { 0 }, in5 = { 0 };
4879  v8i16 filt0, filt1;
4880  v8i16 filt_h0, filt_h1, filter_vec;
4881  v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
4882  v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
4883  v16i8 mask1;
4884  v8i16 dsth0, dsth1, dsth2, dsth3, dsth4, dsth5, dsth6, dsth7, dsth8, dsth9;
4885  v8i16 dsth10, tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, weight_vec;
4886  v8i16 dst10_r, dst32_r, dst54_r, dst76_r, dst98_r, dst21_r, dst43_r;
4887  v8i16 dst65_r, dst87_r, dst109_r, dst10_l, dst32_l, dst54_l, dst76_l;
4888  v8i16 dst98_l, dst21_l, dst43_l, dst65_l, dst87_l, dst109_l;
4889  v8i16 dst1021_l, dst3243_l, dst5465_l, dst7687_l, dst98109_l;
4890  v4i32 dst0_r, dst0_l, dst1_r, dst1_l, dst2_r, dst2_l, dst3_r, dst3_l;
4891  v4i32 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
4892  v4i32 dst4_r, dst5_r, dst6_r, dst7_r;
4893  v4i32 offset_vec, rnd_vec, const_vec;
4894 
4895  src0_ptr -= (src_stride + 1);
4896 
4897  filter_vec = LD_SH(filter_x);
4898  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
4899 
4900  filter_vec = LD_SH(filter_y);
4901  UNPCK_R_SB_SH(filter_vec, filter_vec);
4902 
4903  SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
4904 
4905  mask1 = mask0 + 2;
4906 
4907  offset = (offset0 + offset1) << rnd_val;
4908  weight0 = weight0 & 0x0000FFFF;
4909  weight = weight0 | (weight1 << 16);
4910 
4911  const_vec = __msa_fill_w((128 * weight1));
4912  const_vec <<= 6;
4913  offset_vec = __msa_fill_w(offset);
4914  weight_vec = (v8i16) __msa_fill_w(weight);
4915  rnd_vec = __msa_fill_w(rnd_val + 1);
4916  offset_vec += const_vec;
4917 
4918  LD_SB3(src0_ptr, src_stride, src0, src1, src2);
4919  src0_ptr += (3 * src_stride);
4921 
4922  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
4923  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec2, vec3);
4924  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec4, vec5);
4925  dsth0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
4926  dsth1 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
4927  dsth2 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
4928 
4929  ILVRL_H2_SH(dsth1, dsth0, dst10_r, dst10_l);
4930  ILVRL_H2_SH(dsth2, dsth1, dst21_r, dst21_l);
4931 
4932  LD_SB8(src0_ptr, src_stride, src3, src4, src5, src6, src7, src8, src9,
4933  src10);
4934  XORI_B8_128_SB(src3, src4, src5, src6, src7, src8, src9, src10);
4935 
4936  VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
4937  VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec2, vec3);
4938  VSHF_B2_SB(src5, src5, src5, src5, mask0, mask1, vec4, vec5);
4939  VSHF_B2_SB(src6, src6, src6, src6, mask0, mask1, vec6, vec7);
4940 
4941  dsth3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
4942  dsth4 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
4943  dsth5 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
4944  dsth6 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
4945 
4946  VSHF_B2_SB(src7, src7, src7, src7, mask0, mask1, vec0, vec1);
4947  VSHF_B2_SB(src8, src8, src8, src8, mask0, mask1, vec2, vec3);
4948  VSHF_B2_SB(src9, src9, src9, src9, mask0, mask1, vec4, vec5);
4949  VSHF_B2_SB(src10, src10, src10, src10, mask0, mask1, vec6, vec7);
4950 
4951  dsth7 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
4952  dsth8 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
4953  dsth9 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
4954  dsth10 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
4955 
4956  ILVRL_H2_SH(dsth3, dsth2, dst32_r, dst32_l);
4957  ILVRL_H2_SH(dsth4, dsth3, dst43_r, dst43_l);
4958  ILVRL_H2_SH(dsth5, dsth4, dst54_r, dst54_l);
4959  ILVRL_H2_SH(dsth6, dsth5, dst65_r, dst65_l);
4960  ILVRL_H2_SH(dsth7, dsth6, dst76_r, dst76_l);
4961  ILVRL_H2_SH(dsth8, dsth7, dst87_r, dst87_l);
4962  ILVRL_H2_SH(dsth9, dsth8, dst98_r, dst98_l);
4963  ILVRL_H2_SH(dsth10, dsth9, dst109_r, dst109_l);
4964  PCKEV_D2_SH(dst21_l, dst10_l, dst43_l, dst32_l, dst1021_l, dst3243_l);
4965  PCKEV_D2_SH(dst65_l, dst54_l, dst87_l, dst76_l, dst5465_l, dst7687_l);
4966  dst98109_l = (v8i16) __msa_pckev_d((v2i64) dst109_l, (v2i64) dst98_l);
4967 
4968  dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
4969  dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
4970  dst2_r = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
4971  dst3_r = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
4972  dst4_r = HEVC_FILT_4TAP(dst54_r, dst76_r, filt_h0, filt_h1);
4973  dst5_r = HEVC_FILT_4TAP(dst65_r, dst87_r, filt_h0, filt_h1);
4974  dst6_r = HEVC_FILT_4TAP(dst76_r, dst98_r, filt_h0, filt_h1);
4975  dst7_r = HEVC_FILT_4TAP(dst87_r, dst109_r, filt_h0, filt_h1);
4976  dst0_l = HEVC_FILT_4TAP(dst1021_l, dst3243_l, filt_h0, filt_h1);
4977  dst1_l = HEVC_FILT_4TAP(dst3243_l, dst5465_l, filt_h0, filt_h1);
4978  dst2_l = HEVC_FILT_4TAP(dst5465_l, dst7687_l, filt_h0, filt_h1);
4979  dst3_l = HEVC_FILT_4TAP(dst7687_l, dst98109_l, filt_h0, filt_h1);
4980  SRA_4V(dst0_r, dst1_r, dst2_r, dst3_r, 6);
4981  SRA_4V(dst4_r, dst5_r, dst6_r, dst7_r, 6);
4982  SRA_4V(dst0_l, dst1_l, dst2_l, dst3_l, 6);
4983  PCKEV_H2_SW(dst1_r, dst0_r, dst3_r, dst2_r, dst0, dst1);
4984  PCKEV_H2_SW(dst5_r, dst4_r, dst7_r, dst6_r, dst2, dst3);
4985 
4986  LD2(src1_ptr, src2_stride, tp0, tp1);
4987  INSERT_D2_SH(tp0, tp1, in0);
4988  LD2(src1_ptr + 2 * src2_stride, src2_stride, tp0, tp1);
4989  INSERT_D2_SH(tp0, tp1, in1);
4990 
4991  LD2(src1_ptr + 4 * src2_stride, src2_stride, tp0, tp1);
4992  INSERT_D2_SH(tp0, tp1, in2);
4993  LD2(src1_ptr + 6 * src2_stride, src2_stride, tp0, tp1);
4994  INSERT_D2_SH(tp0, tp1, in3);
4995 
4996  ILVRL_H2_SH(dst0, in0, tmp0, tmp1);
4997  ILVRL_H2_SH(dst1, in1, tmp2, tmp3);
4998  ILVRL_H2_SH(dst2, in2, tmp4, tmp5);
4999  ILVRL_H2_SH(dst3, in3, tmp6, tmp7);
5000  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
5001  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
5002  dst2 = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
5003  dst3 = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
5004  dst4 = __msa_dpadd_s_w(offset_vec, tmp4, weight_vec);
5005  dst5 = __msa_dpadd_s_w(offset_vec, tmp5, weight_vec);
5006  dst6 = __msa_dpadd_s_w(offset_vec, tmp6, weight_vec);
5007  dst7 = __msa_dpadd_s_w(offset_vec, tmp7, weight_vec);
5008  SRAR_W4_SW(dst0, dst1, dst2, dst3, rnd_vec);
5009  SRAR_W4_SW(dst4, dst5, dst6, dst7, rnd_vec);
5010  PCKEV_H4_SH(dst1, dst0, dst3, dst2, dst5, dst4, dst7, dst6, tmp0, tmp1,
5011  tmp2, tmp3);
5012  CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
5013  PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
5014  ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, dst_stride);
5015 
5016  PCKEV_H2_SW(dst1_l, dst0_l, dst3_l, dst2_l, dst4, dst5);
5017 
5018  LW4(src1_ptr + 4, src2_stride, tpw0, tpw1, tpw2, tpw3);
5019  src1_ptr += (4 * src2_stride);
5020  INSERT_W4_SH(tpw0, tpw1, tpw2, tpw3, in4);
5021  LW4(src1_ptr + 4, src2_stride, tpw0, tpw1, tpw2, tpw3);
5022  INSERT_W4_SH(tpw0, tpw1, tpw2, tpw3, in5);
5023 
5024  ILVRL_H2_SH(dst4, in4, tmp0, tmp1);
5025  ILVRL_H2_SH(dst5, in5, tmp2, tmp3);
5026 
5027  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
5028  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
5029  dst2 = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
5030  dst3 = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
5031  SRAR_W4_SW(dst0, dst1, dst2, dst3, rnd_vec);
5032  PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp4, tmp5);
5033 
5034  CLIP_SH2_0_255(tmp4, tmp5);
5035  out2 = (v16u8) __msa_pckev_b((v16i8) tmp5, (v16i8) tmp4);
5036  ST_H8(out2, 0, 1, 2, 3, 4, 5, 6, 7, dst + 4, dst_stride);
5037 }
5038 
5039 static void hevc_hv_biwgt_4t_8x2_msa(const uint8_t *src0_ptr,
5040  int32_t src_stride,
5041  const int16_t *src1_ptr,
5042  int32_t src2_stride,
5043  uint8_t *dst,
5044  int32_t dst_stride,
5045  const int8_t *filter_x,
5046  const int8_t *filter_y,
5047  int32_t weight0,
5048  int32_t weight1,
5049  int32_t offset0,
5050  int32_t offset1,
5051  int32_t rnd_val)
5052 {
5054  v16u8 out;
5055  v16i8 src0, src1, src2, src3, src4;
5056  v8i16 filt0, filt1;
5057  v8i16 filt_h0, filt_h1;
5058  v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
5059  v16i8 mask1;
5060  v8i16 filter_vec, weight_vec;
5061  v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9;
5062  v8i16 dst0, dst1, dst2, dst3, dst4;
5063  v8i16 in0, in1;
5064  v4i32 dst0_r, dst0_l, dst1_r, dst1_l;
5065  v8i16 dst10_r, dst32_r, dst21_r, dst43_r;
5066  v8i16 dst10_l, dst32_l, dst21_l, dst43_l;
5067  v8i16 tmp0, tmp1, tmp2, tmp3;
5068  v4i32 offset_vec, rnd_vec, const_vec;
5069 
5070  src0_ptr -= (src_stride + 1);
5071 
5072  filter_vec = LD_SH(filter_x);
5073  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
5074 
5075  filter_vec = LD_SH(filter_y);
5076  UNPCK_R_SB_SH(filter_vec, filter_vec);
5077 
5078  SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
5079 
5080  mask1 = mask0 + 2;
5081 
5082  offset = (offset0 + offset1) << rnd_val;
5083  weight0 = weight0 & 0x0000FFFF;
5084  weight = weight0 | (weight1 << 16);
5085 
5086  const_vec = __msa_fill_w((128 * weight1));
5087  const_vec <<= 6;
5088  offset_vec = __msa_fill_w(offset);
5089  weight_vec = (v8i16) __msa_fill_w(weight);
5090  rnd_vec = __msa_fill_w(rnd_val + 1);
5091  offset_vec += const_vec;
5092 
5093  LD_SB5(src0_ptr, src_stride, src0, src1, src2, src3, src4);
5094  XORI_B5_128_SB(src0, src1, src2, src3, src4);
5095 
5096  LD_SH2(src1_ptr, src2_stride, in0, in1);
5097 
5098  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
5099  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec2, vec3);
5100  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec4, vec5);
5101  VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec6, vec7);
5102  VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec8, vec9);
5103 
5104  dst0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
5105  dst1 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
5106  dst2 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
5107  dst3 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
5108  dst4 = HEVC_FILT_4TAP_SH(vec8, vec9, filt0, filt1);
5109 
5110  ILVRL_H2_SH(dst1, dst0, dst10_r, dst10_l);
5111  ILVRL_H2_SH(dst2, dst1, dst21_r, dst21_l);
5112  ILVRL_H2_SH(dst3, dst2, dst32_r, dst32_l);
5113  ILVRL_H2_SH(dst4, dst3, dst43_r, dst43_l);
5114  dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
5115  dst0_l = HEVC_FILT_4TAP(dst10_l, dst32_l, filt_h0, filt_h1);
5116  dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
5117  dst1_l = HEVC_FILT_4TAP(dst21_l, dst43_l, filt_h0, filt_h1);
5118  SRA_4V(dst0_r, dst0_l, dst1_r, dst1_l, 6);
5119  PCKEV_H2_SH(dst0_l, dst0_r, dst1_l, dst1_r, tmp1, tmp3);
5120 
5121  ILVRL_H2_SH(tmp1, in0, tmp0, tmp1);
5122  ILVRL_H2_SH(tmp3, in1, tmp2, tmp3);
5123 
5124  dst0_r = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
5125  dst0_l = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
5126  dst1_r = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
5127  dst1_l = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
5128  SRAR_W4_SW(dst0_r, dst0_l, dst1_r, dst1_l, rnd_vec);
5129  PCKEV_H2_SH(dst0_l, dst0_r, dst1_l, dst1_r, tmp0, tmp1);
5130  CLIP_SH2_0_255(tmp0, tmp1);
5131  out = (v16u8) __msa_pckev_b((v16i8) tmp1, (v16i8) tmp0);
5132  ST_D2(out, 0, 1, dst, dst_stride);
5133 }
5134 
5135 static void hevc_hv_biwgt_4t_8multx4_msa(const uint8_t *src0_ptr,
5136  int32_t src_stride,
5137  const int16_t *src1_ptr,
5138  int32_t src2_stride,
5139  uint8_t *dst,
5140  int32_t dst_stride,
5141  const int8_t *filter_x,
5142  const int8_t *filter_y,
5143  int32_t weight0,
5144  int32_t weight1,
5145  int32_t offset0,
5146  int32_t offset1,
5147  int32_t rnd_val,
5148  int32_t width8mult)
5149 {
5151  uint32_t cnt;
5152  v16u8 out0, out1;
5153  v16i8 src0, src1, src2, src3, src4, src5, src6, mask0, mask1;
5154  v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
5155  v8i16 filt0, filt1, filt_h0, filt_h1, filter_vec, weight_vec;
5156  v8i16 dsth0, dsth1, dsth2, dsth3, dsth4, dsth5, dsth6;
5157  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, in0, in1, in2, in3;
5158  v8i16 dst10_r, dst32_r, dst54_r, dst21_r, dst43_r, dst65_r;
5159  v8i16 dst10_l, dst32_l, dst54_l, dst21_l, dst43_l, dst65_l;
5160  v4i32 dst0_r, dst0_l, dst1_r, dst1_l, dst2_r, dst2_l, dst3_r, dst3_l;
5161  v4i32 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
5162  v4i32 offset_vec, rnd_vec, const_vec;
5163 
5164  src0_ptr -= (src_stride + 1);
5165 
5166  filter_vec = LD_SH(filter_x);
5167  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
5168 
5169  filter_vec = LD_SH(filter_y);
5170  UNPCK_R_SB_SH(filter_vec, filter_vec);
5171 
5172  SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
5173 
5174  mask0 = LD_SB(ff_hevc_mask_arr);
5175  mask1 = mask0 + 2;
5176 
5177  offset = (offset0 + offset1) << rnd_val;
5178  weight0 = weight0 & 0x0000FFFF;
5179  weight = weight0 | (weight1 << 16);
5180 
5181  const_vec = __msa_fill_w((128 * weight1));
5182  const_vec <<= 6;
5183  offset_vec = __msa_fill_w(offset);
5184  rnd_vec = __msa_fill_w(rnd_val + 1);
5185  offset_vec += const_vec;
5186  weight_vec = (v8i16) __msa_fill_w(weight);
5187 
5188  for (cnt = width8mult; cnt--;) {
5189  LD_SB7(src0_ptr, src_stride, src0, src1, src2, src3, src4, src5, src6);
5190  src0_ptr += 8;
5191  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
5192 
5193  LD_SH4(src1_ptr, src2_stride, in0, in1, in2, in3);
5194  src1_ptr += 8;
5195 
5196  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
5197  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec2, vec3);
5198  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec4, vec5);
5199 
5200  dsth0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
5201  dsth1 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
5202  dsth2 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
5203 
5204  ILVRL_H2_SH(dsth1, dsth0, dst10_r, dst10_l);
5205  ILVRL_H2_SH(dsth2, dsth1, dst21_r, dst21_l);
5206 
5207  VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec0, vec1);
5208  VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec2, vec3);
5209  VSHF_B2_SB(src5, src5, src5, src5, mask0, mask1, vec4, vec5);
5210  VSHF_B2_SB(src6, src6, src6, src6, mask0, mask1, vec6, vec7);
5211 
5212  dsth3 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
5213  dsth4 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
5214  dsth5 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
5215  dsth6 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
5216 
5217  ILVRL_H2_SH(dsth3, dsth2, dst32_r, dst32_l);
5218  ILVRL_H2_SH(dsth4, dsth3, dst43_r, dst43_l);
5219  ILVRL_H2_SH(dsth5, dsth4, dst54_r, dst54_l);
5220  ILVRL_H2_SH(dsth6, dsth5, dst65_r, dst65_l);
5221 
5222  dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
5223  dst0_l = HEVC_FILT_4TAP(dst10_l, dst32_l, filt_h0, filt_h1);
5224  dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
5225  dst1_l = HEVC_FILT_4TAP(dst21_l, dst43_l, filt_h0, filt_h1);
5226  dst2_r = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
5227  dst2_l = HEVC_FILT_4TAP(dst32_l, dst54_l, filt_h0, filt_h1);
5228  dst3_r = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
5229  dst3_l = HEVC_FILT_4TAP(dst43_l, dst65_l, filt_h0, filt_h1);
5230 
5231  SRA_4V(dst0_r, dst0_l, dst1_r, dst1_l, 6);
5232  SRA_4V(dst2_r, dst2_l, dst3_r, dst3_l, 6);
5233  PCKEV_H4_SW(dst0_l, dst0_r, dst1_l, dst1_r, dst2_l, dst2_r, dst3_l,
5234  dst3_r, dst0, dst1, dst2, dst3);
5235 
5236  ILVRL_H2_SH(dst0, in0, tmp0, tmp1);
5237  ILVRL_H2_SH(dst1, in1, tmp2, tmp3);
5238  ILVRL_H2_SH(dst2, in2, tmp4, tmp5);
5239  ILVRL_H2_SH(dst3, in3, tmp6, tmp7);
5240  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
5241  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
5242  dst2 = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
5243  dst3 = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
5244  dst4 = __msa_dpadd_s_w(offset_vec, tmp4, weight_vec);
5245  dst5 = __msa_dpadd_s_w(offset_vec, tmp5, weight_vec);
5246  dst6 = __msa_dpadd_s_w(offset_vec, tmp6, weight_vec);
5247  dst7 = __msa_dpadd_s_w(offset_vec, tmp7, weight_vec);
5248  SRAR_W4_SW(dst0, dst1, dst2, dst3, rnd_vec);
5249  SRAR_W4_SW(dst4, dst5, dst6, dst7, rnd_vec);
5250  PCKEV_H4_SH(dst1, dst0, dst3, dst2, dst5, dst4, dst7, dst6,
5251  tmp0, tmp1, tmp2, tmp3);
5252  CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
5253  PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
5254  ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
5255  dst += 8;
5256  }
5257 }
5258 
5259 static void hevc_hv_biwgt_4t_8x6_msa(const uint8_t *src0_ptr,
5260  int32_t src_stride,
5261  const int16_t *src1_ptr,
5262  int32_t src2_stride,
5263  uint8_t *dst,
5264  int32_t dst_stride,
5265  const int8_t *filter_x,
5266  const int8_t *filter_y,
5267  int32_t weight0,
5268  int32_t weight1,
5269  int32_t offset0,
5270  int32_t offset1,
5271  int32_t rnd_val)
5272 {
5273  uint32_t offset, weight;
5274  v16u8 out0, out1, out2;
5275  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
5276  v8i16 filt0, filt1;
5277  v8i16 filt_h0, filt_h1;
5278  v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
5279  v16i8 mask1;
5280  v8i16 filter_vec, weight_vec;
5281  v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7, vec8, vec9;
5282  v16i8 vec10, vec11, vec12, vec13, vec14, vec15, vec16, vec17;
5283  v8i16 dsth0, dsth1, dsth2, dsth3, dsth4, dsth5, dsth6, dsth7, dsth8;
5284  v4i32 dst0_r, dst0_l, dst1_r, dst1_l, dst2_r, dst2_l, dst3_r, dst3_l;
5285  v4i32 dst4_r, dst4_l, dst5_r, dst5_l;
5286  v8i16 dst10_r, dst32_r, dst10_l, dst32_l;
5287  v8i16 dst21_r, dst43_r, dst21_l, dst43_l;
5288  v8i16 dst54_r, dst54_l, dst65_r, dst65_l;
5289  v8i16 dst76_r, dst76_l, dst87_r, dst87_l;
5290  v8i16 in0, in1, in2, in3, in4, in5;
5291  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
5292  v4i32 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
5293  v4i32 offset_vec, rnd_vec, const_vec;
5294 
5295  src0_ptr -= (src_stride + 1);
5296 
5297  filter_vec = LD_SH(filter_x);
5298  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
5299 
5300  filter_vec = LD_SH(filter_y);
5301  UNPCK_R_SB_SH(filter_vec, filter_vec);
5302 
5303  SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
5304 
5305  mask1 = mask0 + 2;
5306 
5307  offset = (offset0 + offset1) << rnd_val;
5308  weight0 = weight0 & 0x0000FFFF;
5309  weight = weight0 | (weight1 << 16);
5310 
5311  const_vec = __msa_fill_w((128 * weight1));
5312  const_vec <<= 6;
5313  offset_vec = __msa_fill_w(offset);
5314  weight_vec = (v8i16) __msa_fill_w(weight);
5315  rnd_vec = __msa_fill_w(rnd_val + 1);
5316  offset_vec += const_vec;
5317 
5318  LD_SB5(src0_ptr, src_stride, src0, src1, src2, src3, src4);
5319  src0_ptr += (5 * src_stride);
5320  LD_SB4(src0_ptr, src_stride, src5, src6, src7, src8);
5321 
5322  XORI_B5_128_SB(src0, src1, src2, src3, src4);
5323  XORI_B4_128_SB(src5, src6, src7, src8);
5324 
5325  LD_SH6(src1_ptr, src2_stride, in0, in1, in2, in3, in4, in5);
5326 
5327  VSHF_B2_SB(src0, src0, src0, src0, mask0, mask1, vec0, vec1);
5328  VSHF_B2_SB(src1, src1, src1, src1, mask0, mask1, vec2, vec3);
5329  VSHF_B2_SB(src2, src2, src2, src2, mask0, mask1, vec4, vec5);
5330  VSHF_B2_SB(src3, src3, src3, src3, mask0, mask1, vec6, vec7);
5331  VSHF_B2_SB(src4, src4, src4, src4, mask0, mask1, vec8, vec9);
5332  VSHF_B2_SB(src5, src5, src5, src5, mask0, mask1, vec10, vec11);
5333  VSHF_B2_SB(src6, src6, src6, src6, mask0, mask1, vec12, vec13);
5334  VSHF_B2_SB(src7, src7, src7, src7, mask0, mask1, vec14, vec15);
5335  VSHF_B2_SB(src8, src8, src8, src8, mask0, mask1, vec16, vec17);
5336 
5337  dsth0 = HEVC_FILT_4TAP_SH(vec0, vec1, filt0, filt1);
5338  dsth1 = HEVC_FILT_4TAP_SH(vec2, vec3, filt0, filt1);
5339  dsth2 = HEVC_FILT_4TAP_SH(vec4, vec5, filt0, filt1);
5340  dsth3 = HEVC_FILT_4TAP_SH(vec6, vec7, filt0, filt1);
5341  dsth4 = HEVC_FILT_4TAP_SH(vec8, vec9, filt0, filt1);
5342  dsth5 = HEVC_FILT_4TAP_SH(vec10, vec11, filt0, filt1);
5343  dsth6 = HEVC_FILT_4TAP_SH(vec12, vec13, filt0, filt1);
5344  dsth7 = HEVC_FILT_4TAP_SH(vec14, vec15, filt0, filt1);
5345  dsth8 = HEVC_FILT_4TAP_SH(vec16, vec17, filt0, filt1);
5346 
5347  ILVRL_H2_SH(dsth1, dsth0, dst10_r, dst10_l);
5348  ILVRL_H2_SH(dsth2, dsth1, dst21_r, dst21_l);
5349  ILVRL_H2_SH(dsth3, dsth2, dst32_r, dst32_l);
5350  ILVRL_H2_SH(dsth4, dsth3, dst43_r, dst43_l);
5351  ILVRL_H2_SH(dsth5, dsth4, dst54_r, dst54_l);
5352  ILVRL_H2_SH(dsth6, dsth5, dst65_r, dst65_l);
5353  ILVRL_H2_SH(dsth7, dsth6, dst76_r, dst76_l);
5354  ILVRL_H2_SH(dsth8, dsth7, dst87_r, dst87_l);
5355 
5356  dst0_r = HEVC_FILT_4TAP(dst10_r, dst32_r, filt_h0, filt_h1);
5357  dst0_l = HEVC_FILT_4TAP(dst10_l, dst32_l, filt_h0, filt_h1);
5358  dst1_r = HEVC_FILT_4TAP(dst21_r, dst43_r, filt_h0, filt_h1);
5359  dst1_l = HEVC_FILT_4TAP(dst21_l, dst43_l, filt_h0, filt_h1);
5360  dst2_r = HEVC_FILT_4TAP(dst32_r, dst54_r, filt_h0, filt_h1);
5361  dst2_l = HEVC_FILT_4TAP(dst32_l, dst54_l, filt_h0, filt_h1);
5362  dst3_r = HEVC_FILT_4TAP(dst43_r, dst65_r, filt_h0, filt_h1);
5363  dst3_l = HEVC_FILT_4TAP(dst43_l, dst65_l, filt_h0, filt_h1);
5364  dst4_r = HEVC_FILT_4TAP(dst54_r, dst76_r, filt_h0, filt_h1);
5365  dst4_l = HEVC_FILT_4TAP(dst54_l, dst76_l, filt_h0, filt_h1);
5366  dst5_r = HEVC_FILT_4TAP(dst65_r, dst87_r, filt_h0, filt_h1);
5367  dst5_l = HEVC_FILT_4TAP(dst65_l, dst87_l, filt_h0, filt_h1);
5368 
5369  SRA_4V(dst0_r, dst0_l, dst1_r, dst1_l, 6);
5370  SRA_4V(dst2_r, dst2_l, dst3_r, dst3_l, 6);
5371  SRA_4V(dst4_r, dst4_l, dst5_r, dst5_l, 6);
5372  PCKEV_H4_SW(dst0_l, dst0_r, dst1_l, dst1_r, dst2_l, dst2_r, dst3_l, dst3_r,
5373  dst0, dst1, dst2, dst3);
5374 
5375  ILVRL_H2_SH(dst0, in0, tmp0, tmp1);
5376  ILVRL_H2_SH(dst1, in1, tmp2, tmp3);
5377  ILVRL_H2_SH(dst2, in2, tmp4, tmp5);
5378  ILVRL_H2_SH(dst3, in3, tmp6, tmp7);
5379  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
5380  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
5381  dst2 = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
5382  dst3 = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
5383  dst4 = __msa_dpadd_s_w(offset_vec, tmp4, weight_vec);
5384  dst5 = __msa_dpadd_s_w(offset_vec, tmp5, weight_vec);
5385  dst6 = __msa_dpadd_s_w(offset_vec, tmp6, weight_vec);
5386  dst7 = __msa_dpadd_s_w(offset_vec, tmp7, weight_vec);
5387  SRAR_W4_SW(dst0, dst1, dst2, dst3, rnd_vec);
5388  SRAR_W4_SW(dst4, dst5, dst6, dst7, rnd_vec);
5389  PCKEV_H4_SH(dst1, dst0, dst3, dst2, dst5, dst4, dst7, dst6,
5390  tmp0, tmp1, tmp2, tmp3);
5391  CLIP_SH4_0_255(tmp0, tmp1, tmp2, tmp3);
5392  PCKEV_B2_UB(tmp1, tmp0, tmp3, tmp2, out0, out1);
5393 
5394  PCKEV_H2_SW(dst4_l, dst4_r, dst5_l, dst5_r, dst0, dst1);
5395  ILVRL_H2_SH(dst0, in4, tmp0, tmp1);
5396  ILVRL_H2_SH(dst1, in5, tmp2, tmp3);
5397  dst0 = __msa_dpadd_s_w(offset_vec, tmp0, weight_vec);
5398  dst1 = __msa_dpadd_s_w(offset_vec, tmp1, weight_vec);
5399  dst2 = __msa_dpadd_s_w(offset_vec, tmp2, weight_vec);
5400  dst3 = __msa_dpadd_s_w(offset_vec, tmp3, weight_vec);
5401  SRAR_W4_SW(dst0, dst1, dst2, dst3, rnd_vec);
5402  PCKEV_H2_SH(dst1, dst0, dst3, dst2, tmp4, tmp5);
5403  CLIP_SH2_0_255(tmp4, tmp5);
5404  out2 = (v16u8) __msa_pckev_b((v16i8) tmp5, (v16i8) tmp4);
5405  ST_D4(out0, out1, 0, 1, 0, 1, dst, dst_stride);
5406  ST_D2(out2, 0, 1, dst + 4 * dst_stride, dst_stride);
5407 }
5408 
5409 static void hevc_hv_biwgt_4t_8multx4mult_msa(const uint8_t *src0_ptr,
5410  int32_t src_stride,
5411  const int16_t *src1_ptr,
5412  int32_t src2_stride,
5413  uint8_t *dst,
5414  int32_t dst_stride,
5415  const int8_t *filter_x,
5416  const int8_t *filter_y,
5417  int32_t height,
5418  int32_t weight0,
5419  int32_t weight1,
5420  int32_t offset0,
5421  int32_t offset1,
5422  int32_t rnd_val,
5423  int32_t width)
5424 {
5425  uint32_t loop_cnt;
5426  uint32_t cnt;
5428  const uint8_t *src0_ptr_tmp;
5429  const int16_t *src1_ptr_tmp;
5430  uint8_t *dst_tmp;
5431  v16u8 out0, out1;
5432  v16i8 src0, src1, src2, src3, src4, src5, src6;
5433  v8i16 in0, in1, in2, in3;
5434  v8i16 filt0, filt1;
5435  v8i16 filt_h0, filt_h1;
5436  v16i8 mask0 = LD_SB(ff_hevc_mask_arr);
5437  v16i8 mask1;
5438  v8i16 filter_vec;
5439  v16i8 vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
5440  v8i16 dsth0, dsth1, dsth2, dsth3, dsth4, dsth5, dsth6;
5441  v4i32 dst0_r, dst0_l, dst1_r, dst1_l, dst2_r, dst2_l, dst3_r, dst3_l;
5442  v8i16 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
5443  v4i32 dst0, dst1, dst2, dst3, dst4, dst5, dst6, dst7;
5444  v8i16 dst10_r, dst32_r, dst54_r, dst21_r, dst43_r, dst65_r;
5445  v8i16 dst10_l, dst32_l, dst54_l, dst21_l, dst43_l, dst65_l, weight_vec;
5446  v4i32 offset_vec, rnd_vec, const_vec;
5447 
5448  src0_ptr -= (src_stride + 1);
5449 
5450  filter_vec = LD_SH(filter_x);
5451  SPLATI_H2_SH(filter_vec, 0, 1, filt0, filt1);
5452 
5453  filter_vec = LD_SH(filter_y);
5454  UNPCK_R_SB_SH(filter_vec, filter_vec);
5455 
5456  SPLATI_W2_SH(filter_vec, 0, filt_h0, filt_h1);
5457 
5458  mask1 = mask0 + 2;
5459 
5460  offset = (offset0 + offset1) << rnd_val;
5461  weight0 = weight0 & 0x0000FFFF;
5462  weight = weight0 | (weight1 << 16);