1/*
2 *  Copyright (c) 2015 The WebM project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <assert.h>
12#include "./vpx_dsp_rtcd.h"
13#include "vpx_dsp/mips/vpx_convolve_msa.h"
14
15const uint8_t mc_filt_mask_arr[16 * 3] = {
16  /* 8 width cases */
17  0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
18  /* 4 width cases */
19  0, 1, 1, 2, 2, 3, 3, 4, 16, 17, 17, 18, 18, 19, 19, 20,
20  /* 4 width cases */
21  8, 9, 9, 10, 10, 11, 11, 12, 24, 25, 25, 26, 26, 27, 27, 28
22};
23
24static void common_hv_8ht_8vt_4w_msa(const uint8_t *src, int32_t src_stride,
25                                     uint8_t *dst, int32_t dst_stride,
26                                     int8_t *filter_horiz, int8_t *filter_vert,
27                                     int32_t height) {
28  uint32_t loop_cnt;
29  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
30  v16i8 filt_hz0, filt_hz1, filt_hz2, filt_hz3;
31  v16u8 mask0, mask1, mask2, mask3, out;
32  v8i16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5, hz_out6;
33  v8i16 hz_out7, hz_out8, hz_out9, tmp0, tmp1, out0, out1, out2, out3, out4;
34  v8i16 filt, filt_vt0, filt_vt1, filt_vt2, filt_vt3;
35
36  mask0 = LD_UB(&mc_filt_mask_arr[16]);
37  src -= (3 + 3 * src_stride);
38
39  /* rearranging filter */
40  filt = LD_SH(filter_horiz);
41  SPLATI_H4_SB(filt, 0, 1, 2, 3, filt_hz0, filt_hz1, filt_hz2, filt_hz3);
42
43  mask1 = mask0 + 2;
44  mask2 = mask0 + 4;
45  mask3 = mask0 + 6;
46
47  LD_SB7(src, src_stride, src0, src1, src2, src3, src4, src5, src6);
48  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
49  src += (7 * src_stride);
50
51  hz_out0 = HORIZ_8TAP_FILT(src0, src1, mask0, mask1, mask2, mask3, filt_hz0,
52                            filt_hz1, filt_hz2, filt_hz3);
53  hz_out2 = HORIZ_8TAP_FILT(src2, src3, mask0, mask1, mask2, mask3, filt_hz0,
54                            filt_hz1, filt_hz2, filt_hz3);
55  hz_out4 = HORIZ_8TAP_FILT(src4, src5, mask0, mask1, mask2, mask3, filt_hz0,
56                            filt_hz1, filt_hz2, filt_hz3);
57  hz_out5 = HORIZ_8TAP_FILT(src5, src6, mask0, mask1, mask2, mask3, filt_hz0,
58                            filt_hz1, filt_hz2, filt_hz3);
59  SLDI_B2_SH(hz_out2, hz_out4, hz_out0, hz_out2, hz_out1, hz_out3, 8);
60
61  filt = LD_SH(filter_vert);
62  SPLATI_H4_SH(filt, 0, 1, 2, 3, filt_vt0, filt_vt1, filt_vt2, filt_vt3);
63
64  ILVEV_B2_SH(hz_out0, hz_out1, hz_out2, hz_out3, out0, out1);
65  out2 = (v8i16)__msa_ilvev_b((v16i8)hz_out5, (v16i8)hz_out4);
66
67  for (loop_cnt = (height >> 2); loop_cnt--;) {
68    LD_SB4(src, src_stride, src7, src8, src9, src10);
69    XORI_B4_128_SB(src7, src8, src9, src10);
70    src += (4 * src_stride);
71
72    hz_out7 = HORIZ_8TAP_FILT(src7, src8, mask0, mask1, mask2, mask3, filt_hz0,
73                              filt_hz1, filt_hz2, filt_hz3);
74    hz_out6 = (v8i16)__msa_sldi_b((v16i8)hz_out7, (v16i8)hz_out5, 8);
75    out3 = (v8i16)__msa_ilvev_b((v16i8)hz_out7, (v16i8)hz_out6);
76    tmp0 = FILT_8TAP_DPADD_S_H(out0, out1, out2, out3, filt_vt0, filt_vt1,
77                               filt_vt2, filt_vt3);
78
79    hz_out9 = HORIZ_8TAP_FILT(src9, src10, mask0, mask1, mask2, mask3, filt_hz0,
80                              filt_hz1, filt_hz2, filt_hz3);
81    hz_out8 = (v8i16)__msa_sldi_b((v16i8)hz_out9, (v16i8)hz_out7, 8);
82    out4 = (v8i16)__msa_ilvev_b((v16i8)hz_out9, (v16i8)hz_out8);
83    tmp1 = FILT_8TAP_DPADD_S_H(out1, out2, out3, out4, filt_vt0, filt_vt1,
84                               filt_vt2, filt_vt3);
85    SRARI_H2_SH(tmp0, tmp1, FILTER_BITS);
86    SAT_SH2_SH(tmp0, tmp1, 7);
87    out = PCKEV_XORI128_UB(tmp0, tmp1);
88    ST4x4_UB(out, out, 0, 1, 2, 3, dst, dst_stride);
89    dst += (4 * dst_stride);
90
91    hz_out5 = hz_out9;
92    out0 = out2;
93    out1 = out3;
94    out2 = out4;
95  }
96}
97
98static void common_hv_8ht_8vt_8w_msa(const uint8_t *src, int32_t src_stride,
99                                     uint8_t *dst, int32_t dst_stride,
100                                     int8_t *filter_horiz, int8_t *filter_vert,
101                                     int32_t height) {
102  uint32_t loop_cnt;
103  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, src10;
104  v16i8 filt_hz0, filt_hz1, filt_hz2, filt_hz3;
105  v16u8 mask0, mask1, mask2, mask3, vec0, vec1;
106  v8i16 filt, filt_vt0, filt_vt1, filt_vt2, filt_vt3;
107  v8i16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5, hz_out6;
108  v8i16 hz_out7, hz_out8, hz_out9, hz_out10, tmp0, tmp1, tmp2, tmp3;
109  v8i16 out0, out1, out2, out3, out4, out5, out6, out7, out8, out9;
110
111  mask0 = LD_UB(&mc_filt_mask_arr[0]);
112  src -= (3 + 3 * src_stride);
113
114  /* rearranging filter */
115  filt = LD_SH(filter_horiz);
116  SPLATI_H4_SB(filt, 0, 1, 2, 3, filt_hz0, filt_hz1, filt_hz2, filt_hz3);
117
118  mask1 = mask0 + 2;
119  mask2 = mask0 + 4;
120  mask3 = mask0 + 6;
121
122  LD_SB7(src, src_stride, src0, src1, src2, src3, src4, src5, src6);
123  src += (7 * src_stride);
124
125  XORI_B7_128_SB(src0, src1, src2, src3, src4, src5, src6);
126  hz_out0 = HORIZ_8TAP_FILT(src0, src0, mask0, mask1, mask2, mask3, filt_hz0,
127                            filt_hz1, filt_hz2, filt_hz3);
128  hz_out1 = HORIZ_8TAP_FILT(src1, src1, mask0, mask1, mask2, mask3, filt_hz0,
129                            filt_hz1, filt_hz2, filt_hz3);
130  hz_out2 = HORIZ_8TAP_FILT(src2, src2, mask0, mask1, mask2, mask3, filt_hz0,
131                            filt_hz1, filt_hz2, filt_hz3);
132  hz_out3 = HORIZ_8TAP_FILT(src3, src3, mask0, mask1, mask2, mask3, filt_hz0,
133                            filt_hz1, filt_hz2, filt_hz3);
134  hz_out4 = HORIZ_8TAP_FILT(src4, src4, mask0, mask1, mask2, mask3, filt_hz0,
135                            filt_hz1, filt_hz2, filt_hz3);
136  hz_out5 = HORIZ_8TAP_FILT(src5, src5, mask0, mask1, mask2, mask3, filt_hz0,
137                            filt_hz1, filt_hz2, filt_hz3);
138  hz_out6 = HORIZ_8TAP_FILT(src6, src6, mask0, mask1, mask2, mask3, filt_hz0,
139                            filt_hz1, filt_hz2, filt_hz3);
140
141  filt = LD_SH(filter_vert);
142  SPLATI_H4_SH(filt, 0, 1, 2, 3, filt_vt0, filt_vt1, filt_vt2, filt_vt3);
143
144  ILVEV_B2_SH(hz_out0, hz_out1, hz_out2, hz_out3, out0, out1);
145  ILVEV_B2_SH(hz_out4, hz_out5, hz_out1, hz_out2, out2, out4);
146  ILVEV_B2_SH(hz_out3, hz_out4, hz_out5, hz_out6, out5, out6);
147
148  for (loop_cnt = (height >> 2); loop_cnt--;) {
149    LD_SB4(src, src_stride, src7, src8, src9, src10);
150    src += (4 * src_stride);
151
152    XORI_B4_128_SB(src7, src8, src9, src10);
153
154    hz_out7 = HORIZ_8TAP_FILT(src7, src7, mask0, mask1, mask2, mask3, filt_hz0,
155                              filt_hz1, filt_hz2, filt_hz3);
156    out3 = (v8i16)__msa_ilvev_b((v16i8)hz_out7, (v16i8)hz_out6);
157    tmp0 = FILT_8TAP_DPADD_S_H(out0, out1, out2, out3, filt_vt0, filt_vt1,
158                               filt_vt2, filt_vt3);
159
160    hz_out8 = HORIZ_8TAP_FILT(src8, src8, mask0, mask1, mask2, mask3, filt_hz0,
161                              filt_hz1, filt_hz2, filt_hz3);
162    out7 = (v8i16)__msa_ilvev_b((v16i8)hz_out8, (v16i8)hz_out7);
163    tmp1 = FILT_8TAP_DPADD_S_H(out4, out5, out6, out7, filt_vt0, filt_vt1,
164                               filt_vt2, filt_vt3);
165
166    hz_out9 = HORIZ_8TAP_FILT(src9, src9, mask0, mask1, mask2, mask3, filt_hz0,
167                              filt_hz1, filt_hz2, filt_hz3);
168    out8 = (v8i16)__msa_ilvev_b((v16i8)hz_out9, (v16i8)hz_out8);
169    tmp2 = FILT_8TAP_DPADD_S_H(out1, out2, out3, out8, filt_vt0, filt_vt1,
170                               filt_vt2, filt_vt3);
171
172    hz_out10 = HORIZ_8TAP_FILT(src10, src10, mask0, mask1, mask2, mask3,
173                               filt_hz0, filt_hz1, filt_hz2, filt_hz3);
174    out9 = (v8i16)__msa_ilvev_b((v16i8)hz_out10, (v16i8)hz_out9);
175    tmp3 = FILT_8TAP_DPADD_S_H(out5, out6, out7, out9, filt_vt0, filt_vt1,
176                               filt_vt2, filt_vt3);
177    SRARI_H4_SH(tmp0, tmp1, tmp2, tmp3, FILTER_BITS);
178    SAT_SH4_SH(tmp0, tmp1, tmp2, tmp3, 7);
179    vec0 = PCKEV_XORI128_UB(tmp0, tmp1);
180    vec1 = PCKEV_XORI128_UB(tmp2, tmp3);
181    ST8x4_UB(vec0, vec1, dst, dst_stride);
182    dst += (4 * dst_stride);
183
184    hz_out6 = hz_out10;
185    out0 = out2;
186    out1 = out3;
187    out2 = out8;
188    out4 = out6;
189    out5 = out7;
190    out6 = out9;
191  }
192}
193
194static void common_hv_8ht_8vt_16w_msa(const uint8_t *src, int32_t src_stride,
195                                      uint8_t *dst, int32_t dst_stride,
196                                      int8_t *filter_horiz, int8_t *filter_vert,
197                                      int32_t height) {
198  int32_t multiple8_cnt;
199  for (multiple8_cnt = 2; multiple8_cnt--;) {
200    common_hv_8ht_8vt_8w_msa(src, src_stride, dst, dst_stride, filter_horiz,
201                             filter_vert, height);
202    src += 8;
203    dst += 8;
204  }
205}
206
207static void common_hv_8ht_8vt_32w_msa(const uint8_t *src, int32_t src_stride,
208                                      uint8_t *dst, int32_t dst_stride,
209                                      int8_t *filter_horiz, int8_t *filter_vert,
210                                      int32_t height) {
211  int32_t multiple8_cnt;
212  for (multiple8_cnt = 4; multiple8_cnt--;) {
213    common_hv_8ht_8vt_8w_msa(src, src_stride, dst, dst_stride, filter_horiz,
214                             filter_vert, height);
215    src += 8;
216    dst += 8;
217  }
218}
219
220static void common_hv_8ht_8vt_64w_msa(const uint8_t *src, int32_t src_stride,
221                                      uint8_t *dst, int32_t dst_stride,
222                                      int8_t *filter_horiz, int8_t *filter_vert,
223                                      int32_t height) {
224  int32_t multiple8_cnt;
225  for (multiple8_cnt = 8; multiple8_cnt--;) {
226    common_hv_8ht_8vt_8w_msa(src, src_stride, dst, dst_stride, filter_horiz,
227                             filter_vert, height);
228    src += 8;
229    dst += 8;
230  }
231}
232
233static void common_hv_2ht_2vt_4x4_msa(const uint8_t *src, int32_t src_stride,
234                                      uint8_t *dst, int32_t dst_stride,
235                                      int8_t *filter_horiz,
236                                      int8_t *filter_vert) {
237  v16i8 src0, src1, src2, src3, src4, mask;
238  v16u8 filt_vt, filt_hz, vec0, vec1, res0, res1;
239  v8u16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, filt, tmp0, tmp1;
240
241  mask = LD_SB(&mc_filt_mask_arr[16]);
242
243  /* rearranging filter */
244  filt = LD_UH(filter_horiz);
245  filt_hz = (v16u8)__msa_splati_h((v8i16)filt, 0);
246
247  filt = LD_UH(filter_vert);
248  filt_vt = (v16u8)__msa_splati_h((v8i16)filt, 0);
249
250  LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
251  hz_out0 = HORIZ_2TAP_FILT_UH(src0, src1, mask, filt_hz, FILTER_BITS);
252  hz_out2 = HORIZ_2TAP_FILT_UH(src2, src3, mask, filt_hz, FILTER_BITS);
253  hz_out4 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz, FILTER_BITS);
254  hz_out1 = (v8u16)__msa_sldi_b((v16i8)hz_out2, (v16i8)hz_out0, 8);
255  hz_out3 = (v8u16)__msa_pckod_d((v2i64)hz_out4, (v2i64)hz_out2);
256
257  ILVEV_B2_UB(hz_out0, hz_out1, hz_out2, hz_out3, vec0, vec1);
258  DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp0, tmp1);
259  SRARI_H2_UH(tmp0, tmp1, FILTER_BITS);
260  PCKEV_B2_UB(tmp0, tmp0, tmp1, tmp1, res0, res1);
261  ST4x4_UB(res0, res1, 0, 1, 0, 1, dst, dst_stride);
262}
263
264static void common_hv_2ht_2vt_4x8_msa(const uint8_t *src, int32_t src_stride,
265                                      uint8_t *dst, int32_t dst_stride,
266                                      int8_t *filter_horiz,
267                                      int8_t *filter_vert) {
268  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, src8, mask;
269  v16i8 res0, res1, res2, res3;
270  v16u8 filt_hz, filt_vt, vec0, vec1, vec2, vec3;
271  v8u16 hz_out0, hz_out1, hz_out2, hz_out3, hz_out4, hz_out5, hz_out6;
272  v8u16 hz_out7, hz_out8, vec4, vec5, vec6, vec7, filt;
273
274  mask = LD_SB(&mc_filt_mask_arr[16]);
275
276  /* rearranging filter */
277  filt = LD_UH(filter_horiz);
278  filt_hz = (v16u8)__msa_splati_h((v8i16)filt, 0);
279
280  filt = LD_UH(filter_vert);
281  filt_vt = (v16u8)__msa_splati_h((v8i16)filt, 0);
282
283  LD_SB8(src, src_stride, src0, src1, src2, src3, src4, src5, src6, src7);
284  src += (8 * src_stride);
285  src8 = LD_SB(src);
286
287  hz_out0 = HORIZ_2TAP_FILT_UH(src0, src1, mask, filt_hz, FILTER_BITS);
288  hz_out2 = HORIZ_2TAP_FILT_UH(src2, src3, mask, filt_hz, FILTER_BITS);
289  hz_out4 = HORIZ_2TAP_FILT_UH(src4, src5, mask, filt_hz, FILTER_BITS);
290  hz_out6 = HORIZ_2TAP_FILT_UH(src6, src7, mask, filt_hz, FILTER_BITS);
291  hz_out8 = HORIZ_2TAP_FILT_UH(src8, src8, mask, filt_hz, FILTER_BITS);
292  SLDI_B3_UH(hz_out2, hz_out4, hz_out6, hz_out0, hz_out2, hz_out4, hz_out1,
293             hz_out3, hz_out5, 8);
294  hz_out7 = (v8u16)__msa_pckod_d((v2i64)hz_out8, (v2i64)hz_out6);
295
296  ILVEV_B2_UB(hz_out0, hz_out1, hz_out2, hz_out3, vec0, vec1);
297  ILVEV_B2_UB(hz_out4, hz_out5, hz_out6, hz_out7, vec2, vec3);
298  DOTP_UB4_UH(vec0, vec1, vec2, vec3, filt_vt, filt_vt, filt_vt, filt_vt, vec4,
299              vec5, vec6, vec7);
300  SRARI_H4_UH(vec4, vec5, vec6, vec7, FILTER_BITS);
301  PCKEV_B4_SB(vec4, vec4, vec5, vec5, vec6, vec6, vec7, vec7, res0, res1, res2,
302              res3);
303  ST4x4_UB(res0, res1, 0, 1, 0, 1, dst, dst_stride);
304  dst += (4 * dst_stride);
305  ST4x4_UB(res2, res3, 0, 1, 0, 1, dst, dst_stride);
306}
307
308static void common_hv_2ht_2vt_4w_msa(const uint8_t *src, int32_t src_stride,
309                                     uint8_t *dst, int32_t dst_stride,
310                                     int8_t *filter_horiz, int8_t *filter_vert,
311                                     int32_t height) {
312  if (4 == height) {
313    common_hv_2ht_2vt_4x4_msa(src, src_stride, dst, dst_stride, filter_horiz,
314                              filter_vert);
315  } else if (8 == height) {
316    common_hv_2ht_2vt_4x8_msa(src, src_stride, dst, dst_stride, filter_horiz,
317                              filter_vert);
318  }
319}
320
321static void common_hv_2ht_2vt_8x4_msa(const uint8_t *src, int32_t src_stride,
322                                      uint8_t *dst, int32_t dst_stride,
323                                      int8_t *filter_horiz,
324                                      int8_t *filter_vert) {
325  v16i8 src0, src1, src2, src3, src4, mask, out0, out1;
326  v16u8 filt_hz, filt_vt, vec0, vec1, vec2, vec3;
327  v8u16 hz_out0, hz_out1, tmp0, tmp1, tmp2, tmp3;
328  v8i16 filt;
329
330  mask = LD_SB(&mc_filt_mask_arr[0]);
331
332  /* rearranging filter */
333  filt = LD_SH(filter_horiz);
334  filt_hz = (v16u8)__msa_splati_h(filt, 0);
335
336  filt = LD_SH(filter_vert);
337  filt_vt = (v16u8)__msa_splati_h(filt, 0);
338
339  LD_SB5(src, src_stride, src0, src1, src2, src3, src4);
340
341  hz_out0 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz, FILTER_BITS);
342  hz_out1 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, FILTER_BITS);
343  vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
344  tmp0 = __msa_dotp_u_h(vec0, filt_vt);
345
346  hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz, FILTER_BITS);
347  vec1 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
348  tmp1 = __msa_dotp_u_h(vec1, filt_vt);
349
350  hz_out1 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz, FILTER_BITS);
351  vec2 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
352  tmp2 = __msa_dotp_u_h(vec2, filt_vt);
353
354  hz_out0 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz, FILTER_BITS);
355  vec3 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
356  tmp3 = __msa_dotp_u_h(vec3, filt_vt);
357
358  SRARI_H4_UH(tmp0, tmp1, tmp2, tmp3, FILTER_BITS);
359  PCKEV_B2_SB(tmp1, tmp0, tmp3, tmp2, out0, out1);
360  ST8x4_UB(out0, out1, dst, dst_stride);
361}
362
363static void common_hv_2ht_2vt_8x8mult_msa(const uint8_t *src,
364                                          int32_t src_stride, uint8_t *dst,
365                                          int32_t dst_stride,
366                                          int8_t *filter_horiz,
367                                          int8_t *filter_vert, int32_t height) {
368  uint32_t loop_cnt;
369  v16i8 src0, src1, src2, src3, src4, mask, out0, out1;
370  v16u8 filt_hz, filt_vt, vec0;
371  v8u16 hz_out0, hz_out1, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
372  v8i16 filt;
373
374  mask = LD_SB(&mc_filt_mask_arr[0]);
375
376  /* rearranging filter */
377  filt = LD_SH(filter_horiz);
378  filt_hz = (v16u8)__msa_splati_h(filt, 0);
379
380  filt = LD_SH(filter_vert);
381  filt_vt = (v16u8)__msa_splati_h(filt, 0);
382
383  src0 = LD_SB(src);
384  src += src_stride;
385
386  hz_out0 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz, FILTER_BITS);
387
388  for (loop_cnt = (height >> 3); loop_cnt--;) {
389    LD_SB4(src, src_stride, src1, src2, src3, src4);
390    src += (4 * src_stride);
391
392    hz_out1 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, FILTER_BITS);
393    vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
394    tmp1 = __msa_dotp_u_h(vec0, filt_vt);
395
396    hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz, FILTER_BITS);
397    vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
398    tmp2 = __msa_dotp_u_h(vec0, filt_vt);
399
400    SRARI_H2_UH(tmp1, tmp2, FILTER_BITS);
401
402    hz_out1 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz, FILTER_BITS);
403    vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
404    tmp3 = __msa_dotp_u_h(vec0, filt_vt);
405
406    hz_out0 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz, FILTER_BITS);
407    LD_SB4(src, src_stride, src1, src2, src3, src4);
408    src += (4 * src_stride);
409    vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
410    tmp4 = __msa_dotp_u_h(vec0, filt_vt);
411
412    SRARI_H2_UH(tmp3, tmp4, FILTER_BITS);
413    PCKEV_B2_SB(tmp2, tmp1, tmp4, tmp3, out0, out1);
414    ST8x4_UB(out0, out1, dst, dst_stride);
415    dst += (4 * dst_stride);
416
417    hz_out1 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, FILTER_BITS);
418    vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
419    tmp5 = __msa_dotp_u_h(vec0, filt_vt);
420
421    hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz, FILTER_BITS);
422    vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
423    tmp6 = __msa_dotp_u_h(vec0, filt_vt);
424
425    hz_out1 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz, FILTER_BITS);
426    vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
427    tmp7 = __msa_dotp_u_h(vec0, filt_vt);
428
429    hz_out0 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz, FILTER_BITS);
430    vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
431    tmp8 = __msa_dotp_u_h(vec0, filt_vt);
432
433    SRARI_H4_UH(tmp5, tmp6, tmp7, tmp8, FILTER_BITS);
434    PCKEV_B2_SB(tmp6, tmp5, tmp8, tmp7, out0, out1);
435    ST8x4_UB(out0, out1, dst, dst_stride);
436    dst += (4 * dst_stride);
437  }
438}
439
440static void common_hv_2ht_2vt_8w_msa(const uint8_t *src, int32_t src_stride,
441                                     uint8_t *dst, int32_t dst_stride,
442                                     int8_t *filter_horiz, int8_t *filter_vert,
443                                     int32_t height) {
444  if (4 == height) {
445    common_hv_2ht_2vt_8x4_msa(src, src_stride, dst, dst_stride, filter_horiz,
446                              filter_vert);
447  } else {
448    common_hv_2ht_2vt_8x8mult_msa(src, src_stride, dst, dst_stride,
449                                  filter_horiz, filter_vert, height);
450  }
451}
452
453static void common_hv_2ht_2vt_16w_msa(const uint8_t *src, int32_t src_stride,
454                                      uint8_t *dst, int32_t dst_stride,
455                                      int8_t *filter_horiz, int8_t *filter_vert,
456                                      int32_t height) {
457  uint32_t loop_cnt;
458  v16i8 src0, src1, src2, src3, src4, src5, src6, src7, mask;
459  v16u8 filt_hz, filt_vt, vec0, vec1;
460  v8u16 tmp1, tmp2, hz_out0, hz_out1, hz_out2, hz_out3;
461  v8i16 filt;
462
463  mask = LD_SB(&mc_filt_mask_arr[0]);
464
465  /* rearranging filter */
466  filt = LD_SH(filter_horiz);
467  filt_hz = (v16u8)__msa_splati_h(filt, 0);
468
469  filt = LD_SH(filter_vert);
470  filt_vt = (v16u8)__msa_splati_h(filt, 0);
471
472  LD_SB2(src, 8, src0, src1);
473  src += src_stride;
474
475  hz_out0 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz, FILTER_BITS);
476  hz_out2 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, FILTER_BITS);
477
478  for (loop_cnt = (height >> 2); loop_cnt--;) {
479    LD_SB4(src, src_stride, src0, src2, src4, src6);
480    LD_SB4(src + 8, src_stride, src1, src3, src5, src7);
481    src += (4 * src_stride);
482
483    hz_out1 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz, FILTER_BITS);
484    hz_out3 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, FILTER_BITS);
485    ILVEV_B2_UB(hz_out0, hz_out1, hz_out2, hz_out3, vec0, vec1);
486    DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
487    SRARI_H2_UH(tmp1, tmp2, FILTER_BITS);
488    PCKEV_ST_SB(tmp1, tmp2, dst);
489    dst += dst_stride;
490
491    hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz, FILTER_BITS);
492    hz_out2 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz, FILTER_BITS);
493    ILVEV_B2_UB(hz_out1, hz_out0, hz_out3, hz_out2, vec0, vec1);
494    DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
495    SRARI_H2_UH(tmp1, tmp2, FILTER_BITS);
496    PCKEV_ST_SB(tmp1, tmp2, dst);
497    dst += dst_stride;
498
499    hz_out1 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz, FILTER_BITS);
500    hz_out3 = HORIZ_2TAP_FILT_UH(src5, src5, mask, filt_hz, FILTER_BITS);
501    ILVEV_B2_UB(hz_out0, hz_out1, hz_out2, hz_out3, vec0, vec1);
502    DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
503    SRARI_H2_UH(tmp1, tmp2, FILTER_BITS);
504    PCKEV_ST_SB(tmp1, tmp2, dst);
505    dst += dst_stride;
506
507    hz_out0 = HORIZ_2TAP_FILT_UH(src6, src6, mask, filt_hz, FILTER_BITS);
508    hz_out2 = HORIZ_2TAP_FILT_UH(src7, src7, mask, filt_hz, FILTER_BITS);
509    ILVEV_B2_UB(hz_out1, hz_out0, hz_out3, hz_out2, vec0, vec1);
510    DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
511    SRARI_H2_UH(tmp1, tmp2, FILTER_BITS);
512    PCKEV_ST_SB(tmp1, tmp2, dst);
513    dst += dst_stride;
514  }
515}
516
517static void common_hv_2ht_2vt_32w_msa(const uint8_t *src, int32_t src_stride,
518                                      uint8_t *dst, int32_t dst_stride,
519                                      int8_t *filter_horiz, int8_t *filter_vert,
520                                      int32_t height) {
521  int32_t multiple8_cnt;
522  for (multiple8_cnt = 2; multiple8_cnt--;) {
523    common_hv_2ht_2vt_16w_msa(src, src_stride, dst, dst_stride, filter_horiz,
524                              filter_vert, height);
525    src += 16;
526    dst += 16;
527  }
528}
529
530static void common_hv_2ht_2vt_64w_msa(const uint8_t *src, int32_t src_stride,
531                                      uint8_t *dst, int32_t dst_stride,
532                                      int8_t *filter_horiz, int8_t *filter_vert,
533                                      int32_t height) {
534  int32_t multiple8_cnt;
535  for (multiple8_cnt = 4; multiple8_cnt--;) {
536    common_hv_2ht_2vt_16w_msa(src, src_stride, dst, dst_stride, filter_horiz,
537                              filter_vert, height);
538    src += 16;
539    dst += 16;
540  }
541}
542
543void vpx_convolve8_msa(const uint8_t *src, ptrdiff_t src_stride, uint8_t *dst,
544                       ptrdiff_t dst_stride, const int16_t *filter_x,
545                       int32_t x_step_q4, const int16_t *filter_y,
546                       int32_t y_step_q4, int32_t w, int32_t h) {
547  int8_t cnt, filt_hor[8], filt_ver[8];
548
549  assert(x_step_q4 == 16);
550  assert(y_step_q4 == 16);
551  assert(((const int32_t *)filter_x)[1] != 0x800000);
552  assert(((const int32_t *)filter_y)[1] != 0x800000);
553
554  for (cnt = 0; cnt < 8; ++cnt) {
555    filt_hor[cnt] = filter_x[cnt];
556    filt_ver[cnt] = filter_y[cnt];
557  }
558
559  if (((const int32_t *)filter_x)[0] == 0 &&
560      ((const int32_t *)filter_y)[0] == 0) {
561    switch (w) {
562      case 4:
563        common_hv_2ht_2vt_4w_msa(src, (int32_t)src_stride, dst,
564                                 (int32_t)dst_stride, &filt_hor[3],
565                                 &filt_ver[3], (int32_t)h);
566        break;
567      case 8:
568        common_hv_2ht_2vt_8w_msa(src, (int32_t)src_stride, dst,
569                                 (int32_t)dst_stride, &filt_hor[3],
570                                 &filt_ver[3], (int32_t)h);
571        break;
572      case 16:
573        common_hv_2ht_2vt_16w_msa(src, (int32_t)src_stride, dst,
574                                  (int32_t)dst_stride, &filt_hor[3],
575                                  &filt_ver[3], (int32_t)h);
576        break;
577      case 32:
578        common_hv_2ht_2vt_32w_msa(src, (int32_t)src_stride, dst,
579                                  (int32_t)dst_stride, &filt_hor[3],
580                                  &filt_ver[3], (int32_t)h);
581        break;
582      case 64:
583        common_hv_2ht_2vt_64w_msa(src, (int32_t)src_stride, dst,
584                                  (int32_t)dst_stride, &filt_hor[3],
585                                  &filt_ver[3], (int32_t)h);
586        break;
587      default:
588        vpx_convolve8_c(src, src_stride, dst, dst_stride, filter_x, x_step_q4,
589                        filter_y, y_step_q4, w, h);
590        break;
591    }
592  } else if (((const int32_t *)filter_x)[0] == 0 ||
593             ((const int32_t *)filter_y)[0] == 0) {
594    vpx_convolve8_c(src, src_stride, dst, dst_stride, filter_x, x_step_q4,
595                    filter_y, y_step_q4, w, h);
596  } else {
597    switch (w) {
598      case 4:
599        common_hv_8ht_8vt_4w_msa(src, (int32_t)src_stride, dst,
600                                 (int32_t)dst_stride, filt_hor, filt_ver,
601                                 (int32_t)h);
602        break;
603      case 8:
604        common_hv_8ht_8vt_8w_msa(src, (int32_t)src_stride, dst,
605                                 (int32_t)dst_stride, filt_hor, filt_ver,
606                                 (int32_t)h);
607        break;
608      case 16:
609        common_hv_8ht_8vt_16w_msa(src, (int32_t)src_stride, dst,
610                                  (int32_t)dst_stride, filt_hor, filt_ver,
611                                  (int32_t)h);
612        break;
613      case 32:
614        common_hv_8ht_8vt_32w_msa(src, (int32_t)src_stride, dst,
615                                  (int32_t)dst_stride, filt_hor, filt_ver,
616                                  (int32_t)h);
617        break;
618      case 64:
619        common_hv_8ht_8vt_64w_msa(src, (int32_t)src_stride, dst,
620                                  (int32_t)dst_stride, filt_hor, filt_ver,
621                                  (int32_t)h);
622        break;
623      default:
624        vpx_convolve8_c(src, src_stride, dst, dst_stride, filter_x, x_step_q4,
625                        filter_y, y_step_q4, w, h);
626        break;
627    }
628  }
629}
630