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 "./vp9_rtcd.h"
12 #include "vpx_dsp/mips/macros_msa.h"
13
vp9_avg_8x8_msa(const uint8_t * src,int32_t src_stride)14 uint32_t vp9_avg_8x8_msa(const uint8_t *src, int32_t src_stride) {
15 uint32_t sum_out;
16 v16u8 src0, src1, src2, src3, src4, src5, src6, src7;
17 v8u16 sum0, sum1, sum2, sum3, sum4, sum5, sum6, sum7;
18 v4u32 sum = { 0 };
19
20 LD_UB8(src, src_stride, src0, src1, src2, src3, src4, src5, src6, src7);
21 HADD_UB4_UH(src0, src1, src2, src3, sum0, sum1, sum2, sum3);
22 HADD_UB4_UH(src4, src5, src6, src7, sum4, sum5, sum6, sum7);
23 ADD4(sum0, sum1, sum2, sum3, sum4, sum5, sum6, sum7, sum0, sum2, sum4, sum6);
24 ADD2(sum0, sum2, sum4, sum6, sum0, sum4);
25 sum0 += sum4;
26
27 sum = __msa_hadd_u_w(sum0, sum0);
28 sum0 = (v8u16)__msa_pckev_h((v8i16)sum, (v8i16)sum);
29 sum = __msa_hadd_u_w(sum0, sum0);
30 sum = (v4u32)__msa_srari_w((v4i32)sum, 6);
31 sum_out = __msa_copy_u_w((v4i32)sum, 0);
32
33 return sum_out;
34 }
35
vp9_avg_4x4_msa(const uint8_t * src,int32_t src_stride)36 uint32_t vp9_avg_4x4_msa(const uint8_t *src, int32_t src_stride) {
37 uint32_t sum_out;
38 uint32_t src0, src1, src2, src3;
39 v16u8 vec = { 0 };
40 v8u16 sum0;
41 v4u32 sum1;
42 v2u64 sum2;
43
44 LW4(src, src_stride, src0, src1, src2, src3);
45 INSERT_W4_UB(src0, src1, src2, src3, vec);
46
47 sum0 = __msa_hadd_u_h(vec, vec);
48 sum1 = __msa_hadd_u_w(sum0, sum0);
49 sum0 = (v8u16)__msa_pckev_h((v8i16)sum1, (v8i16)sum1);
50 sum1 = __msa_hadd_u_w(sum0, sum0);
51 sum2 = __msa_hadd_u_d(sum1, sum1);
52 sum1 = (v4u32)__msa_srari_w((v4i32)sum2, 4);
53 sum_out = __msa_copy_u_w((v4i32)sum1, 0);
54
55 return sum_out;
56 }
57