h264chroma_msa.c 79.8 KB
Newer Older
1
/*
2
 * Copyright (c) 2015 - 2017 Shivraj Patil (Shivraj.Patil@imgtec.com)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
 *
 * This file is part of FFmpeg.
 *
 * FFmpeg is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * FFmpeg is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with FFmpeg; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include "libavutil/mips/generic_macros_msa.h"
#include "h264chroma_mips.h"

static const uint8_t chroma_mask_arr[16 * 5] = {
    0, 1, 1, 2, 2, 3, 3, 4, 16, 17, 17, 18, 18, 19, 19, 20,
    0, 2, 2, 4, 4, 6, 6, 8, 16, 18, 18, 20, 20, 22, 22, 24,
    0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
    0, 1, 1, 2, 16, 17, 17, 18, 4, 5, 5, 6, 6, 7, 7, 8,
    0, 1, 1, 2, 16, 17, 17, 18, 16, 17, 17, 18, 18, 19, 19, 20
};

32
static void avc_chroma_hz_2x2_msa(uint8_t *src, uint8_t *dst, int32_t stride,
33 34 35 36 37 38 39 40 41 42 43 44 45
                                  uint32_t coeff0, uint32_t coeff1)
{
    uint16_t out0, out1;
    v16i8 src0, src1;
    v8u16 res_r;
    v8i16 res;
    v16i8 mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[0]);

46
    LD_SB2(src, stride, src0, src1);
47 48 49 50 51 52 53 54 55 56 57 58

    src0 = __msa_vshf_b(mask, src1, src0);
    res_r = __msa_dotp_u_h((v16u8) src0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);
    res = (v8i16) __msa_pckev_b((v16i8) res_r, (v16i8) res_r);

    out0 = __msa_copy_u_h(res, 0);
    out1 = __msa_copy_u_h(res, 2);

    SH(out0, dst);
59
    dst += stride;
60 61 62
    SH(out1, dst);
}

63
static void avc_chroma_hz_2x4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
64 65 66 67 68 69 70 71 72 73 74 75
                                  uint32_t coeff0, uint32_t coeff1)
{
    v16u8 src0, src1, src2, src3;
    v8u16 res_r;
    v8i16 res;
    v16i8 mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[64]);

76
    LD_UB4(src, stride, src0, src1, src2, src3);
77 78 79 80 81 82 83 84 85 86 87

    VSHF_B2_UB(src0, src1, src2, src3, mask, mask, src0, src2);

    src0 = (v16u8) __msa_ilvr_d((v2i64) src2, (v2i64) src0);

    res_r = __msa_dotp_u_h(src0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);
    res = (v8i16) __msa_pckev_b((v16i8) res_r, (v16i8) res_r);

88
    ST_H4(res, 0, 1, 2, 3, dst, stride);
89 90
}

91
static void avc_chroma_hz_2w_msa(uint8_t *src, uint8_t *dst, int32_t stride,
92 93 94 95
                                 uint32_t coeff0, uint32_t coeff1,
                                 int32_t height)
{
    if (2 == height) {
96
        avc_chroma_hz_2x2_msa(src, dst, stride, coeff0, coeff1);
97
    } else if (4 == height) {
98
        avc_chroma_hz_2x4_msa(src, dst, stride, coeff0, coeff1);
99 100 101
    }
}

102
static void avc_chroma_hz_4x2_msa(uint8_t *src, uint8_t *dst, int32_t stride,
103 104 105 106 107 108 109 110 111 112 113 114
                                  uint32_t coeff0, uint32_t coeff1)
{
    v16i8 src0, src1;
    v8u16 res_r;
    v4i32 res;
    v16i8 mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[0]);

115
    LD_SB2(src, stride, src0, src1);
116 117 118 119 120 121 122 123

    src0 = __msa_vshf_b(mask, src1, src0);
    res_r = __msa_dotp_u_h((v16u8) src0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);
    res = (v4i32) __msa_pckev_b((v16i8) res_r, (v16i8) res_r);

124
    ST_W2(res, 0, 1, dst, stride);
125 126
}

127 128
static void avc_chroma_hz_4x4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coeff0, uint32_t coeff1)
129
{
130
    v16u8 src0, src1, src2, src3, out;
131 132 133 134 135 136 137 138
    v8u16 res0_r, res1_r;
    v16i8 mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[0]);

139 140 141 142 143 144 145 146
    LD_UB4(src, stride, src0, src1, src2, src3);
    VSHF_B2_UB(src0, src1, src2, src3, mask, mask, src0, src2);
    DOTP_UB2_UH(src0, src2, coeff_vec, coeff_vec, res0_r, res1_r);
    res0_r <<= 3;
    res1_r <<= 3;
    SRARI_H2_UH(res0_r, res1_r, 6);
    SAT_UH2_UH(res0_r, res1_r, 7);
    out = (v16u8) __msa_pckev_b((v16i8) res1_r, (v16i8) res0_r);
147
    ST_W4(out, 0, 1, 2, 3, dst, stride);
148
}
149

150 151 152 153 154 155 156 157 158
static void avc_chroma_hz_4x8_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coeff0, uint32_t coeff1)
{
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, out0, out1;
    v16i8 mask;
    v8u16 res0, res1, res2, res3;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);
159

160
    mask = LD_SB(&chroma_mask_arr[0]);
161

162 163 164 165 166 167 168 169 170
    LD_UB8(src, stride, src0, src1, src2, src3, src4, src5, src6, src7);
    VSHF_B2_UB(src0, src1, src2, src3, mask, mask, src0, src2);
    VSHF_B2_UB(src4, src5, src6, src7, mask, mask, src4, src6);
    DOTP_UB2_UH(src0, src2, coeff_vec, coeff_vec, res0, res1);
    DOTP_UB2_UH(src4, src6, coeff_vec, coeff_vec, res2, res3);
    SLLI_4V(res0, res1, res2, res3, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
171
    ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, stride);
172 173
}

174
static void avc_chroma_hz_4w_msa(uint8_t *src, uint8_t *dst, int32_t stride,
175 176 177 178
                                 uint32_t coeff0, uint32_t coeff1,
                                 int32_t height)
{
    if (2 == height) {
179 180 181 182 183
        avc_chroma_hz_4x2_msa(src, dst, stride, coeff0, coeff1);
    } else if (4 == height) {
        avc_chroma_hz_4x4_msa(src, dst, stride, coeff0, coeff1);
    } else if (8 == height) {
        avc_chroma_hz_4x8_msa(src, dst, stride, coeff0, coeff1);
184 185 186
    }
}

187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
static void avc_chroma_hz_8x4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coeff0, uint32_t coeff1)
{
    v16u8 src0, src1, src2, src3, out0, out1;
    v8u16 res0, res1, res2, res3;
    v16i8 mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[32]);
    LD_UB4(src, stride, src0, src1, src2, src3);
    VSHF_B2_UB(src0, src0, src1, src1, mask, mask, src0, src1);
    VSHF_B2_UB(src2, src2, src3, src3, mask, mask, src2, src3);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res0, res1, res2, res3);
    SLLI_4V(res0, res1, res2, res3, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
207
    ST_D4(out0, out1, 0, 1, 0, 1, dst, stride);
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
}

static void avc_chroma_hz_8x8_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coeff0, uint32_t coeff1)
{
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7;
    v16u8 out0, out1, out2, out3;
    v8u16 res0, res1, res2, res3, res4, res5, res6, res7;
    v16i8 mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[32]);

    LD_UB8(src, stride, src0, src1, src2, src3, src4, src5, src6, src7);
    VSHF_B2_UB(src0, src0, src1, src1, mask, mask, src0, src1);
    VSHF_B2_UB(src2, src2, src3, src3, mask, mask, src2, src3);
    VSHF_B2_UB(src4, src4, src5, src5, mask, mask, src4, src5);
    VSHF_B2_UB(src6, src6, src7, src7, mask, mask, src6, src7);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res0, res1, res2, res3);
    DOTP_UB4_UH(src4, src5, src6, src7, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res4, res5, res6, res7);
    SLLI_4V(res0, res1, res2, res3, 3);
    SLLI_4V(res4, res5, res6, res7, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SRARI_H4_UH(res4, res5, res6, res7, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    SAT_UH4_UH(res4, res5, res6, res7, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
    PCKEV_B2_UB(res5, res4, res7, res6, out2, out3);
240
    ST_D8(out0, out1, out2, out3, 0, 1, 0, 1, 0, 1, 0, 1, dst, stride);
241 242 243 244 245
}

static void avc_chroma_hz_nonmult_msa(uint8_t *src, uint8_t *dst,
                                      int32_t stride, uint32_t coeff0,
                                      uint32_t coeff1, int32_t height)
246 247 248 249 250 251 252 253 254 255 256 257
{
    uint32_t row;
    v16u8 src0, src1, src2, src3, out0, out1;
    v8u16 res0, res1, res2, res3;
    v16i8 mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[32]);

    for (row = height >> 2; row--;) {
258 259
        LD_UB4(src, stride, src0, src1, src2, src3);
        src += (4 * stride);
260 261 262 263 264 265 266 267 268

        VSHF_B2_UB(src0, src0, src1, src1, mask, mask, src0, src1);
        VSHF_B2_UB(src2, src2, src3, src3, mask, mask, src2, src3);
        DOTP_UB4_UH(src0, src1, src2, src3, coeff_vec, coeff_vec, coeff_vec,
                    coeff_vec, res0, res1, res2, res3);
        SLLI_4V(res0, res1, res2, res3, 3);
        SRARI_H4_UH(res0, res1, res2, res3, 6);
        SAT_UH4_UH(res0, res1, res2, res3, 7);
        PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
269
        ST_D4(out0, out1, 0, 1, 0, 1, dst, stride);
270
        dst += (4 * stride);
271 272 273 274 275
    }

    if (0 != (height % 4)) {
        for (row = (height % 4); row--;) {
            src0 = LD_UB(src);
276
            src += stride;
277 278 279 280 281 282 283 284 285

            src0 = (v16u8) __msa_vshf_b(mask, (v16i8) src0, (v16i8) src0);

            res0 = __msa_dotp_u_h(src0, coeff_vec);
            res0 <<= 3;
            res0 = (v8u16) __msa_srari_h((v8i16) res0, 6);
            res0 = __msa_sat_u_h(res0, 7);
            res0 = (v8u16) __msa_pckev_b((v16i8) res0, (v16i8) res0);

286
            ST_D1(res0, 0, dst);
287
            dst += stride;
288 289 290 291
        }
    }
}

292 293 294 295 296 297 298 299 300 301 302 303 304
static void avc_chroma_hz_8w_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                 uint32_t coeff0, uint32_t coeff1,
                                 int32_t height)
{
    if (4 == height) {
        avc_chroma_hz_8x4_msa(src, dst, stride, coeff0, coeff1);
    } else if (8 == height) {
        avc_chroma_hz_8x8_msa(src, dst, stride, coeff0, coeff1);
    } else {
        avc_chroma_hz_nonmult_msa(src, dst, stride, coeff0, coeff1, height);
    }
}

305
static void avc_chroma_vt_2x2_msa(uint8_t *src, uint8_t *dst, int32_t stride,
306 307 308 309 310 311 312 313 314 315 316
                                  uint32_t coeff0, uint32_t coeff1)
{
    uint16_t out0, out1;
    v16i8 src0, src1, src2;
    v16u8 tmp0, tmp1;
    v8i16 res;
    v8u16 res_r;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

317
    LD_SB3(src, stride, src0, src1, src2);
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332

    ILVR_B2_UB(src1, src0, src2, src1, tmp0, tmp1);

    tmp0 = (v16u8) __msa_ilvr_d((v2i64) tmp1, (v2i64) tmp0);

    res_r = __msa_dotp_u_h(tmp0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);
    res = (v8i16) __msa_pckev_b((v16i8) res_r, (v16i8) res_r);

    out0 = __msa_copy_u_h(res, 0);
    out1 = __msa_copy_u_h(res, 2);

    SH(out0, dst);
333
    dst += stride;
334 335 336
    SH(out1, dst);
}

337
static void avc_chroma_vt_2x4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
338 339 340 341 342 343 344 345 346 347
                                  uint32_t coeff0, uint32_t coeff1)
{
    v16u8 src0, src1, src2, src3, src4;
    v16u8 tmp0, tmp1, tmp2, tmp3;
    v8i16 res;
    v8u16 res_r;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

348
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
349 350 351 352 353 354 355 356 357 358 359 360 361
    ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3,
               tmp0, tmp1, tmp2, tmp3);
    ILVR_W2_UB(tmp1, tmp0, tmp3, tmp2, tmp0, tmp2);

    tmp0 = (v16u8) __msa_ilvr_d((v2i64) tmp2, (v2i64) tmp0);

    res_r = __msa_dotp_u_h(tmp0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);

    res = (v8i16) __msa_pckev_b((v16i8) res_r, (v16i8) res_r);

362
    ST_H4(res, 0, 1, 2, 3, dst, stride);
363 364
}

365
static void avc_chroma_vt_2w_msa(uint8_t *src, uint8_t *dst, int32_t stride,
366 367 368 369
                                 uint32_t coeff0, uint32_t coeff1,
                                 int32_t height)
{
    if (2 == height) {
370
        avc_chroma_vt_2x2_msa(src, dst, stride, coeff0, coeff1);
371
    } else if (4 == height) {
372
        avc_chroma_vt_2x4_msa(src, dst, stride, coeff0, coeff1);
373 374 375
    }
}

376
static void avc_chroma_vt_4x2_msa(uint8_t *src, uint8_t *dst, int32_t stride,
377 378 379 380 381 382 383 384 385 386
                                  uint32_t coeff0, uint32_t coeff1)
{
    v16u8 src0, src1, src2;
    v16u8 tmp0, tmp1;
    v4i32 res;
    v8u16 res_r;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

387
    LD_UB3(src, stride, src0, src1, src2);
388 389 390 391 392 393 394 395 396
    ILVR_B2_UB(src1, src0, src2, src1, tmp0, tmp1);

    tmp0 = (v16u8) __msa_ilvr_d((v2i64) tmp1, (v2i64) tmp0);
    res_r = __msa_dotp_u_h(tmp0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);
    res = (v4i32) __msa_pckev_b((v16i8) res_r, (v16i8) res_r);

397
    ST_W2(res, 0, 1, dst, stride);
398 399
}

400 401
static void avc_chroma_vt_4x4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coeff0, uint32_t coeff1)
402 403 404
{
    v16u8 src0, src1, src2, src3, src4;
    v16u8 tmp0, tmp1, tmp2, tmp3;
405
    v16u8 out;
406 407 408 409 410
    v8u16 res0_r, res1_r;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

411 412 413 414 415 416 417 418 419 420
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3, tmp0, tmp1, tmp2,
               tmp3);
    ILVR_D2_UB(tmp1, tmp0, tmp3, tmp2, tmp0, tmp2);
    DOTP_UB2_UH(tmp0, tmp2, coeff_vec, coeff_vec, res0_r, res1_r);
    res0_r <<= 3;
    res1_r <<= 3;
    SRARI_H2_UH(res0_r, res1_r, 6);
    SAT_UH2_UH(res0_r, res1_r, 7);
    out = (v16u8) __msa_pckev_b((v16i8) res1_r, (v16i8) res0_r);
421
    ST_W4(out, 0, 1, 2, 3, dst, stride);
422
}
423

424 425 426 427 428 429 430 431 432
static void avc_chroma_vt_4x8_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coeff0, uint32_t coeff1)
{
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
    v16u8 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, out0, out1;
    v8u16 res0, res1, res2, res3;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);
433

434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    src += (5 * stride);
    LD_UB4(src, stride, src5, src6, src7, src8);
    ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3, tmp0, tmp1, tmp2,
               tmp3);
    ILVR_B4_UB(src5, src4, src6, src5, src7, src6, src8, src7, tmp4, tmp5, tmp6,
               tmp7);
    ILVR_D2_UB(tmp1, tmp0, tmp3, tmp2, tmp0, tmp2);
    ILVR_D2_UB(tmp5, tmp4, tmp7, tmp6, tmp4, tmp6);
    DOTP_UB2_UH(tmp0, tmp2, coeff_vec, coeff_vec, res0, res1);
    DOTP_UB2_UH(tmp4, tmp6, coeff_vec, coeff_vec, res2, res3);
    SLLI_4V(res0, res1, res2, res3, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
449
    ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, stride);
450 451
}

452
static void avc_chroma_vt_4w_msa(uint8_t *src, uint8_t *dst, int32_t stride,
453 454 455 456
                                 uint32_t coeff0, uint32_t coeff1,
                                 int32_t height)
{
    if (2 == height) {
457 458 459 460 461
        avc_chroma_vt_4x2_msa(src, dst, stride, coeff0, coeff1);
    } else if (4 == height) {
        avc_chroma_vt_4x4_msa(src, dst, stride, coeff0, coeff1);
    } else if (8 == height) {
        avc_chroma_vt_4x8_msa(src, dst, stride, coeff0, coeff1);
462 463 464
    }
}

465 466
static void avc_chroma_vt_8x4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coeff0, uint32_t coeff1)
467 468 469 470 471 472 473
{
    v16u8 src0, src1, src2, src3, src4, out0, out1;
    v8u16 res0, res1, res2, res3;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

474 475 476 477 478 479 480 481 482
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3, src0, src1, src2,
               src3);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res0, res1, res2, res3);
    SLLI_4V(res0, res1, res2, res3, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
483
    ST_D4(out0, out1, 0, 1, 0, 1, dst, stride);
484
}
485

486 487 488 489 490 491 492 493 494
static void avc_chroma_vt_8x8_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coeff0, uint32_t coeff1)
{
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
    v16u8 out0, out1, out2, out3;
    v8u16 res0, res1, res2, res3, res4, res5, res6, res7;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);
495

496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    src += (5 * stride);
    LD_UB4(src, stride, src5, src6, src7, src8);
    ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3, src0, src1, src2,
               src3);
    ILVR_B4_UB(src5, src4, src6, src5, src7, src6, src8, src7, src4, src5, src6,
               src7);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res0, res1, res2, res3);
    DOTP_UB4_UH(src4, src5, src6, src7, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res4, res5, res6, res7);
    SLLI_4V(res0, res1, res2, res3, 3);
    SLLI_4V(res4, res5, res6, res7, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SRARI_H4_UH(res4, res5, res6, res7, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
    PCKEV_B2_UB(res5, res4, res7, res6, out2, out3);
515
    ST_D8(out0, out1, out2, out3, 0, 1, 0, 1, 0, 1, 0, 1, dst, stride);
516
}
517

518 519 520 521 522 523 524 525
static void avc_chroma_vt_8w_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                 uint32_t coeff0, uint32_t coeff1,
                                 int32_t height)
{
    if (4 == height) {
        avc_chroma_vt_8x4_msa(src, dst, stride, coeff0, coeff1);
    } else if (8 == height) {
        avc_chroma_vt_8x8_msa(src, dst, stride, coeff0, coeff1);
526 527 528
    }
}

529
static void avc_chroma_hv_2x2_msa(uint8_t *src, uint8_t *dst, int32_t stride,
530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
                                  uint32_t coef_hor0, uint32_t coef_hor1,
                                  uint32_t coef_ver0, uint32_t coef_ver1)
{
    uint16_t out0, out1;
    v16u8 src0, src1, src2;
    v8u16 res_hz0, res_hz1, res_vt0, res_vt1;
    v8i16 res_vert;
    v16i8 mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[48]);

546
    LD_UB3(src, stride, src0, src1, src2);
547 548 549 550 551 552 553 554 555 556 557 558 559
    VSHF_B2_UB(src0, src1, src1, src2, mask, mask, src0, src1);
    DOTP_UB2_UH(src0, src1, coeff_hz_vec, coeff_hz_vec, res_hz0, res_hz1);
    MUL2(res_hz0, coeff_vt_vec1, res_hz1, coeff_vt_vec0, res_vt0, res_vt1);

    res_vt0 += res_vt1;
    res_vt0 = (v8u16) __msa_srari_h((v8i16) res_vt0, 6);
    res_vt0 = __msa_sat_u_h(res_vt0, 7);
    res_vert = (v8i16) __msa_pckev_b((v16i8) res_vt0, (v16i8) res_vt0);

    out0 = __msa_copy_u_h(res_vert, 0);
    out1 = __msa_copy_u_h(res_vert, 1);

    SH(out0, dst);
560
    dst += stride;
561 562 563
    SH(out1, dst);
}

564
static void avc_chroma_hv_2x4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580
                                  uint32_t coef_hor0, uint32_t coef_hor1,
                                  uint32_t coef_ver0, uint32_t coef_ver1)
{
    v16u8 src0, src1, src2, src3, src4;
    v16u8 tmp0, tmp1, tmp2, tmp3;
    v8u16 res_hz0, res_hz1, res_vt0, res_vt1;
    v8i16 res;
    v16i8 mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[48]);

581
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
582 583 584 585 586 587 588 589 590 591 592 593 594

    VSHF_B2_UB(src0, src1, src2, src3, mask, mask, tmp0, tmp1);
    VSHF_B2_UB(src1, src2, src3, src4, mask, mask, tmp2, tmp3);
    ILVR_D2_UB(tmp1, tmp0, tmp3, tmp2, src0, src1);
    DOTP_UB2_UH(src0, src1, coeff_hz_vec, coeff_hz_vec, res_hz0, res_hz1);
    MUL2(res_hz0, coeff_vt_vec1, res_hz1, coeff_vt_vec0, res_vt0, res_vt1);

    res_vt0 += res_vt1;
    res_vt0 = (v8u16) __msa_srari_h((v8i16) res_vt0, 6);
    res_vt0 = __msa_sat_u_h(res_vt0, 7);

    res = (v8i16) __msa_pckev_b((v16i8) res_vt0, (v16i8) res_vt0);

595
    ST_H4(res, 0, 1, 2, 3, dst, stride);
596 597
}

598
static void avc_chroma_hv_2w_msa(uint8_t *src, uint8_t *dst, int32_t stride,
599 600 601 602 603
                                 uint32_t coef_hor0, uint32_t coef_hor1,
                                 uint32_t coef_ver0, uint32_t coef_ver1,
                                 int32_t height)
{
    if (2 == height) {
604 605
        avc_chroma_hv_2x2_msa(src, dst, stride, coef_hor0, coef_hor1, coef_ver0,
                              coef_ver1);
606
    } else if (4 == height) {
607 608
        avc_chroma_hv_2x4_msa(src, dst, stride, coef_hor0, coef_hor1, coef_ver0,
                              coef_ver1);
609 610 611
    }
}

612
static void avc_chroma_hv_4x2_msa(uint8_t *src, uint8_t *dst, int32_t stride,
613 614 615 616 617 618 619 620 621 622 623 624 625 626
                                  uint32_t coef_hor0, uint32_t coef_hor1,
                                  uint32_t coef_ver0, uint32_t coef_ver1)
{
    v16u8 src0, src1, src2;
    v8u16 res_hz0, res_hz1, res_vt0, res_vt1;
    v16i8 mask;
    v4i32 res;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[0]);
627
    LD_UB3(src, stride, src0, src1, src2);
628 629 630 631 632 633 634 635 636
    VSHF_B2_UB(src0, src1, src1, src2, mask, mask, src0, src1);
    DOTP_UB2_UH(src0, src1, coeff_hz_vec, coeff_hz_vec, res_hz0, res_hz1);
    MUL2(res_hz0, coeff_vt_vec1, res_hz1, coeff_vt_vec0, res_vt0, res_vt1);

    res_vt0 += res_vt1;
    res_vt0 = (v8u16) __msa_srari_h((v8i16) res_vt0, 6);
    res_vt0 = __msa_sat_u_h(res_vt0, 7);
    res = (v4i32) __msa_pckev_b((v16i8) res_vt0, (v16i8) res_vt0);

637
    ST_W2(res, 0, 1, dst, stride);
638 639
}

640 641 642
static void avc_chroma_hv_4x4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coef_hor0, uint32_t coef_hor1,
                                  uint32_t coef_ver0, uint32_t coef_ver1)
643 644 645 646 647 648 649 650 651 652 653 654 655 656
{
    v16u8 src0, src1, src2, src3, src4;
    v8u16 res_hz0, res_hz1, res_hz2, res_hz3;
    v8u16 res_vt0, res_vt1, res_vt2, res_vt3;
    v16i8 mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);
    v4i32 res0, res1;

    mask = LD_SB(&chroma_mask_arr[0]);

657 658 659 660 661 662 663 664 665 666 667 668
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    VSHF_B2_UB(src0, src1, src1, src2, mask, mask, src0, src1);
    VSHF_B2_UB(src2, src3, src3, src4, mask, mask, src2, src3);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz0, res_hz1, res_hz2,
                res_hz3);
    MUL4(res_hz0, coeff_vt_vec1, res_hz1, coeff_vt_vec0, res_hz2, coeff_vt_vec1,
         res_hz3, coeff_vt_vec0, res_vt0, res_vt1, res_vt2, res_vt3);
    ADD2(res_vt0, res_vt1, res_vt2, res_vt3, res_vt0, res_vt1);
    SRARI_H2_UH(res_vt0, res_vt1, 6);
    SAT_UH2_UH(res_vt0, res_vt1, 7);
    PCKEV_B2_SW(res_vt0, res_vt0, res_vt1, res_vt1, res0, res1);
669 670
    ST_W2(res0, 0, 1, dst, stride);
    ST_W2(res1, 0, 1, dst + 2 * stride, stride);
671
}
672

673 674 675 676 677 678 679 680 681 682 683 684 685
static void avc_chroma_hv_4x8_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coef_hor0, uint32_t coef_hor1,
                                  uint32_t coef_ver0, uint32_t coef_ver1)
{
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8, res0, res1;
    v8u16 res_hz0, res_hz1, res_hz2, res_hz3, res_hz4, res_hz5, res_hz6, res_hz7;
    v8u16 res_vt0, res_vt1, res_vt2, res_vt3, res_vt4, res_vt5, res_vt6, res_vt7;
    v16i8 mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);
686

687
    mask = LD_SB(&chroma_mask_arr[0]);
688

689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    src += (5 * stride);
    LD_UB4(src, stride, src5, src6, src7, src8);

    VSHF_B2_UB(src0, src1, src1, src2, mask, mask, src0, src1);
    VSHF_B2_UB(src2, src3, src3, src4, mask, mask, src2, src3);
    VSHF_B2_UB(src4, src5, src5, src6, mask, mask, src4, src5);
    VSHF_B2_UB(src6, src7, src7, src8, mask, mask, src6, src7);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz0, res_hz1, res_hz2, res_hz3);
    DOTP_UB4_UH(src4, src5, src6, src7, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz4, res_hz5, res_hz6, res_hz7);
    MUL4(res_hz0, coeff_vt_vec1, res_hz1, coeff_vt_vec0, res_hz2, coeff_vt_vec1,
         res_hz3, coeff_vt_vec0, res_vt0, res_vt1, res_vt2, res_vt3);
    MUL4(res_hz4, coeff_vt_vec1, res_hz5, coeff_vt_vec0, res_hz6, coeff_vt_vec1,
         res_hz7, coeff_vt_vec0, res_vt4, res_vt5, res_vt6, res_vt7);
    ADD2(res_vt0, res_vt1, res_vt2, res_vt3, res_vt0, res_vt1);
    ADD2(res_vt4, res_vt5, res_vt6, res_vt7, res_vt2, res_vt3);
    SRARI_H4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 6);
    SAT_UH4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 7);
    PCKEV_B2_UB(res_vt1, res_vt0, res_vt3, res_vt2, res0, res1);
710
    ST_W8(res0, res1, 0, 1, 2, 3, 0, 1, 2, 3, dst, stride);
711 712
}

713
static void avc_chroma_hv_4w_msa(uint8_t *src, uint8_t *dst, int32_t stride,
714 715 716 717 718
                                 uint32_t coef_hor0, uint32_t coef_hor1,
                                 uint32_t coef_ver0, uint32_t coef_ver1,
                                 int32_t height)
{
    if (2 == height) {
719 720 721 722 723 724 725 726
        avc_chroma_hv_4x2_msa(src, dst, stride, coef_hor0, coef_hor1, coef_ver0,
                              coef_ver1);
    } else if (4 == height) {
        avc_chroma_hv_4x4_msa(src, dst, stride, coef_hor0, coef_hor1, coef_ver0,
                              coef_ver1);
    } else if (8 == height) {
        avc_chroma_hv_4x8_msa(src, dst, stride, coef_hor0, coef_hor1, coef_ver0,
                              coef_ver1);
727 728 729
    }
}

730 731 732
static void avc_chroma_hv_8x4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coef_hor0, uint32_t coef_hor1,
                                  uint32_t coef_ver0, uint32_t coef_ver1)
733 734 735 736 737 738 739 740 741 742 743 744 745 746
{
    v16u8 src0, src1, src2, src3, src4, out0, out1;
    v8u16 res_hz0, res_hz1, res_hz2, res_hz3, res_hz4;
    v8u16 res_vt0, res_vt1, res_vt2, res_vt3;
    v16i8 mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[32]);

    src0 = LD_UB(src);
747
    src += stride;
748 749 750 751

    src0 = (v16u8) __msa_vshf_b(mask, (v16i8) src0, (v16i8) src0);
    res_hz0 = __msa_dotp_u_h(src0, coeff_hz_vec);

752 753
    LD_UB4(src, stride, src1, src2, src3, src4);
    src += (4 * stride);
754

755 756 757 758 759 760
    VSHF_B2_UB(src1, src1, src2, src2, mask, mask, src1, src2);
    VSHF_B2_UB(src3, src3, src4, src4, mask, mask, src3, src4);
    DOTP_UB4_UH(src1, src2, src3, src4, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz1, res_hz2, res_hz3, res_hz4);
    MUL4(res_hz1, coeff_vt_vec0, res_hz2, coeff_vt_vec0, res_hz3, coeff_vt_vec0,
         res_hz4, coeff_vt_vec0, res_vt0, res_vt1, res_vt2, res_vt3);
761

762 763 764 765
    res_vt0 += (res_hz0 * coeff_vt_vec1);
    res_vt1 += (res_hz1 * coeff_vt_vec1);
    res_vt2 += (res_hz2 * coeff_vt_vec1);
    res_vt3 += (res_hz3 * coeff_vt_vec1);
766

767 768 769
    SRARI_H4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 6);
    SAT_UH4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 7);
    PCKEV_B2_UB(res_vt1, res_vt0, res_vt3, res_vt2, out0, out1);
770
    ST_D4(out0, out1, 0, 1, 0, 1, dst, stride);
771
}
772

773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
static void avc_chroma_hv_8x8_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                  uint32_t coef_hor0, uint32_t coef_hor1,
                                  uint32_t coef_ver0, uint32_t coef_ver1)
{
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
    v16u8 out0, out1, out2, out3;
    v8u16 res_hz0, res_hz1, res_hz2, res_hz3, res_hz4;
    v8u16 res_hz5, res_hz6, res_hz7, res_hz8;
    v8u16 res_vt0, res_vt1, res_vt2, res_vt3;
    v8u16 res_vt4, res_vt5, res_vt6, res_vt7;
    v16i8 mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);
789

790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825
    mask = LD_SB(&chroma_mask_arr[32]);

    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    src += (5 * stride);
    LD_UB4(src, stride, src5, src6, src7, src8);
    src0 = (v16u8) __msa_vshf_b(mask, (v16i8) src0, (v16i8) src0);
    VSHF_B2_UB(src1, src1, src2, src2, mask, mask, src1, src2);
    VSHF_B2_UB(src3, src3, src4, src4, mask, mask, src3, src4);
    VSHF_B2_UB(src5, src5, src6, src6, mask, mask, src5, src6);
    VSHF_B2_UB(src7, src7, src8, src8, mask, mask, src7, src8);
    res_hz0 = __msa_dotp_u_h(src0, coeff_hz_vec);
    DOTP_UB4_UH(src1, src2, src3, src4, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz1, res_hz2, res_hz3,
                res_hz4);
    DOTP_UB4_UH(src5, src6, src7, src8, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz5, res_hz6, res_hz7, res_hz8);
    MUL4(res_hz1, coeff_vt_vec0, res_hz2, coeff_vt_vec0, res_hz3,
         coeff_vt_vec0, res_hz4, coeff_vt_vec0, res_vt0, res_vt1, res_vt2,
         res_vt3);
    MUL4(res_hz5, coeff_vt_vec0, res_hz6, coeff_vt_vec0, res_hz7,
         coeff_vt_vec0, res_hz8, coeff_vt_vec0, res_vt4, res_vt5, res_vt6,
         res_vt7);
    res_vt0 += (res_hz0 * coeff_vt_vec1);
    res_vt1 += (res_hz1 * coeff_vt_vec1);
    res_vt2 += (res_hz2 * coeff_vt_vec1);
    res_vt3 += (res_hz3 * coeff_vt_vec1);
    res_vt4 += (res_hz4 * coeff_vt_vec1);
    res_vt5 += (res_hz5 * coeff_vt_vec1);
    res_vt6 += (res_hz6 * coeff_vt_vec1);
    res_vt7 += (res_hz7 * coeff_vt_vec1);
    SRARI_H4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 6);
    SRARI_H4_UH(res_vt4, res_vt5, res_vt6, res_vt7, 6);
    SAT_UH4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 7);
    SAT_UH4_UH(res_vt4, res_vt5, res_vt6, res_vt7, 7);
    PCKEV_B2_UB(res_vt1, res_vt0, res_vt3, res_vt2, out0, out1);
    PCKEV_B2_UB(res_vt5, res_vt4, res_vt7, res_vt6, out2, out3);
826
    ST_D8(out0, out1, out2, out3, 0, 1, 0, 1, 0, 1, 0, 1, dst, stride);
827 828 829 830 831 832 833 834 835 836 837 838 839
}

static void avc_chroma_hv_8w_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                                 uint32_t coef_hor0, uint32_t coef_hor1,
                                 uint32_t coef_ver0, uint32_t coef_ver1,
                                 int32_t height)
{
    if (4 == height) {
        avc_chroma_hv_8x4_msa(src, dst, stride, coef_hor0, coef_hor1, coef_ver0,
                              coef_ver1);
    } else if (8 == height) {
        avc_chroma_hv_8x8_msa(src, dst, stride, coef_hor0, coef_hor1, coef_ver0,
                              coef_ver1);
840 841 842
    }
}

843 844 845
static void avc_chroma_hz_and_aver_dst_2x2_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
846 847 848 849 850 851 852 853 854 855 856 857 858
{
    uint16_t out0, out1;
    v16i8 src0, src1;
    v16u8 dst_data = { 0 };
    v8u16 res_r;
    v16u8 res;
    v16i8 mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[0]);

859
    LD_SB2(src, stride, src0, src1);
860

861 862
    out0 = LH(dst);
    out1 = LH(dst + stride);
863

864 865
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 0, out0);
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 2, out1);
866 867 868 869 870 871 872 873 874 875 876 877 878 879 880

    src0 = __msa_vshf_b(mask, src1, src0);

    res_r = __msa_dotp_u_h((v16u8) src0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);

    res = (v16u8) __msa_pckev_b((v16i8) res_r, (v16i8) res_r);
    dst_data = __msa_aver_u_b(res, dst_data);

    out0 = __msa_copy_u_h((v8i16) dst_data, 0);
    out1 = __msa_copy_u_h((v8i16) dst_data, 2);

    SH(out0, dst);
881
    dst += stride;
882 883 884
    SH(out1, dst);
}

885 886 887
static void avc_chroma_hz_and_aver_dst_2x4_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
888
{
889
    uint16_t tp0, tp1, tp2, tp3;
890
    v16u8 src0, src1, src2, src3;
891
    v16u8 dst0, dst_data = { 0 };
892
    v8u16 res_r;
893
    v16i8 mask;
894 895 896 897 898 899
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[64]);

900 901 902 903 904 905 906 907 908
    LD_UB4(src, stride, src0, src1, src2, src3);
    tp0 = LH(dst);
    tp1 = LH(dst + stride);
    tp2 = LH(dst + 2 * stride);
    tp3 = LH(dst + 3 * stride);
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 0, tp0);
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 1, tp1);
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 2, tp2);
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 3, tp3);
909 910 911 912 913 914 915 916 917 918

    VSHF_B2_UB(src0, src1, src2, src3, mask, mask, src0, src2);

    src0 = (v16u8) __msa_ilvr_d((v2i64) src2, (v2i64) src0);

    res_r = __msa_dotp_u_h(src0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);

919 920
    dst0 = (v16u8) __msa_pckev_b((v16i8) res_r, (v16i8) res_r);
    dst0 = __msa_aver_u_b(dst0, dst_data);
921

922
    ST_H4(dst0, 0, 1, 2, 3, dst, stride);
923 924
}

925 926 927
static void avc_chroma_hz_and_aver_dst_2w_msa(uint8_t *src, uint8_t *dst,
                                              int32_t stride, uint32_t coeff0,
                                              uint32_t coeff1, int32_t height)
928 929
{
    if (2 == height) {
930
        avc_chroma_hz_and_aver_dst_2x2_msa(src, dst, stride, coeff0, coeff1);
931
    } else if (4 == height) {
932
        avc_chroma_hz_and_aver_dst_2x4_msa(src, dst, stride, coeff0, coeff1);
933 934 935
    }
}

936 937 938
static void avc_chroma_hz_and_aver_dst_4x2_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
939 940 941 942 943 944 945 946 947 948 949 950
{
    uint32_t load0, load1;
    v16i8 src0, src1;
    v16u8 dst_data = { 0 };
    v8u16 res_r;
    v16i8 res, mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[0]);

951
    LD_SB2(src, stride, src0, src1);
952

953
    LW2(dst, stride, load0, load1);
954 955 956 957 958 959 960 961 962 963 964 965

    INSERT_W2_UB(load0, load1, dst_data);

    src0 = __msa_vshf_b(mask, src1, src0);

    res_r = __msa_dotp_u_h((v16u8) src0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);
    res = __msa_pckev_b((v16i8) res_r, (v16i8) res_r);
    dst_data = __msa_aver_u_b((v16u8) res, dst_data);

966
    ST_W2(dst_data, 0, 1, dst, stride);
967 968
}

969 970 971
static void avc_chroma_hz_and_aver_dst_4x4_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
972
{
973
    uint32_t tp0, tp1, tp2, tp3;
974
    v16u8 src0, src1, src2, src3;
975 976
    v16u8 out, dst_data = { 0 };
    v16i8 mask;
977 978 979 980 981
    v8u16 res0_r, res1_r;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

982
    mask = LD_SB(&chroma_mask_arr[0]);
983

984 985 986 987 988 989 990 991 992 993 994
    LD_UB4(src, stride, src0, src1, src2, src3);
    LW4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_W4_UB(tp0, tp1, tp2, tp3, dst_data);
    VSHF_B2_UB(src0, src1, src2, src3, mask, mask, src0, src2);
    DOTP_UB2_UH(src0, src2, coeff_vec, coeff_vec, res0_r, res1_r);
    res0_r <<= 3;
    res1_r <<= 3;
    SRARI_H2_UH(res0_r, res1_r, 6);
    SAT_UH2_UH(res0_r, res1_r, 7);
    out = (v16u8) __msa_pckev_b((v16i8) res1_r, (v16i8) res0_r);
    out = __msa_aver_u_b(out, dst_data);
995
    ST_W4(out, 0, 1, 2, 3, dst, stride);
996
}
997

998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
static void avc_chroma_hz_and_aver_dst_4x8_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
{
    uint32_t tp0, tp1, tp2, tp3;
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, out0, out1;
    v16u8 dst0 = { 0 }, dst1 = { 0 };
    v16i8 mask;
    v8u16 res0, res1, res2, res3;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);
1010

1011
    mask = LD_SB(&chroma_mask_arr[0]);
1012

1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
    LD_UB8(src, stride, src0, src1, src2, src3, src4, src5, src6, src7);
    LW4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_W4_UB(tp0, tp1, tp2, tp3, dst0);
    LW4(dst + 4 * stride, stride, tp0, tp1, tp2, tp3);
    INSERT_W4_UB(tp0, tp1, tp2, tp3, dst1);
    VSHF_B2_UB(src0, src1, src2, src3, mask, mask, src0, src2);
    VSHF_B2_UB(src4, src5, src6, src7, mask, mask, src4, src6);
    DOTP_UB2_UH(src0, src2, coeff_vec, coeff_vec, res0, res1);
    DOTP_UB2_UH(src4, src6, coeff_vec, coeff_vec, res2, res3);
    SLLI_4V(res0, res1, res2, res3, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
    AVER_UB2_UB(out0, dst0, out1, dst1, out0, out1);
1027
    ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, stride);
1028 1029
}

1030 1031 1032
static void avc_chroma_hz_and_aver_dst_4w_msa(uint8_t *src, uint8_t *dst,
                                              int32_t stride, uint32_t coeff0,
                                              uint32_t coeff1, int32_t height)
1033 1034
{
    if (2 == height) {
1035 1036 1037 1038 1039
        avc_chroma_hz_and_aver_dst_4x2_msa(src, dst, stride, coeff0, coeff1);
    } else if (4 == height) {
        avc_chroma_hz_and_aver_dst_4x4_msa(src, dst, stride, coeff0, coeff1);
    } else if (8 == height) {
        avc_chroma_hz_and_aver_dst_4x8_msa(src, dst, stride, coeff0, coeff1);
1040 1041 1042
    }
}

1043 1044 1045
static void avc_chroma_hz_and_aver_dst_8x4_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
1046
{
1047
    uint64_t tp0, tp1, tp2, tp3;
1048
    v16u8 src0, src1, src2, src3, out0, out1;
1049
    v16u8 dst0 = { 0 }, dst1 = { 0 };
1050 1051 1052 1053 1054 1055 1056
    v8u16 res0, res1, res2, res3;
    v16i8 mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[32]);
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
    LD_UB4(src, stride, src0, src1, src2, src3);
    LD4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_D2_UB(tp0, tp1, dst0);
    INSERT_D2_UB(tp2, tp3, dst1);
    VSHF_B2_UB(src0, src0, src1, src1, mask, mask, src0, src1);
    VSHF_B2_UB(src2, src2, src3, src3, mask, mask, src2, src3);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res0, res1, res2, res3);
    SLLI_4V(res0, res1, res2, res3, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
    AVER_UB2_UB(out0, dst0, out1, dst1, dst0, dst1);
1070
    ST_D4(dst0, dst1, 0, 1, 0, 1, dst, stride);
1071
}
1072

1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113
static void avc_chroma_hz_and_aver_dst_8x8_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
{
    uint64_t tp0, tp1, tp2, tp3;
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7;
    v16u8 out0, out1, out2, out3;
    v16u8 dst0 = { 0 }, dst1 = { 0 }, dst2 = { 0 }, dst3 = { 0 };
    v8u16 res0, res1, res2, res3, res4, res5, res6, res7;
    v16i8 mask;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

    mask = LD_SB(&chroma_mask_arr[32]);

    LD_UB8(src, stride, src0, src1, src2, src3, src4, src5, src6, src7);
    LD4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_D2_UB(tp0, tp1, dst0);
    INSERT_D2_UB(tp2, tp3, dst1);
    LD4(dst + 4 * stride, stride, tp0, tp1, tp2, tp3);
    INSERT_D2_UB(tp0, tp1, dst2);
    INSERT_D2_UB(tp2, tp3, dst3);
    VSHF_B2_UB(src0, src0, src1, src1, mask, mask, src0, src1);
    VSHF_B2_UB(src2, src2, src3, src3, mask, mask, src2, src3);
    VSHF_B2_UB(src4, src4, src5, src5, mask, mask, src4, src5);
    VSHF_B2_UB(src6, src6, src7, src7, mask, mask, src6, src7);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res0, res1, res2, res3);
    DOTP_UB4_UH(src4, src5, src6, src7, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res4, res5, res6, res7);
    SLLI_4V(res0, res1, res2, res3, 3);
    SLLI_4V(res4, res5, res6, res7, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SRARI_H4_UH(res4, res5, res6, res7, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    SAT_UH4_UH(res4, res5, res6, res7, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
    PCKEV_B2_UB(res5, res4, res7, res6, out2, out3);
    AVER_UB2_UB(out0, dst0, out1, dst1, out0, out1);
    AVER_UB2_UB(out2, dst2, out3, dst3, out2, out3);
1114
    ST_D8(out0, out1, out2, out3, 0, 1, 0, 1, 0, 1, 0, 1, dst, stride);
1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
}

static void avc_chroma_hz_and_aver_dst_8w_msa(uint8_t *src, uint8_t *dst,
                                              int32_t stride, uint32_t coeff0,
                                              uint32_t coeff1, int32_t height)
{
    if (4 == height) {
        avc_chroma_hz_and_aver_dst_8x4_msa(src, dst, stride, coeff0, coeff1);
    } else if (8 == height) {
        avc_chroma_hz_and_aver_dst_8x8_msa(src, dst, stride, coeff0, coeff1);
1125 1126 1127
    }
}

1128 1129 1130
static void avc_chroma_vt_and_aver_dst_2x2_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
1131 1132 1133 1134
{
    uint16_t out0, out1;
    v16i8 src0, src1, src2, tmp0, tmp1, res;
    v16u8 dst_data = { 0 };
1135
    v8i16 out;
1136 1137 1138 1139 1140
    v8u16 res_r;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

1141 1142 1143
    LD_SB3(src, stride, src0, src1, src2);
    out0 = LH(dst);
    out1 = LH(dst + stride);
1144

1145 1146
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 0, out0);
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 2, out1);
1147 1148 1149 1150 1151 1152 1153 1154 1155

    ILVR_B2_SB(src1, src0, src2, src1, tmp0, tmp1);

    tmp0 = (v16i8) __msa_ilvr_d((v2i64) tmp1, (v2i64) tmp0);
    res_r = __msa_dotp_u_h((v16u8) tmp0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);
    res = __msa_pckev_b((v16i8) res_r, (v16i8) res_r);
1156 1157 1158
    out = (v8i16) __msa_aver_u_b((v16u8) res, dst_data);
    out0 = __msa_copy_u_h(out, 0);
    out1 = __msa_copy_u_h(out, 2);
1159 1160

    SH(out0, dst);
1161
    dst += stride;
1162 1163 1164
    SH(out1, dst);
}

1165 1166 1167
static void avc_chroma_vt_and_aver_dst_2x4_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
1168
{
1169
    uint16_t tp0, tp1, tp2, tp3;
1170 1171 1172 1173 1174 1175 1176 1177 1178
    v16i8 src0, src1, src2, src3, src4;
    v16u8 tmp0, tmp1, tmp2, tmp3;
    v8u16 res_r;
    v8i16 res;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);
    v16u8 dst_data = { 0 };

1179
    LD_SB5(src, stride, src0, src1, src2, src3, src4);
1180

1181 1182 1183 1184 1185 1186 1187 1188
    tp0 = LH(dst);
    tp1 = LH(dst + stride);
    tp2 = LH(dst + 2 * stride);
    tp3 = LH(dst + 3 * stride);
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 0, tp0);
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 1, tp1);
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 2, tp2);
    dst_data = (v16u8) __msa_insert_h((v8i16) dst_data, 3, tp3);
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203

    ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3,
               tmp0, tmp1, tmp2, tmp3);
    ILVR_W2_UB(tmp1, tmp0, tmp3, tmp2, tmp0, tmp2);

    tmp0 = (v16u8) __msa_ilvr_d((v2i64) tmp2, (v2i64) tmp0);

    res_r = __msa_dotp_u_h(tmp0, coeff_vec);
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);

    res = (v8i16) __msa_pckev_b((v16i8) res_r, (v16i8) res_r);
    res = (v8i16) __msa_aver_u_b((v16u8) res, dst_data);

1204
    ST_H4(res, 0, 1, 2, 3, dst, stride);
1205 1206
}

1207 1208 1209
static void avc_chroma_vt_and_aver_dst_2w_msa(uint8_t *src, uint8_t *dst,
                                              int32_t stride, uint32_t coeff0,
                                              uint32_t coeff1, int32_t height)
1210 1211
{
    if (2 == height) {
1212
        avc_chroma_vt_and_aver_dst_2x2_msa(src, dst, stride, coeff0, coeff1);
1213
    } else if (4 == height) {
1214
        avc_chroma_vt_and_aver_dst_2x4_msa(src, dst, stride, coeff0, coeff1);
1215 1216 1217
    }
}

1218 1219 1220
static void avc_chroma_vt_and_aver_dst_4x2_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
1221 1222
{
    uint32_t load0, load1;
1223
    v16u8 src0, src1, src2, tmp0, tmp1;
1224 1225 1226 1227 1228 1229 1230
    v16u8 dst_data = { 0 };
    v8u16 res_r;
    v16u8 res;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

1231
    LD_UB3(src, stride, src0, src1, src2);
1232

1233
    LW2(dst, stride, load0, load1);
1234 1235

    INSERT_W2_UB(load0, load1, dst_data);
1236
    ILVR_B2_UB(src1, src0, src2, src1, tmp0, tmp1);
1237

1238
    tmp0 = (v16u8) __msa_ilvr_d((v2i64) tmp1, (v2i64) tmp0);
1239

1240
    res_r = __msa_dotp_u_h(tmp0, coeff_vec);
1241 1242 1243 1244 1245 1246
    res_r <<= 3;
    res_r = (v8u16) __msa_srari_h((v8i16) res_r, 6);
    res_r = __msa_sat_u_h(res_r, 7);
    res = (v16u8) __msa_pckev_b((v16i8) res_r, (v16i8) res_r);
    res = __msa_aver_u_b(res, dst_data);

1247
    ST_W2(res, 0, 1, dst, stride);
1248 1249
}

1250 1251 1252
static void avc_chroma_vt_and_aver_dst_4x4_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
1253
{
1254 1255
    uint32_t tp0, tp1, tp2, tp3;
    v16u8 src0, src1, src2, src3, src4;
1256 1257 1258
    v16u8 tmp0, tmp1, tmp2, tmp3;
    v16u8 dst0 = { 0 };
    v8u16 res0_r, res1_r;
1259
    v16u8 out;
1260 1261 1262 1263
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    LW4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_W4_UB(tp0, tp1, tp2, tp3, dst0);
    ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3, tmp0, tmp1, tmp2,
               tmp3);
    ILVR_D2_UB(tmp1, tmp0, tmp3, tmp2, tmp0, tmp2);
    DOTP_UB2_UH(tmp0, tmp2, coeff_vec, coeff_vec, res0_r, res1_r);
    res0_r <<= 3;
    res1_r <<= 3;
    SRARI_H2_UH(res0_r, res1_r, 6);
    SAT_UH2_UH(res0_r, res1_r, 7);
    out = (v16u8) __msa_pckev_b((v16i8) res1_r, (v16i8) res0_r);
    out = __msa_aver_u_b(out, dst0);
1277
    ST_W4(out, 0, 1, 2, 3, dst, stride);
1278
}
1279

1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291
static void avc_chroma_vt_and_aver_dst_4x8_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
{
    uint32_t tp0, tp1, tp2, tp3;
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
    v16u8 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, out0, out1;
    v16u8 dst0 = { 0 }, dst1 = { 0 };
    v8u16 res0, res1, res2, res3;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);
1292

1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    src += (5 * stride);
    LD_UB4(src, stride, src5, src6, src7, src8);
    LW4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_W4_UB(tp0, tp1, tp2, tp3, dst0);
    LW4(dst + 4 * stride, stride, tp0, tp1, tp2, tp3);
    INSERT_W4_UB(tp0, tp1, tp2, tp3, dst1);
    ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3, tmp0, tmp1, tmp2,
               tmp3);
    ILVR_B4_UB(src5, src4, src6, src5, src7, src6, src8, src7, tmp4, tmp5, tmp6,
               tmp7);
    ILVR_D2_UB(tmp1, tmp0, tmp3, tmp2, tmp0, tmp2);
    ILVR_D2_UB(tmp5, tmp4, tmp7, tmp6, tmp4, tmp6);
    DOTP_UB2_UH(tmp0, tmp2, coeff_vec, coeff_vec, res0, res1);
    DOTP_UB2_UH(tmp4, tmp6, coeff_vec, coeff_vec, res2, res3);
    SLLI_4V(res0, res1, res2, res3, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
    AVER_UB2_UB(out0, dst0, out1, dst1, out0, out1);
1313
    ST_W8(out0, out1, 0, 1, 2, 3, 0, 1, 2, 3, dst, stride);
1314 1315
}

1316 1317 1318
static void avc_chroma_vt_and_aver_dst_4w_msa(uint8_t *src, uint8_t *dst,
                                              int32_t stride, uint32_t coeff0,
                                              uint32_t coeff1, int32_t height)
1319 1320
{
    if (2 == height) {
1321 1322 1323 1324 1325
        avc_chroma_vt_and_aver_dst_4x2_msa(src, dst, stride, coeff0, coeff1);
    } else if (4 == height) {
        avc_chroma_vt_and_aver_dst_4x4_msa(src, dst, stride, coeff0, coeff1);
    } else if (8 == height) {
        avc_chroma_vt_and_aver_dst_4x8_msa(src, dst, stride, coeff0, coeff1);
1326 1327 1328
    }
}

1329 1330 1331
static void avc_chroma_vt_and_aver_dst_8x4_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
1332
{
1333
    uint64_t tp0, tp1, tp2, tp3;
1334 1335 1336
    v16u8 src0, src1, src2, src3, src4;
    v16u8 out0, out1;
    v8u16 res0, res1, res2, res3;
1337
    v16u8 dst0 = { 0 }, dst1 = { 0 };
1338 1339 1340 1341
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);

1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    LD4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_D2_UB(tp0, tp1, dst0);
    INSERT_D2_UB(tp2, tp3, dst1);
    ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3,
               src0, src1, src2, src3);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res0, res1, res2, res3);
    SLLI_4V(res0, res1, res2, res3, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
    AVER_UB2_UB(out0, dst0, out1, dst1, out0, out1);
1355
    ST_D4(out0, out1, 0, 1, 0, 1, dst, stride);
1356
}
1357

1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
static void avc_chroma_vt_and_aver_dst_8x8_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride, uint32_t coeff0,
                                               uint32_t coeff1)
{
    uint64_t tp0, tp1, tp2, tp3;
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
    v16u8 out0, out1, out2, out3;
    v16u8 dst0 = { 0 }, dst1 = { 0 }, dst2 = { 0 }, dst3 = { 0 };
    v8u16 res0, res1, res2, res3, res4, res5, res6, res7;
    v16i8 coeff_vec0 = __msa_fill_b(coeff0);
    v16i8 coeff_vec1 = __msa_fill_b(coeff1);
    v16u8 coeff_vec = (v16u8) __msa_ilvr_b(coeff_vec0, coeff_vec1);
1370

1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    src += (5 * stride);
    LD_UB4(src, stride, src5, src6, src7, src8);
    LD4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_D2_UB(tp0, tp1, dst0);
    INSERT_D2_UB(tp2, tp3, dst1);
    LD4(dst + 4 * stride, stride, tp0, tp1, tp2, tp3);
    INSERT_D2_UB(tp0, tp1, dst2);
    INSERT_D2_UB(tp2, tp3, dst3);
    ILVR_B4_UB(src1, src0, src2, src1, src3, src2, src4, src3,
               src0, src1, src2, src3);
    ILVR_B4_UB(src5, src4, src6, src5, src7, src6, src8, src7,
               src4, src5, src6, src7);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res0, res1, res2, res3);
    DOTP_UB4_UH(src4, src5, src6, src7, coeff_vec, coeff_vec, coeff_vec,
                coeff_vec, res4, res5, res6, res7);
    SLLI_4V(res0, res1, res2, res3, 3);
    SLLI_4V(res4, res5, res6, res7, 3);
    SRARI_H4_UH(res0, res1, res2, res3, 6);
    SRARI_H4_UH(res4, res5, res6, res7, 6);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    SAT_UH4_UH(res0, res1, res2, res3, 7);
    PCKEV_B2_UB(res1, res0, res3, res2, out0, out1);
    PCKEV_B2_UB(res5, res4, res7, res6, out2, out3);
    AVER_UB2_UB(out0, dst0, out1, dst1, out0, out1);
    AVER_UB2_UB(out2, dst2, out3, dst3, out2, out3);
1398
    ST_D8(out0, out1, out2, out3, 0, 1, 0, 1, 0, 1, 0, 1, dst, stride);
1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
}

static void avc_chroma_vt_and_aver_dst_8w_msa(uint8_t *src, uint8_t *dst,
                                              int32_t stride, uint32_t coeff0,
                                              uint32_t coeff1, int32_t height)
{
    if (4 == height) {
        avc_chroma_vt_and_aver_dst_8x4_msa(src, dst, stride, coeff0, coeff1);
    } else if (8 == height) {
        avc_chroma_vt_and_aver_dst_8x8_msa(src, dst, stride, coeff0, coeff1);
1409 1410 1411
    }
}

1412 1413
static void avc_chroma_hv_and_aver_dst_2x2_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride,
1414 1415 1416 1417 1418 1419
                                               uint32_t coef_hor0,
                                               uint32_t coef_hor1,
                                               uint32_t coef_ver0,
                                               uint32_t coef_ver1)
{
    uint16_t out0, out1;
1420
    v16u8 dst0 = { 0 };
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
    v16u8 src0, src1, src2;
    v8u16 res_hz0, res_hz1, res_vt0, res_vt1;
    v16i8 res, mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[48]);

1432 1433 1434 1435 1436
    LD_UB3(src, stride, src0, src1, src2);
    out0 = LH(dst);
    out1 = LH(dst + stride);
    dst0 = (v16u8) __msa_insert_h((v8i16) dst0, 0, out0);
    dst0 = (v16u8) __msa_insert_h((v8i16) dst0, 1, out1);
1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449
    VSHF_B2_UB(src0, src1, src1, src2, mask, mask, src0, src1);
    DOTP_UB2_UH(src0, src1, coeff_hz_vec, coeff_hz_vec, res_hz0, res_hz1);
    MUL2(res_hz0, coeff_vt_vec1, res_hz1, coeff_vt_vec0, res_vt0, res_vt1);

    res_vt0 += res_vt1;
    res_vt0 = (v8u16) __msa_srari_h((v8i16) res_vt0, 6);
    res_vt0 = __msa_sat_u_h(res_vt0, 7);
    res = __msa_pckev_b((v16i8) res_vt0, (v16i8) res_vt0);
    dst0 = __msa_aver_u_b((v16u8) res, dst0);
    out0 = __msa_copy_u_h((v8i16) dst0, 0);
    out1 = __msa_copy_u_h((v8i16) dst0, 1);

    SH(out0, dst);
1450
    dst += stride;
1451 1452 1453
    SH(out1, dst);
}

1454 1455
static void avc_chroma_hv_and_aver_dst_2x4_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride,
1456 1457 1458 1459 1460
                                               uint32_t coef_hor0,
                                               uint32_t coef_hor1,
                                               uint32_t coef_ver0,
                                               uint32_t coef_ver1)
{
1461
    uint16_t tp0, tp1, tp2, tp3;
1462 1463
    v16u8 src0, src1, src2, src3, src4;
    v16u8 tmp0, tmp1, tmp2, tmp3;
1464
    v16u8 dst0 = { 0 };
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474
    v8u16 res_hz0, res_hz1, res_vt0, res_vt1;
    v16i8 res, mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[48]);

1475 1476 1477 1478 1479 1480 1481 1482 1483
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    tp0 = LH(dst);
    tp1 = LH(dst + stride);
    tp2 = LH(dst + 2 * stride);
    tp3 = LH(dst + 3 * stride);
    dst0 = (v16u8) __msa_insert_h((v8i16) dst0, 0, tp0);
    dst0 = (v16u8) __msa_insert_h((v8i16) dst0, 1, tp1);
    dst0 = (v16u8) __msa_insert_h((v8i16) dst0, 2, tp2);
    dst0 = (v16u8) __msa_insert_h((v8i16) dst0, 3, tp3);
1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
    VSHF_B2_UB(src0, src1, src2, src3, mask, mask, tmp0, tmp1);
    VSHF_B2_UB(src1, src2, src3, src4, mask, mask, tmp2, tmp3);
    ILVR_D2_UB(tmp1, tmp0, tmp3, tmp2, src0, src1);
    DOTP_UB2_UH(src0, src1, coeff_hz_vec, coeff_hz_vec, res_hz0, res_hz1);
    MUL2(res_hz0, coeff_vt_vec1, res_hz1, coeff_vt_vec0, res_vt0, res_vt1);

    res_vt0 += res_vt1;
    res_vt0 = (v8u16) __msa_srari_h((v8i16) res_vt0, 6);
    res_vt0 = __msa_sat_u_h(res_vt0, 7);
    res = __msa_pckev_b((v16i8) res_vt0, (v16i8) res_vt0);
    dst0 = __msa_aver_u_b((v16u8) res, dst0);

1496
    ST_H4(dst0, 0, 1, 2, 3, dst, stride);
1497 1498
}

1499 1500
static void avc_chroma_hv_and_aver_dst_2w_msa(uint8_t *src, uint8_t *dst,
                                              int32_t stride,
1501 1502 1503 1504 1505 1506 1507
                                              uint32_t coef_hor0,
                                              uint32_t coef_hor1,
                                              uint32_t coef_ver0,
                                              uint32_t coef_ver1,
                                              int32_t height)
{
    if (2 == height) {
1508 1509
        avc_chroma_hv_and_aver_dst_2x2_msa(src, dst, stride, coef_hor0,
                                           coef_hor1, coef_ver0, coef_ver1);
1510
    } else if (4 == height) {
1511 1512
        avc_chroma_hv_and_aver_dst_2x4_msa(src, dst, stride, coef_hor0,
                                           coef_hor1, coef_ver0, coef_ver1);
1513 1514 1515
    }
}

1516 1517
static void avc_chroma_hv_and_aver_dst_4x2_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride,
1518 1519 1520 1521 1522
                                               uint32_t coef_hor0,
                                               uint32_t coef_hor1,
                                               uint32_t coef_ver0,
                                               uint32_t coef_ver1)
{
1523
    uint32_t tp0, tp1;
1524
    v16u8 src0, src1, src2;
1525
    v16u8 dst0, dst_data = { 0 };
1526
    v8u16 res_hz0, res_hz1, res_vt0, res_vt1;
1527
    v16i8 mask;
1528 1529 1530 1531 1532 1533 1534 1535
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[0]);

1536 1537 1538
    LD_UB3(src, stride, src0, src1, src2);
    LW2(dst, stride, tp0, tp1);
    INSERT_W2_UB(tp0, tp1, dst_data);
1539 1540 1541 1542 1543 1544 1545
    VSHF_B2_UB(src0, src1, src1, src2, mask, mask, src0, src1);
    DOTP_UB2_UH(src0, src1, coeff_hz_vec, coeff_hz_vec, res_hz0, res_hz1);
    MUL2(res_hz0, coeff_vt_vec1, res_hz1, coeff_vt_vec0, res_vt0, res_vt1);

    res_vt0 += res_vt1;
    res_vt0 = (v8u16) __msa_srari_h((v8i16) res_vt0, 6);
    res_vt0 = __msa_sat_u_h(res_vt0, 7);
1546 1547
    dst0 = (v16u8) __msa_pckev_b((v16i8) res_vt0, (v16i8) res_vt0);
    dst0 = __msa_aver_u_b(dst0, dst_data);
1548

1549
    ST_W2(dst0, 0, 1, dst, stride);
1550 1551
}

1552 1553 1554 1555 1556 1557
static void avc_chroma_hv_and_aver_dst_4x4_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride,
                                               uint32_t coef_hor0,
                                               uint32_t coef_hor1,
                                               uint32_t coef_ver0,
                                               uint32_t coef_ver1)
1558
{
1559
    uint32_t tp0, tp1, tp2, tp3;
1560
    v16u8 src0, src1, src2, src3, src4;
1561
    v16u8 out, dst_data = { 0 };
1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
    v8u16 res_hz0, res_hz1, res_hz2, res_hz3;
    v8u16 res_vt0, res_vt1, res_vt2, res_vt3;
    v16i8 mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[0]);

1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587
    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    LW4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_W4_UB(tp0, tp1, tp2, tp3, dst_data);
    VSHF_B2_UB(src0, src1, src1, src2, mask, mask, src0, src1);
    VSHF_B2_UB(src2, src3, src3, src4, mask, mask, src2, src3);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz0, res_hz1, res_hz2,
                res_hz3);
    MUL4(res_hz0, coeff_vt_vec1, res_hz1, coeff_vt_vec0, res_hz2, coeff_vt_vec1,
         res_hz3, coeff_vt_vec0, res_vt0, res_vt1, res_vt2, res_vt3);
    ADD2(res_vt0, res_vt1, res_vt2, res_vt3, res_vt0, res_vt1);
    SRARI_H2_UH(res_vt0, res_vt1, 6);
    SAT_UH2_UH(res_vt0, res_vt1, 7);
    out = (v16u8) __msa_pckev_b((v16i8) res_vt1, (v16i8) res_vt0);
    out = __msa_aver_u_b(out, dst_data);
1588
    ST_W4(out, 0, 1, 2, 3, dst, stride);
1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636
}

static void avc_chroma_hv_and_aver_dst_4x8_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride,
                                               uint32_t coef_hor0,
                                               uint32_t coef_hor1,
                                               uint32_t coef_ver0,
                                               uint32_t coef_ver1)
{
    uint32_t tp0, tp1, tp2, tp3;
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8, res0, res1;
    v16u8 dst0 = { 0 }, dst1 = { 0 };
    v8u16 res_hz0, res_hz1, res_hz2, res_hz3, res_hz4, res_hz5, res_hz6, res_hz7;
    v8u16 res_vt0, res_vt1, res_vt2, res_vt3, res_vt4, res_vt5, res_vt6, res_vt7;
    v16i8 mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[0]);

    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    src += (5 * stride);
    LD_UB4(src, stride, src5, src6, src7, src8);
    LW4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_W4_UB(tp0, tp1, tp2, tp3, dst0);
    LW4(dst + 4 * stride, stride, tp0, tp1, tp2, tp3);
    INSERT_W4_UB(tp0, tp1, tp2, tp3, dst1);
    VSHF_B2_UB(src0, src1, src1, src2, mask, mask, src0, src1);
    VSHF_B2_UB(src2, src3, src3, src4, mask, mask, src2, src3);
    VSHF_B2_UB(src4, src5, src5, src6, mask, mask, src4, src5);
    VSHF_B2_UB(src6, src7, src7, src8, mask, mask, src6, src7);
    DOTP_UB4_UH(src0, src1, src2, src3, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz0, res_hz1, res_hz2, res_hz3);
    DOTP_UB4_UH(src4, src5, src6, src7, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz4, res_hz5, res_hz6, res_hz7);
    MUL4(res_hz0, coeff_vt_vec1, res_hz1, coeff_vt_vec0, res_hz2, coeff_vt_vec1,
         res_hz3, coeff_vt_vec0, res_vt0, res_vt1, res_vt2, res_vt3);
    MUL4(res_hz4, coeff_vt_vec1, res_hz5, coeff_vt_vec0, res_hz6, coeff_vt_vec1,
         res_hz7, coeff_vt_vec0, res_vt4, res_vt5, res_vt6, res_vt7);
    ADD2(res_vt0, res_vt1, res_vt2, res_vt3, res_vt0, res_vt1);
    ADD2(res_vt4, res_vt5, res_vt6, res_vt7, res_vt2, res_vt3);
    SRARI_H4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 6);
    SAT_UH4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 7);
    PCKEV_B2_UB(res_vt1, res_vt0, res_vt3, res_vt2, res0, res1);
    AVER_UB2_UB(res0, dst0, res1, dst1, res0, res1);
1637
    ST_W8(res0, res1, 0, 1, 2, 3, 0, 1, 2, 3, dst, stride);
1638 1639
}

1640 1641
static void avc_chroma_hv_and_aver_dst_4w_msa(uint8_t *src, uint8_t *dst,
                                              int32_t stride,
1642 1643 1644 1645 1646 1647 1648
                                              uint32_t coef_hor0,
                                              uint32_t coef_hor1,
                                              uint32_t coef_ver0,
                                              uint32_t coef_ver1,
                                              int32_t height)
{
    if (2 == height) {
1649 1650 1651 1652 1653 1654 1655 1656
        avc_chroma_hv_and_aver_dst_4x2_msa(src, dst, stride, coef_hor0,
                                           coef_hor1, coef_ver0, coef_ver1);
    } else if (4 == height) {
        avc_chroma_hv_and_aver_dst_4x4_msa(src, dst, stride, coef_hor0,
                                           coef_hor1, coef_ver0, coef_ver1);
    } else if (8 == height) {
        avc_chroma_hv_and_aver_dst_4x8_msa(src, dst, stride, coef_hor0,
                                           coef_hor1, coef_ver0, coef_ver1);
1657 1658 1659
    }
}

1660 1661 1662 1663 1664 1665
static void avc_chroma_hv_and_aver_dst_8x4_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride,
                                               uint32_t coef_hor0,
                                               uint32_t coef_hor1,
                                               uint32_t coef_ver0,
                                               uint32_t coef_ver1)
1666
{
1667
    uint64_t tp0, tp1, tp2, tp3;
1668 1669 1670 1671
    v16u8 src0, src1, src2, src3, src4, out0, out1;
    v8u16 res_hz0, res_hz1, res_hz2;
    v8u16 res_hz3, res_hz4;
    v8u16 res_vt0, res_vt1, res_vt2, res_vt3;
1672
    v16u8 dst0 = { 0 }, dst1 = { 0 };
1673 1674 1675 1676 1677 1678 1679 1680 1681 1682
    v16i8 mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[32]);

    src0 = LD_UB(src);
1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704
    src += stride;
    src0 = (v16u8) __msa_vshf_b(mask, (v16i8) src0, (v16i8) src0);
    res_hz0 = __msa_dotp_u_h(src0, coeff_hz_vec);
    LD_UB4(src, stride, src1, src2, src3, src4);
    src += (4 * stride);
    LD4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_D2_UB(tp0, tp1, dst0);
    INSERT_D2_UB(tp2, tp3, dst1);
    VSHF_B2_UB(src1, src1, src2, src2, mask, mask, src1, src2);
    VSHF_B2_UB(src3, src3, src4, src4, mask, mask, src3, src4);
    DOTP_UB4_UH(src1, src2, src3, src4, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz1, res_hz2, res_hz3, res_hz4);
    MUL4(res_hz1, coeff_vt_vec0, res_hz2, coeff_vt_vec0, res_hz3, coeff_vt_vec0,
         res_hz4, coeff_vt_vec0, res_vt0, res_vt1, res_vt2, res_vt3);
    res_vt0 += (res_hz0 * coeff_vt_vec1);
    res_vt1 += (res_hz1 * coeff_vt_vec1);
    res_vt2 += (res_hz2 * coeff_vt_vec1);
    res_vt3 += (res_hz3 * coeff_vt_vec1);
    SRARI_H4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 6);
    SAT_UH4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 7);
    PCKEV_B2_UB(res_vt1, res_vt0, res_vt3, res_vt2, out0, out1);
    AVER_UB2_UB(out0, dst0, out1, dst1, out0, out1);
1705
    ST_D4(out0, out1, 0, 1, 0, 1, dst, stride);
1706
}
1707

1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
static void avc_chroma_hv_and_aver_dst_8x8_msa(uint8_t *src, uint8_t *dst,
                                               int32_t stride,
                                               uint32_t coef_hor0,
                                               uint32_t coef_hor1,
                                               uint32_t coef_ver0,
                                               uint32_t coef_ver1)
{
    uint64_t tp0, tp1, tp2, tp3;
    v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8;
    v16u8 out0, out1, out2, out3;
    v16u8 dst0 = { 0 }, dst1 = { 0 }, dst2 = { 0 }, dst3 = { 0 };
    v8u16 res_hz0, res_hz1, res_hz2, res_hz3, res_hz4;
    v8u16 res_hz5, res_hz6, res_hz7, res_hz8;
    v8u16 res_vt0, res_vt1, res_vt2, res_vt3;
    v8u16 res_vt4, res_vt5, res_vt6, res_vt7;
    v16i8 mask;
    v16i8 coeff_hz_vec0 = __msa_fill_b(coef_hor0);
    v16i8 coeff_hz_vec1 = __msa_fill_b(coef_hor1);
    v16u8 coeff_hz_vec = (v16u8) __msa_ilvr_b(coeff_hz_vec0, coeff_hz_vec1);
    v8u16 coeff_vt_vec0 = (v8u16) __msa_fill_h(coef_ver0);
    v8u16 coeff_vt_vec1 = (v8u16) __msa_fill_h(coef_ver1);

    mask = LD_SB(&chroma_mask_arr[32]);

    LD_UB5(src, stride, src0, src1, src2, src3, src4);
    src += (5 * stride);
    LD_UB4(src, stride, src5, src6, src7, src8);
1735
    src0 = (v16u8) __msa_vshf_b(mask, (v16i8) src0, (v16i8) src0);
1736 1737 1738 1739
    VSHF_B2_UB(src1, src1, src2, src2, mask, mask, src1, src2);
    VSHF_B2_UB(src3, src3, src4, src4, mask, mask, src3, src4);
    VSHF_B2_UB(src5, src5, src6, src6, mask, mask, src5, src6);
    VSHF_B2_UB(src7, src7, src8, src8, mask, mask, src7, src8);
1740
    res_hz0 = __msa_dotp_u_h(src0, coeff_hz_vec);
1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773
    DOTP_UB4_UH(src1, src2, src3, src4, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz1, res_hz2, res_hz3,
                res_hz4);
    DOTP_UB4_UH(src5, src6, src7, src8, coeff_hz_vec, coeff_hz_vec,
                coeff_hz_vec, coeff_hz_vec, res_hz5, res_hz6, res_hz7, res_hz8);
    MUL4(res_hz1, coeff_vt_vec0, res_hz2, coeff_vt_vec0, res_hz3,
         coeff_vt_vec0, res_hz4, coeff_vt_vec0, res_vt0, res_vt1, res_vt2,
         res_vt3);
    MUL4(res_hz5, coeff_vt_vec0, res_hz6, coeff_vt_vec0, res_hz7,
         coeff_vt_vec0, res_hz8, coeff_vt_vec0, res_vt4, res_vt5, res_vt6,
         res_vt7);
    LD4(dst, stride, tp0, tp1, tp2, tp3);
    INSERT_D2_UB(tp0, tp1, dst0);
    INSERT_D2_UB(tp2, tp3, dst1);
    LD4(dst + 4 * stride, stride, tp0, tp1, tp2, tp3);
    INSERT_D2_UB(tp0, tp1, dst2);
    INSERT_D2_UB(tp2, tp3, dst3);
    res_vt0 += (res_hz0 * coeff_vt_vec1);
    res_vt1 += (res_hz1 * coeff_vt_vec1);
    res_vt2 += (res_hz2 * coeff_vt_vec1);
    res_vt3 += (res_hz3 * coeff_vt_vec1);
    res_vt4 += (res_hz4 * coeff_vt_vec1);
    res_vt5 += (res_hz5 * coeff_vt_vec1);
    res_vt6 += (res_hz6 * coeff_vt_vec1);
    res_vt7 += (res_hz7 * coeff_vt_vec1);
    SRARI_H4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 6);
    SRARI_H4_UH(res_vt4, res_vt5, res_vt6, res_vt7, 6);
    SAT_UH4_UH(res_vt0, res_vt1, res_vt2, res_vt3, 7);
    SAT_UH4_UH(res_vt4, res_vt5, res_vt6, res_vt7, 7);
    PCKEV_B2_UB(res_vt1, res_vt0, res_vt3, res_vt2, out0, out1);
    PCKEV_B2_UB(res_vt5, res_vt4, res_vt7, res_vt6, out2, out3);
    AVER_UB2_UB(out0, dst0, out1, dst1, out0, out1);
    AVER_UB2_UB(out2, dst2, out3, dst3, out2, out3);
1774
    ST_D8(out0, out1, out2, out3, 0, 1, 0, 1, 0, 1, 0, 1, dst, stride);
1775
}
1776

1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790
static void avc_chroma_hv_and_aver_dst_8w_msa(uint8_t *src, uint8_t *dst,
                                              int32_t stride,
                                              uint32_t coef_hor0,
                                              uint32_t coef_hor1,
                                              uint32_t coef_ver0,
                                              uint32_t coef_ver1,
                                              int32_t height)
{
    if (4 == height) {
        avc_chroma_hv_and_aver_dst_8x4_msa(src, dst, stride, coef_hor0,
                                           coef_hor1, coef_ver0, coef_ver1);
    } else if (8 == height) {
        avc_chroma_hv_and_aver_dst_8x8_msa(src, dst, stride, coef_hor0,
                                           coef_hor1, coef_ver0, coef_ver1);
1791 1792 1793
    }
}

1794
static void copy_width4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
1795 1796
                            int32_t height)
{
1797
    uint32_t tp0, tp1, tp2, tp3, tp4, tp5, tp6, tp7;
1798

1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813
    if (8 == height) {
        LW4(src, stride, tp0, tp1, tp2, tp3);
        src += 4 * stride;
        LW4(src, stride, tp4, tp5, tp6, tp7);
        SW4(tp0, tp1, tp2, tp3, dst, stride);
        dst += 4 * stride;
        SW4(tp4, tp5, tp6, tp7, dst, stride);
    } else if (4 == height) {
        LW4(src, stride, tp0, tp1, tp2, tp3);
        SW4(tp0, tp1, tp2, tp3, dst, stride);
    } else if (2 == height) {
        LW2(src, stride, tp0, tp1);
        SW(tp0, dst);
        dst += stride;
        SW(tp1, dst);
1814 1815 1816
    }
}

1817 1818
static void copy_width8_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                            int32_t height)
1819
{
1820
    uint64_t src0, src1, src2, src3, src4, src5, src6, src7;
1821

1822 1823 1824 1825 1826 1827 1828 1829 1830 1831
    if (8 == height) {
        LD4(src, stride, src0, src1, src2, src3);
        src += 4 * stride;
        LD4(src, stride, src4, src5, src6, src7);
        SD4(src0, src1, src2, src3, dst, stride);
        dst += 4 * stride;
        SD4(src4, src5, src6, src7, dst, stride);
    } else if (4 == height) {
        LD4(src, stride, src0, src1, src2, src3);
        SD4(src0, src1, src2, src3, dst, stride);
1832 1833 1834
    }
}

1835
static void avg_width4_msa(uint8_t *src, uint8_t *dst, int32_t stride,
1836 1837
                           int32_t height)
{
1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851
    uint32_t tp0, tp1, tp2, tp3;
    v16u8 src0 = { 0 }, src1 = { 0 }, dst0 = { 0 }, dst1 = { 0 };

    if (8 == height) {
        LW4(src, stride, tp0, tp1, tp2, tp3);
        src += 4 * stride;
        INSERT_W4_UB(tp0, tp1, tp2, tp3, src0);
        LW4(src, stride, tp0, tp1, tp2, tp3);
        INSERT_W4_UB(tp0, tp1, tp2, tp3, src1);
        LW4(dst, stride, tp0, tp1, tp2, tp3);
        INSERT_W4_UB(tp0, tp1, tp2, tp3, dst0);
        LW4(dst + 4 * stride, stride, tp0, tp1, tp2, tp3);
        INSERT_W4_UB(tp0, tp1, tp2, tp3, dst1);
        AVER_UB2_UB(src0, dst0, src1, dst1, dst0, dst1);
1852
        ST_W8(dst0, dst1, 0, 1, 2, 3, 0, 1, 2, 3, dst, stride);
1853 1854 1855 1856 1857 1858
    } else if (4 == height) {
        LW4(src, stride, tp0, tp1, tp2, tp3);
        INSERT_W4_UB(tp0, tp1, tp2, tp3, src0);
        LW4(dst, stride, tp0, tp1, tp2, tp3);
        INSERT_W4_UB(tp0, tp1, tp2, tp3, dst0);
        dst0 = __msa_aver_u_b(src0, dst0);
1859
        ST_W4(dst0, 0, 1, 2, 3, dst, stride);
1860 1861 1862 1863 1864 1865
    } else if (2 == height) {
        LW2(src, stride, tp0, tp1);
        INSERT_W2_UB(tp0, tp1, src0);
        LW2(dst, stride, tp0, tp1);
        INSERT_W2_UB(tp0, tp1, dst0);
        dst0 = __msa_aver_u_b(src0, dst0);
1866
        ST_W2(dst0, 0, 1, dst, stride);
1867 1868
    }
}
1869

1870 1871 1872 1873 1874 1875
static void avg_width8_msa(uint8_t *src, uint8_t *dst, int32_t stride,
                           int32_t height)
{
    uint64_t tp0, tp1, tp2, tp3, tp4, tp5, tp6, tp7;
    v16u8 src0 = { 0 }, src1 = { 0 }, src2 = { 0 }, src3 = { 0 };
    v16u8 dst0 = { 0 }, dst1 = { 0 }, dst2 = { 0 }, dst3 = { 0 };
1876

1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892
    if (8 == height) {
        LD4(src, stride, tp0, tp1, tp2, tp3);
        src += 4 * stride;
        LD4(src, stride, tp4, tp5, tp6, tp7);
        INSERT_D2_UB(tp0, tp1, src0);
        INSERT_D2_UB(tp2, tp3, src1);
        INSERT_D2_UB(tp4, tp5, src2);
        INSERT_D2_UB(tp6, tp7, src3);
        LD4(dst, stride, tp0, tp1, tp2, tp3);
        LD4(dst + 4 * stride, stride, tp4, tp5, tp6, tp7);
        INSERT_D2_UB(tp0, tp1, dst0);
        INSERT_D2_UB(tp2, tp3, dst1);
        INSERT_D2_UB(tp4, tp5, dst2);
        INSERT_D2_UB(tp6, tp7, dst3);
        AVER_UB4_UB(src0, dst0, src1, dst1, src2, dst2, src3, dst3, dst0, dst1,
                    dst2, dst3);
1893
        ST_D8(dst0, dst1, dst2, dst3, 0, 1, 0, 1, 0, 1, 0, 1, dst, stride);
1894 1895 1896 1897 1898 1899 1900 1901
    } else if (4 == height) {
        LD4(src, stride, tp0, tp1, tp2, tp3);
        INSERT_D2_UB(tp0, tp1, src0);
        INSERT_D2_UB(tp2, tp3, src1);
        LD4(dst, stride, tp0, tp1, tp2, tp3);
        INSERT_D2_UB(tp0, tp1, dst0);
        INSERT_D2_UB(tp2, tp3, dst1);
        AVER_UB2_UB(src0, dst0, src1, dst1, dst0, dst1);
1902
        ST_D4(dst0, dst1, 0, 1, 0, 1, dst, stride);
1903 1904 1905 1906
    }
}

void ff_put_h264_chroma_mc8_msa(uint8_t *dst, uint8_t *src,
James Almer's avatar
James Almer committed
1907
                                ptrdiff_t stride, int height, int x, int y)
1908 1909 1910 1911
{
    av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);

    if (x && y) {
1912
        avc_chroma_hv_8w_msa(src, dst, stride, x, (8 - x), y, (8 - y), height);
1913
    } else if (x) {
1914
        avc_chroma_hz_8w_msa(src, dst, stride, x, (8 - x), height);
1915
    } else if (y) {
1916
        avc_chroma_vt_8w_msa(src, dst, stride, y, (8 - y), height);
1917
    } else {
1918
        copy_width8_msa(src, dst, stride, height);
1919 1920 1921 1922
    }
}

void ff_put_h264_chroma_mc4_msa(uint8_t *dst, uint8_t *src,
James Almer's avatar
James Almer committed
1923
                                ptrdiff_t stride, int height, int x, int y)
1924 1925 1926 1927
{
    av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);

    if (x && y) {
1928
        avc_chroma_hv_4w_msa(src, dst, stride, x, (8 - x), y, (8 - y), height);
1929
    } else if (x) {
1930
        avc_chroma_hz_4w_msa(src, dst, stride, x, (8 - x), height);
1931
    } else if (y) {
1932
        avc_chroma_vt_4w_msa(src, dst, stride, y, (8 - y), height);
1933
    } else {
1934
        copy_width4_msa(src, dst, stride, height);
1935 1936 1937 1938
    }
}

void ff_put_h264_chroma_mc2_msa(uint8_t *dst, uint8_t *src,
James Almer's avatar
James Almer committed
1939
                                ptrdiff_t stride, int height, int x, int y)
1940 1941 1942 1943 1944 1945
{
    int32_t cnt;

    av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);

    if (x && y) {
1946
        avc_chroma_hv_2w_msa(src, dst, stride, x, (8 - x), y, (8 - y), height);
1947
    } else if (x) {
1948
        avc_chroma_hz_2w_msa(src, dst, stride, x, (8 - x), height);
1949
    } else if (y) {
1950
        avc_chroma_vt_2w_msa(src, dst, stride, y, (8 - y), height);
1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961
    } else {
        for (cnt = height; cnt--;) {
            *((uint16_t *) dst) = *((uint16_t *) src);

            src += stride;
            dst += stride;
        }
    }
}

void ff_avg_h264_chroma_mc8_msa(uint8_t *dst, uint8_t *src,
James Almer's avatar
James Almer committed
1962
                                ptrdiff_t stride, int height, int x, int y)
1963 1964 1965 1966 1967
{
    av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);


    if (x && y) {
1968
        avc_chroma_hv_and_aver_dst_8w_msa(src, dst, stride, x, (8 - x), y,
1969 1970
                                          (8 - y), height);
    } else if (x) {
1971
        avc_chroma_hz_and_aver_dst_8w_msa(src, dst, stride, x, (8 - x), height);
1972
    } else if (y) {
1973
        avc_chroma_vt_and_aver_dst_8w_msa(src, dst, stride, y, (8 - y), height);
1974
    } else {
1975
        avg_width8_msa(src, dst, stride, height);
1976 1977 1978 1979
    }
}

void ff_avg_h264_chroma_mc4_msa(uint8_t *dst, uint8_t *src,
James Almer's avatar
James Almer committed
1980
                                ptrdiff_t stride, int height, int x, int y)
1981 1982 1983 1984
{
    av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);

    if (x && y) {
1985
        avc_chroma_hv_and_aver_dst_4w_msa(src, dst, stride, x, (8 - x), y,
1986 1987
                                          (8 - y), height);
    } else if (x) {
1988
        avc_chroma_hz_and_aver_dst_4w_msa(src, dst, stride, x, (8 - x), height);
1989
    } else if (y) {
1990
        avc_chroma_vt_and_aver_dst_4w_msa(src, dst, stride, y, (8 - y), height);
1991
    } else {
1992
        avg_width4_msa(src, dst, stride, height);
1993 1994 1995 1996
    }
}

void ff_avg_h264_chroma_mc2_msa(uint8_t *dst, uint8_t *src,
James Almer's avatar
James Almer committed
1997
                                ptrdiff_t stride, int height, int x, int y)
1998 1999 2000 2001 2002 2003
{
    int32_t cnt;

    av_assert2(x < 8 && y < 8 && x >= 0 && y >= 0);

    if (x && y) {
2004
        avc_chroma_hv_and_aver_dst_2w_msa(src, dst, stride, x, (8 - x), y,
2005 2006
                                          (8 - y), height);
    } else if (x) {
2007
        avc_chroma_hz_and_aver_dst_2w_msa(src, dst, stride, x, (8 - x), height);
2008
    } else if (y) {
2009
        avc_chroma_vt_and_aver_dst_2w_msa(src, dst, stride, y, (8 - y), height);
2010 2011 2012 2013 2014 2015 2016 2017 2018 2019
    } else {
        for (cnt = height; cnt--;) {
            dst[0] = (dst[0] + src[0] + 1) >> 1;
            dst[1] = (dst[1] + src[1] + 1) >> 1;

            src += stride;
            dst += stride;
        }
    }
}