• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 const 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 
common_hv_8ht_8vt_4w_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)24 static 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,
73                               filt_hz0, 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,
80                               filt_hz0, 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 
common_hv_8ht_8vt_8w_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)98 static 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,
155                               filt_hz0, 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,
161                               filt_hz0, 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,
167                               filt_hz0, 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 
common_hv_8ht_8vt_16w_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)194 static 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 
common_hv_8ht_8vt_32w_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)207 static 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 
common_hv_8ht_8vt_64w_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)220 static 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 
common_hv_2ht_2vt_4x4_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert)233 static 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 
common_hv_2ht_2vt_4x8_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert)264 static 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,
299               vec4, 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,
302               res2, 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 
common_hv_2ht_2vt_4w_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)308 static 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 
common_hv_2ht_2vt_8x4_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert)321 static 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 
common_hv_2ht_2vt_8x8mult_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)363 static void common_hv_2ht_2vt_8x8mult_msa(const uint8_t *src,
364                                           int32_t src_stride,
365                                           uint8_t *dst,
366                                           int32_t dst_stride,
367                                           int8_t *filter_horiz,
368                                           int8_t *filter_vert,
369                                           int32_t height) {
370   uint32_t loop_cnt;
371   v16i8 src0, src1, src2, src3, src4, mask, out0, out1;
372   v16u8 filt_hz, filt_vt, vec0;
373   v8u16 hz_out0, hz_out1, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8;
374   v8i16 filt;
375 
376   mask = LD_SB(&mc_filt_mask_arr[0]);
377 
378   /* rearranging filter */
379   filt = LD_SH(filter_horiz);
380   filt_hz = (v16u8)__msa_splati_h(filt, 0);
381 
382   filt = LD_SH(filter_vert);
383   filt_vt = (v16u8)__msa_splati_h(filt, 0);
384 
385   src0 = LD_SB(src);
386   src += src_stride;
387 
388   hz_out0 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz, FILTER_BITS);
389 
390   for (loop_cnt = (height >> 3); loop_cnt--;) {
391     LD_SB4(src, src_stride, src1, src2, src3, src4);
392     src += (4 * src_stride);
393 
394     hz_out1 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, FILTER_BITS);
395     vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
396     tmp1 = __msa_dotp_u_h(vec0, filt_vt);
397 
398     hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz, FILTER_BITS);
399     vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
400     tmp2 = __msa_dotp_u_h(vec0, filt_vt);
401 
402     SRARI_H2_UH(tmp1, tmp2, FILTER_BITS);
403 
404     hz_out1 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz, FILTER_BITS);
405     vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
406     tmp3 = __msa_dotp_u_h(vec0, filt_vt);
407 
408     hz_out0 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz, FILTER_BITS);
409     LD_SB4(src, src_stride, src1, src2, src3, src4);
410     src += (4 * src_stride);
411     vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
412     tmp4 = __msa_dotp_u_h(vec0, filt_vt);
413 
414     SRARI_H2_UH(tmp3, tmp4, FILTER_BITS);
415     PCKEV_B2_SB(tmp2, tmp1, tmp4, tmp3, out0, out1);
416     ST8x4_UB(out0, out1, dst, dst_stride);
417     dst += (4 * dst_stride);
418 
419     hz_out1 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, FILTER_BITS);
420     vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
421     tmp5 = __msa_dotp_u_h(vec0, filt_vt);
422 
423     hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz, FILTER_BITS);
424     vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
425     tmp6 = __msa_dotp_u_h(vec0, filt_vt);
426 
427     hz_out1 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz, FILTER_BITS);
428     vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out1, (v16i8)hz_out0);
429     tmp7 = __msa_dotp_u_h(vec0, filt_vt);
430 
431     hz_out0 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz, FILTER_BITS);
432     vec0 = (v16u8)__msa_ilvev_b((v16i8)hz_out0, (v16i8)hz_out1);
433     tmp8 = __msa_dotp_u_h(vec0, filt_vt);
434 
435     SRARI_H4_UH(tmp5, tmp6, tmp7, tmp8, FILTER_BITS);
436     PCKEV_B2_SB(tmp6, tmp5, tmp8, tmp7, out0, out1);
437     ST8x4_UB(out0, out1, dst, dst_stride);
438     dst += (4 * dst_stride);
439   }
440 }
441 
common_hv_2ht_2vt_8w_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)442 static void common_hv_2ht_2vt_8w_msa(const uint8_t *src, int32_t src_stride,
443                                      uint8_t *dst, int32_t dst_stride,
444                                      int8_t *filter_horiz, int8_t *filter_vert,
445                                      int32_t height) {
446   if (4 == height) {
447     common_hv_2ht_2vt_8x4_msa(src, src_stride, dst, dst_stride, filter_horiz,
448                               filter_vert);
449   } else {
450     common_hv_2ht_2vt_8x8mult_msa(src, src_stride, dst, dst_stride,
451                                   filter_horiz, filter_vert, height);
452   }
453 }
454 
common_hv_2ht_2vt_16w_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)455 static void common_hv_2ht_2vt_16w_msa(const uint8_t *src, int32_t src_stride,
456                                       uint8_t *dst, int32_t dst_stride,
457                                       int8_t *filter_horiz, int8_t *filter_vert,
458                                       int32_t height) {
459   uint32_t loop_cnt;
460   v16i8 src0, src1, src2, src3, src4, src5, src6, src7, mask;
461   v16u8 filt_hz, filt_vt, vec0, vec1;
462   v8u16 tmp1, tmp2, hz_out0, hz_out1, hz_out2, hz_out3;
463   v8i16 filt;
464 
465   mask = LD_SB(&mc_filt_mask_arr[0]);
466 
467   /* rearranging filter */
468   filt = LD_SH(filter_horiz);
469   filt_hz = (v16u8)__msa_splati_h(filt, 0);
470 
471   filt = LD_SH(filter_vert);
472   filt_vt = (v16u8)__msa_splati_h(filt, 0);
473 
474   LD_SB2(src, 8, src0, src1);
475   src += src_stride;
476 
477   hz_out0 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz, FILTER_BITS);
478   hz_out2 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, FILTER_BITS);
479 
480   for (loop_cnt = (height >> 2); loop_cnt--;) {
481     LD_SB4(src, src_stride, src0, src2, src4, src6);
482     LD_SB4(src + 8, src_stride, src1, src3, src5, src7);
483     src += (4 * src_stride);
484 
485     hz_out1 = HORIZ_2TAP_FILT_UH(src0, src0, mask, filt_hz, FILTER_BITS);
486     hz_out3 = HORIZ_2TAP_FILT_UH(src1, src1, mask, filt_hz, FILTER_BITS);
487     ILVEV_B2_UB(hz_out0, hz_out1, hz_out2, hz_out3, vec0, vec1);
488     DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
489     SRARI_H2_UH(tmp1, tmp2, FILTER_BITS);
490     PCKEV_ST_SB(tmp1, tmp2, dst);
491     dst += dst_stride;
492 
493     hz_out0 = HORIZ_2TAP_FILT_UH(src2, src2, mask, filt_hz, FILTER_BITS);
494     hz_out2 = HORIZ_2TAP_FILT_UH(src3, src3, mask, filt_hz, FILTER_BITS);
495     ILVEV_B2_UB(hz_out1, hz_out0, hz_out3, hz_out2, vec0, vec1);
496     DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
497     SRARI_H2_UH(tmp1, tmp2, FILTER_BITS);
498     PCKEV_ST_SB(tmp1, tmp2, dst);
499     dst += dst_stride;
500 
501     hz_out1 = HORIZ_2TAP_FILT_UH(src4, src4, mask, filt_hz, FILTER_BITS);
502     hz_out3 = HORIZ_2TAP_FILT_UH(src5, src5, mask, filt_hz, FILTER_BITS);
503     ILVEV_B2_UB(hz_out0, hz_out1, hz_out2, hz_out3, vec0, vec1);
504     DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
505     SRARI_H2_UH(tmp1, tmp2, FILTER_BITS);
506     PCKEV_ST_SB(tmp1, tmp2, dst);
507     dst += dst_stride;
508 
509     hz_out0 = HORIZ_2TAP_FILT_UH(src6, src6, mask, filt_hz, FILTER_BITS);
510     hz_out2 = HORIZ_2TAP_FILT_UH(src7, src7, mask, filt_hz, FILTER_BITS);
511     ILVEV_B2_UB(hz_out1, hz_out0, hz_out3, hz_out2, vec0, vec1);
512     DOTP_UB2_UH(vec0, vec1, filt_vt, filt_vt, tmp1, tmp2);
513     SRARI_H2_UH(tmp1, tmp2, FILTER_BITS);
514     PCKEV_ST_SB(tmp1, tmp2, dst);
515     dst += dst_stride;
516   }
517 }
518 
common_hv_2ht_2vt_32w_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)519 static void common_hv_2ht_2vt_32w_msa(const uint8_t *src, int32_t src_stride,
520                                       uint8_t *dst, int32_t dst_stride,
521                                       int8_t *filter_horiz, int8_t *filter_vert,
522                                       int32_t height) {
523   int32_t multiple8_cnt;
524   for (multiple8_cnt = 2; multiple8_cnt--;) {
525     common_hv_2ht_2vt_16w_msa(src, src_stride, dst, dst_stride, filter_horiz,
526                               filter_vert, height);
527     src += 16;
528     dst += 16;
529   }
530 }
531 
common_hv_2ht_2vt_64w_msa(const uint8_t * src,int32_t src_stride,uint8_t * dst,int32_t dst_stride,int8_t * filter_horiz,int8_t * filter_vert,int32_t height)532 static void common_hv_2ht_2vt_64w_msa(const uint8_t *src, int32_t src_stride,
533                                       uint8_t *dst, int32_t dst_stride,
534                                       int8_t *filter_horiz, int8_t *filter_vert,
535                                       int32_t height) {
536   int32_t multiple8_cnt;
537   for (multiple8_cnt = 4; multiple8_cnt--;) {
538     common_hv_2ht_2vt_16w_msa(src, src_stride, dst, dst_stride, filter_horiz,
539                               filter_vert, height);
540     src += 16;
541     dst += 16;
542   }
543 }
544 
vpx_convolve8_msa(const uint8_t * src,ptrdiff_t src_stride,uint8_t * dst,ptrdiff_t dst_stride,const int16_t * filter_x,int32_t x_step_q4,const int16_t * filter_y,int32_t y_step_q4,int32_t w,int32_t h)545 void vpx_convolve8_msa(const uint8_t *src, ptrdiff_t src_stride,
546                        uint8_t *dst, ptrdiff_t dst_stride,
547                        const int16_t *filter_x, int32_t x_step_q4,
548                        const int16_t *filter_y, int32_t y_step_q4,
549                        int32_t w, int32_t h) {
550   int8_t cnt, filt_hor[8], filt_ver[8];
551 
552   assert(x_step_q4 == 16);
553   assert(y_step_q4 == 16);
554   assert(((const int32_t *)filter_x)[1] != 0x800000);
555   assert(((const int32_t *)filter_y)[1] != 0x800000);
556 
557   for (cnt = 0; cnt < 8; ++cnt) {
558     filt_hor[cnt] = filter_x[cnt];
559     filt_ver[cnt] = filter_y[cnt];
560   }
561 
562   if (((const int32_t *)filter_x)[0] == 0 &&
563       ((const int32_t *)filter_y)[0] == 0) {
564     switch (w) {
565       case 4:
566         common_hv_2ht_2vt_4w_msa(src, (int32_t)src_stride,
567                                  dst, (int32_t)dst_stride,
568                                  &filt_hor[3], &filt_ver[3], (int32_t)h);
569         break;
570       case 8:
571         common_hv_2ht_2vt_8w_msa(src, (int32_t)src_stride,
572                                  dst, (int32_t)dst_stride,
573                                  &filt_hor[3], &filt_ver[3], (int32_t)h);
574         break;
575       case 16:
576         common_hv_2ht_2vt_16w_msa(src, (int32_t)src_stride,
577                                   dst, (int32_t)dst_stride,
578                                   &filt_hor[3], &filt_ver[3], (int32_t)h);
579         break;
580       case 32:
581         common_hv_2ht_2vt_32w_msa(src, (int32_t)src_stride,
582                                   dst, (int32_t)dst_stride,
583                                   &filt_hor[3], &filt_ver[3], (int32_t)h);
584         break;
585       case 64:
586         common_hv_2ht_2vt_64w_msa(src, (int32_t)src_stride,
587                                   dst, (int32_t)dst_stride,
588                                   &filt_hor[3], &filt_ver[3], (int32_t)h);
589         break;
590       default:
591         vpx_convolve8_c(src, src_stride, dst, dst_stride,
592                         filter_x, x_step_q4, filter_y, y_step_q4,
593                         w, h);
594         break;
595     }
596   } else if (((const int32_t *)filter_x)[0] == 0 ||
597              ((const int32_t *)filter_y)[0] == 0) {
598     vpx_convolve8_c(src, src_stride, dst, dst_stride,
599                     filter_x, x_step_q4, filter_y, y_step_q4,
600                     w, h);
601   } else {
602     switch (w) {
603       case 4:
604         common_hv_8ht_8vt_4w_msa(src, (int32_t)src_stride,
605                                  dst, (int32_t)dst_stride,
606                                  filt_hor, filt_ver, (int32_t)h);
607         break;
608       case 8:
609         common_hv_8ht_8vt_8w_msa(src, (int32_t)src_stride,
610                                  dst, (int32_t)dst_stride,
611                                  filt_hor, filt_ver, (int32_t)h);
612         break;
613       case 16:
614         common_hv_8ht_8vt_16w_msa(src, (int32_t)src_stride,
615                                   dst, (int32_t)dst_stride,
616                                   filt_hor, filt_ver, (int32_t)h);
617         break;
618       case 32:
619         common_hv_8ht_8vt_32w_msa(src, (int32_t)src_stride,
620                                   dst, (int32_t)dst_stride,
621                                   filt_hor, filt_ver, (int32_t)h);
622         break;
623       case 64:
624         common_hv_8ht_8vt_64w_msa(src, (int32_t)src_stride,
625                                   dst, (int32_t)dst_stride,
626                                   filt_hor, filt_ver, (int32_t)h);
627         break;
628       default:
629         vpx_convolve8_c(src, src_stride, dst, dst_stride,
630                         filter_x, x_step_q4, filter_y, y_step_q4,
631                         w, h);
632         break;
633     }
634   }
635 }
636