summaryrefslogtreecommitdiff
path: root/vp10/encoder/mips/msa/error_msa.c
blob: dacca32c05ad1abfb503ea853fa1f0e9a4c3ce7c (plain)
1
2
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 *  Copyright (c) 2015 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#include "./vp10_rtcd.h"
#include "vpx_dsp/mips/macros_msa.h"

#define BLOCK_ERROR_BLOCKSIZE_MSA(BSize)                                   \
static int64_t block_error_##BSize##size_msa(const int16_t *coeff_ptr,     \
                                             const int16_t *dq_coeff_ptr,  \
                                             int64_t *ssz) {               \
  int64_t err = 0;                                                         \
  uint32_t loop_cnt;                                                       \
  v8i16 coeff, dq_coeff, coeff_r_h, coeff_l_h;                             \
  v4i32 diff_r, diff_l, coeff_r_w, coeff_l_w;                              \
  v2i64 sq_coeff_r, sq_coeff_l;                                            \
  v2i64 err0, err_dup0, err1, err_dup1;                                    \
                                                                           \
  coeff = LD_SH(coeff_ptr);                                                \
  dq_coeff = LD_SH(dq_coeff_ptr);                                          \
  UNPCK_SH_SW(coeff, coeff_r_w, coeff_l_w);                                \
  ILVRL_H2_SH(coeff, dq_coeff, coeff_r_h, coeff_l_h);                      \
  HSUB_UH2_SW(coeff_r_h, coeff_l_h, diff_r, diff_l);                       \
  DOTP_SW2_SD(coeff_r_w, coeff_l_w, coeff_r_w, coeff_l_w,                  \
              sq_coeff_r, sq_coeff_l);                                     \
  DOTP_SW2_SD(diff_r, diff_l, diff_r, diff_l, err0, err1);                 \
                                                                           \
  coeff = LD_SH(coeff_ptr + 8);                                            \
  dq_coeff = LD_SH(dq_coeff_ptr + 8);                                      \
  UNPCK_SH_SW(coeff, coeff_r_w, coeff_l_w);                                \
  ILVRL_H2_SH(coeff, dq_coeff, coeff_r_h, coeff_l_h);                      \
  HSUB_UH2_SW(coeff_r_h, coeff_l_h, diff_r, diff_l);                       \
  DPADD_SD2_SD(coeff_r_w, coeff_l_w, sq_coeff_r, sq_coeff_l);              \
  DPADD_SD2_SD(diff_r, diff_l, err0, err1);                                \
                                                                           \
  coeff_ptr += 16;                                                         \
  dq_coeff_ptr += 16;                                                      \
                                                                           \
  for (loop_cnt = ((BSize >> 4) - 1); loop_cnt--;) {                       \
    coeff = LD_SH(coeff_ptr);                                              \
    dq_coeff = LD_SH(dq_coeff_ptr);                                        \
    UNPCK_SH_SW(coeff, coeff_r_w, coeff_l_w);                              \
    ILVRL_H2_SH(coeff, dq_coeff, coeff_r_h, coeff_l_h);                    \
    HSUB_UH2_SW(coeff_r_h, coeff_l_h, diff_r, diff_l);                     \
    DPADD_SD2_SD(coeff_r_w, coeff_l_w, sq_coeff_r, sq_coeff_l);            \
    DPADD_SD2_SD(diff_r, diff_l, err0, err1);                              \
                                                                           \
    coeff = LD_SH(coeff_ptr + 8);                                          \
    dq_coeff = LD_SH(dq_coeff_ptr + 8);                                    \
    UNPCK_SH_SW(coeff, coeff_r_w, coeff_l_w);                              \
    ILVRL_H2_SH(coeff, dq_coeff, coeff_r_h, coeff_l_h);                    \
    HSUB_UH2_SW(coeff_r_h, coeff_l_h, diff_r, diff_l);                     \
    DPADD_SD2_SD(coeff_r_w, coeff_l_w, sq_coeff_r, sq_coeff_l);            \
    DPADD_SD2_SD(diff_r, diff_l, err0, err1);                              \
                                                                           \
    coeff_ptr += 16;                                                       \
    dq_coeff_ptr += 16;                                                    \
  }                                                                        \
                                                                           \
  err_dup0 = __msa_splati_d(sq_coeff_r, 1);                                \
  err_dup1 = __msa_splati_d(sq_coeff_l, 1);                                \
  sq_coeff_r += err_dup0;                                                  \
  sq_coeff_l += err_dup1;                                                  \
  *ssz = __msa_copy_s_d(sq_coeff_r, 0);                                    \
  *ssz += __msa_copy_s_d(sq_coeff_l, 0);                                   \
                                                                           \
  err_dup0 = __msa_splati_d(err0, 1);                                      \
  err_dup1 = __msa_splati_d(err1, 1);                                      \
  err0 += err_dup0;                                                        \
  err1 += err_dup1;                                                        \
  err = __msa_copy_s_d(err0, 0);                                           \
  err += __msa_copy_s_d(err1, 0);                                          \
                                                                           \
  return err;                                                              \
}

BLOCK_ERROR_BLOCKSIZE_MSA(16);
BLOCK_ERROR_BLOCKSIZE_MSA(64);
BLOCK_ERROR_BLOCKSIZE_MSA(256);
BLOCK_ERROR_BLOCKSIZE_MSA(1024);

int64_t vp10_block_error_msa(const tran_low_t *coeff_ptr,
                            const tran_low_t *dq_coeff_ptr,
                            intptr_t blk_size, int64_t *ssz) {
  int64_t err;
  const int16_t *coeff = (const int16_t *)coeff_ptr;
  const int16_t *dq_coeff = (const int16_t *)dq_coeff_ptr;

  switch (blk_size) {
    case 16:
      err = block_error_16size_msa(coeff, dq_coeff, ssz);
      break;
    case 64:
      err = block_error_64size_msa(coeff, dq_coeff, ssz);
      break;
    case 256:
      err = block_error_256size_msa(coeff, dq_coeff, ssz);
      break;
    case 1024:
      err = block_error_1024size_msa(coeff, dq_coeff, ssz);
      break;
    default:
      err = vp10_block_error_c(coeff_ptr, dq_coeff_ptr, blk_size, ssz);
      break;
  }

  return err;
}