xref: /aosp_15_r20/external/libvpx/vpx_dsp/loongarch/variance_lsx.h (revision fb1b10ab9aebc7c7068eedab379b749d7e3900be)
1 /*
2  *  Copyright (c) 2022 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 #ifndef VPX_VPX_DSP_LOONGARCH_VARIANCE_LSX_H_
12 #define VPX_VPX_DSP_LOONGARCH_VARIANCE_LSX_H_
13 
14 #include "vpx_util/loongson_intrinsics.h"
15 
16 #define HADD_SW_S32(in0, in1)                  \
17   do {                                         \
18     __m128i res0_m;                            \
19                                                \
20     res0_m = __lsx_vhaddw_d_w(in0, in0);       \
21     res0_m = __lsx_vhaddw_q_d(res0_m, res0_m); \
22     in1 = __lsx_vpickve2gr_w(res0_m, 0);       \
23   } while (0)
24 
25 #define HORIZ_2TAP_FILT_UH(in0, in1, mask, coeff, shift, in2) \
26   do {                                                        \
27     __m128i tmp0_m, tmp1_m;                                   \
28                                                               \
29     tmp0_m = __lsx_vshuf_b(in1, in0, mask);                   \
30     tmp1_m = __lsx_vdp2_h_bu(tmp0_m, coeff);                  \
31     in2 = __lsx_vsrari_h(tmp1_m, shift);                      \
32   } while (0)
33 
34 #define CALC_MSE_B(src, ref, var)                                         \
35   do {                                                                    \
36     __m128i src_l0_m, src_l1_m;                                           \
37     __m128i res_l0_m, res_l1_m;                                           \
38                                                                           \
39     src_l0_m = __lsx_vilvl_b(src, ref);                                   \
40     src_l1_m = __lsx_vilvh_b(src, ref);                                   \
41     DUP2_ARG2(__lsx_vhsubw_hu_bu, src_l0_m, src_l0_m, src_l1_m, src_l1_m, \
42               res_l0_m, res_l1_m);                                        \
43     var = __lsx_vdp2add_w_h(var, res_l0_m, res_l0_m);                     \
44     var = __lsx_vdp2add_w_h(var, res_l1_m, res_l1_m);                     \
45   } while (0)
46 
47 #define CALC_MSE_AVG_B(src, ref, var, sub)                                \
48   do {                                                                    \
49     __m128i src_l0_m, src_l1_m;                                           \
50     __m128i res_l0_m, res_l1_m;                                           \
51                                                                           \
52     src_l0_m = __lsx_vilvl_b(src, ref);                                   \
53     src_l1_m = __lsx_vilvh_b(src, ref);                                   \
54     DUP2_ARG2(__lsx_vhsubw_hu_bu, src_l0_m, src_l0_m, src_l1_m, src_l1_m, \
55               res_l0_m, res_l1_m);                                        \
56     var = __lsx_vdp2add_w_h(var, res_l0_m, res_l0_m);                     \
57     var = __lsx_vdp2add_w_h(var, res_l1_m, res_l1_m);                     \
58     sub = __lsx_vadd_h(sub, res_l0_m);                                    \
59     sub = __lsx_vadd_h(sub, res_l1_m);                                    \
60   } while (0)
61 
62 #endif  // VPX_VPX_DSP_LOONGARCH_VARIANCE_LSX_H_
63