[FFmpeg-devel] [PATCH 3/4] avcodec: [loongarch] Optimize vp9_lpf/idct with LSX.

Hao Chen chenhao at loongson.cn
Sat Dec 18 16:27:56 EET 2021


From: Jin Bo <jinbo at loongson.cn>

ffmpeg -i ../10_vp9_1080p_30fps_3Mbps.webm -f rawvideo -y /dev/null -an
before:294fps
after :567fps
---
 libavcodec/loongarch/Makefile                |    4 +-
 libavcodec/loongarch/vp9_idct_lsx.c          | 1411 ++++++++
 libavcodec/loongarch/vp9_lpf_lsx.c           | 3141 ++++++++++++++++++
 libavcodec/loongarch/vp9dsp_init_loongarch.c |   33 +
 libavcodec/loongarch/vp9dsp_loongarch.h      |   38 +
 5 files changed, 4626 insertions(+), 1 deletion(-)
 create mode 100644 libavcodec/loongarch/vp9_idct_lsx.c
 create mode 100644 libavcodec/loongarch/vp9_lpf_lsx.c

diff --git a/libavcodec/loongarch/Makefile b/libavcodec/loongarch/Makefile
index 6fcebe40a3..4b83f20e92 100644
--- a/libavcodec/loongarch/Makefile
+++ b/libavcodec/loongarch/Makefile
@@ -13,4 +13,6 @@ LASX-OBJS-$(CONFIG_H264PRED)          += loongarch/h264_intrapred_lasx.o
 LSX-OBJS-$(CONFIG_VP8_DECODER)        += loongarch/vp8_mc_lsx.o \
                                          loongarch/vp8_lpf_lsx.o
 LSX-OBJS-$(CONFIG_VP9_DECODER)        += loongarch/vp9_mc_lsx.o \
-                                         loongarch/vp9_intra_lsx.o
+                                         loongarch/vp9_intra_lsx.o \
+                                         loongarch/vp9_lpf_lsx.o \
+                                         loongarch/vp9_idct_lsx.o
diff --git a/libavcodec/loongarch/vp9_idct_lsx.c b/libavcodec/loongarch/vp9_idct_lsx.c
new file mode 100644
index 0000000000..88805814c6
--- /dev/null
+++ b/libavcodec/loongarch/vp9_idct_lsx.c
@@ -0,0 +1,1411 @@
+/*
+ * Copyright (c) 2021 Loongson Technology Corporation Limited
+ * Contributed by Jin Bo <jinbo at loongson.cn>
+ *
+ * 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 "libavcodec/vp9dsp.h"
+#include "libavutil/loongarch/loongson_intrinsics.h"
+#include "vp9dsp_loongarch.h"
+#include "libavutil/attributes.h"
+
+#define VP9_DCT_CONST_BITS   14
+#define ALLOC_ALIGNED(align) __attribute__ ((aligned(align)))
+#define ROUND_POWER_OF_TWO(value, n) (((value) + (1 << ((n) - 1))) >> (n))
+
+const int32_t cospi_1_64 = 16364;
+const int32_t cospi_2_64 = 16305;
+const int32_t cospi_3_64 = 16207;
+const int32_t cospi_4_64 = 16069;
+const int32_t cospi_5_64 = 15893;
+const int32_t cospi_6_64 = 15679;
+const int32_t cospi_7_64 = 15426;
+const int32_t cospi_8_64 = 15137;
+const int32_t cospi_9_64 = 14811;
+const int32_t cospi_10_64 = 14449;
+const int32_t cospi_11_64 = 14053;
+const int32_t cospi_12_64 = 13623;
+const int32_t cospi_13_64 = 13160;
+const int32_t cospi_14_64 = 12665;
+const int32_t cospi_15_64 = 12140;
+const int32_t cospi_16_64 = 11585;
+const int32_t cospi_17_64 = 11003;
+const int32_t cospi_18_64 = 10394;
+const int32_t cospi_19_64 = 9760;
+const int32_t cospi_20_64 = 9102;
+const int32_t cospi_21_64 = 8423;
+const int32_t cospi_22_64 = 7723;
+const int32_t cospi_23_64 = 7005;
+const int32_t cospi_24_64 = 6270;
+const int32_t cospi_25_64 = 5520;
+const int32_t cospi_26_64 = 4756;
+const int32_t cospi_27_64 = 3981;
+const int32_t cospi_28_64 = 3196;
+const int32_t cospi_29_64 = 2404;
+const int32_t cospi_30_64 = 1606;
+const int32_t cospi_31_64 = 804;
+
+const int32_t sinpi_1_9 = 5283;
+const int32_t sinpi_2_9 = 9929;
+const int32_t sinpi_3_9 = 13377;
+const int32_t sinpi_4_9 = 15212;
+
+#define VP9_DOTP_CONST_PAIR(reg0, reg1, cnst0, cnst1, out0, out1)  \
+{                                                                  \
+    __m128i k0_m = __lsx_vreplgr2vr_h(cnst0);                      \
+    __m128i s0_m, s1_m, s2_m, s3_m;                                \
+                                                                   \
+    s0_m = __lsx_vreplgr2vr_h(cnst1);                              \
+    k0_m = __lsx_vpackev_h(s0_m, k0_m);                            \
+                                                                   \
+    s1_m = __lsx_vilvl_h(__lsx_vneg_h(reg1), reg0);                \
+    s0_m = __lsx_vilvh_h(__lsx_vneg_h(reg1), reg0);                \
+    s3_m = __lsx_vilvl_h(reg0, reg1);                              \
+    s2_m = __lsx_vilvh_h(reg0, reg1);                              \
+    DUP2_ARG2(__lsx_vdp2_w_h, s1_m, k0_m, s0_m, k0_m, s1_m, s0_m); \
+    DUP2_ARG2(__lsx_vsrari_w, s1_m, VP9_DCT_CONST_BITS,            \
+              s0_m, VP9_DCT_CONST_BITS, s1_m, s0_m);               \
+    out0 = __lsx_vpickev_h(s0_m, s1_m);                            \
+    DUP2_ARG2(__lsx_vdp2_w_h, s3_m, k0_m, s2_m, k0_m, s1_m, s0_m); \
+    DUP2_ARG2(__lsx_vsrari_w, s1_m, VP9_DCT_CONST_BITS,            \
+              s0_m, VP9_DCT_CONST_BITS, s1_m, s0_m);               \
+    out1 = __lsx_vpickev_h(s0_m, s1_m);                            \
+}
+
+#define VP9_SET_COSPI_PAIR(c0_h, c1_h)    \
+( {                                       \
+    __m128i out0_m, r0_m, r1_m;           \
+                                          \
+    r0_m = __lsx_vreplgr2vr_h(c0_h);      \
+    r1_m = __lsx_vreplgr2vr_h(c1_h);      \
+    out0_m = __lsx_vpackev_h(r1_m, r0_m); \
+                                          \
+    out0_m;                               \
+} )
+
+#define VP9_ADDBLK_ST8x4_UB(dst, dst_stride, in0, in1, in2, in3)      \
+{                                                                     \
+    uint8_t *dst_m = (uint8_t *) (dst);                               \
+    __m128i dst0_m, dst1_m, dst2_m, dst3_m;                           \
+    __m128i tmp0_m, tmp1_m;                                           \
+    __m128i res0_m, res1_m, res2_m, res3_m;                           \
+    __m128i zero_m = __lsx_vldi(0);                                   \
+    DUP4_ARG2(__lsx_vld, dst_m, 0, dst_m + dst_stride, 0,             \
+              dst_m + 2 * dst_stride, 0, dst_m + 3 * dst_stride, 0,   \
+              dst0_m, dst1_m, dst2_m, dst3_m);                        \
+    DUP4_ARG2(__lsx_vilvl_b, zero_m, dst0_m, zero_m, dst1_m, zero_m,  \
+              dst2_m, zero_m, dst3_m, res0_m, res1_m, res2_m, res3_m);\
+    DUP4_ARG2(__lsx_vadd_h, res0_m, in0, res1_m, in1, res2_m, in2,    \
+              res3_m, in3, res0_m, res1_m, res2_m, res3_m);           \
+    DUP4_ARG1(__lsx_vclip255_h, res0_m, res1_m, res2_m, res3_m,       \
+              res0_m, res1_m, res2_m, res3_m);                        \
+    DUP2_ARG2(__lsx_vpickev_b, res1_m, res0_m, res3_m, res2_m,        \
+              tmp0_m, tmp1_m);                                        \
+    __lsx_vstelm_d(tmp0_m, dst_m, 0, 0);                              \
+    __lsx_vstelm_d(tmp0_m, dst_m + dst_stride, 0, 1);                 \
+    __lsx_vstelm_d(tmp1_m, dst_m + 2 * dst_stride, 0, 0);             \
+    __lsx_vstelm_d(tmp1_m, dst_m + 3 * dst_stride, 0, 1);             \
+}
+
+#define VP9_UNPCK_UB_SH(in, out_h, out_l) \
+{                                         \
+    __m128i zero = __lsx_vldi(0);         \
+    out_l = __lsx_vilvl_b(zero, in);      \
+    out_h = __lsx_vilvh_b(zero, in);      \
+}
+
+#define VP9_ILVLTRANS4x8_H(in0, in1, in2, in3, in4, in5, in6, in7,          \
+                           out0, out1, out2, out3, out4, out5, out6, out7)  \
+{                                                                           \
+    __m128i tmp0_m, tmp1_m, tmp2_m, tmp3_m;                                 \
+    __m128i tmp0_n, tmp1_n, tmp2_n, tmp3_n;                                 \
+    __m128i zero_m = __lsx_vldi(0);                                         \
+                                                                            \
+    DUP4_ARG2(__lsx_vilvl_h, in1, in0, in3, in2, in5, in4, in7, in6,        \
+              tmp0_n, tmp1_n, tmp2_n, tmp3_n);                              \
+    tmp0_m = __lsx_vilvl_w(tmp1_n, tmp0_n);                                 \
+    tmp2_m = __lsx_vilvh_w(tmp1_n, tmp0_n);                                 \
+    tmp1_m = __lsx_vilvl_w(tmp3_n, tmp2_n);                                 \
+    tmp3_m = __lsx_vilvh_w(tmp3_n, tmp2_n);                                 \
+                                                                            \
+    out0 = __lsx_vilvl_d(tmp1_m, tmp0_m);                                   \
+    out1 = __lsx_vilvh_d(tmp1_m, tmp0_m);                                   \
+    out2 = __lsx_vilvl_d(tmp3_m, tmp2_m);                                   \
+    out3 = __lsx_vilvh_d(tmp3_m, tmp2_m);                                   \
+                                                                            \
+    out4 = zero_m;                                                          \
+    out5 = zero_m;                                                          \
+    out6 = zero_m;                                                          \
+    out7 = zero_m;                                                          \
+}
+
+/* multiply and add macro */
+#define VP9_MADD(inp0, inp1, inp2, inp3, cst0, cst1, cst2, cst3,            \
+                 out0, out1, out2, out3)                                    \
+{                                                                           \
+    __m128i madd_s0_m, madd_s1_m, madd_s2_m, madd_s3_m;                     \
+    __m128i tmp0_m, tmp1_m, tmp2_m, tmp3_m;                                 \
+                                                                            \
+    madd_s1_m = __lsx_vilvl_h(inp1, inp0);                                  \
+    madd_s0_m = __lsx_vilvh_h(inp1, inp0);                                  \
+    madd_s3_m = __lsx_vilvl_h(inp3, inp2);                                  \
+    madd_s2_m = __lsx_vilvh_h(inp3, inp2);                                  \
+    DUP4_ARG2(__lsx_vdp2_w_h, madd_s1_m, cst0, madd_s0_m, cst0,             \
+              madd_s1_m, cst1, madd_s0_m, cst1, tmp0_m, tmp1_m,             \
+              tmp2_m, tmp3_m);                                              \
+    DUP4_ARG2(__lsx_vsrari_w, tmp0_m, VP9_DCT_CONST_BITS, tmp1_m,           \
+              VP9_DCT_CONST_BITS, tmp2_m, VP9_DCT_CONST_BITS, tmp3_m,       \
+              VP9_DCT_CONST_BITS, tmp0_m, tmp1_m, tmp2_m, tmp3_m);          \
+    DUP2_ARG2(__lsx_vpickev_h, tmp1_m, tmp0_m, tmp3_m, tmp2_m, out0, out1); \
+    DUP4_ARG2(__lsx_vdp2_w_h, madd_s3_m, cst2, madd_s2_m, cst2, madd_s3_m,  \
+              cst3, madd_s2_m, cst3, tmp0_m, tmp1_m, tmp2_m, tmp3_m);       \
+    DUP4_ARG2(__lsx_vsrari_w, tmp0_m, VP9_DCT_CONST_BITS,                   \
+              tmp1_m, VP9_DCT_CONST_BITS, tmp2_m, VP9_DCT_CONST_BITS,       \
+              tmp3_m, VP9_DCT_CONST_BITS, tmp0_m, tmp1_m, tmp2_m, tmp3_m);  \
+    DUP2_ARG2(__lsx_vpickev_h, tmp1_m, tmp0_m, tmp3_m, tmp2_m, out2, out3); \
+}
+
+#define VP9_SET_CONST_PAIR(mask_h, idx1_h, idx2_h)                           \
+( {                                                                          \
+    __m128i c0_m, c1_m;                                                      \
+                                                                             \
+    DUP2_ARG2(__lsx_vreplvei_h, mask_h, idx1_h, mask_h, idx2_h, c0_m, c1_m); \
+    c0_m = __lsx_vpackev_h(c1_m, c0_m);                                      \
+                                                                             \
+    c0_m;                                                                    \
+} )
+
+/* idct 8x8 macro */
+#define VP9_IDCT8x8_1D(in0, in1, in2, in3, in4, in5, in6, in7,                 \
+                       out0, out1, out2, out3, out4, out5, out6, out7)         \
+{                                                                              \
+    __m128i tp0_m, tp1_m, tp2_m, tp3_m, tp4_m, tp5_m, tp6_m, tp7_m;            \
+    __m128i k0_m, k1_m, k2_m, k3_m, res0_m, res1_m, res2_m, res3_m;            \
+    __m128i tmp0_m, tmp1_m, tmp2_m, tmp3_m;                                    \
+    v8i16 mask_m = { cospi_28_64, cospi_4_64, cospi_20_64, cospi_12_64,        \
+          cospi_16_64, -cospi_4_64, -cospi_20_64, -cospi_16_64 };              \
+                                                                               \
+    k0_m = VP9_SET_CONST_PAIR(mask_m, 0, 5);                                   \
+    k1_m = VP9_SET_CONST_PAIR(mask_m, 1, 0);                                   \
+    k2_m = VP9_SET_CONST_PAIR(mask_m, 6, 3);                                   \
+    k3_m = VP9_SET_CONST_PAIR(mask_m, 3, 2);                                   \
+    VP9_MADD(in1, in7, in3, in5, k0_m, k1_m, k2_m, k3_m, in1, in7, in3, in5);  \
+    DUP2_ARG2(__lsx_vsub_h, in1, in3, in7, in5, res0_m, res1_m);               \
+    k0_m = VP9_SET_CONST_PAIR(mask_m, 4, 7);                                   \
+    k1_m = __lsx_vreplvei_h(mask_m, 4);                                        \
+                                                                               \
+    res2_m = __lsx_vilvl_h(res0_m, res1_m);                                    \
+    res3_m = __lsx_vilvh_h(res0_m, res1_m);                                    \
+    DUP4_ARG2(__lsx_vdp2_w_h, res2_m, k0_m, res3_m, k0_m, res2_m, k1_m,        \
+              res3_m, k1_m, tmp0_m, tmp1_m, tmp2_m, tmp3_m);                   \
+    DUP4_ARG2(__lsx_vsrari_w, tmp0_m, VP9_DCT_CONST_BITS,                      \
+              tmp1_m, VP9_DCT_CONST_BITS, tmp2_m, VP9_DCT_CONST_BITS,          \
+              tmp3_m, VP9_DCT_CONST_BITS, tmp0_m, tmp1_m, tmp2_m, tmp3_m);     \
+    tp4_m = __lsx_vadd_h(in1, in3);                                            \
+    DUP2_ARG2(__lsx_vpickev_h, tmp1_m, tmp0_m, tmp3_m, tmp2_m, tp5_m, tp6_m);  \
+    tp7_m = __lsx_vadd_h(in7, in5);                                            \
+    k2_m = VP9_SET_COSPI_PAIR(cospi_24_64, -cospi_8_64);                       \
+    k3_m = VP9_SET_COSPI_PAIR(cospi_8_64, cospi_24_64);                        \
+    VP9_MADD(in0, in4, in2, in6, k1_m, k0_m, k2_m, k3_m,                       \
+             in0, in4, in2, in6);                                              \
+    LSX_BUTTERFLY_4_H(in0, in4, in2, in6, tp0_m, tp1_m, tp2_m, tp3_m);         \
+    LSX_BUTTERFLY_8_H(tp0_m, tp1_m, tp2_m, tp3_m, tp4_m, tp5_m, tp6_m, tp7_m,  \
+                  out0, out1, out2, out3, out4, out5, out6, out7);             \
+}
+
+static av_always_inline
+void vp9_idct8x8_1_add_lsx(int16_t *input, uint8_t *dst,
+                                  int32_t dst_stride)
+{
+    int16_t out;
+    int32_t val;
+    __m128i vec;
+
+    out = ROUND_POWER_OF_TWO((input[0] * cospi_16_64), VP9_DCT_CONST_BITS);
+    out = ROUND_POWER_OF_TWO((out * cospi_16_64), VP9_DCT_CONST_BITS);
+    val = ROUND_POWER_OF_TWO(out, 5);
+    vec = __lsx_vreplgr2vr_h(val);
+    input[0] = 0;
+
+    VP9_ADDBLK_ST8x4_UB(dst, dst_stride, vec, vec, vec, vec);
+    dst += (4 * dst_stride);
+    VP9_ADDBLK_ST8x4_UB(dst, dst_stride, vec, vec, vec, vec);
+}
+
+static void vp9_idct8x8_12_colcol_addblk_lsx(int16_t *input, uint8_t *dst,
+                                             int32_t dst_stride)
+{
+    __m128i in0, in1, in2, in3, in4, in5, in6, in7;
+    __m128i s0, s1, s2, s3, s4, s5, s6, s7, k0, k1, k2, k3, m0, m1, m2, m3;
+    __m128i tmp0, tmp1, tmp2, tmp3;
+    __m128i zero = __lsx_vldi(0);
+
+    /* load vector elements of 8x8 block */
+    DUP4_ARG2(__lsx_vld, input, 0, input, 16, input, 32, input, 48,
+              in0, in1, in2, in3);
+    DUP4_ARG2(__lsx_vld, input, 64, input, 80, input, 96, input, 112,
+              in4, in5, in6, in7);
+    __lsx_vst(zero, input, 0);
+    __lsx_vst(zero, input, 16);
+    __lsx_vst(zero, input, 32);
+    __lsx_vst(zero, input, 48);
+    __lsx_vst(zero, input, 64);
+    __lsx_vst(zero, input, 80);
+    __lsx_vst(zero, input, 96);
+    __lsx_vst(zero, input, 112);
+    DUP4_ARG2(__lsx_vilvl_d,in1, in0, in3, in2, in5, in4, in7,
+              in6, in0, in1, in2, in3);
+
+    /* stage1 */
+    DUP2_ARG2(__lsx_vilvh_h, in3, in0, in2, in1, s0, s1);
+    k0 = VP9_SET_COSPI_PAIR(cospi_28_64, -cospi_4_64);
+    k1 = VP9_SET_COSPI_PAIR(cospi_4_64, cospi_28_64);
+    k2 = VP9_SET_COSPI_PAIR(-cospi_20_64, cospi_12_64);
+    k3 = VP9_SET_COSPI_PAIR(cospi_12_64, cospi_20_64);
+    DUP4_ARG2(__lsx_vdp2_w_h, s0, k0, s0, k1, s1, k2, s1, k3,
+              tmp0, tmp1, tmp2, tmp3);
+    DUP4_ARG2(__lsx_vsrari_w, tmp0, VP9_DCT_CONST_BITS, tmp1,
+              VP9_DCT_CONST_BITS, tmp2, VP9_DCT_CONST_BITS, tmp3,
+              VP9_DCT_CONST_BITS, tmp0, tmp1, tmp2, tmp3);
+    DUP4_ARG2(__lsx_vpickev_h, zero, tmp0, zero, tmp1, zero, tmp2, zero, tmp3,
+              s0, s1, s2, s3);
+    LSX_BUTTERFLY_4_H(s0, s1, s3, s2, s4, s7, s6, s5);
+
+    /* stage2 */
+    DUP2_ARG2(__lsx_vilvl_h, in3, in1, in2, in0, s1, s0);
+    k0 = VP9_SET_COSPI_PAIR(cospi_16_64, cospi_16_64);
+    k1 = VP9_SET_COSPI_PAIR(cospi_16_64, -cospi_16_64);
+    k2 = VP9_SET_COSPI_PAIR(cospi_24_64, -cospi_8_64);
+    k3 = VP9_SET_COSPI_PAIR(cospi_8_64, cospi_24_64);
+    DUP4_ARG2(__lsx_vdp2_w_h, s0, k0, s0, k1, s1, k2, s1, k3,
+                  tmp0, tmp1, tmp2, tmp3);
+    DUP4_ARG2(__lsx_vsrari_w, tmp0, VP9_DCT_CONST_BITS, tmp1,
+              VP9_DCT_CONST_BITS, tmp2, VP9_DCT_CONST_BITS, tmp3,
+              VP9_DCT_CONST_BITS, tmp0, tmp1, tmp2, tmp3);
+    DUP4_ARG2(__lsx_vpickev_h, zero, tmp0, zero, tmp1, zero, tmp2, zero, tmp3,
+              s0, s1, s2, s3);
+    LSX_BUTTERFLY_4_H(s0, s1, s2, s3, m0, m1, m2, m3);
+
+    /* stage3 */
+    s0 = __lsx_vilvl_h(s6, s5);
+
+    k1 = VP9_SET_COSPI_PAIR(-cospi_16_64, cospi_16_64);
+    DUP2_ARG2(__lsx_vdp2_w_h, s0, k1, s0, k0, tmp0, tmp1);
+    DUP2_ARG2(__lsx_vsrari_w, tmp0, VP9_DCT_CONST_BITS, tmp1,
+              VP9_DCT_CONST_BITS, tmp0, tmp1);
+    DUP2_ARG2(__lsx_vpickev_h, zero, tmp0, zero, tmp1, s2, s3);
+
+    /* stage4 */
+    LSX_BUTTERFLY_8_H(m0, m1, m2, m3, s4, s2, s3, s7,
+                      in0, in1, in2, in3, in4, in5, in6, in7);
+    VP9_ILVLTRANS4x8_H(in0, in1, in2, in3, in4, in5, in6, in7,
+                       in0, in1, in2, in3, in4, in5, in6, in7);
+    VP9_IDCT8x8_1D(in0, in1, in2, in3, in4, in5, in6, in7,
+                   in0, in1, in2, in3, in4, in5, in6, in7);
+
+    /* final rounding (add 2^4, divide by 2^5) and shift */
+    DUP4_ARG2(__lsx_vsrari_h, in0 , 5, in1, 5, in2, 5, in3, 5,
+              in0, in1, in2, in3);
+    DUP4_ARG2(__lsx_vsrari_h, in4 , 5, in5, 5, in6, 5, in7, 5,
+              in4, in5, in6, in7);
+
+    /* add block and store 8x8 */
+    VP9_ADDBLK_ST8x4_UB(dst, dst_stride, in0, in1, in2, in3);
+    dst += (4 * dst_stride);
+    VP9_ADDBLK_ST8x4_UB(dst, dst_stride, in4, in5, in6, in7);
+}
+
+static void vp9_idct8x8_colcol_addblk_lsx(int16_t *input, uint8_t *dst,
+                                          int32_t dst_stride)
+{
+    __m128i in0, in1, in2, in3, in4, in5, in6, in7;
+    __m128i zero = __lsx_vldi(0);
+
+    /* load vector elements of 8x8 block */
+    DUP4_ARG2(__lsx_vld, input, 0, input, 16, input, 32, input, 48,
+              in0, in1, in2, in3);
+    DUP4_ARG2(__lsx_vld, input, 64, input, 80, input, 96, input, 112,
+              in4, in5, in6, in7);
+    __lsx_vst(zero, input, 0);
+    __lsx_vst(zero, input, 16);
+    __lsx_vst(zero, input, 32);
+    __lsx_vst(zero, input, 48);
+    __lsx_vst(zero, input, 64);
+    __lsx_vst(zero, input, 80);
+    __lsx_vst(zero, input, 96);
+    __lsx_vst(zero, input, 112);
+    /* 1D idct8x8 */
+    VP9_IDCT8x8_1D(in0, in1, in2, in3, in4, in5, in6, in7,
+                   in0, in1, in2, in3, in4, in5, in6, in7);
+    /* columns transform */
+    LSX_TRANSPOSE8x8_H(in0, in1, in2, in3, in4, in5, in6, in7,
+                       in0, in1, in2, in3, in4, in5, in6, in7);
+    /* 1D idct8x8 */
+    VP9_IDCT8x8_1D(in0, in1, in2, in3, in4, in5, in6, in7,
+                   in0, in1, in2, in3, in4, in5, in6, in7);
+    /* final rounding (add 2^4, divide by 2^5) and shift */
+    DUP4_ARG2(__lsx_vsrari_h, in0, 5, in1, 5, in2, 5, in3, 5,
+              in0, in1, in2, in3);
+    DUP4_ARG2(__lsx_vsrari_h, in4, 5, in5, 5, in6, 5, in7, 5,
+              in4, in5, in6, in7);
+    /* add block and store 8x8 */
+    VP9_ADDBLK_ST8x4_UB(dst, dst_stride, in0, in1, in2, in3);
+    dst += (4 * dst_stride);
+    VP9_ADDBLK_ST8x4_UB(dst, dst_stride, in4, in5, in6, in7);
+}
+
+static void vp9_idct16_1d_columns_addblk_lsx(int16_t *input, uint8_t *dst,
+                                             int32_t dst_stride)
+{
+    __m128i loc0, loc1, loc2, loc3;
+    __m128i reg0, reg2, reg4, reg6, reg8, reg10, reg12, reg14;
+    __m128i reg1, reg3, reg5, reg7, reg9, reg11, reg13, reg15;
+    __m128i tmp5, tmp6, tmp7;
+    __m128i zero = __lsx_vldi(0);
+    int32_t offset = dst_stride << 2;
+
+    DUP4_ARG2(__lsx_vld, input, 32*0, input, 32*1, input, 32*2, input, 32*3,
+              reg0, reg1, reg2, reg3);
+    DUP4_ARG2(__lsx_vld, input, 32*4, input, 32*5, input, 32*6, input, 32*7,
+              reg4, reg5, reg6, reg7);
+    DUP4_ARG2(__lsx_vld, input, 32*8, input, 32*9, input, 32*10, input, 32*11,
+              reg8, reg9, reg10, reg11);
+    DUP4_ARG2(__lsx_vld, input, 32*12, input, 32*13, input, 32*14, input,
+              32*15, reg12, reg13, reg14, reg15);
+
+    __lsx_vst(zero, input, 32*0);
+    __lsx_vst(zero, input, 32*1);
+    __lsx_vst(zero, input, 32*2);
+    __lsx_vst(zero, input, 32*3);
+    __lsx_vst(zero, input, 32*4);
+    __lsx_vst(zero, input, 32*5);
+    __lsx_vst(zero, input, 32*6);
+    __lsx_vst(zero, input, 32*7);
+    __lsx_vst(zero, input, 32*8);
+    __lsx_vst(zero, input, 32*9);
+    __lsx_vst(zero, input, 32*10);
+    __lsx_vst(zero, input, 32*11);
+    __lsx_vst(zero, input, 32*12);
+    __lsx_vst(zero, input, 32*13);
+    __lsx_vst(zero, input, 32*14);
+    __lsx_vst(zero, input, 32*15);
+
+    VP9_DOTP_CONST_PAIR(reg2, reg14, cospi_28_64, cospi_4_64, reg2, reg14);
+    VP9_DOTP_CONST_PAIR(reg10, reg6, cospi_12_64, cospi_20_64, reg10, reg6);
+    LSX_BUTTERFLY_4_H(reg2, reg14, reg6, reg10, loc0, loc1, reg14, reg2);
+    VP9_DOTP_CONST_PAIR(reg14, reg2, cospi_16_64, cospi_16_64, loc2, loc3);
+    VP9_DOTP_CONST_PAIR(reg0, reg8, cospi_16_64, cospi_16_64, reg0, reg8);
+    VP9_DOTP_CONST_PAIR(reg4, reg12, cospi_24_64, cospi_8_64, reg4, reg12);
+    LSX_BUTTERFLY_4_H(reg8, reg0, reg4, reg12, reg2, reg6, reg10, reg14);
+
+    reg0 = __lsx_vsub_h(reg2, loc1);
+    reg2 = __lsx_vadd_h(reg2, loc1);
+    reg12 = __lsx_vsub_h(reg14, loc0);
+    reg14 = __lsx_vadd_h(reg14, loc0);
+    reg4 = __lsx_vsub_h(reg6, loc3);
+    reg6 = __lsx_vadd_h(reg6, loc3);
+    reg8 = __lsx_vsub_h(reg10, loc2);
+    reg10 = __lsx_vadd_h(reg10, loc2);
+
+    /* stage2 */
+    VP9_DOTP_CONST_PAIR(reg1, reg15, cospi_30_64, cospi_2_64, reg1, reg15);
+    VP9_DOTP_CONST_PAIR(reg9, reg7, cospi_14_64, cospi_18_64, loc2, loc3);
+
+    reg9 = __lsx_vsub_h(reg1, loc2);
+    reg1 = __lsx_vadd_h(reg1, loc2);
+    reg7 = __lsx_vsub_h(reg15, loc3);
+    reg15 = __lsx_vadd_h(reg15, loc3);
+
+    VP9_DOTP_CONST_PAIR(reg5, reg11, cospi_22_64, cospi_10_64, reg5, reg11);
+    VP9_DOTP_CONST_PAIR(reg13, reg3, cospi_6_64, cospi_26_64, loc0, loc1);
+    LSX_BUTTERFLY_4_H(loc0, loc1, reg11, reg5, reg13, reg3, reg11, reg5);
+
+    loc1 = __lsx_vadd_h(reg15, reg3);
+    reg3 = __lsx_vsub_h(reg15, reg3);
+    loc2 = __lsx_vadd_h(reg2, loc1);
+    reg15 = __lsx_vsub_h(reg2, loc1);
+
+    loc1 = __lsx_vadd_h(reg1, reg13);
+    reg13 = __lsx_vsub_h(reg1, reg13);
+    loc0 = __lsx_vadd_h(reg0, loc1);
+    loc1 = __lsx_vsub_h(reg0, loc1);
+    tmp6 = loc0;
+    tmp7 = loc1;
+    reg0 = loc2;
+
+    VP9_DOTP_CONST_PAIR(reg7, reg9, cospi_24_64, cospi_8_64, reg7, reg9);
+    VP9_DOTP_CONST_PAIR(__lsx_vneg_h(reg5), __lsx_vneg_h(reg11), cospi_8_64,
+                        cospi_24_64, reg5, reg11);
+
+    loc0 = __lsx_vadd_h(reg9, reg5);
+    reg5 = __lsx_vsub_h(reg9, reg5);
+    reg2 = __lsx_vadd_h(reg6, loc0);
+    reg1 = __lsx_vsub_h(reg6, loc0);
+
+    loc0 = __lsx_vadd_h(reg7, reg11);
+    reg11 = __lsx_vsub_h(reg7, reg11);
+    loc1 = __lsx_vadd_h(reg4, loc0);
+    loc2 = __lsx_vsub_h(reg4, loc0);
+    tmp5 = loc1;
+
+    VP9_DOTP_CONST_PAIR(reg5, reg11, cospi_16_64, cospi_16_64, reg5, reg11);
+    LSX_BUTTERFLY_4_H(reg8, reg10, reg11, reg5, loc0, reg4, reg9, loc1);
+
+    reg10 = loc0;
+    reg11 = loc1;
+
+    VP9_DOTP_CONST_PAIR(reg3, reg13, cospi_16_64, cospi_16_64, reg3, reg13);
+    LSX_BUTTERFLY_4_H(reg12, reg14, reg13, reg3, reg8, reg6, reg7, reg5);
+    reg13 = loc2;
+
+    /* Transpose and store the output */
+    reg12 = tmp5;
+    reg14 = tmp6;
+    reg3 = tmp7;
+
+    DUP4_ARG2(__lsx_vsrari_h, reg0, 6, reg2, 6, reg4, 6, reg6, 6,
+              reg0, reg2, reg4, reg6);
+    VP9_ADDBLK_ST8x4_UB(dst, dst_stride, reg0, reg2, reg4, reg6);
+    dst += offset;
+    DUP4_ARG2(__lsx_vsrari_h, reg8, 6, reg10, 6, reg12, 6, reg14, 6,
+              reg8, reg10, reg12, reg14);
+    VP9_ADDBLK_ST8x4_UB(dst, dst_stride, reg8, reg10, reg12, reg14);
+    dst += offset;
+    DUP4_ARG2(__lsx_vsrari_h, reg3, 6, reg5, 6, reg11, 6, reg13, 6,
+              reg3, reg5, reg11, reg13);
+    VP9_ADDBLK_ST8x4_UB(dst, dst_stride, reg3, reg13, reg11, reg5);
+    dst += offset;
+    DUP4_ARG2(__lsx_vsrari_h, reg1, 6, reg7, 6, reg9, 6, reg15, 6,
+              reg1, reg7, reg9, reg15);
+    VP9_ADDBLK_ST8x4_UB(dst, dst_stride, reg7, reg9, reg1, reg15);
+}
+
+static void vp9_idct16_1d_columns_lsx(int16_t *input, int16_t *output)
+{
+    __m128i loc0, loc1, loc2, loc3;
+    __m128i reg1, reg3, reg5, reg7, reg9, reg11, reg13, reg15;
+    __m128i reg0, reg2, reg4, reg6, reg8, reg10, reg12, reg14;
+    __m128i tmp5, tmp6, tmp7;
+    __m128i zero = __lsx_vldi(0);
+    int16_t *offset;
+
+    DUP4_ARG2(__lsx_vld, input, 32*0, input, 32*1, input, 32*2, input, 32*3,
+              reg0, reg1, reg2, reg3);
+    DUP4_ARG2(__lsx_vld, input, 32*4, input, 32*5, input, 32*6, input, 32*7,
+              reg4, reg5, reg6, reg7);
+    DUP4_ARG2(__lsx_vld, input, 32*8, input, 32*9, input, 32*10, input, 32*11,
+              reg8, reg9, reg10, reg11);
+    DUP4_ARG2(__lsx_vld, input, 32*12, input, 32*13, input, 32*14, input,
+              32*15, reg12, reg13, reg14, reg15);
+
+    __lsx_vst(zero, input, 32*0);
+    __lsx_vst(zero, input, 32*1);
+    __lsx_vst(zero, input, 32*2);
+    __lsx_vst(zero, input, 32*3);
+    __lsx_vst(zero, input, 32*4);
+    __lsx_vst(zero, input, 32*5);
+    __lsx_vst(zero, input, 32*6);
+    __lsx_vst(zero, input, 32*7);
+    __lsx_vst(zero, input, 32*8);
+    __lsx_vst(zero, input, 32*9);
+    __lsx_vst(zero, input, 32*10);
+    __lsx_vst(zero, input, 32*11);
+    __lsx_vst(zero, input, 32*12);
+    __lsx_vst(zero, input, 32*13);
+    __lsx_vst(zero, input, 32*14);
+    __lsx_vst(zero, input, 32*15);
+
+    VP9_DOTP_CONST_PAIR(reg2, reg14, cospi_28_64, cospi_4_64, reg2, reg14);
+    VP9_DOTP_CONST_PAIR(reg10, reg6, cospi_12_64, cospi_20_64, reg10, reg6);
+    LSX_BUTTERFLY_4_H(reg2, reg14, reg6, reg10, loc0, loc1, reg14, reg2);
+    VP9_DOTP_CONST_PAIR(reg14, reg2, cospi_16_64, cospi_16_64, loc2, loc3);
+    VP9_DOTP_CONST_PAIR(reg0, reg8, cospi_16_64, cospi_16_64, reg0, reg8);
+    VP9_DOTP_CONST_PAIR(reg4, reg12, cospi_24_64, cospi_8_64, reg4, reg12);
+    LSX_BUTTERFLY_4_H(reg8, reg0, reg4, reg12, reg2, reg6, reg10, reg14);
+
+    reg0 = __lsx_vsub_h(reg2, loc1);
+    reg2 = __lsx_vadd_h(reg2, loc1);
+    reg12 = __lsx_vsub_h(reg14, loc0);
+    reg14 = __lsx_vadd_h(reg14, loc0);
+    reg4 = __lsx_vsub_h(reg6, loc3);
+    reg6 = __lsx_vadd_h(reg6, loc3);
+    reg8 = __lsx_vsub_h(reg10, loc2);
+    reg10 = __lsx_vadd_h(reg10, loc2);
+
+    /* stage2 */
+    VP9_DOTP_CONST_PAIR(reg1, reg15, cospi_30_64, cospi_2_64, reg1, reg15);
+    VP9_DOTP_CONST_PAIR(reg9, reg7, cospi_14_64, cospi_18_64, loc2, loc3);
+
+    reg9 = __lsx_vsub_h(reg1, loc2);
+    reg1 = __lsx_vadd_h(reg1, loc2);
+    reg7 = __lsx_vsub_h(reg15, loc3);
+    reg15 = __lsx_vadd_h(reg15, loc3);
+
+    VP9_DOTP_CONST_PAIR(reg5, reg11, cospi_22_64, cospi_10_64, reg5, reg11);
+    VP9_DOTP_CONST_PAIR(reg13, reg3, cospi_6_64, cospi_26_64, loc0, loc1);
+    LSX_BUTTERFLY_4_H(loc0, loc1, reg11, reg5, reg13, reg3, reg11, reg5);
+
+    loc1 = __lsx_vadd_h(reg15, reg3);
+    reg3 = __lsx_vsub_h(reg15, reg3);
+    loc2 = __lsx_vadd_h(reg2, loc1);
+    reg15 = __lsx_vsub_h(reg2, loc1);
+
+    loc1 = __lsx_vadd_h(reg1, reg13);
+    reg13 = __lsx_vsub_h(reg1, reg13);
+    loc0 = __lsx_vadd_h(reg0, loc1);
+    loc1 = __lsx_vsub_h(reg0, loc1);
+    tmp6 = loc0;
+    tmp7 = loc1;
+    reg0 = loc2;
+
+    VP9_DOTP_CONST_PAIR(reg7, reg9, cospi_24_64, cospi_8_64, reg7, reg9);
+    VP9_DOTP_CONST_PAIR(__lsx_vneg_h(reg5), __lsx_vneg_h(reg11), cospi_8_64,
+                        cospi_24_64, reg5, reg11);
+
+    loc0 = __lsx_vadd_h(reg9, reg5);
+    reg5 = __lsx_vsub_h(reg9, reg5);
+    reg2 = __lsx_vadd_h(reg6, loc0);
+    reg1 = __lsx_vsub_h(reg6, loc0);
+
+    loc0 = __lsx_vadd_h(reg7, reg11);
+    reg11 = __lsx_vsub_h(reg7, reg11);
+    loc1 = __lsx_vadd_h(reg4, loc0);
+    loc2 = __lsx_vsub_h(reg4, loc0);
+
+    tmp5 = loc1;
+
+    VP9_DOTP_CONST_PAIR(reg5, reg11, cospi_16_64, cospi_16_64, reg5, reg11);
+    LSX_BUTTERFLY_4_H(reg8, reg10, reg11, reg5, loc0, reg4, reg9, loc1);
+
+    reg10 = loc0;
+    reg11 = loc1;
+
+    VP9_DOTP_CONST_PAIR(reg3, reg13, cospi_16_64, cospi_16_64, reg3, reg13);
+    LSX_BUTTERFLY_4_H(reg12, reg14, reg13, reg3, reg8, reg6, reg7, reg5);
+    reg13 = loc2;
+
+    /* Transpose and store the output */
+    reg12 = tmp5;
+    reg14 = tmp6;
+    reg3 = tmp7;
+
+    /* transpose block */
+    LSX_TRANSPOSE8x8_H(reg0, reg2, reg4, reg6, reg8, reg10, reg12, reg14,
+                       reg0, reg2, reg4, reg6, reg8, reg10, reg12, reg14);
+
+    __lsx_vst(reg0, output, 32*0);
+    __lsx_vst(reg2, output, 32*1);
+    __lsx_vst(reg4, output, 32*2);
+    __lsx_vst(reg6, output, 32*3);
+    __lsx_vst(reg8, output, 32*4);
+    __lsx_vst(reg10, output, 32*5);
+    __lsx_vst(reg12, output, 32*6);
+    __lsx_vst(reg14, output, 32*7);
+
+    /* transpose block */
+    LSX_TRANSPOSE8x8_H(reg3, reg13, reg11, reg5, reg7, reg9, reg1, reg15,
+                       reg3, reg13, reg11, reg5, reg7, reg9, reg1, reg15);
+
+    offset = output + 8;
+    __lsx_vst(reg3, offset, 32*0);
+    __lsx_vst(reg13, offset, 32*1);
+    __lsx_vst(reg11, offset, 32*2);
+    __lsx_vst(reg5, offset, 32*3);
+
+    offset = output + 8 + 4 * 16;
+    __lsx_vst(reg7, offset, 32*0);
+    __lsx_vst(reg9, offset, 32*1);
+    __lsx_vst(reg1, offset, 32*2);
+    __lsx_vst(reg15, offset, 32*3);
+}
+
+static void vp9_idct16x16_1_add_lsx(int16_t *input, uint8_t *dst,
+                                    int32_t dst_stride)
+{
+    uint8_t i;
+    int16_t out;
+    __m128i vec, res0, res1, res2, res3, res4, res5, res6, res7;
+    __m128i dst0, dst1, dst2, dst3, tmp0, tmp1, tmp2, tmp3;
+    int32_t stride2 = dst_stride << 1;
+    int32_t stride3 = stride2 + dst_stride;
+    int32_t stride4 = stride2 << 1;
+
+    out = ROUND_POWER_OF_TWO((input[0] * cospi_16_64), VP9_DCT_CONST_BITS);
+    out = ROUND_POWER_OF_TWO((out * cospi_16_64), VP9_DCT_CONST_BITS);
+    out = ROUND_POWER_OF_TWO(out, 6);
+    input[0] = 0;
+    vec = __lsx_vreplgr2vr_h(out);
+
+    for (i = 4; i--;) {
+        dst0 = __lsx_vld(dst, 0);
+        DUP2_ARG2(__lsx_vldx, dst, dst_stride, dst, stride2, dst1, dst2);
+        dst3 = __lsx_vldx(dst, stride3);
+        VP9_UNPCK_UB_SH(dst0, res4, res0);
+        VP9_UNPCK_UB_SH(dst1, res5, res1);
+        VP9_UNPCK_UB_SH(dst2, res6, res2);
+        VP9_UNPCK_UB_SH(dst3, res7, res3);
+        DUP4_ARG2(__lsx_vadd_h, res0, vec, res1, vec, res2, vec, res3, vec,
+                  res0, res1, res2, res3);
+        DUP4_ARG2(__lsx_vadd_h, res4, vec, res5, vec, res6, vec, res7, vec,
+                  res4, res5, res6, res7);
+        DUP4_ARG1(__lsx_vclip255_h, res0, res1, res2, res3,
+                  res0, res1, res2, res3);
+        DUP4_ARG1(__lsx_vclip255_h, res4, res5, res6, res7,
+                  res4, res5, res6, res7);
+        DUP4_ARG2(__lsx_vpickev_b, res4, res0, res5, res1, res6,
+                  res2, res7, res3, tmp0, tmp1, tmp2, tmp3);
+        __lsx_vst(tmp0, dst, 0);
+        __lsx_vstx(tmp1, dst, dst_stride);
+        __lsx_vstx(tmp2, dst, stride2);
+        __lsx_vstx(tmp3, dst, stride3);
+        dst += stride4;
+    }
+}
+
+static void vp9_idct16x16_10_colcol_addblk_lsx(int16_t *input, uint8_t *dst,
+                                               int32_t dst_stride)
+{
+    int32_t i;
+    int16_t out_arr[16 * 16] ALLOC_ALIGNED(16);
+    int16_t *out = out_arr;
+    __m128i zero = __lsx_vldi(0);
+
+    /* transform rows */
+    vp9_idct16_1d_columns_lsx(input, out);
+
+    /* short case just considers top 4 rows as valid output */
+    out += 4 * 16;
+    for (i = 3; i--;) {
+        __lsx_vst(zero, out, 0);
+        __lsx_vst(zero, out, 16);
+        __lsx_vst(zero, out, 32);
+        __lsx_vst(zero, out, 48);
+        __lsx_vst(zero, out, 64);
+        __lsx_vst(zero, out, 80);
+        __lsx_vst(zero, out, 96);
+        __lsx_vst(zero, out, 112);
+        out += 64;
+    }
+
+    out = out_arr;
+
+    /* transform columns */
+    for (i = 0; i < 2; i++) {
+        /* process 8 * 16 block */
+        vp9_idct16_1d_columns_addblk_lsx((out + (i << 3)), (dst + (i << 3)),
+                                         dst_stride);
+    }
+}
+
+static void vp9_idct16x16_colcol_addblk_lsx(int16_t *input, uint8_t *dst,
+                                            int32_t dst_stride)
+{
+    int32_t i;
+    int16_t out_arr[16 * 16] ALLOC_ALIGNED(16);
+    int16_t *out = out_arr;
+
+    /* transform rows */
+    for (i = 0; i < 2; i++) {
+        /* process 8 * 16 block */
+        vp9_idct16_1d_columns_lsx((input + (i << 3)), (out + (i << 7)));
+    }
+
+    /* transform columns */
+    for (i = 0; i < 2; i++) {
+        /* process 8 * 16 block */
+        vp9_idct16_1d_columns_addblk_lsx((out + (i << 3)), (dst + (i << 3)),
+                                         dst_stride);
+    }
+}
+
+static void vp9_idct_butterfly_transpose_store(int16_t *tmp_buf,
+                                               int16_t *tmp_eve_buf,
+                                               int16_t *tmp_odd_buf,
+                                               int16_t *dst)
+{
+    __m128i vec0, vec1, vec2, vec3, loc0, loc1, loc2, loc3;
+    __m128i m0, m1, m2, m3, m4, m5, m6, m7, n0, n1, n2, n3, n4, n5, n6, n7;
+
+    /* FINAL BUTTERFLY : Dependency on Even & Odd */
+    vec0 = __lsx_vld(tmp_odd_buf, 0);
+    vec1 = __lsx_vld(tmp_odd_buf, 9 * 16);
+    vec2 = __lsx_vld(tmp_odd_buf, 14 * 16);
+    vec3 = __lsx_vld(tmp_odd_buf, 6 * 16);
+    loc0 = __lsx_vld(tmp_eve_buf, 0);
+    loc1 = __lsx_vld(tmp_eve_buf, 8 * 16);
+    loc2 = __lsx_vld(tmp_eve_buf, 4 * 16);
+    loc3 = __lsx_vld(tmp_eve_buf, 12 * 16);
+
+    DUP4_ARG2(__lsx_vadd_h,loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              m0, m4, m2, m6);
+
+    #define SUB(a, b) __lsx_vsub_h(a, b)
+
+    __lsx_vst(SUB(loc0, vec3), tmp_buf, 31 * 16);
+    __lsx_vst(SUB(loc1, vec2), tmp_buf, 23 * 16);
+    __lsx_vst(SUB(loc2, vec1), tmp_buf, 27 * 16);
+    __lsx_vst(SUB(loc3, vec0), tmp_buf, 19 * 16);
+
+    /* Load 8 & Store 8 */
+    vec0 = __lsx_vld(tmp_odd_buf, 4 * 16);
+    vec1 = __lsx_vld(tmp_odd_buf, 13 * 16);
+    vec2 = __lsx_vld(tmp_odd_buf, 10 * 16);
+    vec3 = __lsx_vld(tmp_odd_buf, 3 * 16);
+    loc0 = __lsx_vld(tmp_eve_buf, 2 * 16);
+    loc1 = __lsx_vld(tmp_eve_buf, 10 * 16);
+    loc2 = __lsx_vld(tmp_eve_buf, 6 * 16);
+    loc3 = __lsx_vld(tmp_eve_buf, 14 * 16);
+
+    DUP4_ARG2(__lsx_vadd_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              m1, m5, m3, m7);
+
+    __lsx_vst(SUB(loc0, vec3), tmp_buf, 29 * 16);
+    __lsx_vst(SUB(loc1, vec2), tmp_buf, 21 * 16);
+    __lsx_vst(SUB(loc2, vec1), tmp_buf, 25 * 16);
+    __lsx_vst(SUB(loc3, vec0), tmp_buf, 17 * 16);
+
+    /* Load 8 & Store 8 */
+    vec0 = __lsx_vld(tmp_odd_buf, 2 * 16);
+    vec1 = __lsx_vld(tmp_odd_buf, 11 * 16);
+    vec2 = __lsx_vld(tmp_odd_buf, 12 * 16);
+    vec3 = __lsx_vld(tmp_odd_buf, 7 * 16);
+    loc0 = __lsx_vld(tmp_eve_buf, 1 * 16);
+    loc1 = __lsx_vld(tmp_eve_buf, 9 * 16);
+    loc2 = __lsx_vld(tmp_eve_buf, 5 * 16);
+    loc3 = __lsx_vld(tmp_eve_buf, 13 * 16);
+
+    DUP4_ARG2(__lsx_vadd_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              n0, n4, n2, n6);
+
+    __lsx_vst(SUB(loc0, vec3), tmp_buf, 30 * 16);
+    __lsx_vst(SUB(loc1, vec2), tmp_buf, 22 * 16);
+    __lsx_vst(SUB(loc2, vec1), tmp_buf, 26 * 16);
+    __lsx_vst(SUB(loc3, vec0), tmp_buf, 18 * 16);
+
+    /* Load 8 & Store 8 */
+    vec0 = __lsx_vld(tmp_odd_buf, 5 * 16);
+    vec1 = __lsx_vld(tmp_odd_buf, 15 * 16);
+    vec2 = __lsx_vld(tmp_odd_buf, 8 * 16);
+    vec3 = __lsx_vld(tmp_odd_buf, 1 * 16);
+    loc0 = __lsx_vld(tmp_eve_buf, 3 * 16);
+    loc1 = __lsx_vld(tmp_eve_buf, 11 * 16);
+    loc2 = __lsx_vld(tmp_eve_buf, 7 * 16);
+    loc3 = __lsx_vld(tmp_eve_buf, 15 * 16);
+
+    DUP4_ARG2(__lsx_vadd_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              n1, n5, n3, n7);
+
+    __lsx_vst(SUB(loc0, vec3), tmp_buf, 28 * 16);
+    __lsx_vst(SUB(loc1, vec2), tmp_buf, 20 * 16);
+    __lsx_vst(SUB(loc2, vec1), tmp_buf, 24 * 16);
+    __lsx_vst(SUB(loc3, vec0), tmp_buf, 16 * 16);
+
+    /* Transpose : 16 vectors */
+    /* 1st & 2nd 8x8 */
+    LSX_TRANSPOSE8x8_H(m0, n0, m1, n1, m2, n2, m3, n3,
+                       m0, n0, m1, n1, m2, n2, m3, n3);
+    __lsx_vst(m0, dst, 0);
+    __lsx_vst(n0, dst, 32 * 2);
+    __lsx_vst(m1, dst, 32 * 4);
+    __lsx_vst(n1, dst, 32 * 6);
+    __lsx_vst(m2, dst, 32 * 8);
+    __lsx_vst(n2, dst, 32 * 10);
+    __lsx_vst(m3, dst, 32 * 12);
+    __lsx_vst(n3, dst, 32 * 14);
+
+    LSX_TRANSPOSE8x8_H(m4, n4, m5, n5, m6, n6, m7, n7,
+                       m4, n4, m5, n5, m6, n6, m7, n7);
+
+    __lsx_vst(m4, dst, 16);
+    __lsx_vst(n4, dst, 16 + 32 * 2);
+    __lsx_vst(m5, dst, 16 + 32 * 4);
+    __lsx_vst(n5, dst, 16 + 32 * 6);
+    __lsx_vst(m6, dst, 16 + 32 * 8);
+    __lsx_vst(n6, dst, 16 + 32 * 10);
+    __lsx_vst(m7, dst, 16 + 32 * 12);
+    __lsx_vst(n7, dst, 16 + 32 * 14);
+
+    /* 3rd & 4th 8x8 */
+    DUP4_ARG2(__lsx_vld, tmp_buf, 16 * 16, tmp_buf, 16 * 17,
+              tmp_buf, 16 * 18, tmp_buf, 16 * 19, m0, n0, m1, n1);
+    DUP4_ARG2(__lsx_vld, tmp_buf, 16 * 20, tmp_buf, 16 * 21,
+              tmp_buf, 16 * 22, tmp_buf, 16 * 23, m2, n2, m3, n3);
+
+    DUP4_ARG2(__lsx_vld, tmp_buf, 16 * 24, tmp_buf, 16 * 25,
+              tmp_buf, 16 * 26, tmp_buf, 16 * 27, m4, n4, m5, n5);
+    DUP4_ARG2(__lsx_vld, tmp_buf, 16 * 28, tmp_buf, 16 * 29,
+              tmp_buf, 16 * 30, tmp_buf, 16 * 31, m6, n6, m7, n7);
+
+    LSX_TRANSPOSE8x8_H(m0, n0, m1, n1, m2, n2, m3, n3,
+                       m0, n0, m1, n1, m2, n2, m3, n3);
+
+    __lsx_vst(m0, dst, 32);
+    __lsx_vst(n0, dst, 32 + 32 * 2);
+    __lsx_vst(m1, dst, 32 + 32 * 4);
+    __lsx_vst(n1, dst, 32 + 32 * 6);
+    __lsx_vst(m2, dst, 32 + 32 * 8);
+    __lsx_vst(n2, dst, 32 + 32 * 10);
+    __lsx_vst(m3, dst, 32 + 32 * 12);
+    __lsx_vst(n3, dst, 32 + 32 * 14);
+
+    LSX_TRANSPOSE8x8_H(m4, n4, m5, n5, m6, n6, m7, n7,
+                       m4, n4, m5, n5, m6, n6, m7, n7);
+
+    __lsx_vst(m4, dst, 48);
+    __lsx_vst(n4, dst, 48 + 32 * 2);
+    __lsx_vst(m5, dst, 48 + 32 * 4);
+    __lsx_vst(n5, dst, 48 + 32 * 6);
+    __lsx_vst(m6, dst, 48 + 32 * 8);
+    __lsx_vst(n6, dst, 48 + 32 * 10);
+    __lsx_vst(m7, dst, 48 + 32 * 12);
+    __lsx_vst(n7, dst, 48 + 32 * 14);
+}
+
+static void vp9_idct8x32_column_even_process_store(int16_t *tmp_buf,
+                                                   int16_t *tmp_eve_buf)
+{
+    __m128i vec0, vec1, vec2, vec3, loc0, loc1, loc2, loc3;
+    __m128i reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7;
+    __m128i stp0, stp1, stp2, stp3, stp4, stp5, stp6, stp7;
+    __m128i zero = __lsx_vldi(0);
+
+    /* Even stage 1 */
+    DUP4_ARG2(__lsx_vld, tmp_buf, 0, tmp_buf, 32 * 8,
+              tmp_buf, 32 * 16, tmp_buf, 32 * 24, reg0, reg1, reg2, reg3);
+    DUP4_ARG2(__lsx_vld, tmp_buf, 32 * 32, tmp_buf, 32 * 40,
+              tmp_buf, 32 * 48, tmp_buf, 32 * 56, reg4, reg5, reg6, reg7);
+
+    __lsx_vst(zero, tmp_buf, 0);
+    __lsx_vst(zero, tmp_buf, 32 * 8);
+    __lsx_vst(zero, tmp_buf, 32 * 16);
+    __lsx_vst(zero, tmp_buf, 32 * 24);
+    __lsx_vst(zero, tmp_buf, 32 * 32);
+    __lsx_vst(zero, tmp_buf, 32 * 40);
+    __lsx_vst(zero, tmp_buf, 32 * 48);
+    __lsx_vst(zero, tmp_buf, 32 * 56);
+
+    tmp_buf += (2 * 32);
+
+    VP9_DOTP_CONST_PAIR(reg1, reg7, cospi_28_64, cospi_4_64, reg1, reg7);
+    VP9_DOTP_CONST_PAIR(reg5, reg3, cospi_12_64, cospi_20_64, reg5, reg3);
+    LSX_BUTTERFLY_4_H(reg1, reg7, reg3, reg5, vec1, vec3, vec2, vec0);
+    VP9_DOTP_CONST_PAIR(vec2, vec0, cospi_16_64, cospi_16_64, loc2, loc3);
+
+    loc1 = vec3;
+    loc0 = vec1;
+
+    VP9_DOTP_CONST_PAIR(reg0, reg4, cospi_16_64, cospi_16_64, reg0, reg4);
+    VP9_DOTP_CONST_PAIR(reg2, reg6, cospi_24_64, cospi_8_64, reg2, reg6);
+    LSX_BUTTERFLY_4_H(reg4, reg0, reg2, reg6, vec1, vec3, vec2, vec0);
+    LSX_BUTTERFLY_4_H(vec0, vec1, loc1, loc0, stp3, stp0, stp7, stp4);
+    LSX_BUTTERFLY_4_H(vec2, vec3, loc3, loc2, stp2, stp1, stp6, stp5);
+
+    /* Even stage 2 */
+    /* Load 8 */
+    DUP4_ARG2(__lsx_vld, tmp_buf, 0, tmp_buf, 32 * 8,
+              tmp_buf, 32 * 16, tmp_buf, 32 * 24, reg0, reg1, reg2, reg3);
+    DUP4_ARG2(__lsx_vld, tmp_buf, 32 * 32, tmp_buf, 32 * 40,
+              tmp_buf, 32 * 48, tmp_buf, 32 * 56, reg4, reg5, reg6, reg7);
+
+    __lsx_vst(zero, tmp_buf, 0);
+    __lsx_vst(zero, tmp_buf, 32 * 8);
+    __lsx_vst(zero, tmp_buf, 32 * 16);
+    __lsx_vst(zero, tmp_buf, 32 * 24);
+    __lsx_vst(zero, tmp_buf, 32 * 32);
+    __lsx_vst(zero, tmp_buf, 32 * 40);
+    __lsx_vst(zero, tmp_buf, 32 * 48);
+    __lsx_vst(zero, tmp_buf, 32 * 56);
+
+    VP9_DOTP_CONST_PAIR(reg0, reg7, cospi_30_64, cospi_2_64, reg0, reg7);
+    VP9_DOTP_CONST_PAIR(reg4, reg3, cospi_14_64, cospi_18_64, reg4, reg3);
+    VP9_DOTP_CONST_PAIR(reg2, reg5, cospi_22_64, cospi_10_64, reg2, reg5);
+    VP9_DOTP_CONST_PAIR(reg6, reg1, cospi_6_64, cospi_26_64, reg6, reg1);
+
+    vec0 = __lsx_vadd_h(reg0, reg4);
+    reg0 = __lsx_vsub_h(reg0, reg4);
+    reg4 = __lsx_vadd_h(reg6, reg2);
+    reg6 = __lsx_vsub_h(reg6, reg2);
+    reg2 = __lsx_vadd_h(reg1, reg5);
+    reg1 = __lsx_vsub_h(reg1, reg5);
+    reg5 = __lsx_vadd_h(reg7, reg3);
+    reg7 = __lsx_vsub_h(reg7, reg3);
+    reg3 = vec0;
+
+    vec1 = reg2;
+    reg2 = __lsx_vadd_h(reg3, reg4);
+    reg3 = __lsx_vsub_h(reg3, reg4);
+    reg4 = __lsx_vsub_h(reg5, vec1);
+    reg5 = __lsx_vadd_h(reg5, vec1);
+
+    VP9_DOTP_CONST_PAIR(reg7, reg0, cospi_24_64, cospi_8_64, reg0, reg7);
+    VP9_DOTP_CONST_PAIR(__lsx_vneg_h(reg6), reg1, cospi_24_64, cospi_8_64,
+                        reg6, reg1);
+
+    vec0 = __lsx_vsub_h(reg0, reg6);
+    reg0 = __lsx_vadd_h(reg0, reg6);
+    vec1 = __lsx_vsub_h(reg7, reg1);
+    reg7 = __lsx_vadd_h(reg7, reg1);
+
+    VP9_DOTP_CONST_PAIR(vec1, vec0, cospi_16_64, cospi_16_64, reg6, reg1);
+    VP9_DOTP_CONST_PAIR(reg4, reg3, cospi_16_64, cospi_16_64, reg3, reg4);
+
+    /* Even stage 3 : Dependency on Even stage 1 & Even stage 2 */
+    /* Store 8 */
+    LSX_BUTTERFLY_4_H(stp0, stp1, reg7, reg5, loc1, loc3, loc2, loc0);
+    __lsx_vst(loc1, tmp_eve_buf, 0);
+    __lsx_vst(loc3, tmp_eve_buf, 16);
+    __lsx_vst(loc2, tmp_eve_buf, 14 * 16);
+    __lsx_vst(loc0, tmp_eve_buf, 14 * 16 + 16);
+    LSX_BUTTERFLY_4_H(stp2, stp3, reg4, reg1, loc1, loc3, loc2, loc0);
+    __lsx_vst(loc1, tmp_eve_buf, 2 * 16);
+    __lsx_vst(loc3, tmp_eve_buf, 2 * 16 + 16);
+    __lsx_vst(loc2, tmp_eve_buf, 12 * 16);
+    __lsx_vst(loc0, tmp_eve_buf, 12 * 16 + 16);
+
+    /* Store 8 */
+    LSX_BUTTERFLY_4_H(stp4, stp5, reg6, reg3, loc1, loc3, loc2, loc0);
+    __lsx_vst(loc1, tmp_eve_buf, 4 * 16);
+    __lsx_vst(loc3, tmp_eve_buf, 4 * 16 + 16);
+    __lsx_vst(loc2, tmp_eve_buf, 10 * 16);
+    __lsx_vst(loc0, tmp_eve_buf, 10 * 16 + 16);
+
+    LSX_BUTTERFLY_4_H(stp6, stp7, reg2, reg0, loc1, loc3, loc2, loc0);
+    __lsx_vst(loc1, tmp_eve_buf, 6 * 16);
+    __lsx_vst(loc3, tmp_eve_buf, 6 * 16 + 16);
+    __lsx_vst(loc2, tmp_eve_buf, 8 * 16);
+    __lsx_vst(loc0, tmp_eve_buf, 8 * 16 + 16);
+}
+
+static void vp9_idct8x32_column_odd_process_store(int16_t *tmp_buf,
+                                                  int16_t *tmp_odd_buf)
+{
+    __m128i vec0, vec1, vec2, vec3, loc0, loc1, loc2, loc3;
+    __m128i reg0, reg1, reg2, reg3, reg4, reg5, reg6, reg7;
+    __m128i zero = __lsx_vldi(0);
+
+    /* Odd stage 1 */
+    reg0 = __lsx_vld(tmp_buf, 64);
+    reg1 = __lsx_vld(tmp_buf, 7 * 64);
+    reg2 = __lsx_vld(tmp_buf, 9 * 64);
+    reg3 = __lsx_vld(tmp_buf, 15 * 64);
+    reg4 = __lsx_vld(tmp_buf, 17 * 64);
+    reg5 = __lsx_vld(tmp_buf, 23 * 64);
+    reg6 = __lsx_vld(tmp_buf, 25 * 64);
+    reg7 = __lsx_vld(tmp_buf, 31 * 64);
+
+    __lsx_vst(zero, tmp_buf, 64);
+    __lsx_vst(zero, tmp_buf, 7 * 64);
+    __lsx_vst(zero, tmp_buf, 9 * 64);
+    __lsx_vst(zero, tmp_buf, 15 * 64);
+    __lsx_vst(zero, tmp_buf, 17 * 64);
+    __lsx_vst(zero, tmp_buf, 23 * 64);
+    __lsx_vst(zero, tmp_buf, 25 * 64);
+    __lsx_vst(zero, tmp_buf, 31 * 64);
+
+    VP9_DOTP_CONST_PAIR(reg0, reg7, cospi_31_64, cospi_1_64, reg0, reg7);
+    VP9_DOTP_CONST_PAIR(reg4, reg3, cospi_15_64, cospi_17_64, reg3, reg4);
+    VP9_DOTP_CONST_PAIR(reg2, reg5, cospi_23_64, cospi_9_64, reg2, reg5);
+    VP9_DOTP_CONST_PAIR(reg6, reg1, cospi_7_64, cospi_25_64, reg1, reg6);
+
+    vec0 = __lsx_vadd_h(reg0, reg3);
+    reg0 = __lsx_vsub_h(reg0, reg3);
+    reg3 = __lsx_vadd_h(reg7, reg4);
+    reg7 = __lsx_vsub_h(reg7, reg4);
+    reg4 = __lsx_vadd_h(reg1, reg2);
+    reg1 = __lsx_vsub_h(reg1, reg2);
+    reg2 = __lsx_vadd_h(reg6, reg5);
+    reg6 = __lsx_vsub_h(reg6, reg5);
+    reg5 = vec0;
+
+    /* 4 Stores */
+    DUP2_ARG2(__lsx_vadd_h, reg5, reg4, reg3, reg2, vec0, vec1);
+    __lsx_vst(vec0, tmp_odd_buf, 4 * 16);
+    __lsx_vst(vec1, tmp_odd_buf, 4 * 16 + 16);
+    DUP2_ARG2(__lsx_vsub_h, reg5, reg4, reg3, reg2, vec0, vec1);
+    VP9_DOTP_CONST_PAIR(vec1, vec0, cospi_24_64, cospi_8_64, vec0, vec1);
+    __lsx_vst(vec0, tmp_odd_buf, 0);
+    __lsx_vst(vec1, tmp_odd_buf, 16);
+
+    /* 4 Stores */
+    VP9_DOTP_CONST_PAIR(reg7, reg0, cospi_28_64, cospi_4_64, reg0, reg7);
+    VP9_DOTP_CONST_PAIR(reg6, reg1, -cospi_4_64, cospi_28_64, reg1, reg6);
+    LSX_BUTTERFLY_4_H(reg0, reg7, reg6, reg1, vec0, vec1, vec2, vec3);
+    __lsx_vst(vec0, tmp_odd_buf, 6 * 16);
+    __lsx_vst(vec1, tmp_odd_buf, 6 * 16 + 16);
+    VP9_DOTP_CONST_PAIR(vec2, vec3, cospi_24_64, cospi_8_64, vec2, vec3);
+    __lsx_vst(vec2, tmp_odd_buf, 2 * 16);
+    __lsx_vst(vec3, tmp_odd_buf, 2 * 16 + 16);
+
+    /* Odd stage 2 */
+    /* 8 loads */
+    reg0 = __lsx_vld(tmp_buf, 3 * 64);
+    reg1 = __lsx_vld(tmp_buf, 5 * 64);
+    reg2 = __lsx_vld(tmp_buf, 11 * 64);
+    reg3 = __lsx_vld(tmp_buf, 13 * 64);
+    reg4 = __lsx_vld(tmp_buf, 19 * 64);
+    reg5 = __lsx_vld(tmp_buf, 21 * 64);
+    reg6 = __lsx_vld(tmp_buf, 27 * 64);
+    reg7 = __lsx_vld(tmp_buf, 29 * 64);
+
+    __lsx_vst(zero, tmp_buf, 3 * 64);
+    __lsx_vst(zero, tmp_buf, 5 * 64);
+    __lsx_vst(zero, tmp_buf, 11 * 64);
+    __lsx_vst(zero, tmp_buf, 13 * 64);
+    __lsx_vst(zero, tmp_buf, 19 * 64);
+    __lsx_vst(zero, tmp_buf, 21 * 64);
+    __lsx_vst(zero, tmp_buf, 27 * 64);
+    __lsx_vst(zero, tmp_buf, 29 * 64);
+
+    VP9_DOTP_CONST_PAIR(reg1, reg6, cospi_27_64, cospi_5_64, reg1, reg6);
+    VP9_DOTP_CONST_PAIR(reg5, reg2, cospi_11_64, cospi_21_64, reg2, reg5);
+    VP9_DOTP_CONST_PAIR(reg3, reg4, cospi_19_64, cospi_13_64, reg3, reg4);
+    VP9_DOTP_CONST_PAIR(reg7, reg0, cospi_3_64, cospi_29_64, reg0, reg7);
+
+    /* 4 Stores */
+    DUP4_ARG2(__lsx_vsub_h,reg1, reg2, reg6, reg5, reg0, reg3, reg7, reg4,
+              vec0, vec1, vec2, vec3);
+    VP9_DOTP_CONST_PAIR(vec1, vec0, cospi_12_64, cospi_20_64, loc0, loc1);
+    VP9_DOTP_CONST_PAIR(vec3, vec2, -cospi_20_64, cospi_12_64, loc2, loc3);
+    LSX_BUTTERFLY_4_H(loc2, loc3, loc1, loc0, vec0, vec1, vec3, vec2);
+    __lsx_vst(vec0, tmp_odd_buf, 12 * 16);
+    __lsx_vst(vec1, tmp_odd_buf, 12 * 16 + 3 * 16);
+    VP9_DOTP_CONST_PAIR(vec3, vec2, -cospi_8_64, cospi_24_64, vec0, vec1);
+    __lsx_vst(vec0, tmp_odd_buf, 10 * 16);
+    __lsx_vst(vec1, tmp_odd_buf, 10 * 16 + 16);
+
+    /* 4 Stores */
+    DUP4_ARG2(__lsx_vadd_h, reg0, reg3, reg1, reg2, reg5, reg6, reg4, reg7,
+              vec0, vec1, vec2, vec3);
+    LSX_BUTTERFLY_4_H(vec0, vec3, vec2, vec1, reg0, reg1, reg3, reg2);
+    __lsx_vst(reg0, tmp_odd_buf, 13 * 16);
+    __lsx_vst(reg1, tmp_odd_buf, 13 * 16 + 16);
+    VP9_DOTP_CONST_PAIR(reg3, reg2, -cospi_8_64, cospi_24_64,
+                        reg0, reg1);
+    __lsx_vst(reg0, tmp_odd_buf, 8 * 16);
+    __lsx_vst(reg1, tmp_odd_buf, 8 * 16 + 16);
+
+    /* Odd stage 3 : Dependency on Odd stage 1 & Odd stage 2 */
+    /* Load 8 & Store 8 */
+    DUP4_ARG2(__lsx_vld, tmp_odd_buf, 0, tmp_odd_buf, 16,
+              tmp_odd_buf, 32, tmp_odd_buf, 48, reg0, reg1, reg2, reg3);
+    DUP4_ARG2(__lsx_vld, tmp_odd_buf, 8 * 16, tmp_odd_buf, 8 * 16 + 16,
+              tmp_odd_buf, 8 * 16 + 32, tmp_odd_buf, 8 * 16 + 48,
+              reg4, reg5, reg6, reg7);
+
+    DUP4_ARG2(__lsx_vadd_h, reg0, reg4, reg1, reg5, reg2, reg6, reg3, reg7,
+                  loc0, loc1, loc2, loc3);
+    __lsx_vst(loc0, tmp_odd_buf, 0);
+    __lsx_vst(loc1, tmp_odd_buf, 16);
+    __lsx_vst(loc2, tmp_odd_buf, 32);
+    __lsx_vst(loc3, tmp_odd_buf, 48);
+    DUP2_ARG2(__lsx_vsub_h, reg0, reg4, reg1, reg5, vec0, vec1);
+    VP9_DOTP_CONST_PAIR(vec1, vec0, cospi_16_64, cospi_16_64, loc0, loc1);
+
+    DUP2_ARG2(__lsx_vsub_h, reg2, reg6, reg3, reg7, vec0, vec1);
+    VP9_DOTP_CONST_PAIR(vec1, vec0, cospi_16_64, cospi_16_64, loc2, loc3);
+    __lsx_vst(loc0, tmp_odd_buf, 8 * 16);
+    __lsx_vst(loc1, tmp_odd_buf, 8 * 16 + 16);
+    __lsx_vst(loc2, tmp_odd_buf, 8 * 16 + 32);
+    __lsx_vst(loc3, tmp_odd_buf, 8 * 16 + 48);
+
+    /* Load 8 & Store 8 */
+    DUP4_ARG2(__lsx_vld, tmp_odd_buf, 4 * 16, tmp_odd_buf, 4 * 16 + 16,
+              tmp_odd_buf, 4 * 16 + 32, tmp_odd_buf, 4 * 16 + 48,
+              reg1, reg2, reg0, reg3);
+    DUP4_ARG2(__lsx_vld, tmp_odd_buf, 12 * 16, tmp_odd_buf, 12 * 16 + 16,
+              tmp_odd_buf, 12 * 16 + 32, tmp_odd_buf, 12 * 16 + 48,
+              reg4, reg5, reg6, reg7);
+
+    DUP4_ARG2(__lsx_vadd_h, reg0, reg4, reg1, reg5, reg2, reg6, reg3, reg7,
+              loc0, loc1, loc2, loc3);
+    __lsx_vst(loc0, tmp_odd_buf, 4 * 16);
+    __lsx_vst(loc1, tmp_odd_buf, 4 * 16 + 16);
+    __lsx_vst(loc2, tmp_odd_buf, 4 * 16 + 32);
+    __lsx_vst(loc3, tmp_odd_buf, 4 * 16 + 48);
+
+    DUP2_ARG2(__lsx_vsub_h, reg0, reg4, reg3, reg7, vec0, vec1);
+    VP9_DOTP_CONST_PAIR(vec1, vec0, cospi_16_64, cospi_16_64, loc0, loc1);
+
+    DUP2_ARG2(__lsx_vsub_h, reg1, reg5, reg2, reg6, vec0, vec1);
+    VP9_DOTP_CONST_PAIR(vec1, vec0, cospi_16_64, cospi_16_64, loc2, loc3);
+    __lsx_vst(loc0, tmp_odd_buf, 12 * 16);
+    __lsx_vst(loc1, tmp_odd_buf, 12 * 16 + 16);
+    __lsx_vst(loc2, tmp_odd_buf, 12 * 16 + 32);
+    __lsx_vst(loc3, tmp_odd_buf, 12 * 16 + 48);
+}
+
+static void vp9_idct8x32_column_butterfly_addblk(int16_t *tmp_eve_buf,
+                                                 int16_t *tmp_odd_buf,
+                                                 uint8_t *dst,
+                                                 int32_t dst_stride)
+{
+    __m128i vec0, vec1, vec2, vec3, loc0, loc1, loc2, loc3;
+    __m128i m0, m1, m2, m3, m4, m5, m6, m7, n0, n1, n2, n3, n4, n5, n6, n7;
+
+    /* FINAL BUTTERFLY : Dependency on Even & Odd */
+    vec0 = __lsx_vld(tmp_odd_buf, 0);
+    vec1 = __lsx_vld(tmp_odd_buf, 9 * 16);
+    vec2 = __lsx_vld(tmp_odd_buf, 14 * 16);
+    vec3 = __lsx_vld(tmp_odd_buf, 6 * 16);
+    loc0 = __lsx_vld(tmp_eve_buf, 0);
+    loc1 = __lsx_vld(tmp_eve_buf, 8 * 16);
+    loc2 = __lsx_vld(tmp_eve_buf, 4 * 16);
+    loc3 = __lsx_vld(tmp_eve_buf, 12 * 16);
+
+    DUP4_ARG2(__lsx_vadd_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              m0, m4, m2, m6);
+    DUP4_ARG2(__lsx_vsrari_h, m0, 6, m2, 6, m4, 6, m6, 6, m0, m2, m4, m6);
+    VP9_ADDBLK_ST8x4_UB(dst, (4 * dst_stride), m0, m2, m4, m6);
+
+    DUP4_ARG2(__lsx_vsub_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              m6, m2, m4, m0);
+    DUP4_ARG2(__lsx_vsrari_h, m0, 6, m2, 6, m4, 6, m6, 6, m0, m2, m4, m6);
+    VP9_ADDBLK_ST8x4_UB((dst + 19 * dst_stride), (4 * dst_stride),
+                        m0, m2, m4, m6);
+
+    /* Load 8 & Store 8 */
+    vec0 = __lsx_vld(tmp_odd_buf, 4 * 16);
+    vec1 = __lsx_vld(tmp_odd_buf, 13 * 16);
+    vec2 = __lsx_vld(tmp_odd_buf, 10 * 16);
+    vec3 = __lsx_vld(tmp_odd_buf, 3 * 16);
+    loc0 = __lsx_vld(tmp_eve_buf, 2 * 16);
+    loc1 = __lsx_vld(tmp_eve_buf, 10 * 16);
+    loc2 = __lsx_vld(tmp_eve_buf, 6 * 16);
+    loc3 = __lsx_vld(tmp_eve_buf, 14 * 16);
+
+    DUP4_ARG2(__lsx_vadd_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+               m1, m5, m3, m7);
+    DUP4_ARG2(__lsx_vsrari_h, m1, 6, m3, 6, m5, 6, m7, 6, m1, m3, m5, m7);
+    VP9_ADDBLK_ST8x4_UB((dst + 2 * dst_stride), (4 * dst_stride),
+                        m1, m3, m5, m7);
+
+    DUP4_ARG2(__lsx_vsub_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              m7, m3, m5, m1);
+    DUP4_ARG2(__lsx_vsrari_h, m1, 6, m3, 6, m5, 6, m7, 6, m1, m3, m5, m7);
+    VP9_ADDBLK_ST8x4_UB((dst + 17 * dst_stride), (4 * dst_stride),
+                        m1, m3, m5, m7);
+
+    /* Load 8 & Store 8 */
+    vec0 = __lsx_vld(tmp_odd_buf, 2 * 16);
+    vec1 = __lsx_vld(tmp_odd_buf, 11 * 16);
+    vec2 = __lsx_vld(tmp_odd_buf, 12 * 16);
+    vec3 = __lsx_vld(tmp_odd_buf, 7 * 16);
+    loc0 = __lsx_vld(tmp_eve_buf, 1 * 16);
+    loc1 = __lsx_vld(tmp_eve_buf, 9 * 16);
+    loc2 = __lsx_vld(tmp_eve_buf, 5 * 16);
+    loc3 = __lsx_vld(tmp_eve_buf, 13 * 16);
+
+    DUP4_ARG2(__lsx_vadd_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              n0, n4, n2, n6);
+    DUP4_ARG2(__lsx_vsrari_h, n0, 6, n2, 6, n4, 6, n6, 6, n0, n2, n4, n6);
+    VP9_ADDBLK_ST8x4_UB((dst + 1 * dst_stride), (4 * dst_stride),
+                        n0, n2, n4, n6);
+    DUP4_ARG2(__lsx_vsub_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              n6, n2, n4, n0);
+    DUP4_ARG2(__lsx_vsrari_h, n0, 6, n2, 6, n4, 6, n6, 6, n0, n2, n4, n6);
+    VP9_ADDBLK_ST8x4_UB((dst + 18 * dst_stride), (4 * dst_stride),
+                        n0, n2, n4, n6);
+
+    /* Load 8 & Store 8 */
+    vec0 = __lsx_vld(tmp_odd_buf, 5 * 16);
+    vec1 = __lsx_vld(tmp_odd_buf, 15 * 16);
+    vec2 = __lsx_vld(tmp_odd_buf, 8 * 16);
+    vec3 = __lsx_vld(tmp_odd_buf, 1 * 16);
+    loc0 = __lsx_vld(tmp_eve_buf, 3 * 16);
+    loc1 = __lsx_vld(tmp_eve_buf, 11 * 16);
+    loc2 = __lsx_vld(tmp_eve_buf, 7 * 16);
+    loc3 = __lsx_vld(tmp_eve_buf, 15 * 16);
+
+    DUP4_ARG2(__lsx_vadd_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              n1, n5, n3, n7);
+    DUP4_ARG2(__lsx_vsrari_h, n1, 6, n3, 6, n5, 6, n7, 6, n1, n3, n5, n7);
+    VP9_ADDBLK_ST8x4_UB((dst + 3 * dst_stride), (4 * dst_stride),
+                        n1, n3, n5, n7);
+    DUP4_ARG2(__lsx_vsub_h, loc0, vec3, loc1, vec2, loc2, vec1, loc3, vec0,
+              n7, n3, n5, n1);
+    DUP4_ARG2(__lsx_vsrari_h, n1, 6, n3, 6, n5, 6, n7, 6, n1, n3, n5, n7);
+    VP9_ADDBLK_ST8x4_UB((dst + 16 * dst_stride), (4 * dst_stride),
+                        n1, n3, n5, n7);
+}
+
+static void vp9_idct8x32_1d_columns_addblk_lsx(int16_t *input, uint8_t *dst,
+                                               int32_t dst_stride)
+{
+    int16_t tmp_odd_buf[16 * 8] ALLOC_ALIGNED(16);
+    int16_t tmp_eve_buf[16 * 8] ALLOC_ALIGNED(16);
+
+    vp9_idct8x32_column_even_process_store(input, &tmp_eve_buf[0]);
+    vp9_idct8x32_column_odd_process_store(input, &tmp_odd_buf[0]);
+    vp9_idct8x32_column_butterfly_addblk(&tmp_eve_buf[0], &tmp_odd_buf[0],
+                                         dst, dst_stride);
+}
+
+static void vp9_idct8x32_1d_columns_lsx(int16_t *input, int16_t *output,
+                                        int16_t *tmp_buf)
+{
+    int16_t tmp_odd_buf[16 * 8] ALLOC_ALIGNED(16);
+    int16_t tmp_eve_buf[16 * 8] ALLOC_ALIGNED(16);
+
+    vp9_idct8x32_column_even_process_store(input, &tmp_eve_buf[0]);
+    vp9_idct8x32_column_odd_process_store(input, &tmp_odd_buf[0]);
+    vp9_idct_butterfly_transpose_store(tmp_buf, &tmp_eve_buf[0],
+                                       &tmp_odd_buf[0], output);
+}
+
+static void vp9_idct32x32_1_add_lsx(int16_t *input, uint8_t *dst,
+                                    int32_t dst_stride)
+{
+    int32_t i;
+    int16_t out;
+    uint8_t *dst_tmp = dst + dst_stride;
+    __m128i zero = __lsx_vldi(0);
+    __m128i dst0, dst1, dst2, dst3, tmp0, tmp1, tmp2, tmp3;
+    __m128i res0, res1, res2, res3, res4, res5, res6, res7, vec;
+
+    out = ROUND_POWER_OF_TWO((input[0] * cospi_16_64), VP9_DCT_CONST_BITS);
+    out = ROUND_POWER_OF_TWO((out * cospi_16_64), VP9_DCT_CONST_BITS);
+    out = ROUND_POWER_OF_TWO(out, 6);
+    input[0] = 0;
+
+    vec = __lsx_vreplgr2vr_h(out);
+
+    for (i = 16; i--;) {
+        DUP2_ARG2(__lsx_vld, dst, 0, dst, 16, dst0, dst1);
+        DUP2_ARG2(__lsx_vld, dst_tmp, 0, dst_tmp, 16, dst2, dst3);
+
+        DUP4_ARG2(__lsx_vilvl_b, zero, dst0, zero, dst1, zero, dst2, zero, dst3,
+                  res0, res1, res2, res3);
+        DUP4_ARG2(__lsx_vilvh_b, zero, dst0, zero, dst1, zero, dst2, zero, dst3,
+                  res4, res5, res6, res7);
+        DUP4_ARG2(__lsx_vadd_h, res0, vec, res1, vec, res2, vec, res3, vec,
+                  res0, res1, res2, res3);
+        DUP4_ARG2(__lsx_vadd_h, res4, vec, res5, vec, res6, vec, res7, vec,
+                  res4, res5, res6, res7);
+        DUP4_ARG1(__lsx_vclip255_h, res0, res1, res2, res3, res0, res1, res2, res3);
+        DUP4_ARG1(__lsx_vclip255_h, res4, res5, res6, res7, res4, res5, res6, res7);
+        DUP4_ARG2(__lsx_vpickev_b, res4, res0, res5, res1, res6, res2, res7, res3,
+                  tmp0, tmp1, tmp2, tmp3);
+
+        __lsx_vst(tmp0, dst, 0);
+        __lsx_vst(tmp1, dst, 16);
+        __lsx_vst(tmp2, dst_tmp, 0);
+        __lsx_vst(tmp3, dst_tmp, 16);
+        dst = dst_tmp + dst_stride;
+        dst_tmp = dst + dst_stride;
+    }
+}
+
+static void vp9_idct32x32_34_colcol_addblk_lsx(int16_t *input, uint8_t *dst,
+                                               int32_t dst_stride)
+{
+    int32_t i;
+    int16_t out_arr[32 * 32] ALLOC_ALIGNED(16);
+    int16_t *out_ptr = out_arr;
+    int16_t tmp_buf[8 * 32] ALLOC_ALIGNED(16);
+    __m128i zero = __lsx_vldi(0);
+
+    for (i = 16; i--;) {
+        __lsx_vst(zero, out_ptr, 0);
+        __lsx_vst(zero, out_ptr, 16);
+        __lsx_vst(zero, out_ptr, 32);
+        __lsx_vst(zero, out_ptr, 48);
+        __lsx_vst(zero, out_ptr, 64);
+        __lsx_vst(zero, out_ptr, 80);
+        __lsx_vst(zero, out_ptr, 96);
+        __lsx_vst(zero, out_ptr, 112);
+        out_ptr += 64;
+    }
+
+    out_ptr = out_arr;
+
+    /* process 8*32 block */
+    vp9_idct8x32_1d_columns_lsx(input, out_ptr, &tmp_buf[0]);
+
+    /* transform columns */
+    for (i = 0; i < 4; i++) {
+        /* process 8*32 block */
+        vp9_idct8x32_1d_columns_addblk_lsx((out_ptr + (i << 3)),
+                                           (dst + (i << 3)), dst_stride);
+    }
+}
+
+static void vp9_idct32x32_colcol_addblk_lsx(int16_t *input, uint8_t *dst,
+                                            int32_t dst_stride)
+{
+    int32_t i;
+    int16_t out_arr[32 * 32] ALLOC_ALIGNED(16);
+    int16_t *out_ptr = out_arr;
+    int16_t tmp_buf[8 * 32] ALLOC_ALIGNED(16);
+
+    /* transform rows */
+    for (i = 0; i < 4; i++) {
+        /* process 8*32 block */
+        vp9_idct8x32_1d_columns_lsx((input + (i << 3)), (out_ptr + (i << 8)),
+                                    &tmp_buf[0]);
+    }
+
+    /* transform columns */
+    for (i = 0; i < 4; i++) {
+        /* process 8*32 block */
+        vp9_idct8x32_1d_columns_addblk_lsx((out_ptr + (i << 3)),
+                                           (dst + (i << 3)), dst_stride);
+    }
+}
+
+void ff_idct_idct_8x8_add_lsx(uint8_t *dst, ptrdiff_t stride,
+                              int16_t *block, int eob)
+{
+    if (eob == 1) {
+        vp9_idct8x8_1_add_lsx(block, dst, stride);
+    }
+    else if (eob <= 12) {
+        vp9_idct8x8_12_colcol_addblk_lsx(block, dst, stride);
+    }
+    else {
+        vp9_idct8x8_colcol_addblk_lsx(block, dst, stride);
+    }
+}
+
+void ff_idct_idct_16x16_add_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int16_t *block, int eob)
+{
+    if (eob == 1) {
+        /* DC only DCT coefficient. */
+        vp9_idct16x16_1_add_lsx(block, dst, stride);
+    }
+    else if (eob <= 10) {
+        vp9_idct16x16_10_colcol_addblk_lsx(block, dst, stride);
+    }
+    else {
+        vp9_idct16x16_colcol_addblk_lsx(block, dst, stride);
+    }
+}
+
+void ff_idct_idct_32x32_add_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int16_t *block, int eob)
+{
+    if (eob == 1) {
+        vp9_idct32x32_1_add_lsx(block, dst, stride);
+    }
+    else if (eob <= 34) {
+        vp9_idct32x32_34_colcol_addblk_lsx(block, dst, stride);
+    }
+    else {
+        vp9_idct32x32_colcol_addblk_lsx(block, dst, stride);
+    }
+}
diff --git a/libavcodec/loongarch/vp9_lpf_lsx.c b/libavcodec/loongarch/vp9_lpf_lsx.c
new file mode 100644
index 0000000000..8e1915b888
--- /dev/null
+++ b/libavcodec/loongarch/vp9_lpf_lsx.c
@@ -0,0 +1,3141 @@
+/*
+ * Copyright (c) 2021 Loongson Technology Corporation Limited
+ * Contributed by Jin Bo <jinbo at loongson.cn>
+ *
+ * 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 "libavcodec/vp9dsp.h"
+#include "libavutil/loongarch/loongson_intrinsics.h"
+#include "libavutil/common.h"
+#include "vp9dsp_loongarch.h"
+
+#define LSX_LD_8(_src, _stride, _stride2, _stride3, _stride4, _in0, _in1, _in2, \
+                 _in3, _in4, _in5, _in6, _in7)                                  \
+{                                                                               \
+    _in0 = __lsx_vld(_src, 0);                                                  \
+    _in1 = __lsx_vldx(_src, _stride);                                           \
+    _in2 = __lsx_vldx(_src, _stride2);                                          \
+    _in3 = __lsx_vldx(_src, _stride3);                                          \
+    _src += _stride4;                                                           \
+    _in4 = __lsx_vld(_src, 0);                                                  \
+    _in5 = __lsx_vldx(_src, _stride);                                           \
+    _in6 = __lsx_vldx(_src, _stride2);                                          \
+    _in7 = __lsx_vldx(_src, _stride3);                                          \
+}
+
+#define LSX_ST_8(_dst0, _dst1, _dst2, _dst3, _dst4, _dst5, _dst6, _dst7,        \
+                 _dst, _stride, _stride2, _stride3, _stride4)                   \
+{                                                                               \
+    __lsx_vst(_dst0, _dst, 0);                                                  \
+    __lsx_vstx(_dst1, _dst, _stride);                                           \
+    __lsx_vstx(_dst2, _dst, _stride2);                                          \
+    __lsx_vstx(_dst3, _dst, _stride3);                                          \
+    _dst += _stride4;                                                           \
+    __lsx_vst(_dst4, _dst, 0);                                                  \
+    __lsx_vstx(_dst5, _dst, _stride);                                           \
+    __lsx_vstx(_dst6, _dst, _stride2);                                          \
+    __lsx_vstx(_dst7, _dst, _stride3);                                          \
+}
+
+#define VP9_LPF_FILTER4_4W(p1_src, p0_src, q0_src, q1_src, mask_src, hev_src, \
+                           p1_dst, p0_dst, q0_dst, q1_dst)                    \
+{                                                                             \
+    __m128i p1_tmp, p0_tmp, q0_tmp, q1_tmp, q0_sub_p0, filt, filt1, filt2;    \
+    const __m128i cnst3b = __lsx_vldi(3);                                     \
+    const __m128i cnst4b = __lsx_vldi(4);                                     \
+                                                                              \
+    p1_tmp = __lsx_vxori_b(p1_src, 0x80);                                     \
+    p0_tmp = __lsx_vxori_b(p0_src, 0x80);                                     \
+    q0_tmp = __lsx_vxori_b(q0_src, 0x80);                                     \
+    q1_tmp = __lsx_vxori_b(q1_src, 0x80);                                     \
+                                                                              \
+    filt = __lsx_vssub_b(p1_tmp, q1_tmp);                                     \
+                                                                              \
+    filt = filt & hev_src;                                                    \
+                                                                              \
+    q0_sub_p0 = __lsx_vssub_b(q0_tmp, p0_tmp);                                \
+    filt = __lsx_vsadd_b(filt, q0_sub_p0);                                    \
+    filt = __lsx_vsadd_b(filt, q0_sub_p0);                                    \
+    filt = __lsx_vsadd_b(filt, q0_sub_p0);                                    \
+    filt = filt & mask_src;                                                   \
+                                                                              \
+    filt1 = __lsx_vsadd_b(filt, cnst4b);                                      \
+    filt1 = __lsx_vsrai_b(filt1, 3);                                          \
+                                                                              \
+    filt2 = __lsx_vsadd_b(filt, cnst3b);                                      \
+    filt2 = __lsx_vsrai_b(filt2, 3);                                          \
+                                                                              \
+    q0_tmp = __lsx_vssub_b(q0_tmp, filt1);                                    \
+    q0_dst = __lsx_vxori_b(q0_tmp, 0x80);                                     \
+    p0_tmp = __lsx_vsadd_b(p0_tmp, filt2);                                    \
+    p0_dst = __lsx_vxori_b(p0_tmp, 0x80);                                     \
+                                                                              \
+    filt = __lsx_vsrari_b(filt1, 1);                                          \
+    hev_src = __lsx_vxori_b(hev_src, 0xff);                                   \
+    filt = filt & hev_src;                                                    \
+                                                                              \
+    q1_tmp = __lsx_vssub_b(q1_tmp, filt);                                     \
+    q1_dst = __lsx_vxori_b(q1_tmp, 0x80);                                     \
+    p1_tmp = __lsx_vsadd_b(p1_tmp, filt);                                     \
+    p1_dst = __lsx_vxori_b(p1_tmp, 0x80);                                     \
+}
+
+#define VP9_FLAT4(p3_src, p2_src, p0_src, q0_src, q2_src, q3_src, flat_dst)  \
+{                                                                            \
+    __m128i f_tmp = __lsx_vldi(1);                                           \
+    __m128i p2_a_sub_p0, q2_a_sub_q0, p3_a_sub_p0, q3_a_sub_q0;              \
+                                                                             \
+    p2_a_sub_p0 = __lsx_vabsd_bu(p2_src, p0_src);                            \
+    q2_a_sub_q0 = __lsx_vabsd_bu(q2_src, q0_src);                            \
+    p3_a_sub_p0 = __lsx_vabsd_bu(p3_src, p0_src);                            \
+    q3_a_sub_q0 = __lsx_vabsd_bu(q3_src, q0_src);                            \
+                                                                             \
+    p2_a_sub_p0 = __lsx_vmax_bu(p2_a_sub_p0, q2_a_sub_q0);                   \
+    flat_dst = __lsx_vmax_bu(p2_a_sub_p0, flat_dst);                         \
+    p3_a_sub_p0 = __lsx_vmax_bu(p3_a_sub_p0, q3_a_sub_q0);                   \
+    flat_dst = __lsx_vmax_bu(p3_a_sub_p0, flat_dst);                         \
+                                                                             \
+    flat_dst = __lsx_vslt_bu(f_tmp, flat_dst);                               \
+    flat_dst = __lsx_vxori_b(flat_dst, 0xff);                                \
+    flat_dst = flat_dst & mask;                                              \
+}
+
+#define VP9_FLAT5(p7_src, p6_src, p5_src, p4_src, p0_src, q0_src, q4_src, \
+                  q5_src, q6_src, q7_src, flat_src, flat2_dst)            \
+{                                                                         \
+    __m128i f_tmp = __lsx_vldi(1);                                        \
+    __m128i p4_a_sub_p0, q4_a_sub_q0, p5_a_sub_p0, q5_a_sub_q0;           \
+    __m128i p6_a_sub_p0, q6_a_sub_q0, p7_a_sub_p0, q7_a_sub_q0;           \
+                                                                          \
+    p4_a_sub_p0 = __lsx_vabsd_bu(p4_src, p0_src);                         \
+    q4_a_sub_q0 = __lsx_vabsd_bu(q4_src, q0_src);                         \
+    p5_a_sub_p0 = __lsx_vabsd_bu(p5_src, p0_src);                         \
+    q5_a_sub_q0 = __lsx_vabsd_bu(q5_src, q0_src);                         \
+    p6_a_sub_p0 = __lsx_vabsd_bu(p6_src, p0_src);                         \
+    q6_a_sub_q0 = __lsx_vabsd_bu(q6_src, q0_src);                         \
+    p7_a_sub_p0 = __lsx_vabsd_bu(p7_src, p0_src);                         \
+    q7_a_sub_q0 = __lsx_vabsd_bu(q7_src, q0_src);                         \
+                                                                          \
+    p4_a_sub_p0 = __lsx_vmax_bu(p4_a_sub_p0, q4_a_sub_q0);                \
+    flat2_dst = __lsx_vmax_bu(p5_a_sub_p0, q5_a_sub_q0);                  \
+    flat2_dst = __lsx_vmax_bu(p4_a_sub_p0, flat2_dst);                    \
+    p6_a_sub_p0 = __lsx_vmax_bu(p6_a_sub_p0, q6_a_sub_q0);                \
+    flat2_dst = __lsx_vmax_bu(p6_a_sub_p0, flat2_dst);                    \
+    p7_a_sub_p0 = __lsx_vmax_bu(p7_a_sub_p0, q7_a_sub_q0);                \
+    flat2_dst = __lsx_vmax_bu(p7_a_sub_p0, flat2_dst);                    \
+                                                                          \
+    flat2_dst = __lsx_vslt_bu(f_tmp, flat2_dst);                          \
+    flat2_dst = __lsx_vxori_b(flat2_dst, 0xff);                           \
+    flat2_dst = flat2_dst & flat_src;                                     \
+}
+
+#define VP9_FILTER8(p3_src, p2_src, p1_src, p0_src,            \
+                    q0_src, q1_src, q2_src, q3_src,            \
+                    p2_filt8_dst, p1_filt8_dst, p0_filt8_dst,  \
+                    q0_filt8_dst, q1_filt8_dst, q2_filt8_dst)  \
+{                                                              \
+    __m128i tmp0, tmp1, tmp2;                                  \
+                                                               \
+    tmp2 = __lsx_vadd_h(p2_src, p1_src);                       \
+    tmp2 = __lsx_vadd_h(tmp2, p0_src);                         \
+    tmp0 = __lsx_vslli_h(p3_src, 1);                           \
+                                                               \
+    tmp0 = __lsx_vadd_h(tmp0, tmp2);                           \
+    tmp0 = __lsx_vadd_h(tmp0, q0_src);                         \
+    tmp1 = __lsx_vadd_h(tmp0, p3_src);                         \
+    tmp1 = __lsx_vadd_h(tmp1, p2_src);                         \
+    p2_filt8_dst = __lsx_vsrari_h(tmp1, 3);                    \
+                                                               \
+    tmp1 = __lsx_vadd_h(tmp0, p1_src);                         \
+    tmp1 = __lsx_vadd_h(tmp1, q1_src);                         \
+    p1_filt8_dst = __lsx_vsrari_h(tmp1, 3);                    \
+                                                               \
+    tmp1 = __lsx_vadd_h(q2_src, q1_src);                       \
+    tmp1 = __lsx_vadd_h(tmp1, q0_src);                         \
+    tmp2 = __lsx_vadd_h(tmp2, tmp1);                           \
+    tmp0 = __lsx_vadd_h(tmp2, p0_src);                         \
+    tmp0 = __lsx_vadd_h(tmp0, p3_src);                         \
+    p0_filt8_dst = __lsx_vsrari_h(tmp0, 3);                    \
+                                                               \
+    tmp0 = __lsx_vadd_h(q2_src, q3_src);                       \
+    tmp0 = __lsx_vadd_h(tmp0, p0_src);                         \
+    tmp0 = __lsx_vadd_h(tmp0, tmp1);                           \
+    tmp1 = __lsx_vadd_h(q3_src, q3_src);                       \
+    tmp1 = __lsx_vadd_h(tmp1, tmp0);                           \
+    q2_filt8_dst = __lsx_vsrari_h(tmp1, 3);                    \
+                                                               \
+    tmp0 = __lsx_vadd_h(tmp2, q3_src);                         \
+    tmp1 = __lsx_vadd_h(tmp0, q0_src);                         \
+    q0_filt8_dst = __lsx_vsrari_h(tmp1, 3);                    \
+                                                               \
+    tmp1 = __lsx_vsub_h(tmp0, p2_src);                         \
+    tmp0 = __lsx_vadd_h(q1_src, q3_src);                       \
+    tmp1 = __lsx_vadd_h(tmp0, tmp1);                           \
+    q1_filt8_dst = __lsx_vsrari_h(tmp1, 3);                    \
+}
+
+#define LPF_MASK_HEV(p3_src, p2_src, p1_src, p0_src, q0_src, q1_src,        \
+                     q2_src, q3_src, limit_src, b_limit_src, thresh_src,    \
+                     hev_dst, mask_dst, flat_dst)                           \
+{                                                                           \
+    __m128i p3_asub_p2_tmp, p2_asub_p1_tmp, p1_asub_p0_tmp, q1_asub_q0_tmp; \
+    __m128i p1_asub_q1_tmp, p0_asub_q0_tmp, q3_asub_q2_tmp, q2_asub_q1_tmp; \
+                                                                            \
+    /* absolute subtraction of pixel values */                              \
+    p3_asub_p2_tmp = __lsx_vabsd_bu(p3_src, p2_src);                        \
+    p2_asub_p1_tmp = __lsx_vabsd_bu(p2_src, p1_src);                        \
+    p1_asub_p0_tmp = __lsx_vabsd_bu(p1_src, p0_src);                        \
+    q1_asub_q0_tmp = __lsx_vabsd_bu(q1_src, q0_src);                        \
+    q2_asub_q1_tmp = __lsx_vabsd_bu(q2_src, q1_src);                        \
+    q3_asub_q2_tmp = __lsx_vabsd_bu(q3_src, q2_src);                        \
+    p0_asub_q0_tmp = __lsx_vabsd_bu(p0_src, q0_src);                        \
+    p1_asub_q1_tmp = __lsx_vabsd_bu(p1_src, q1_src);                        \
+                                                                            \
+    /* calculation of hev */                                                \
+    flat_dst = __lsx_vmax_bu(p1_asub_p0_tmp, q1_asub_q0_tmp);               \
+    hev_dst = __lsx_vslt_bu(thresh_src, flat_dst);                          \
+                                                                            \
+    /* calculation of mask */                                               \
+    p0_asub_q0_tmp = __lsx_vsadd_bu(p0_asub_q0_tmp, p0_asub_q0_tmp);        \
+    p1_asub_q1_tmp = __lsx_vsrli_b(p1_asub_q1_tmp, 1);                      \
+    p0_asub_q0_tmp = __lsx_vsadd_bu(p0_asub_q0_tmp, p1_asub_q1_tmp);        \
+                                                                            \
+    mask_dst = __lsx_vslt_bu(b_limit_src, p0_asub_q0_tmp);                  \
+    mask_dst = __lsx_vmax_bu(flat_dst, mask_dst);                           \
+    p3_asub_p2_tmp = __lsx_vmax_bu(p3_asub_p2_tmp, p2_asub_p1_tmp);         \
+    mask_dst = __lsx_vmax_bu(p3_asub_p2_tmp, mask_dst);                     \
+    q2_asub_q1_tmp = __lsx_vmax_bu(q2_asub_q1_tmp, q3_asub_q2_tmp);         \
+    mask_dst = __lsx_vmax_bu(q2_asub_q1_tmp, mask_dst);                     \
+                                                                            \
+    mask_dst = __lsx_vslt_bu(limit_src, mask_dst);                          \
+    mask_dst = __lsx_vxori_b(mask_dst, 0xff);                               \
+}
+
+void ff_loop_filter_v_4_8_lsx(uint8_t *dst, ptrdiff_t stride,
+                              int32_t b_limit_ptr,
+                              int32_t limit_ptr,
+                              int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    __m128i mask, hev, flat, thresh, b_limit, limit;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0, p1_out, p0_out, q0_out, q1_out;
+
+    DUP4_ARG2(__lsx_vldx, dst, -stride4, dst, -stride3, dst, -stride2,
+              dst, -stride, p3, p2, p1, p0);
+    q0 = __lsx_vld(dst, 0);
+    DUP2_ARG2(__lsx_vldx, dst, stride, dst, stride2, q1, q2);
+    q3 = __lsx_vldx(dst, stride3);
+
+    thresh  = __lsx_vreplgr2vr_b(thresh_ptr);
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    limit   = __lsx_vreplgr2vr_b(limit_ptr);
+
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    __lsx_vstelm_d(p1_out, dst - stride2, 0, 0);
+    __lsx_vstelm_d(p0_out, dst -  stride, 0, 0);
+    __lsx_vstelm_d(q0_out, dst          , 0, 0);
+    __lsx_vstelm_d(q1_out, dst +  stride, 0, 0);
+}
+
+void ff_loop_filter_v_44_16_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int32_t b_limit_ptr,
+                                int32_t limit_ptr,
+                                int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    __m128i mask, hev, flat, thresh0, b_limit0;
+    __m128i limit0, thresh1, b_limit1, limit1;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+
+    DUP4_ARG2(__lsx_vldx, dst, -stride4, dst, -stride3, dst, -stride2,
+              dst, -stride, p3, p2, p1, p0);
+    q0 = __lsx_vld(dst, 0);
+    DUP2_ARG2(__lsx_vldx, dst, stride, dst, stride2, q1, q2);
+    q3 = __lsx_vldx(dst, stride3);
+
+    thresh0 = __lsx_vreplgr2vr_b(thresh_ptr);
+    thresh1 = __lsx_vreplgr2vr_b(thresh_ptr >> 8);
+    thresh0 = __lsx_vilvl_d(thresh1, thresh0);
+
+    b_limit0 = __lsx_vreplgr2vr_b(b_limit_ptr);
+    b_limit1 = __lsx_vreplgr2vr_b(b_limit_ptr >> 8);
+    b_limit0 = __lsx_vilvl_d(b_limit1, b_limit0);
+
+    limit0 = __lsx_vreplgr2vr_b(limit_ptr);
+    limit1 = __lsx_vreplgr2vr_b(limit_ptr >> 8);
+    limit0 = __lsx_vilvl_d(limit1, limit0);
+
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit0, b_limit0, thresh0,
+                 hev, mask, flat);
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1, p0, q0, q1);
+
+    __lsx_vst(p1, dst - stride2, 0);
+    __lsx_vst(p0, dst -  stride, 0);
+    __lsx_vst(q0, dst          , 0);
+    __lsx_vst(q1, dst +  stride, 0);
+}
+
+void ff_loop_filter_v_8_8_lsx(uint8_t *dst, ptrdiff_t stride,
+                              int32_t b_limit_ptr,
+                              int32_t limit_ptr,
+                              int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    __m128i mask, hev, flat, thresh, b_limit, limit;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p2_out, p1_out, p0_out, q0_out, q1_out, q2_out;
+    __m128i p2_filter8, p1_filter8, p0_filter8;
+    __m128i q0_filter8, q1_filter8, q2_filter8;
+    __m128i p3_l, p2_l, p1_l, p0_l, q3_l, q2_l, q1_l, q0_l;
+    __m128i zero = __lsx_vldi(0);
+
+    DUP4_ARG2(__lsx_vldx, dst, -stride4, dst, -stride3, dst, -stride2,
+              dst, -stride, p3, p2, p1, p0);
+    q0 = __lsx_vld(dst, 0);
+    DUP2_ARG2(__lsx_vldx, dst, stride, dst, stride2, q1, q2);
+    q3 = __lsx_vldx(dst, stride3);
+
+    thresh  = __lsx_vreplgr2vr_b(thresh_ptr);
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    limit   = __lsx_vreplgr2vr_b(limit_ptr);
+
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    flat = __lsx_vilvl_d(zero, flat);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        __lsx_vstelm_d(p1_out, dst - stride2, 0, 0);
+        __lsx_vstelm_d(p0_out, dst -  stride, 0, 0);
+        __lsx_vstelm_d(q0_out, dst          , 0, 0);
+        __lsx_vstelm_d(q1_out, dst +  stride, 0, 0);
+    } else {
+        DUP4_ARG2(__lsx_vilvl_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_l, p2_l, p1_l, p0_l);
+        DUP4_ARG2(__lsx_vilvl_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_l, q1_l, q2_l, q3_l);
+        VP9_FILTER8(p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l, p2_filter8,
+                    p1_filter8, p0_filter8, q0_filter8, q1_filter8, q2_filter8);
+
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, zero, p2_filter8, zero, p1_filter8,
+                  zero, p0_filter8, zero, q0_filter8, p2_filter8,
+                  p1_filter8, p0_filter8, q0_filter8);
+        DUP2_ARG2(__lsx_vpickev_b, zero, q1_filter8, zero, q2_filter8,
+                  q1_filter8, q2_filter8);
+
+        /* store pixel values */
+        p2_out = __lsx_vbitsel_v(p2, p2_filter8, flat);
+        p1_out = __lsx_vbitsel_v(p1_out, p1_filter8, flat);
+        p0_out = __lsx_vbitsel_v(p0_out, p0_filter8, flat);
+        q0_out = __lsx_vbitsel_v(q0_out, q0_filter8, flat);
+        q1_out = __lsx_vbitsel_v(q1_out, q1_filter8, flat);
+        q2_out = __lsx_vbitsel_v(q2, q2_filter8, flat);
+
+        __lsx_vstelm_d(p2_out, dst - stride3, 0, 0);
+        __lsx_vstelm_d(p1_out, dst - stride2, 0, 0);
+        __lsx_vstelm_d(p0_out, dst - stride, 0, 0);
+        __lsx_vstelm_d(q0_out, dst, 0, 0);
+        __lsx_vstelm_d(q1_out, dst + stride, 0, 0);
+        __lsx_vstelm_d(q2_out, dst + stride2, 0, 0);
+    }
+}
+
+void ff_loop_filter_v_88_16_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int32_t b_limit_ptr,
+                                int32_t limit_ptr,
+                                int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p2_out, p1_out, p0_out, q0_out, q1_out, q2_out;
+    __m128i flat, mask, hev, tmp, thresh, b_limit, limit;
+    __m128i p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l;
+    __m128i p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h;
+    __m128i p2_filt8_l, p1_filt8_l, p0_filt8_l;
+    __m128i q0_filt8_l, q1_filt8_l, q2_filt8_l;
+    __m128i p2_filt8_h, p1_filt8_h, p0_filt8_h;
+    __m128i q0_filt8_h, q1_filt8_h, q2_filt8_h;
+    __m128i zero = __lsx_vldi(0);
+
+    /* load vector elements */
+    DUP4_ARG2(__lsx_vldx, dst, -stride4, dst, -stride3, dst, -stride2,
+              dst, -stride, p3, p2, p1, p0);
+    q0 = __lsx_vld(dst, 0);
+    DUP2_ARG2(__lsx_vldx, dst, stride, dst, stride2, q1, q2);
+    q3 = __lsx_vldx(dst, stride3);
+
+    thresh = __lsx_vreplgr2vr_b(thresh_ptr);
+    tmp    = __lsx_vreplgr2vr_b(thresh_ptr >> 8);
+    thresh = __lsx_vilvl_d(tmp, thresh);
+
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    tmp     = __lsx_vreplgr2vr_b(b_limit_ptr >> 8);
+    b_limit = __lsx_vilvl_d(tmp, b_limit);
+
+    limit = __lsx_vreplgr2vr_b(limit_ptr);
+    tmp   = __lsx_vreplgr2vr_b(limit_ptr >> 8);
+    limit = __lsx_vilvl_d(tmp, limit);
+
+    /* mask and hev */
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        __lsx_vst(p1_out, dst - stride2, 0);
+        __lsx_vst(p0_out, dst - stride, 0);
+        __lsx_vst(q0_out, dst, 0);
+        __lsx_vst(q1_out, dst + stride, 0);
+    } else {
+        DUP4_ARG2(__lsx_vilvl_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_l, p2_l, p1_l, p0_l);
+        DUP4_ARG2(__lsx_vilvl_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_l, q1_l, q2_l, q3_l);
+        VP9_FILTER8(p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l, p2_filt8_l,
+                    p1_filt8_l, p0_filt8_l, q0_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        DUP4_ARG2(__lsx_vilvh_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_h, p2_h, p1_h, p0_h);
+        DUP4_ARG2(__lsx_vilvh_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_h, q1_h, q2_h, q3_h);
+        VP9_FILTER8(p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h, p2_filt8_h,
+                    p1_filt8_h, p0_filt8_h, q0_filt8_h, q1_filt8_h, q2_filt8_h);
+
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, p2_filt8_h, p2_filt8_l, p1_filt8_h,
+                  p1_filt8_l, p0_filt8_h, p0_filt8_l, q0_filt8_h, q0_filt8_l,
+                  p2_filt8_l, p1_filt8_l, p0_filt8_l, q0_filt8_l);
+        DUP2_ARG2(__lsx_vpickev_b, q1_filt8_h, q1_filt8_l, q2_filt8_h,
+                  q2_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        /* store pixel values */
+        p2_out = __lsx_vbitsel_v(p2, p2_filt8_l, flat);
+        p1_out = __lsx_vbitsel_v(p1_out, p1_filt8_l, flat);
+        p0_out = __lsx_vbitsel_v(p0_out, p0_filt8_l, flat);
+        q0_out = __lsx_vbitsel_v(q0_out, q0_filt8_l, flat);
+        q1_out = __lsx_vbitsel_v(q1_out, q1_filt8_l, flat);
+        q2_out = __lsx_vbitsel_v(q2, q2_filt8_l, flat);
+
+
+        __lsx_vstx(p2_out, dst, -stride3);
+        __lsx_vstx(p1_out, dst, -stride2);
+        __lsx_vstx(p0_out, dst, -stride);
+        __lsx_vst(q0_out, dst, 0);
+        __lsx_vstx(q1_out, dst, stride);
+        __lsx_vstx(q2_out, dst, stride2);
+    }
+}
+
+void ff_loop_filter_v_84_16_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int32_t b_limit_ptr,
+                                int32_t limit_ptr,
+                                int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p2_out, p1_out, p0_out, q0_out, q1_out, q2_out;
+    __m128i flat, mask, hev, tmp, thresh, b_limit, limit;
+    __m128i p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l;
+    __m128i p2_filt8_l, p1_filt8_l, p0_filt8_l;
+    __m128i q0_filt8_l, q1_filt8_l, q2_filt8_l;
+    __m128i zero = __lsx_vldi(0);
+
+    /* load vector elements */
+    DUP4_ARG2(__lsx_vldx, dst, -stride4, dst, -stride3, dst, -stride2,
+              dst, -stride, p3, p2, p1, p0);
+    q0 = __lsx_vld(dst, 0);
+    DUP2_ARG2(__lsx_vldx, dst, stride, dst, stride2, q1, q2);
+    q3 = __lsx_vldx(dst, stride3);
+
+    thresh = __lsx_vreplgr2vr_b(thresh_ptr);
+    tmp    = __lsx_vreplgr2vr_b(thresh_ptr >> 8);
+    thresh = __lsx_vilvl_d(tmp, thresh);
+
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    tmp     = __lsx_vreplgr2vr_b(b_limit_ptr >> 8);
+    b_limit = __lsx_vilvl_d(tmp, b_limit);
+
+    limit = __lsx_vreplgr2vr_b(limit_ptr);
+    tmp   = __lsx_vreplgr2vr_b(limit_ptr >> 8);
+    limit = __lsx_vilvl_d(tmp, limit);
+
+    /* mask and hev */
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    flat = __lsx_vilvl_d(zero, flat);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        __lsx_vstx(p1_out, dst, -stride2);
+        __lsx_vstx(p0_out, dst, -stride);
+        __lsx_vst(q0_out, dst, 0);
+        __lsx_vstx(q1_out, dst, stride);
+    } else {
+        DUP4_ARG2(__lsx_vilvl_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_l, p2_l, p1_l, p0_l);
+        DUP4_ARG2(__lsx_vilvl_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_l, q1_l, q2_l, q3_l);
+        VP9_FILTER8(p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l, p2_filt8_l,
+                    p1_filt8_l, p0_filt8_l, q0_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, p2_filt8_l, p2_filt8_l, p1_filt8_l,
+                  p1_filt8_l, p0_filt8_l, p0_filt8_l, q0_filt8_l, q0_filt8_l,
+                  p2_filt8_l, p1_filt8_l, p0_filt8_l, q0_filt8_l);
+        DUP2_ARG2(__lsx_vpickev_b, q1_filt8_l, q1_filt8_l, q2_filt8_l,
+                  q2_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        /* store pixel values */
+        p2_out = __lsx_vbitsel_v(p2, p2_filt8_l, flat);
+        p1_out = __lsx_vbitsel_v(p1_out, p1_filt8_l, flat);
+        p0_out = __lsx_vbitsel_v(p0_out, p0_filt8_l, flat);
+        q0_out = __lsx_vbitsel_v(q0_out, q0_filt8_l, flat);
+        q1_out = __lsx_vbitsel_v(q1_out, q1_filt8_l, flat);
+        q2_out = __lsx_vbitsel_v(q2, q2_filt8_l, flat);
+
+        __lsx_vstx(p2_out, dst, -stride3);
+        __lsx_vstx(p1_out, dst, -stride2);
+        __lsx_vstx(p0_out, dst, -stride);
+        __lsx_vst(q0_out, dst, 0);
+        __lsx_vstx(q1_out, dst, stride);
+        __lsx_vstx(q2_out, dst, stride2);
+    }
+}
+
+void ff_loop_filter_v_48_16_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int32_t b_limit_ptr,
+                                int32_t limit_ptr,
+                                int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p2_out, p1_out, p0_out, q0_out, q1_out, q2_out;
+    __m128i flat, mask, hev, tmp, thresh, b_limit, limit;
+    __m128i p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h;
+    __m128i p2_filt8_h, p1_filt8_h, p0_filt8_h;
+    __m128i q0_filt8_h, q1_filt8_h, q2_filt8_h;
+    __m128i zero = { 0 };
+
+    /* load vector elements */
+    DUP4_ARG2(__lsx_vldx, dst, -stride4, dst, -stride3, dst, -stride2,
+              dst, -stride, p3, p2, p1, p0);
+    q0 = __lsx_vld(dst, 0);
+    DUP2_ARG2(__lsx_vldx, dst, stride, dst, stride2, q1, q2);
+    q3 = __lsx_vldx(dst, stride3);
+
+    thresh = __lsx_vreplgr2vr_b(thresh_ptr);
+    tmp    = __lsx_vreplgr2vr_b(thresh_ptr >> 8);
+    thresh = __lsx_vilvl_d(tmp, thresh);
+
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    tmp     = __lsx_vreplgr2vr_b(b_limit_ptr >> 8);
+    b_limit = __lsx_vilvl_d(tmp, b_limit);
+
+    limit = __lsx_vreplgr2vr_b(limit_ptr);
+    tmp   = __lsx_vreplgr2vr_b(limit_ptr >> 8);
+    limit = __lsx_vilvl_d(tmp, limit);
+
+    /* mask and hev */
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    flat = __lsx_vilvh_d(flat, zero);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        __lsx_vstx(p1_out, dst, -stride2);
+        __lsx_vstx(p0_out, dst, -stride);
+        __lsx_vst(q0_out, dst, 0);
+        __lsx_vstx(q1_out, dst, stride);
+    } else {
+        DUP4_ARG2(__lsx_vilvh_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_h, p2_h, p1_h, p0_h);
+        DUP4_ARG2(__lsx_vilvh_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_h, q1_h, q2_h, q3_h);
+        VP9_FILTER8(p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h, p2_filt8_h,
+                    p1_filt8_h, p0_filt8_h, q0_filt8_h, q1_filt8_h, q2_filt8_h);
+
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, p2_filt8_h, p2_filt8_h, p1_filt8_h,
+                  p1_filt8_h, p0_filt8_h, p0_filt8_h, q0_filt8_h, q0_filt8_h,
+                  p2_filt8_h, p1_filt8_h, p0_filt8_h, q0_filt8_h);
+        DUP2_ARG2(__lsx_vpickev_b, q1_filt8_h, q1_filt8_h, q2_filt8_h,
+                  q2_filt8_h, q1_filt8_h, q2_filt8_h);
+
+        /* store pixel values */
+        p2_out = __lsx_vbitsel_v(p2, p2_filt8_h, flat);
+        p1_out = __lsx_vbitsel_v(p1_out, p1_filt8_h, flat);
+        p0_out = __lsx_vbitsel_v(p0_out, p0_filt8_h, flat);
+        q0_out = __lsx_vbitsel_v(q0_out, q0_filt8_h, flat);
+        q1_out = __lsx_vbitsel_v(q1_out, q1_filt8_h, flat);
+        q2_out = __lsx_vbitsel_v(q2, q2_filt8_h, flat);
+
+        __lsx_vstx(p2_out, dst, -stride3);
+        __lsx_vstx(p1_out, dst, -stride2);
+        __lsx_vstx(p0_out, dst, -stride);
+        __lsx_vst(q0_out, dst, 0);
+        __lsx_vstx(q1_out, dst, stride);
+        __lsx_vstx(q2_out, dst, stride2);
+    }
+}
+
+static int32_t vp9_hz_lpf_t4_and_t8_16w(uint8_t *dst, ptrdiff_t stride,
+                                        uint8_t *filter48,
+                                        int32_t b_limit_ptr,
+                                        int32_t limit_ptr,
+                                        int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p2_out, p1_out, p0_out, q0_out, q1_out, q2_out;
+    __m128i flat, mask, hev, thresh, b_limit, limit;
+    __m128i p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l;
+    __m128i p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h;
+    __m128i p2_filt8_l, p1_filt8_l, p0_filt8_l;
+    __m128i q0_filt8_l, q1_filt8_l, q2_filt8_l;
+    __m128i p2_filt8_h, p1_filt8_h, p0_filt8_h;
+    __m128i q0_filt8_h, q1_filt8_h, q2_filt8_h;
+    __m128i zero = __lsx_vldi(0);
+
+    /* load vector elements */
+    DUP4_ARG2(__lsx_vldx, dst, -stride4, dst, -stride3, dst, -stride2,
+              dst, -stride, p3, p2, p1, p0);
+    q0 = __lsx_vld(dst, 0);
+    DUP2_ARG2(__lsx_vldx, dst, stride, dst, stride2, q1, q2);
+    q3 = __lsx_vldx(dst, stride3);
+
+    thresh  = __lsx_vreplgr2vr_b(thresh_ptr);
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    limit   = __lsx_vreplgr2vr_b(limit_ptr);
+
+    /* mask and hev */
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        __lsx_vstx(p1_out, dst, -stride2);
+        __lsx_vstx(p0_out, dst, -stride);
+        __lsx_vst(q0_out, dst, 0);
+        __lsx_vstx(q1_out, dst, stride);
+        return 1;
+    } else {
+        DUP4_ARG2(__lsx_vilvl_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_l, p2_l, p1_l, p0_l);
+        DUP4_ARG2(__lsx_vilvl_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_l, q1_l, q2_l, q3_l);
+        VP9_FILTER8(p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l, p2_filt8_l,
+                    p1_filt8_l, p0_filt8_l, q0_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        DUP4_ARG2(__lsx_vilvh_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_h, p2_h, p1_h, p0_h);
+        DUP4_ARG2(__lsx_vilvh_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_h, q1_h, q2_h, q3_h);
+        VP9_FILTER8(p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h, p2_filt8_h,
+                    p1_filt8_h, p0_filt8_h, q0_filt8_h, q1_filt8_h, q2_filt8_h);
+
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, p2_filt8_h, p2_filt8_l, p1_filt8_h,
+                  p1_filt8_l, p0_filt8_h, p0_filt8_l, q0_filt8_h, q0_filt8_l,
+                  p2_filt8_l, p1_filt8_l, p0_filt8_l, q0_filt8_l);
+        DUP2_ARG2(__lsx_vpickev_b, q1_filt8_h, q1_filt8_l, q2_filt8_h,
+                  q2_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        /* store pixel values */
+        p2_out = __lsx_vbitsel_v(p2, p2_filt8_l, flat);
+        p1_out = __lsx_vbitsel_v(p1_out, p1_filt8_l, flat);
+        p0_out = __lsx_vbitsel_v(p0_out, p0_filt8_l, flat);
+        q0_out = __lsx_vbitsel_v(q0_out, q0_filt8_l, flat);
+        q1_out = __lsx_vbitsel_v(q1_out, q1_filt8_l, flat);
+        q2_out = __lsx_vbitsel_v(q2, q2_filt8_l, flat);
+
+        __lsx_vst(p2_out, filter48, 0);
+        __lsx_vst(p1_out, filter48, 16);
+        __lsx_vst(p0_out, filter48, 32);
+        __lsx_vst(q0_out, filter48, 48);
+        __lsx_vst(q1_out, filter48, 64);
+        __lsx_vst(q2_out, filter48, 80);
+        __lsx_vst(flat, filter48, 96);
+
+        return 0;
+    }
+}
+
+static void vp9_hz_lpf_t16_16w(uint8_t *dst, ptrdiff_t stride,
+                               uint8_t *filter48)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    uint8_t *dst_tmp = dst - stride4;
+    uint8_t *dst_tmp1 = dst + stride4;
+    __m128i p7, p6, p5, p4, p3, p2, p1, p0, q0, q1, q2, q3, q4, q5, q6, q7;
+    __m128i flat, flat2, filter8;
+    __m128i zero = __lsx_vldi(0);
+    __m128i out_h, out_l;
+    v8u16 p7_l_in, p6_l_in, p5_l_in, p4_l_in;
+    v8u16 p3_l_in, p2_l_in, p1_l_in, p0_l_in;
+    v8u16 q7_l_in, q6_l_in, q5_l_in, q4_l_in;
+    v8u16 q3_l_in, q2_l_in, q1_l_in, q0_l_in;
+    v8u16 p7_h_in, p6_h_in, p5_h_in, p4_h_in;
+    v8u16 p3_h_in, p2_h_in, p1_h_in, p0_h_in;
+    v8u16 q7_h_in, q6_h_in, q5_h_in, q4_h_in;
+    v8u16 q3_h_in, q2_h_in, q1_h_in, q0_h_in;
+    v8u16 tmp0_l, tmp1_l, tmp0_h, tmp1_h;
+
+    flat = __lsx_vld(filter48, 96);
+
+    DUP4_ARG2(__lsx_vldx, dst_tmp, -stride4, dst_tmp, -stride3, dst_tmp,
+              -stride2, dst_tmp, -stride, p7, p6, p5, p4);
+    p3 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, p2, p1);
+    p0 = __lsx_vldx(dst_tmp, stride3);
+
+    q0 = __lsx_vld(dst, 0);
+    DUP2_ARG2(__lsx_vldx, dst, stride, dst, stride2, q1, q2);
+    q3 = __lsx_vldx(dst, stride3);
+
+    q4 = __lsx_vld(dst_tmp1, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp1, stride, dst_tmp1, stride2, q5, q6);
+    q7 = __lsx_vldx(dst_tmp1, stride3);
+    VP9_FLAT5(p7, p6, p5, p4, p0, q0, q4, q5, q6, q7, flat, flat2);
+
+    /* if flat2 is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat2)) {
+        DUP4_ARG2(__lsx_vld, filter48, 0, filter48, 16, filter48, 32, filter48,
+                  48, p2, p1, p0, q0);
+        DUP2_ARG2(__lsx_vld, filter48, 64, filter48, 80, q1, q2);
+
+        __lsx_vstx(p2, dst, -stride3);
+        __lsx_vstx(p1, dst, -stride2);
+        __lsx_vstx(p0, dst, -stride);
+        __lsx_vst(q0, dst, 0);
+        __lsx_vstx(q1, dst, stride);
+        __lsx_vstx(q2, dst, stride2);
+    } else {
+        dst = dst_tmp - stride3;
+
+        p7_l_in = (v8u16)__lsx_vilvl_b(zero, p7);
+        p6_l_in = (v8u16)__lsx_vilvl_b(zero, p6);
+        p5_l_in = (v8u16)__lsx_vilvl_b(zero, p5);
+        p4_l_in = (v8u16)__lsx_vilvl_b(zero, p4);
+        p3_l_in = (v8u16)__lsx_vilvl_b(zero, p3);
+        p2_l_in = (v8u16)__lsx_vilvl_b(zero, p2);
+        p1_l_in = (v8u16)__lsx_vilvl_b(zero, p1);
+        p0_l_in = (v8u16)__lsx_vilvl_b(zero, p0);
+
+        q0_l_in = (v8u16)__lsx_vilvl_b(zero, q0);
+
+        tmp0_l = p7_l_in << 3;
+        tmp0_l -= p7_l_in;
+        tmp0_l += p6_l_in;
+        tmp0_l += q0_l_in;
+        tmp1_l = p6_l_in + p5_l_in;
+        tmp1_l += p4_l_in;
+        tmp1_l += p3_l_in;
+        tmp1_l += p2_l_in;
+        tmp1_l += p1_l_in;
+        tmp1_l += p0_l_in;
+        tmp1_l += tmp0_l;
+
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        p7_h_in = (v8u16)__lsx_vilvh_b(zero, p7);
+        p6_h_in = (v8u16)__lsx_vilvh_b(zero, p6);
+        p5_h_in = (v8u16)__lsx_vilvh_b(zero, p5);
+        p4_h_in = (v8u16)__lsx_vilvh_b(zero, p4);
+
+        p3_h_in = (v8u16)__lsx_vilvh_b(zero, p3);
+        p2_h_in = (v8u16)__lsx_vilvh_b(zero, p2);
+        p1_h_in = (v8u16)__lsx_vilvh_b(zero, p1);
+        p0_h_in = (v8u16)__lsx_vilvh_b(zero, p0);
+        q0_h_in = (v8u16)__lsx_vilvh_b(zero, q0);
+
+        tmp0_h = p7_h_in << 3;
+        tmp0_h -= p7_h_in;
+        tmp0_h += p6_h_in;
+        tmp0_h += q0_h_in;
+        tmp1_h = p6_h_in + p5_h_in;
+        tmp1_h += p4_h_in;
+        tmp1_h += p3_h_in;
+        tmp1_h += p2_h_in;
+        tmp1_h += p1_h_in;
+        tmp1_h += p0_h_in;
+        tmp1_h += tmp0_h;
+
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        p6 = __lsx_vbitsel_v(p6, out_l, flat2);
+        __lsx_vst(p6, dst, 0);
+        dst += stride;
+
+        /* p5 */
+        q1_l_in = (v8u16)__lsx_vilvl_b(zero, q1);
+        tmp0_l = p5_l_in - p6_l_in;
+        tmp0_l += q1_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        q1_h_in = (v8u16)__lsx_vilvh_b(zero, q1);
+        tmp0_h = p5_h_in - p6_h_in;
+        tmp0_h += q1_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        p5 = __lsx_vbitsel_v(p5, out_l, flat2);
+        __lsx_vst(p5, dst, 0);
+        dst += stride;
+
+        /* p4 */
+        q2_l_in = (v8u16)__lsx_vilvl_b(zero, q2);
+        tmp0_l = p4_l_in - p5_l_in;
+        tmp0_l += q2_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        q2_h_in = (v8u16)__lsx_vilvh_b(zero, q2);
+        tmp0_h = p4_h_in - p5_h_in;
+        tmp0_h += q2_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        p4 = __lsx_vbitsel_v(p4, out_l, flat2);
+        __lsx_vst(p4, dst, 0);
+        dst += stride;
+
+        /* p3 */
+        q3_l_in = (v8u16)__lsx_vilvl_b(zero, q3);
+        tmp0_l = p3_l_in - p4_l_in;
+        tmp0_l += q3_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        q3_h_in = (v8u16)__lsx_vilvh_b(zero, q3);
+        tmp0_h = p3_h_in - p4_h_in;
+        tmp0_h += q3_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        p3 = __lsx_vbitsel_v(p3, out_l, flat2);
+        __lsx_vst(p3, dst, 0);
+        dst += stride;
+
+        /* p2 */
+        q4_l_in = (v8u16)__lsx_vilvl_b(zero, q4);
+        filter8 = __lsx_vld(filter48, 0);
+        tmp0_l = p2_l_in - p3_l_in;
+        tmp0_l += q4_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        q4_h_in = (v8u16)__lsx_vilvh_b(zero, q4);
+        tmp0_h = p2_h_in - p3_h_in;
+        tmp0_h += q4_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 0);
+        dst += stride;
+
+        /* p1 */
+        q5_l_in = (v8u16)__lsx_vilvl_b(zero, q5);
+        filter8 = __lsx_vld(filter48, 16);
+        tmp0_l = p1_l_in - p2_l_in;
+        tmp0_l += q5_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        q5_h_in = (v8u16)__lsx_vilvh_b(zero, q5);
+        tmp0_h = p1_h_in - p2_h_in;
+        tmp0_h += q5_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 0);
+        dst += stride;
+
+        /* p0 */
+        q6_l_in = (v8u16)__lsx_vilvl_b(zero, q6);
+        filter8 = __lsx_vld(filter48, 32);
+        tmp0_l = p0_l_in - p1_l_in;
+        tmp0_l += q6_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        q6_h_in = (v8u16)__lsx_vilvh_b(zero, q6);
+        tmp0_h = p0_h_in - p1_h_in;
+        tmp0_h += q6_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 0);
+        dst += stride;
+
+        /* q0 */
+        q7_l_in = (v8u16)__lsx_vilvl_b(zero, q7);
+        filter8 = __lsx_vld(filter48, 48);
+        tmp0_l = q7_l_in - p0_l_in;
+        tmp0_l += q0_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        q7_h_in = (v8u16)__lsx_vilvh_b(zero, q7);
+        tmp0_h = q7_h_in - p0_h_in;
+        tmp0_h += q0_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 0);
+        dst += stride;
+
+        /* q1 */
+        filter8 = __lsx_vld(filter48, 64);
+        tmp0_l = q7_l_in - q0_l_in;
+        tmp0_l += q1_l_in;
+        tmp0_l -= p6_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        tmp0_h = q7_h_in - q0_h_in;
+        tmp0_h += q1_h_in;
+        tmp0_h -= p6_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 0);
+        dst += stride;
+
+        /* q2 */
+        filter8 = __lsx_vld(filter48, 80);
+        tmp0_l = q7_l_in - q1_l_in;
+        tmp0_l += q2_l_in;
+        tmp0_l -= p5_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        tmp0_h = q7_h_in - q1_h_in;
+        tmp0_h += q2_h_in;
+        tmp0_h -= p5_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 0);
+        dst += stride;
+
+        /* q3 */
+        tmp0_l = q7_l_in - q2_l_in;
+        tmp0_l += q3_l_in;
+        tmp0_l -= p4_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        tmp0_h = q7_h_in - q2_h_in;
+        tmp0_h += q3_h_in;
+        tmp0_h -= p4_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        q3 = __lsx_vbitsel_v(q3, out_l, flat2);
+        __lsx_vst(q3, dst, 0);
+        dst += stride;
+
+        /* q4 */
+        tmp0_l = q7_l_in - q3_l_in;
+        tmp0_l += q4_l_in;
+        tmp0_l -= p3_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        tmp0_h = q7_h_in - q3_h_in;
+        tmp0_h += q4_h_in;
+        tmp0_h -= p3_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        q4 = __lsx_vbitsel_v(q4, out_l, flat2);
+        __lsx_vst(q4, dst, 0);
+        dst += stride;
+
+        /* q5 */
+        tmp0_l = q7_l_in - q4_l_in;
+        tmp0_l += q5_l_in;
+        tmp0_l -= p2_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        tmp0_h = q7_h_in - q4_h_in;
+        tmp0_h += q5_h_in;
+        tmp0_h -= p2_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        q5 = __lsx_vbitsel_v(q5, out_l, flat2);
+        __lsx_vst(q5, dst, 0);
+        dst += stride;
+
+        /* q6 */
+        tmp0_l = q7_l_in - q5_l_in;
+        tmp0_l += q6_l_in;
+        tmp0_l -= p1_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        tmp0_h = q7_h_in - q5_h_in;
+        tmp0_h += q6_h_in;
+        tmp0_h -= p1_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        q6 = __lsx_vbitsel_v(q6, out_l, flat2);
+        __lsx_vst(q6, dst, 0);
+    }
+}
+
+void ff_loop_filter_v_16_16_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int32_t b_limit_ptr,
+                                int32_t limit_ptr,
+                                int32_t thresh_ptr)
+{
+    uint8_t filter48[16 * 8] __attribute__ ((aligned(16)));
+    uint8_t early_exit = 0;
+
+    early_exit = vp9_hz_lpf_t4_and_t8_16w(dst, stride, &filter48[0],
+                                          b_limit_ptr, limit_ptr, thresh_ptr);
+
+    if (0 == early_exit) {
+        vp9_hz_lpf_t16_16w(dst, stride, filter48);
+    }
+}
+
+void ff_loop_filter_v_16_8_lsx(uint8_t *dst, ptrdiff_t stride,
+                               int32_t b_limit_ptr,
+                               int32_t limit_ptr,
+                               int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    uint8_t *dst_tmp = dst - stride4;
+    uint8_t *dst_tmp1 = dst + stride4;
+    __m128i zero = __lsx_vldi(0);
+    __m128i flat2, mask, hev, flat, thresh, b_limit, limit;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0, p7, p6, p5, p4, q4, q5, q6, q7;
+    __m128i p2_out, p1_out, p0_out, q0_out, q1_out, q2_out;
+    __m128i p0_filter16, p1_filter16;
+    __m128i p2_filter8, p1_filter8, p0_filter8;
+    __m128i q0_filter8, q1_filter8, q2_filter8;
+    __m128i p7_l, p6_l, p5_l, p4_l, q7_l, q6_l, q5_l, q4_l;
+    __m128i p3_l, p2_l, p1_l, p0_l, q3_l, q2_l, q1_l, q0_l;
+    __m128i tmp0, tmp1, tmp2;
+
+    /* load vector elements */
+    DUP4_ARG2(__lsx_vldx, dst, -stride4, dst, -stride3, dst, -stride2,
+              dst, -stride, p3, p2, p1, p0);
+    q0 = __lsx_vld(dst, 0);
+    DUP2_ARG2(__lsx_vldx, dst, stride, dst, stride2, q1, q2);
+    q3 = __lsx_vldx(dst, stride3);
+
+    thresh  = __lsx_vreplgr2vr_b(thresh_ptr);
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    limit   = __lsx_vreplgr2vr_b(limit_ptr);
+
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    flat = __lsx_vilvl_d(zero, flat);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        __lsx_vstelm_d(p1_out, dst - stride2, 0, 0);
+        __lsx_vstelm_d(p0_out, dst -   stride, 0, 0);
+        __lsx_vstelm_d(q0_out, dst           , 0, 0);
+        __lsx_vstelm_d(q1_out, dst +   stride, 0, 0);
+    } else {
+        /* convert 8 bit input data into 16 bit */
+        DUP4_ARG2(__lsx_vilvl_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_l, p2_l, p1_l, p0_l);
+        DUP4_ARG2(__lsx_vilvl_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_l, q1_l, q2_l, q3_l);
+        VP9_FILTER8(p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l,
+                    p2_filter8, p1_filter8, p0_filter8, q0_filter8,
+                    q1_filter8, q2_filter8);
+
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, zero, p2_filter8, zero, p1_filter8,
+                  zero, p0_filter8, zero, q0_filter8, p2_filter8,
+                  p1_filter8, p0_filter8, q0_filter8);
+        DUP2_ARG2(__lsx_vpickev_b, zero, q1_filter8, zero, q2_filter8,
+                  q1_filter8, q2_filter8);
+
+        /* store pixel values */
+        p2_out = __lsx_vbitsel_v(p2, p2_filter8, flat);
+        p1_out = __lsx_vbitsel_v(p1_out, p1_filter8, flat);
+        p0_out = __lsx_vbitsel_v(p0_out, p0_filter8, flat);
+        q0_out = __lsx_vbitsel_v(q0_out, q0_filter8, flat);
+        q1_out = __lsx_vbitsel_v(q1_out, q1_filter8, flat);
+        q2_out = __lsx_vbitsel_v(q2, q2_filter8, flat);
+
+        /* load 16 vector elements */
+        DUP4_ARG2(__lsx_vld, dst_tmp - stride4, 0, dst_tmp - stride3, 0,
+                  dst_tmp - stride2, 0, dst_tmp - stride, 0, p7, p6, p5, p4);
+        DUP4_ARG2(__lsx_vld, dst_tmp1, 0, dst_tmp1 + stride, 0,
+                dst_tmp1 + stride2, 0, dst_tmp1 + stride3, 0, q4, q5, q6, q7);
+
+        VP9_FLAT5(p7, p6, p5, p4, p0, q0, q4, q5, q6, q7, flat, flat2);
+
+        /* if flat2 is zero for all pixels, then no need to calculate other filter */
+        if (__lsx_bz_v(flat2)) {
+            dst -= stride3;
+            __lsx_vstelm_d(p2_out, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(p1_out, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(p0_out, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(q0_out, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(q1_out, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(q2_out, dst, 0, 0);
+        } else {
+            /* LSB(right) 8 pixel operation */
+            DUP4_ARG2(__lsx_vilvl_b, zero, p7, zero, p6, zero, p5, zero, p4,
+                      p7_l, p6_l, p5_l, p4_l);
+            DUP4_ARG2(__lsx_vilvl_b, zero, q4, zero, q5, zero, q6, zero, q7,
+                      q4_l, q5_l, q6_l, q7_l);
+
+            tmp0 = __lsx_vslli_h(p7_l, 3);
+            tmp0 = __lsx_vsub_h(tmp0, p7_l);
+            tmp0 = __lsx_vadd_h(tmp0, p6_l);
+            tmp0 = __lsx_vadd_h(tmp0, q0_l);
+
+            dst = dst_tmp - stride3;
+
+            /* calculation of p6 and p5 */
+            tmp1 = __lsx_vadd_h(p6_l, p5_l);
+            tmp1 = __lsx_vadd_h(tmp1, p4_l);
+            tmp1 = __lsx_vadd_h(tmp1, p3_l);
+            tmp1 = __lsx_vadd_h(tmp1, p2_l);
+            tmp1 = __lsx_vadd_h(tmp1, p1_l);
+            tmp1 = __lsx_vadd_h(tmp1, p0_l);
+            tmp1 = __lsx_vadd_h(tmp1, tmp0);
+
+            p0_filter16 = __lsx_vsrari_h(tmp1, 4);
+            tmp0 = __lsx_vsub_h(p5_l, p6_l);
+            tmp0 = __lsx_vadd_h(tmp0, q1_l);
+            tmp0 = __lsx_vsub_h(tmp0, p7_l);
+            tmp1 = __lsx_vadd_h(tmp1, tmp0);
+
+            p1_filter16 = __lsx_vsrari_h(tmp1, 4);
+            DUP2_ARG2(__lsx_vpickev_b, zero, p0_filter16, zero,
+                      p1_filter16, p0_filter16, p1_filter16);
+            p0_filter16 = __lsx_vbitsel_v(p6, p0_filter16, flat2);
+            p1_filter16 = __lsx_vbitsel_v(p5, p1_filter16, flat2);
+            __lsx_vstelm_d(p0_filter16, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(p1_filter16, dst, 0, 0);
+            dst += stride;
+
+            /* calculation of p4 and p3 */
+            tmp0 = __lsx_vsub_h(p4_l, p5_l);
+            tmp0 = __lsx_vadd_h(tmp0, q2_l);
+            tmp0 = __lsx_vsub_h(tmp0, p7_l);
+            tmp2 = __lsx_vsub_h(p3_l, p4_l);
+            tmp2 = __lsx_vadd_h(tmp2, q3_l);
+            tmp2 = __lsx_vsub_h(tmp2, p7_l);
+            tmp1 = __lsx_vadd_h(tmp1, tmp0);
+            p0_filter16 = __lsx_vsrari_h(tmp1, 4);
+            tmp1 = __lsx_vadd_h(tmp1, tmp2);
+            p1_filter16 = __lsx_vsrari_h(tmp1, 4);
+            DUP2_ARG2(__lsx_vpickev_b, zero, p0_filter16, zero,
+                      p1_filter16, p0_filter16, p1_filter16);
+            p0_filter16 = __lsx_vbitsel_v(p4, p0_filter16, flat2);
+            p1_filter16 = __lsx_vbitsel_v(p3, p1_filter16, flat2);
+            __lsx_vstelm_d(p0_filter16, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(p1_filter16, dst, 0, 0);
+            dst += stride;
+
+            /* calculation of p2 and p1 */
+            tmp0 = __lsx_vsub_h(p2_l, p3_l);
+            tmp0 = __lsx_vadd_h(tmp0, q4_l);
+            tmp0 = __lsx_vsub_h(tmp0, p7_l);
+            tmp2 = __lsx_vsub_h(p1_l, p2_l);
+            tmp2 = __lsx_vadd_h(tmp2, q5_l);
+            tmp2 = __lsx_vsub_h(tmp2, p7_l);
+            tmp1 = __lsx_vadd_h(tmp1, tmp0);
+            p0_filter16 = __lsx_vsrari_h(tmp1, 4);
+            tmp1 = __lsx_vadd_h(tmp1, tmp2);
+            p1_filter16 = __lsx_vsrari_h(tmp1, 4);
+            DUP2_ARG2(__lsx_vpickev_b, zero, p0_filter16, zero,
+                      p1_filter16, p0_filter16, p1_filter16);
+            p0_filter16 = __lsx_vbitsel_v(p2_out, p0_filter16, flat2);
+            p1_filter16 = __lsx_vbitsel_v(p1_out, p1_filter16, flat2);
+            __lsx_vstelm_d(p0_filter16, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(p1_filter16, dst, 0, 0);
+            dst += stride;
+
+            /* calculation of p0 and q0 */
+            tmp0 = __lsx_vsub_h(p0_l, p1_l);
+            tmp0 = __lsx_vadd_h(tmp0, q6_l);
+            tmp0 = __lsx_vsub_h(tmp0, p7_l);
+            tmp2 = __lsx_vsub_h(q7_l, p0_l);
+            tmp2 = __lsx_vadd_h(tmp2, q0_l);
+            tmp2 = __lsx_vsub_h(tmp2, p7_l);
+            tmp1 = __lsx_vadd_h(tmp1, tmp0);
+            p0_filter16 = __lsx_vsrari_h((__m128i)tmp1, 4);
+            tmp1 = __lsx_vadd_h(tmp1, tmp2);
+            p1_filter16 = __lsx_vsrari_h((__m128i)tmp1, 4);
+            DUP2_ARG2(__lsx_vpickev_b, zero, p0_filter16, zero,
+                      p1_filter16, p0_filter16, p1_filter16);
+            p0_filter16 = __lsx_vbitsel_v(p0_out, p0_filter16, flat2);
+            p1_filter16 = __lsx_vbitsel_v(q0_out, p1_filter16, flat2);
+            __lsx_vstelm_d(p0_filter16, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(p1_filter16, dst, 0, 0);
+            dst += stride;
+
+            /* calculation of q1 and q2 */
+            tmp0 = __lsx_vsub_h(q7_l, q0_l);
+            tmp0 = __lsx_vadd_h(tmp0, q1_l);
+            tmp0 = __lsx_vsub_h(tmp0, p6_l);
+            tmp2 = __lsx_vsub_h(q7_l, q1_l);
+            tmp2 = __lsx_vadd_h(tmp2, q2_l);
+            tmp2 = __lsx_vsub_h(tmp2, p5_l);
+            tmp1 = __lsx_vadd_h(tmp1, tmp0);
+            p0_filter16 = __lsx_vsrari_h(tmp1, 4);
+            tmp1 = __lsx_vadd_h(tmp1, tmp2);
+            p1_filter16 = __lsx_vsrari_h(tmp1, 4);
+            DUP2_ARG2(__lsx_vpickev_b, zero, p0_filter16, zero,
+                      p1_filter16, p0_filter16, p1_filter16);
+            p0_filter16 = __lsx_vbitsel_v(q1_out, p0_filter16, flat2);
+            p1_filter16 = __lsx_vbitsel_v(q2_out, p1_filter16, flat2);
+            __lsx_vstelm_d(p0_filter16, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(p1_filter16, dst, 0, 0);
+            dst += stride;
+
+            /* calculation of q3 and q4 */
+            tmp0 = __lsx_vsub_h(q7_l, q2_l);
+            tmp0 = __lsx_vadd_h(tmp0, q3_l);
+            tmp0 = __lsx_vsub_h(tmp0, p4_l);
+            tmp2 = __lsx_vsub_h(q7_l, q3_l);
+            tmp2 = __lsx_vadd_h(tmp2, q4_l);
+            tmp2 = __lsx_vsub_h(tmp2, p3_l);
+            tmp1 = __lsx_vadd_h(tmp1, tmp0);
+            p0_filter16 = __lsx_vsrari_h(tmp1, 4);
+            tmp1 = __lsx_vadd_h(tmp1, tmp2);
+            p1_filter16 = __lsx_vsrari_h(tmp1, 4);
+            DUP2_ARG2(__lsx_vpickev_b, zero, p0_filter16, zero,
+                      p1_filter16, p0_filter16, p1_filter16);
+            p0_filter16 = __lsx_vbitsel_v(q3, p0_filter16, flat2);
+            p1_filter16 = __lsx_vbitsel_v(q4, p1_filter16, flat2);
+            __lsx_vstelm_d(p0_filter16, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(p1_filter16, dst, 0, 0);
+            dst += stride;
+
+            /* calculation of q5 and q6 */
+            tmp0 = __lsx_vsub_h(q7_l, q4_l);
+            tmp0 = __lsx_vadd_h(tmp0, q5_l);
+            tmp0 = __lsx_vsub_h(tmp0, p2_l);
+            tmp2 = __lsx_vsub_h(q7_l, q5_l);
+            tmp2 = __lsx_vadd_h(tmp2, q6_l);
+            tmp2 = __lsx_vsub_h(tmp2, p1_l);
+            tmp1 = __lsx_vadd_h(tmp1, tmp0);
+            p0_filter16 = __lsx_vsrari_h(tmp1, 4);
+            tmp1 = __lsx_vadd_h(tmp1, tmp2);
+            p1_filter16 = __lsx_vsrari_h(tmp1, 4);
+            DUP2_ARG2(__lsx_vpickev_b, zero, p0_filter16, zero,
+                      p1_filter16, p0_filter16, p1_filter16);
+            p0_filter16 = __lsx_vbitsel_v(q5, p0_filter16, flat2);
+            p1_filter16 = __lsx_vbitsel_v(q6, p1_filter16, flat2);
+            __lsx_vstelm_d(p0_filter16, dst, 0, 0);
+            dst += stride;
+            __lsx_vstelm_d(p1_filter16, dst, 0, 0);
+        }
+    }
+}
+
+void ff_loop_filter_h_4_8_lsx(uint8_t *dst, ptrdiff_t stride,
+                              int32_t b_limit_ptr,
+                              int32_t limit_ptr,
+                              int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    uint8_t *dst_tmp1 = dst - 4;
+    uint8_t *dst_tmp2 = dst_tmp1 + stride4;
+    __m128i mask, hev, flat, limit, thresh, b_limit;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i vec0, vec1, vec2, vec3;
+
+    p3 = __lsx_vld(dst_tmp1, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp1, stride, dst_tmp1, stride2, p2, p1);
+    p0 = __lsx_vldx(dst_tmp1, stride3);
+    q0 = __lsx_vld(dst_tmp2, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp2, stride, dst_tmp2, stride2, q1, q2);
+    q3 = __lsx_vldx(dst_tmp2, stride3);
+
+    thresh  = __lsx_vreplgr2vr_b(thresh_ptr);
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    limit   = __lsx_vreplgr2vr_b(limit_ptr);
+
+    LSX_TRANSPOSE8x8_B(p3, p2, p1, p0, q0, q1, q2, q3,
+                       p3, p2, p1, p0, q0, q1, q2, q3);
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1, p0, q0, q1);
+    DUP2_ARG2(__lsx_vilvl_b, p0, p1, q1, q0, vec0, vec1);
+    vec2 = __lsx_vilvl_h(vec1, vec0);
+    vec3 = __lsx_vilvh_h(vec1, vec0);
+
+    dst -= 2;
+    __lsx_vstelm_w(vec2, dst, 0, 0);
+    __lsx_vstelm_w(vec2, dst + stride, 0, 1);
+    __lsx_vstelm_w(vec2, dst + stride2, 0, 2);
+    __lsx_vstelm_w(vec2, dst + stride3, 0, 3);
+    dst += stride4;
+    __lsx_vstelm_w(vec3, dst, 0, 0);
+    __lsx_vstelm_w(vec3, dst + stride, 0, 1);
+    __lsx_vstelm_w(vec3, dst + stride2, 0, 2);
+    __lsx_vstelm_w(vec3, dst + stride3, 0, 3);
+}
+
+void ff_loop_filter_h_44_16_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int32_t b_limit_ptr,
+                                int32_t limit_ptr,
+                                int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    uint8_t *dst_tmp = dst - 4;
+    __m128i mask, hev, flat;
+    __m128i thresh0, b_limit0, limit0, thresh1, b_limit1, limit1;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i row0, row1, row2, row3, row4, row5, row6, row7;
+    __m128i row8, row9, row10, row11, row12, row13, row14, row15;
+    __m128i tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
+
+    row0 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, row1, row2);
+    row3 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    row4 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, row5, row6);
+    row7 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    row8 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, row9, row10);
+    row11 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    row12 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, row13, row14);
+    row15 = __lsx_vldx(dst_tmp, stride3);
+
+    LSX_TRANSPOSE16x8_B(row0, row1, row2, row3, row4, row5, row6, row7,
+                        row8, row9, row10, row11, row12, row13, row14, row15,
+                        p3, p2, p1, p0, q0, q1, q2, q3);
+
+    thresh0 = __lsx_vreplgr2vr_b(thresh_ptr);
+    thresh1 = __lsx_vreplgr2vr_b(thresh_ptr >> 8);
+    thresh0 = __lsx_vilvl_d(thresh1, thresh0);
+
+    b_limit0 = __lsx_vreplgr2vr_b(b_limit_ptr);
+    b_limit1 = __lsx_vreplgr2vr_b(b_limit_ptr >> 8);
+    b_limit0 = __lsx_vilvl_d(b_limit1, b_limit0);
+
+    limit0 = __lsx_vreplgr2vr_b(limit_ptr);
+    limit1 = __lsx_vreplgr2vr_b(limit_ptr >> 8);
+    limit0 = __lsx_vilvl_d(limit1, limit0);
+
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit0, b_limit0, thresh0,
+                 hev, mask, flat);
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1, p0, q0, q1);
+    DUP2_ARG2(__lsx_vilvl_b, p0, p1, q1, q0, tmp0, tmp1);
+    tmp2 = __lsx_vilvl_h(tmp1, tmp0);
+    tmp3 = __lsx_vilvh_h(tmp1, tmp0);
+    DUP2_ARG2(__lsx_vilvh_b, p0, p1, q1, q0, tmp0, tmp1);
+    tmp4 = __lsx_vilvl_h(tmp1, tmp0);
+    tmp5 = __lsx_vilvh_h(tmp1, tmp0);
+
+    dst -= 2;
+    __lsx_vstelm_w(tmp2, dst, 0, 0);
+    __lsx_vstelm_w(tmp2, dst + stride, 0, 1);
+    __lsx_vstelm_w(tmp2, dst + stride2, 0, 2);
+    __lsx_vstelm_w(tmp2, dst + stride3, 0, 3);
+    dst += stride4;
+    __lsx_vstelm_w(tmp3, dst, 0, 0);
+    __lsx_vstelm_w(tmp3, dst + stride, 0, 1);
+    __lsx_vstelm_w(tmp3, dst + stride2, 0, 2);
+    __lsx_vstelm_w(tmp3, dst + stride3, 0, 3);
+    dst += stride4;
+    __lsx_vstelm_w(tmp4, dst, 0, 0);
+    __lsx_vstelm_w(tmp4, dst + stride, 0, 1);
+    __lsx_vstelm_w(tmp4, dst + stride2, 0, 2);
+    __lsx_vstelm_w(tmp4, dst + stride3, 0, 3);
+    dst += stride4;
+    __lsx_vstelm_w(tmp5, dst, 0, 0);
+    __lsx_vstelm_w(tmp5, dst + stride, 0, 1);
+    __lsx_vstelm_w(tmp5, dst + stride2, 0, 2);
+    __lsx_vstelm_w(tmp5, dst + stride3, 0, 3);
+}
+
+void ff_loop_filter_h_8_8_lsx(uint8_t *dst, ptrdiff_t stride,
+                              int32_t b_limit_ptr,
+                              int32_t limit_ptr,
+                              int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    uint8_t *dst_tmp = dst - 4;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p1_out, p0_out, q0_out, q1_out;
+    __m128i flat, mask, hev, thresh, b_limit, limit;
+    __m128i p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l;
+    __m128i p2_filt8_l, p1_filt8_l, p0_filt8_l;
+    __m128i q0_filt8_l, q1_filt8_l, q2_filt8_l;
+    __m128i vec0, vec1, vec2, vec3, vec4;
+    __m128i zero = __lsx_vldi(0);
+
+    /* load vector elements */
+    p3 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, p2, p1);
+    p0 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    q0 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, q1, q2);
+    q3 = __lsx_vldx(dst_tmp, stride3);
+
+    LSX_TRANSPOSE8x8_B(p3, p2, p1, p0, q0, q1, q2, q3,
+                       p3, p2, p1, p0, q0, q1, q2, q3);
+
+    thresh  = __lsx_vreplgr2vr_b(thresh_ptr);
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    limit   = __lsx_vreplgr2vr_b(limit_ptr);
+
+    /* mask and hev */
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    /* flat4 */
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    /* filter4 */
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    flat = __lsx_vilvl_d(zero, flat);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        /* Store 4 pixels p1-_q1 */
+        DUP2_ARG2(__lsx_vilvl_b, p0_out, p1_out, q1_out, q0_out, vec0, vec1);
+        vec2 = __lsx_vilvl_h(vec1, vec0);
+        vec3 = __lsx_vilvh_h(vec1, vec0);
+
+        dst -= 2;
+        __lsx_vstelm_w(vec2, dst, 0, 0);
+        __lsx_vstelm_w(vec2, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec2, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec2, dst + stride3, 0, 3);
+        dst += stride4;
+        __lsx_vstelm_w(vec3, dst, 0, 0);
+        __lsx_vstelm_w(vec3, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec3, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec3, dst + stride3, 0, 3);
+    } else {
+        DUP4_ARG2(__lsx_vilvl_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_l, p2_l, p1_l, p0_l);
+        DUP4_ARG2(__lsx_vilvl_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_l, q1_l, q2_l, q3_l);
+        VP9_FILTER8(p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l, p2_filt8_l,
+                    p1_filt8_l, p0_filt8_l, q0_filt8_l, q1_filt8_l, q2_filt8_l);
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, p2_filt8_l, p2_filt8_l, p1_filt8_l,
+                  p1_filt8_l, p0_filt8_l, p0_filt8_l, q0_filt8_l,
+                  q0_filt8_l, p2_filt8_l, p1_filt8_l, p0_filt8_l,
+                  q0_filt8_l);
+        DUP2_ARG2(__lsx_vpickev_b, q1_filt8_l, q1_filt8_l, q2_filt8_l,
+                  q2_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        /* store pixel values */
+        p2 = __lsx_vbitsel_v(p2, p2_filt8_l, flat);
+        p1 = __lsx_vbitsel_v(p1_out, p1_filt8_l, flat);
+        p0 = __lsx_vbitsel_v(p0_out, p0_filt8_l, flat);
+        q0 = __lsx_vbitsel_v(q0_out, q0_filt8_l, flat);
+        q1 = __lsx_vbitsel_v(q1_out, q1_filt8_l, flat);
+        q2 = __lsx_vbitsel_v(q2, q2_filt8_l, flat);
+
+        /* Store 6 pixels p2-_q2 */
+        DUP2_ARG2(__lsx_vilvl_b, p1, p2, q0, p0, vec0, vec1);
+        vec2 = __lsx_vilvl_h(vec1, vec0);
+        vec3 = __lsx_vilvh_h(vec1, vec0);
+        vec4 = __lsx_vilvl_b(q2, q1);
+
+        dst -= 3;
+        __lsx_vstelm_w(vec2, dst, 0, 0);
+        __lsx_vstelm_h(vec4, dst, 4, 0);
+        dst += stride;
+        __lsx_vstelm_w(vec2, dst, 0, 1);
+        __lsx_vstelm_h(vec4, dst, 4, 1);
+        dst += stride;
+        __lsx_vstelm_w(vec2, dst, 0, 2);
+        __lsx_vstelm_h(vec4, dst, 4, 2);
+        dst += stride;
+        __lsx_vstelm_w(vec2, dst, 0, 3);
+        __lsx_vstelm_h(vec4, dst, 4, 3);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 0);
+        __lsx_vstelm_h(vec4, dst, 4, 4);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 1);
+        __lsx_vstelm_h(vec4, dst, 4, 5);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 2);
+        __lsx_vstelm_h(vec4, dst, 4, 6);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 3);
+        __lsx_vstelm_h(vec4, dst, 4, 7);
+    }
+}
+
+void ff_loop_filter_h_88_16_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int32_t b_limit_ptr,
+                                int32_t limit_ptr,
+                                int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    uint8_t *dst_tmp = dst - 4;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p1_out, p0_out, q0_out, q1_out;
+    __m128i flat, mask, hev, thresh, b_limit, limit;
+    __m128i row4, row5, row6, row7, row12, row13, row14, row15;
+    __m128i p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l;
+    __m128i p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h;
+    __m128i p2_filt8_l, p1_filt8_l, p0_filt8_l;
+    __m128i q0_filt8_l, q1_filt8_l, q2_filt8_l;
+    __m128i p2_filt8_h, p1_filt8_h, p0_filt8_h;
+    __m128i q0_filt8_h, q1_filt8_h, q2_filt8_h;
+    __m128i vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
+    __m128i zero = __lsx_vldi(0);
+
+    p0 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, p1, p2);
+    p3 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    row4 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, row5, row6);
+    row7 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    q3 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, q2, q1);
+    q0 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    row12 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, row13, row14);
+    row15 = __lsx_vldx(dst_tmp, stride3);
+
+    /* transpose 16x8 matrix into 8x16 */
+    LSX_TRANSPOSE16x8_B(p0, p1, p2, p3, row4, row5, row6, row7,
+                        q3, q2, q1, q0, row12, row13, row14, row15,
+                        p3, p2, p1, p0, q0, q1, q2, q3);
+
+    thresh = __lsx_vreplgr2vr_b(thresh_ptr);
+    vec0   = __lsx_vreplgr2vr_b(thresh_ptr >> 8);
+    thresh = __lsx_vilvl_d(vec0, thresh);
+
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    vec0    = __lsx_vreplgr2vr_b(b_limit_ptr >> 8);
+    b_limit = __lsx_vilvl_d(vec0, b_limit);
+
+    limit = __lsx_vreplgr2vr_b(limit_ptr);
+    vec0  = __lsx_vreplgr2vr_b(limit_ptr >> 8);
+    limit = __lsx_vilvl_d(vec0, limit);
+
+    /* mask and hev */
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    /* flat4 */
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    /* filter4 */
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        DUP2_ARG2(__lsx_vilvl_b, p0_out, p1_out, q1_out, q0_out, vec0, vec1);
+        vec2 = __lsx_vilvl_h(vec1, vec0);
+        vec3 = __lsx_vilvh_h(vec1, vec0);
+        DUP2_ARG2(__lsx_vilvh_b, p0_out, p1_out, q1_out, q0_out, vec0, vec1);
+        vec4 = __lsx_vilvl_h(vec1, vec0);
+        vec5 = __lsx_vilvh_h(vec1, vec0);
+
+        dst -= 2;
+        __lsx_vstelm_w(vec2, dst, 0, 0);
+        __lsx_vstelm_w(vec2, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec2, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec2, dst + stride3, 0, 3);
+        dst += stride4;
+        __lsx_vstelm_w(vec3, dst, 0, 0);
+        __lsx_vstelm_w(vec3, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec3, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec3, dst + stride3, 0, 3);
+        dst += stride4;
+        __lsx_vstelm_w(vec4, dst, 0, 0);
+        __lsx_vstelm_w(vec4, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec4, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec4, dst + stride3, 0, 3);
+        dst += stride4;
+        __lsx_vstelm_w(vec5, dst, 0, 0);
+        __lsx_vstelm_w(vec5, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec5, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec5, dst + stride3, 0, 3);
+    } else {
+        DUP4_ARG2(__lsx_vilvl_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_l, p2_l, p1_l, p0_l);
+        DUP4_ARG2(__lsx_vilvl_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_l, q1_l, q2_l, q3_l);
+        VP9_FILTER8(p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l, p2_filt8_l,
+                    p1_filt8_l, p0_filt8_l, q0_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        DUP4_ARG2(__lsx_vilvh_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_h, p2_h, p1_h, p0_h);
+        DUP4_ARG2(__lsx_vilvh_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_h, q1_h, q2_h, q3_h);
+
+        /* filter8 */
+        VP9_FILTER8(p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h, p2_filt8_h,
+                    p1_filt8_h, p0_filt8_h, q0_filt8_h, q1_filt8_h, q2_filt8_h);
+
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, p2_filt8_h, p2_filt8_l, p1_filt8_h,
+                  p1_filt8_l, p0_filt8_h, p0_filt8_l, q0_filt8_h, q0_filt8_l,
+                  p2_filt8_l, p1_filt8_l, p0_filt8_l, q0_filt8_l);
+        DUP2_ARG2(__lsx_vpickev_b, q1_filt8_h, q1_filt8_l, q2_filt8_h,
+                  q2_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        /* store pixel values */
+        p2 = __lsx_vbitsel_v(p2, p2_filt8_l, flat);
+        p1 = __lsx_vbitsel_v(p1_out, p1_filt8_l, flat);
+        p0 = __lsx_vbitsel_v(p0_out, p0_filt8_l, flat);
+        q0 = __lsx_vbitsel_v(q0_out, q0_filt8_l, flat);
+        q1 = __lsx_vbitsel_v(q1_out, q1_filt8_l, flat);
+        q2 = __lsx_vbitsel_v(q2, q2_filt8_l, flat);
+
+        DUP2_ARG2(__lsx_vilvl_b, p1, p2, q0, p0, vec0, vec1);
+        vec3 = __lsx_vilvl_h(vec1, vec0);
+        vec4 = __lsx_vilvh_h(vec1, vec0);
+        DUP2_ARG2(__lsx_vilvh_b, p1, p2, q0, p0, vec0, vec1);
+        vec6 = __lsx_vilvl_h(vec1, vec0);
+        vec7 = __lsx_vilvh_h(vec1, vec0);
+        vec2 = __lsx_vilvl_b(q2, q1);
+        vec5 = __lsx_vilvh_b(q2, q1);
+
+        dst -= 3;
+        __lsx_vstelm_w(vec3, dst, 0, 0);
+        __lsx_vstelm_h(vec2, dst, 4, 0);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 1);
+        __lsx_vstelm_h(vec2, dst, 4, 1);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 2);
+        __lsx_vstelm_h(vec2, dst, 4, 2);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 3);
+        __lsx_vstelm_h(vec2, dst, 4, 3);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 0);
+        __lsx_vstelm_h(vec2, dst, 4, 4);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 1);
+        __lsx_vstelm_h(vec2, dst, 4, 5);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 2);
+        __lsx_vstelm_h(vec2, dst, 4, 6);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 3);
+        __lsx_vstelm_h(vec2, dst, 4, 7);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 0);
+        __lsx_vstelm_h(vec5, dst, 4, 0);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 1);
+        __lsx_vstelm_h(vec5, dst, 4, 1);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 2);
+        __lsx_vstelm_h(vec5, dst, 4, 2);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 3);
+        __lsx_vstelm_h(vec5, dst, 4, 3);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 0);
+        __lsx_vstelm_h(vec5, dst, 4, 4);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 1);
+        __lsx_vstelm_h(vec5, dst, 4, 5);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 2);
+        __lsx_vstelm_h(vec5, dst, 4, 6);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 3);
+        __lsx_vstelm_h(vec5, dst, 4, 7);
+    }
+}
+
+void ff_loop_filter_h_84_16_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int32_t b_limit_ptr,
+                                int32_t limit_ptr,
+                                int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    uint8_t *dst_tmp = dst - 4;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p1_out, p0_out, q0_out, q1_out;
+    __m128i flat, mask, hev, thresh, b_limit, limit;
+    __m128i row4, row5, row6, row7, row12, row13, row14, row15;
+    __m128i p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l;
+    __m128i p2_filt8_l, p1_filt8_l, p0_filt8_l;
+    __m128i q0_filt8_l, q1_filt8_l, q2_filt8_l;
+    __m128i vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
+    __m128i zero = __lsx_vldi(0);
+
+    p0 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, p1, p2);
+    p3 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    row4 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, row5, row6);
+    row7 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    q3 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, q2, q1);
+    q0 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    row12 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, row13, row14);
+    row15 = __lsx_vldx(dst_tmp, stride3);
+
+    /* transpose 16x8 matrix into 8x16 */
+    LSX_TRANSPOSE16x8_B(p0, p1, p2, p3, row4, row5, row6, row7,
+                        q3, q2, q1, q0, row12, row13, row14, row15,
+                        p3, p2, p1, p0, q0, q1, q2, q3);
+
+    thresh = __lsx_vreplgr2vr_b(thresh_ptr);
+    vec0   = __lsx_vreplgr2vr_b(thresh_ptr >> 8);
+    thresh = __lsx_vilvl_d(vec0, thresh);
+
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    vec0    = __lsx_vreplgr2vr_b(b_limit_ptr >> 8);
+    b_limit = __lsx_vilvl_d(vec0, b_limit);
+
+    limit = __lsx_vreplgr2vr_b(limit_ptr);
+    vec0  = __lsx_vreplgr2vr_b(limit_ptr >> 8);
+    limit = __lsx_vilvl_d(vec0, limit);
+
+    /* mask and hev */
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    /* flat4 */
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    /* filter4 */
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    flat = __lsx_vilvl_d(zero, flat);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        DUP2_ARG2(__lsx_vilvl_b, p0_out, p1_out, q1_out, q0_out, vec0, vec1);
+        vec2 = __lsx_vilvl_h(vec1, vec0);
+        vec3 = __lsx_vilvh_h(vec1, vec0);
+        DUP2_ARG2(__lsx_vilvh_b, p0_out, p1_out, q1_out, q0_out, vec0, vec1);
+        vec4 = __lsx_vilvl_h(vec1, vec0);
+        vec5 = __lsx_vilvh_h(vec1, vec0);
+
+        dst -= 2;
+        __lsx_vstelm_w(vec2, dst, 0, 0);
+        __lsx_vstelm_w(vec2, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec2, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec2, dst + stride3, 0, 3);
+        dst += stride4;
+        __lsx_vstelm_w(vec3, dst, 0, 0);
+        __lsx_vstelm_w(vec3, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec3, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec3, dst + stride3, 0, 3);
+        dst += stride4;
+        __lsx_vstelm_w(vec4, dst, 0, 0);
+        __lsx_vstelm_w(vec4, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec4, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec4, dst + stride3, 0, 3);
+        dst += stride4;
+        __lsx_vstelm_w(vec5, dst, 0, 0);
+        __lsx_vstelm_w(vec5, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec5, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec5, dst + stride3, 0, 3);
+    } else {
+        DUP4_ARG2(__lsx_vilvl_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_l, p2_l, p1_l, p0_l);
+        DUP4_ARG2(__lsx_vilvl_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_l, q1_l, q2_l, q3_l);
+        VP9_FILTER8(p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l, p2_filt8_l,
+                    p1_filt8_l, p0_filt8_l, q0_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, p2_filt8_l, p2_filt8_l, p1_filt8_l, p1_filt8_l,
+                  p0_filt8_l, p0_filt8_l, q0_filt8_l, q0_filt8_l, p2_filt8_l,
+                  p1_filt8_l, p0_filt8_l, q0_filt8_l);
+        DUP2_ARG2(__lsx_vpickev_b, q1_filt8_l, q1_filt8_l, q2_filt8_l, q2_filt8_l,
+                  q1_filt8_l, q2_filt8_l);
+
+        /* store pixel values */
+        p2 = __lsx_vbitsel_v(p2, p2_filt8_l, flat);
+        p1 = __lsx_vbitsel_v(p1_out, p1_filt8_l, flat);
+        p0 = __lsx_vbitsel_v(p0_out, p0_filt8_l, flat);
+        q0 = __lsx_vbitsel_v(q0_out, q0_filt8_l, flat);
+        q1 = __lsx_vbitsel_v(q1_out, q1_filt8_l, flat);
+        q2 = __lsx_vbitsel_v(q2, q2_filt8_l, flat);
+
+        DUP2_ARG2(__lsx_vilvl_b, p1, p2, q0, p0, vec0, vec1);
+        vec3 = __lsx_vilvl_h(vec1, vec0);
+        vec4 = __lsx_vilvh_h(vec1, vec0);
+        DUP2_ARG2(__lsx_vilvh_b, p1, p2, q0, p0, vec0, vec1);
+        vec6 = __lsx_vilvl_h(vec1, vec0);
+        vec7 = __lsx_vilvh_h(vec1, vec0);
+        vec2 = __lsx_vilvl_b(q2, q1);
+        vec5 = __lsx_vilvh_b(q2, q1);
+
+        dst -= 3;
+        __lsx_vstelm_w(vec3, dst, 0, 0);
+        __lsx_vstelm_h(vec2, dst, 4, 0);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 1);
+        __lsx_vstelm_h(vec2, dst, 4, 1);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 2);
+        __lsx_vstelm_h(vec2, dst, 4, 2);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 3);
+        __lsx_vstelm_h(vec2, dst, 4, 3);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 0);
+        __lsx_vstelm_h(vec2, dst, 4, 4);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 1);
+        __lsx_vstelm_h(vec2, dst, 4, 5);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 2);
+        __lsx_vstelm_h(vec2, dst, 4, 6);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 3);
+        __lsx_vstelm_h(vec2, dst, 4, 7);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 0);
+        __lsx_vstelm_h(vec5, dst, 4, 0);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 1);
+        __lsx_vstelm_h(vec5, dst, 4, 1);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 2);
+        __lsx_vstelm_h(vec5, dst, 4, 2);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 3);
+        __lsx_vstelm_h(vec5, dst, 4, 3);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 0);
+        __lsx_vstelm_h(vec5, dst, 4, 4);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 1);
+        __lsx_vstelm_h(vec5, dst, 4, 5);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 2);
+        __lsx_vstelm_h(vec5, dst, 4, 6);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 3);
+        __lsx_vstelm_h(vec5, dst, 4, 7);
+    }
+}
+
+void ff_loop_filter_h_48_16_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int32_t b_limit_ptr,
+                                int32_t limit_ptr,
+                                int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    uint8_t *dst_tmp = dst - 4;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p1_out, p0_out, q0_out, q1_out;
+    __m128i flat, mask, hev, thresh, b_limit, limit;
+    __m128i row4, row5, row6, row7, row12, row13, row14, row15;
+    __m128i p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h;
+    __m128i p2_filt8_h, p1_filt8_h, p0_filt8_h;
+    __m128i q0_filt8_h, q1_filt8_h, q2_filt8_h;
+    __m128i vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
+    __m128i zero = __lsx_vldi(0);
+
+    p0 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, p1, p2);
+    p3 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    row4 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, row5, row6);
+    row7 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    q3 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, q2, q1);
+    q0 = __lsx_vldx(dst_tmp, stride3);
+    dst_tmp += stride4;
+    row12 = __lsx_vld(dst_tmp, 0);
+    DUP2_ARG2(__lsx_vldx, dst_tmp, stride, dst_tmp, stride2, row13, row14);
+    row15 = __lsx_vldx(dst_tmp, stride3);
+
+    /* transpose 16x8 matrix into 8x16 */
+    LSX_TRANSPOSE16x8_B(p0, p1, p2, p3, row4, row5, row6, row7,
+                        q3, q2, q1, q0, row12, row13, row14, row15,
+                        p3, p2, p1, p0, q0, q1, q2, q3);
+
+    thresh = __lsx_vreplgr2vr_b(thresh_ptr);
+    vec0   = __lsx_vreplgr2vr_b(thresh_ptr >> 8);
+    thresh = __lsx_vilvl_d(vec0, thresh);
+
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    vec0    = __lsx_vreplgr2vr_b(b_limit_ptr >> 8);
+    b_limit = __lsx_vilvl_d(vec0, b_limit);
+
+    limit = __lsx_vreplgr2vr_b(limit_ptr);
+    vec0  = __lsx_vreplgr2vr_b(limit_ptr >> 8);
+    limit = __lsx_vilvl_d(vec0, limit);
+
+    /* mask and hev */
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    /* flat4 */
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    /* filter4 */
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    flat = __lsx_vilvh_d(flat, zero);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        DUP2_ARG2(__lsx_vilvl_b, p0_out, p1_out, q1_out, q0_out, vec0, vec1);
+        vec2 = __lsx_vilvl_h(vec1, vec0);
+        vec3 = __lsx_vilvh_h(vec1, vec0);
+        DUP2_ARG2(__lsx_vilvh_b, p0_out, p1_out, q1_out, q0_out, vec0, vec1);
+        vec4 = __lsx_vilvl_h(vec1, vec0);
+        vec5 = __lsx_vilvh_h(vec1, vec0);
+
+        dst -= 2;
+        __lsx_vstelm_w(vec2, dst, 0, 0);
+        __lsx_vstelm_w(vec2, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec2, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec2, dst + stride3, 0, 3);
+        dst += stride4;
+        __lsx_vstelm_w(vec3, dst, 0, 0);
+        __lsx_vstelm_w(vec3, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec3, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec3, dst + stride3, 0, 3);
+        dst += stride4;
+        __lsx_vstelm_w(vec4, dst, 0, 0);
+        __lsx_vstelm_w(vec4, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec4, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec4, dst + stride3, 0, 3);
+        dst += stride4;
+        __lsx_vstelm_w(vec5, dst, 0, 0);
+        __lsx_vstelm_w(vec5, dst + stride, 0, 1);
+        __lsx_vstelm_w(vec5, dst + stride2, 0, 2);
+        __lsx_vstelm_w(vec5, dst + stride3, 0, 3);
+    } else {
+        DUP4_ARG2(__lsx_vilvh_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_h, p2_h, p1_h, p0_h);
+        DUP4_ARG2(__lsx_vilvh_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_h, q1_h, q2_h, q3_h);
+
+        VP9_FILTER8(p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h, p2_filt8_h,
+                    p1_filt8_h, p0_filt8_h, q0_filt8_h, q1_filt8_h, q2_filt8_h);
+
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, p2_filt8_h, p2_filt8_h, p1_filt8_h,
+                  p1_filt8_h, p0_filt8_h, p0_filt8_h, q0_filt8_h, q0_filt8_h,
+                  p2_filt8_h, p1_filt8_h, p0_filt8_h, q0_filt8_h);
+        DUP2_ARG2(__lsx_vpickev_b, q1_filt8_h, q1_filt8_h, q2_filt8_h,
+                  q2_filt8_h, q1_filt8_h, q2_filt8_h);
+
+        /* store pixel values */
+        p2 = __lsx_vbitsel_v(p2, p2_filt8_h, flat);
+        p1 = __lsx_vbitsel_v(p1_out, p1_filt8_h, flat);
+        p0 = __lsx_vbitsel_v(p0_out, p0_filt8_h, flat);
+        q0 = __lsx_vbitsel_v(q0_out, q0_filt8_h, flat);
+        q1 = __lsx_vbitsel_v(q1_out, q1_filt8_h, flat);
+        q2 = __lsx_vbitsel_v(q2, q2_filt8_h, flat);
+
+        DUP2_ARG2(__lsx_vilvl_b, p1, p2, q0, p0, vec0, vec1);
+        vec3 = __lsx_vilvl_h(vec1, vec0);
+        vec4 = __lsx_vilvh_h(vec1, vec0);
+        DUP2_ARG2(__lsx_vilvh_b, p1, p2, q0, p0, vec0, vec1);
+        vec6 = __lsx_vilvl_h(vec1, vec0);
+        vec7 = __lsx_vilvh_h(vec1, vec0);
+        vec2 = __lsx_vilvl_b(q2, q1);
+        vec5 = __lsx_vilvh_b(q2, q1);
+
+        dst -= 3;
+        __lsx_vstelm_w(vec3, dst, 0, 0);
+        __lsx_vstelm_h(vec2, dst, 4, 0);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 1);
+        __lsx_vstelm_h(vec2, dst, 4, 1);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 2);
+        __lsx_vstelm_h(vec2, dst, 4, 2);
+        dst += stride;
+        __lsx_vstelm_w(vec3, dst, 0, 3);
+        __lsx_vstelm_h(vec2, dst, 4, 3);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 0);
+        __lsx_vstelm_h(vec2, dst, 4, 4);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 1);
+        __lsx_vstelm_h(vec2, dst, 4, 5);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 2);
+        __lsx_vstelm_h(vec2, dst, 4, 6);
+        dst += stride;
+        __lsx_vstelm_w(vec4, dst, 0, 3);
+        __lsx_vstelm_h(vec2, dst, 4, 7);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 0);
+        __lsx_vstelm_h(vec5, dst, 4, 0);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 1);
+        __lsx_vstelm_h(vec5, dst, 4, 1);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 2);
+        __lsx_vstelm_h(vec5, dst, 4, 2);
+        dst += stride;
+        __lsx_vstelm_w(vec6, dst, 0, 3);
+        __lsx_vstelm_h(vec5, dst, 4, 3);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 0);
+        __lsx_vstelm_h(vec5, dst, 4, 4);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 1);
+        __lsx_vstelm_h(vec5, dst, 4, 5);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 2);
+        __lsx_vstelm_h(vec5, dst, 4, 6);
+        dst += stride;
+        __lsx_vstelm_w(vec7, dst, 0, 3);
+        __lsx_vstelm_h(vec5, dst, 4, 7);
+    }
+}
+
+static void vp9_transpose_16x8_to_8x16(uint8_t *input, ptrdiff_t in_pitch,
+                                       uint8_t *output)
+{
+    __m128i p7_org, p6_org, p5_org, p4_org, p3_org, p2_org, p1_org, p0_org;
+    __m128i tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
+    __m128i p7, p6, p5, p4, p3, p2, p1, p0, q0, q1, q2, q3, q4, q5, q6, q7;
+    ptrdiff_t in_pitch2 = in_pitch << 1;
+    ptrdiff_t in_pitch3 = in_pitch2 + in_pitch;
+    ptrdiff_t in_pitch4 = in_pitch2 << 1;
+
+    LSX_LD_8(input, in_pitch, in_pitch2, in_pitch3, in_pitch4,
+             p7_org, p6_org, p5_org, p4_org, p3_org, p2_org, p1_org, p0_org);
+    /* 8x8 transpose */
+    LSX_TRANSPOSE8x8_B(p7_org, p6_org, p5_org, p4_org, p3_org, p2_org, p1_org,
+                       p0_org, p7, p6, p5, p4, p3, p2, p1, p0);
+    /* 8x8 transpose */
+    DUP4_ARG2(__lsx_vilvh_b, p5_org, p7_org, p4_org, p6_org, p1_org,
+              p3_org, p0_org, p2_org, tmp0, tmp1, tmp2, tmp3);
+    DUP2_ARG2(__lsx_vilvl_b, tmp1, tmp0, tmp3, tmp2, tmp4, tmp6);
+    DUP2_ARG2(__lsx_vilvh_b, tmp1, tmp0, tmp3, tmp2, tmp5, tmp7);
+    DUP2_ARG2(__lsx_vilvl_w, tmp6, tmp4, tmp7, tmp5, q0, q4);
+    DUP2_ARG2(__lsx_vilvh_w, tmp6, tmp4, tmp7, tmp5, q2, q6);
+    DUP4_ARG2(__lsx_vbsrl_v, q0, 8, q2, 8, q4, 8, q6, 8, q1, q3, q5, q7);
+
+    __lsx_vst(p7, output, 0);
+    __lsx_vst(p6, output, 16);
+    __lsx_vst(p5, output, 32);
+    __lsx_vst(p4, output, 48);
+    __lsx_vst(p3, output, 64);
+    __lsx_vst(p2, output, 80);
+    __lsx_vst(p1, output, 96);
+    __lsx_vst(p0, output, 112);
+    __lsx_vst(q0, output, 128);
+    __lsx_vst(q1, output, 144);
+    __lsx_vst(q2, output, 160);
+    __lsx_vst(q3, output, 176);
+    __lsx_vst(q4, output, 192);
+    __lsx_vst(q5, output, 208);
+    __lsx_vst(q6, output, 224);
+    __lsx_vst(q7, output, 240);
+}
+
+static void vp9_transpose_8x16_to_16x8(uint8_t *input, uint8_t *output,
+                                       ptrdiff_t out_pitch)
+{
+    __m128i p7_o, p6_o, p5_o, p4_o, p3_o, p2_o, p1_o, p0_o;
+    __m128i p7, p6, p5, p4, p3, p2, p1, p0, q0, q1, q2, q3, q4, q5, q6, q7;
+    ptrdiff_t out_pitch2 = out_pitch << 1;
+    ptrdiff_t out_pitch3 = out_pitch2 + out_pitch;
+    ptrdiff_t out_pitch4 = out_pitch2 << 1;
+
+    DUP4_ARG2(__lsx_vld, input, 0, input, 16, input, 32, input, 48,
+              p7, p6, p5, p4);
+    DUP4_ARG2(__lsx_vld, input, 64, input, 80, input, 96, input, 112,
+              p3, p2, p1, p0);
+    DUP4_ARG2(__lsx_vld, input, 128, input, 144, input, 160, input, 176,
+              q0, q1, q2, q3);
+    DUP4_ARG2(__lsx_vld, input, 192, input, 208, input, 224, input, 240,
+              q4, q5, q6, q7);
+    LSX_TRANSPOSE16x8_B(p7, p6, p5, p4, p3, p2, p1, p0, q0, q1, q2, q3, q4, q5,
+                        q6, q7, p7_o, p6_o, p5_o, p4_o, p3_o, p2_o, p1_o, p0_o);
+    LSX_ST_8(p7_o, p6_o, p5_o, p4_o, p3_o, p2_o, p1_o, p0_o,
+             output, out_pitch, out_pitch2, out_pitch3, out_pitch4);
+}
+
+static void vp9_transpose_16x16(uint8_t *input, int32_t in_stride,
+                                uint8_t *output, int32_t out_stride)
+{
+    __m128i row0, row1, row2, row3, row4, row5, row6, row7;
+    __m128i row8, row9, row10, row11, row12, row13, row14, row15;
+    __m128i tmp0, tmp1, tmp4, tmp5, tmp6, tmp7;
+    __m128i tmp2, tmp3;
+    __m128i p7, p6, p5, p4, p3, p2, p1, p0, q0, q1, q2, q3, q4, q5, q6, q7;
+    int32_t in_stride2 = in_stride << 1;
+    int32_t in_stride3 = in_stride2 + in_stride;
+    int32_t in_stride4 = in_stride2 << 1;
+    int32_t out_stride2 = out_stride << 1;
+    int32_t out_stride3 = out_stride2 + out_stride;
+    int32_t out_stride4 = out_stride2 << 1;
+
+    LSX_LD_8(input, in_stride, in_stride2, in_stride3, in_stride4,
+             row0, row1, row2, row3, row4, row5, row6, row7);
+    input += in_stride4;
+    LSX_LD_8(input, in_stride, in_stride2, in_stride3, in_stride4,
+             row8, row9, row10, row11, row12, row13, row14, row15);
+
+    LSX_TRANSPOSE16x8_B(row0, row1, row2, row3, row4, row5, row6, row7,
+                        row8, row9, row10, row11, row12, row13, row14, row15,
+                        p7, p6, p5, p4, p3, p2, p1, p0);
+
+    /* transpose 16x8 matrix into 8x16 */
+    /* total 8 intermediate register and 32 instructions */
+    q7 = __lsx_vpackod_d(row8, row0);
+    q6 = __lsx_vpackod_d(row9, row1);
+    q5 = __lsx_vpackod_d(row10, row2);
+    q4 = __lsx_vpackod_d(row11, row3);
+    q3 = __lsx_vpackod_d(row12, row4);
+    q2 = __lsx_vpackod_d(row13, row5);
+    q1 = __lsx_vpackod_d(row14, row6);
+    q0 = __lsx_vpackod_d(row15, row7);
+
+    DUP2_ARG2(__lsx_vpackev_b, q6, q7, q4, q5, tmp0, tmp1);
+    DUP2_ARG2(__lsx_vpackod_b, q6, q7, q4, q5, tmp4, tmp5);
+
+    DUP2_ARG2(__lsx_vpackev_b, q2, q3, q0, q1, q5, q7);
+    DUP2_ARG2(__lsx_vpackod_b, q2, q3, q0, q1, tmp6, tmp7);
+
+    DUP2_ARG2(__lsx_vpackev_h, tmp1, tmp0, q7, q5, tmp2, tmp3);
+    q0 = __lsx_vpackev_w(tmp3, tmp2);
+    q4 = __lsx_vpackod_w(tmp3, tmp2);
+
+    tmp2 = __lsx_vpackod_h(tmp1, tmp0);
+    tmp3 = __lsx_vpackod_h(q7, q5);
+    q2 = __lsx_vpackev_w(tmp3, tmp2);
+    q6 = __lsx_vpackod_w(tmp3, tmp2);
+
+    DUP2_ARG2(__lsx_vpackev_h, tmp5, tmp4, tmp7, tmp6, tmp2, tmp3);
+    q1 = __lsx_vpackev_w(tmp3, tmp2);
+    q5 = __lsx_vpackod_w(tmp3, tmp2);
+
+    tmp2 = __lsx_vpackod_h(tmp5, tmp4);
+    tmp3 = __lsx_vpackod_h(tmp7, tmp6);
+    q3 = __lsx_vpackev_w(tmp3, tmp2);
+    q7 = __lsx_vpackod_w(tmp3, tmp2);
+
+    LSX_ST_8(p7, p6, p5, p4, p3, p2, p1, p0, output, out_stride,
+             out_stride2, out_stride3, out_stride4);
+    output += out_stride4;
+    LSX_ST_8(q0, q1, q2, q3, q4, q5, q6, q7, output, out_stride,
+             out_stride2, out_stride3, out_stride4);
+}
+
+static int32_t vp9_vt_lpf_t4_and_t8_8w(uint8_t *src, uint8_t *filter48,
+                                       uint8_t *src_org, int32_t pitch_org,
+                                       int32_t b_limit_ptr,
+                                       int32_t limit_ptr,
+                                       int32_t thresh_ptr)
+{
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p2_out, p1_out, p0_out, q0_out, q1_out, q2_out;
+    __m128i flat, mask, hev, thresh, b_limit, limit;
+    __m128i p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l;
+    __m128i p2_filt8_l, p1_filt8_l, p0_filt8_l;
+    __m128i q0_filt8_l, q1_filt8_l, q2_filt8_l;
+    __m128i vec0, vec1, vec2, vec3;
+    __m128i zero = __lsx_vldi(0);
+
+    /* load vector elements */
+    DUP4_ARG2(__lsx_vld, src, -64, src, -48, src, -32, src, -16,
+              p3, p2, p1, p0);
+    DUP4_ARG2(__lsx_vld, src, 0, src, 16, src, 32, src, 48, q0, q1, q2, q3);
+
+    thresh  = __lsx_vreplgr2vr_b(thresh_ptr);
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    limit   = __lsx_vreplgr2vr_b(limit_ptr);
+
+    /* mask and hev */
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    /* flat4 */
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    /* filter4 */
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    flat = __lsx_vilvl_d(zero, flat);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        DUP2_ARG2(__lsx_vilvl_b, p0_out, p1_out, q1_out, q0_out, vec0, vec1);
+        vec2 = __lsx_vilvl_h(vec1, vec0);
+        vec3 = __lsx_vilvh_h(vec1, vec0);
+
+        src_org -= 2;
+        __lsx_vstelm_w(vec2, src_org, 0, 0);
+        src_org += pitch_org;
+        __lsx_vstelm_w(vec2, src_org, 0, 1);
+        src_org += pitch_org;
+        __lsx_vstelm_w(vec2, src_org, 0, 2);
+        src_org += pitch_org;
+        __lsx_vstelm_w(vec2, src_org, 0, 3);
+        src_org += pitch_org;
+        __lsx_vstelm_w(vec3, src_org, 0, 0);
+        src_org += pitch_org;
+        __lsx_vstelm_w(vec3, src_org, 0, 1);
+        src_org += pitch_org;
+        __lsx_vstelm_w(vec3, src_org, 0, 2);
+        src_org += pitch_org;
+        __lsx_vstelm_w(vec3, src_org, 0, 3);
+        return 1;
+    } else {
+        DUP4_ARG2(__lsx_vilvl_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_l, p2_l, p1_l, p0_l);
+        DUP4_ARG2(__lsx_vilvl_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_l, q1_l, q2_l, q3_l);
+        VP9_FILTER8(p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l, p2_filt8_l,
+                    p1_filt8_l, p0_filt8_l, q0_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        /* convert 16 bit output data into 8 bit */
+        p2_l = __lsx_vpickev_b(p2_filt8_l, p2_filt8_l);
+        p1_l = __lsx_vpickev_b(p1_filt8_l, p1_filt8_l);
+        p0_l = __lsx_vpickev_b(p0_filt8_l, p0_filt8_l);
+        q0_l = __lsx_vpickev_b(q0_filt8_l, q0_filt8_l);
+        q1_l = __lsx_vpickev_b(q1_filt8_l, q1_filt8_l);
+        q2_l = __lsx_vpickev_b(q2_filt8_l, q2_filt8_l);
+
+        /* store pixel values */
+        p2_out = __lsx_vbitsel_v(p2, p2_l, flat);
+        p1_out = __lsx_vbitsel_v(p1_out, p1_l, flat);
+        p0_out = __lsx_vbitsel_v(p0_out, p0_l, flat);
+        q0_out = __lsx_vbitsel_v(q0_out, q0_l, flat);
+        q1_out = __lsx_vbitsel_v(q1_out, q1_l, flat);
+        q2_out = __lsx_vbitsel_v(q2, q2_l, flat);
+
+        __lsx_vst(p2_out, filter48, 0);
+        __lsx_vst(p1_out, filter48, 16);
+        __lsx_vst(p0_out, filter48, 32);
+        __lsx_vst(q0_out, filter48, 48);
+        __lsx_vst(q1_out, filter48, 64);
+        __lsx_vst(q2_out, filter48, 80);
+        __lsx_vst(flat, filter48, 96);
+
+        return 0;
+    }
+}
+
+static int32_t vp9_vt_lpf_t16_8w(uint8_t *dst, uint8_t *dst_org,
+                                 ptrdiff_t stride,
+                                 uint8_t *filter48)
+{
+    __m128i zero = __lsx_vldi(0);
+    __m128i filter8, flat, flat2;
+    __m128i p7, p6, p5, p4, p3, p2, p1, p0, q0, q1, q2, q3, q4, q5, q6, q7;
+    v8u16 p7_l_in, p6_l_in, p5_l_in, p4_l_in;
+    v8u16 p3_l_in, p2_l_in, p1_l_in, p0_l_in;
+    v8u16 q7_l_in, q6_l_in, q5_l_in, q4_l_in;
+    v8u16 q3_l_in, q2_l_in, q1_l_in, q0_l_in;
+    v8u16 tmp0_l, tmp1_l;
+    __m128i out_l;
+    uint8_t *dst_tmp = dst - 128;
+
+    /* load vector elements */
+    DUP4_ARG2(__lsx_vld, dst_tmp, 0, dst_tmp, 16, dst_tmp, 32,
+              dst_tmp, 48, p7, p6, p5, p4);
+    DUP4_ARG2(__lsx_vld, dst_tmp, 64, dst_tmp, 80, dst_tmp, 96,
+              dst_tmp, 112, p3, p2, p1, p0);
+    DUP4_ARG2(__lsx_vld, dst, 0, dst, 16, dst, 32, dst, 48, q0, q1, q2, q3);
+    DUP4_ARG2(__lsx_vld, dst, 64, dst, 80, dst, 96, dst, 112, q4, q5, q6, q7);
+
+    flat = __lsx_vld(filter48, 96);
+
+
+    VP9_FLAT5(p7, p6, p5, p4, p0, q0, q4, q5, q6, q7, flat, flat2);
+
+    /* if flat2 is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat2)) {
+        __m128i vec0, vec1, vec2, vec3, vec4;
+
+        DUP4_ARG2(__lsx_vld, filter48, 0, filter48, 16, filter48, 32,
+                  filter48, 48, p2, p1, p0, q0);
+        DUP2_ARG2(__lsx_vld, filter48, 64, filter48, 80, q1, q2);
+
+        DUP2_ARG2(__lsx_vilvl_b, p1, p2, q0, p0, vec0, vec1);
+        vec3 = __lsx_vilvl_h(vec1, vec0);
+        vec4 = __lsx_vilvh_h(vec1, vec0);
+        vec2 = __lsx_vilvl_b(q2, q1);
+
+        dst_org -= 3;
+        __lsx_vstelm_w(vec3, dst_org, 0, 0);
+        __lsx_vstelm_h(vec2, dst_org, 4, 0);
+        dst_org += stride;
+        __lsx_vstelm_w(vec3, dst_org, 0, 1);
+        __lsx_vstelm_h(vec2, dst_org, 4, 1);
+        dst_org += stride;
+        __lsx_vstelm_w(vec3, dst_org, 0, 2);
+        __lsx_vstelm_h(vec2, dst_org, 4, 2);
+        dst_org += stride;
+        __lsx_vstelm_w(vec3, dst_org, 0, 3);
+        __lsx_vstelm_h(vec2, dst_org, 4, 3);
+        dst_org += stride;
+        __lsx_vstelm_w(vec4, dst_org, 0, 0);
+        __lsx_vstelm_h(vec2, dst_org, 4, 4);
+        dst_org += stride;
+        __lsx_vstelm_w(vec4, dst_org, 0, 1);
+        __lsx_vstelm_h(vec2, dst_org, 4, 5);
+        dst_org += stride;
+        __lsx_vstelm_w(vec4, dst_org, 0, 2);
+        __lsx_vstelm_h(vec2, dst_org, 4, 6);
+        dst_org += stride;
+        __lsx_vstelm_w(vec4, dst_org, 0, 3);
+        __lsx_vstelm_h(vec2, dst_org, 4, 7);
+        return 1;
+    } else {
+        dst -= 7 * 16;
+
+        p7_l_in = (v8u16)__lsx_vilvl_b(zero, p7);
+        p6_l_in = (v8u16)__lsx_vilvl_b(zero, p6);
+        p5_l_in = (v8u16)__lsx_vilvl_b(zero, p5);
+        p4_l_in = (v8u16)__lsx_vilvl_b(zero, p4);
+        p3_l_in = (v8u16)__lsx_vilvl_b(zero, p3);
+        p2_l_in = (v8u16)__lsx_vilvl_b(zero, p2);
+        p1_l_in = (v8u16)__lsx_vilvl_b(zero, p1);
+        p0_l_in = (v8u16)__lsx_vilvl_b(zero, p0);
+        q0_l_in = (v8u16)__lsx_vilvl_b(zero, q0);
+
+        tmp0_l = p7_l_in << 3;
+        tmp0_l -= p7_l_in;
+        tmp0_l += p6_l_in;
+        tmp0_l += q0_l_in;
+        tmp1_l = p6_l_in + p5_l_in;
+        tmp1_l += p4_l_in;
+        tmp1_l += p3_l_in;
+        tmp1_l += p2_l_in;
+        tmp1_l += p1_l_in;
+        tmp1_l += p0_l_in;
+        tmp1_l += tmp0_l;
+
+        out_l =__lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l =__lsx_vpickev_b(out_l, out_l);
+        p6 = __lsx_vbitsel_v(p6, out_l, flat2);
+        __lsx_vstelm_d(p6, dst, 0, 0);
+        dst += 16;
+
+        /* p5 */
+        q1_l_in = (v8u16)__lsx_vilvl_b(zero, q1);
+        tmp0_l = p5_l_in - p6_l_in;
+        tmp0_l += q1_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        p5 = __lsx_vbitsel_v(p5, out_l, flat2);
+        __lsx_vstelm_d(p5, dst, 0, 0);
+        dst += 16;
+
+        /* p4 */
+        q2_l_in = (v8u16)__lsx_vilvl_b(zero, q2);
+        tmp0_l = p4_l_in - p5_l_in;
+        tmp0_l += q2_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        p4 = __lsx_vbitsel_v(p4, out_l, flat2);
+        __lsx_vstelm_d(p4, dst, 0, 0);
+        dst += 16;
+
+        /* p3 */
+        q3_l_in = (v8u16)__lsx_vilvl_b(zero, q3);
+        tmp0_l = p3_l_in - p4_l_in;
+        tmp0_l += q3_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        p3 = __lsx_vbitsel_v(p3, out_l, flat2);
+        __lsx_vstelm_d(p3, dst, 0, 0);
+        dst += 16;
+
+        /* p2 */
+        q4_l_in = (v8u16)__lsx_vilvl_b(zero, q4);
+        filter8 = __lsx_vld(filter48, 0);
+        tmp0_l = p2_l_in - p3_l_in;
+        tmp0_l += q4_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vstelm_d(filter8, dst, 0, 0);
+        dst += 16;
+
+        /* p1 */
+        q5_l_in = (v8u16)__lsx_vilvl_b(zero, q5);
+        filter8 = __lsx_vld(filter48, 16);
+        tmp0_l = p1_l_in - p2_l_in;
+        tmp0_l += q5_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vstelm_d(filter8, dst, 0, 0);
+        dst += 16;
+
+        /* p0 */
+        q6_l_in = (v8u16)__lsx_vilvl_b(zero, q6);
+        filter8 = __lsx_vld(filter48, 32);
+        tmp0_l = p0_l_in - p1_l_in;
+        tmp0_l += q6_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vstelm_d(filter8, dst, 0, 0);
+        dst += 16;
+
+        /* q0 */
+        q7_l_in = (v8u16)__lsx_vilvl_b(zero, q7);
+        filter8 = __lsx_vld(filter48, 48);
+        tmp0_l = q7_l_in - p0_l_in;
+        tmp0_l += q0_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((v8i16) tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vstelm_d(filter8, dst, 0, 0);
+        dst += 16;
+
+        /* q1 */
+        filter8 = __lsx_vld(filter48, 64);
+        tmp0_l = q7_l_in - q0_l_in;
+        tmp0_l += q1_l_in;
+        tmp0_l -= p6_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vstelm_d(filter8, dst, 0, 0);
+        dst += 16;
+
+        /* q2 */
+        filter8 = __lsx_vld(filter48, 80);
+        tmp0_l = q7_l_in - q1_l_in;
+        tmp0_l += q2_l_in;
+        tmp0_l -= p5_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vstelm_d(filter8, dst, 0, 0);
+        dst += 16;
+
+        /* q3 */
+        tmp0_l = q7_l_in - q2_l_in;
+        tmp0_l += q3_l_in;
+        tmp0_l -= p4_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        q3 = __lsx_vbitsel_v(q3, out_l, flat2);
+        __lsx_vstelm_d(q3, dst, 0, 0);
+        dst += 16;
+
+        /* q4 */
+        tmp0_l = q7_l_in - q3_l_in;
+        tmp0_l += q4_l_in;
+        tmp0_l -= p3_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        q4 = __lsx_vbitsel_v(q4, out_l, flat2);
+        __lsx_vstelm_d(q4, dst, 0, 0);
+        dst += 16;
+
+        /* q5 */
+        tmp0_l = q7_l_in - q4_l_in;
+        tmp0_l += q5_l_in;
+        tmp0_l -= p2_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        q5 = __lsx_vbitsel_v(q5, out_l, flat2);
+        __lsx_vstelm_d(q5, dst, 0, 0);
+        dst += 16;
+
+        /* q6 */
+        tmp0_l = q7_l_in - q5_l_in;
+        tmp0_l += q6_l_in;
+        tmp0_l -= p1_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        out_l = __lsx_vpickev_b(out_l, out_l);
+        q6 = __lsx_vbitsel_v(q6, out_l, flat2);
+        __lsx_vstelm_d(q6, dst, 0, 0);
+
+        return 0;
+    }
+}
+
+void ff_loop_filter_h_16_8_lsx(uint8_t *dst, ptrdiff_t stride,
+                               int32_t b_limit_ptr,
+                               int32_t limit_ptr,
+                               int32_t thresh_ptr)
+{
+    uint8_t early_exit = 0;
+    uint8_t transposed_input[16 * 24] __attribute__ ((aligned(16)));
+    uint8_t *filter48 = &transposed_input[16 * 16];
+
+    vp9_transpose_16x8_to_8x16(dst - 8, stride, transposed_input);
+
+    early_exit = vp9_vt_lpf_t4_and_t8_8w((transposed_input + 16 * 8),
+                                         &filter48[0], dst, stride,
+                                         b_limit_ptr, limit_ptr, thresh_ptr);
+
+    if (0 == early_exit) {
+        early_exit = vp9_vt_lpf_t16_8w((transposed_input + 16 * 8), dst, stride,
+                                       &filter48[0]);
+
+        if (0 == early_exit) {
+            vp9_transpose_8x16_to_16x8(transposed_input, dst - 8, stride);
+        }
+    }
+}
+
+static int32_t vp9_vt_lpf_t4_and_t8_16w(uint8_t *dst, uint8_t *filter48,
+                                        uint8_t *dst_org, ptrdiff_t stride,
+                                        int32_t b_limit_ptr,
+                                        int32_t limit_ptr,
+                                        int32_t thresh_ptr)
+{
+    ptrdiff_t stride2 = stride << 1;
+    ptrdiff_t stride3 = stride2 + stride;
+    ptrdiff_t stride4 = stride2 << 1;
+    __m128i p3, p2, p1, p0, q3, q2, q1, q0;
+    __m128i p2_out, p1_out, p0_out, q0_out, q1_out, q2_out;
+    __m128i flat, mask, hev, thresh, b_limit, limit;
+    __m128i p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l;
+    __m128i p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h;
+    __m128i p2_filt8_l, p1_filt8_l, p0_filt8_l;
+    __m128i q0_filt8_l, q1_filt8_l, q2_filt8_l;
+    __m128i p2_filt8_h, p1_filt8_h, p0_filt8_h;
+    __m128i q0_filt8_h, q1_filt8_h, q2_filt8_h;
+    __m128i vec0, vec1, vec2, vec3, vec4, vec5;
+    __m128i zero = __lsx_vldi(0);
+
+    /* load vector elements */
+    DUP4_ARG2(__lsx_vld, dst, -64, dst, -48, dst, -32, dst, -16,
+              p3, p2, p1, p0);
+    DUP4_ARG2(__lsx_vld, dst, 0, dst, 16, dst, 32, dst, 48, q0, q1, q2, q3);
+
+    thresh  = __lsx_vreplgr2vr_b(thresh_ptr);
+    b_limit = __lsx_vreplgr2vr_b(b_limit_ptr);
+    limit   = __lsx_vreplgr2vr_b(limit_ptr);
+
+    /* mask and hev */
+    LPF_MASK_HEV(p3, p2, p1, p0, q0, q1, q2, q3, limit, b_limit, thresh,
+                 hev, mask, flat);
+    /* flat4 */
+    VP9_FLAT4(p3, p2, p0, q0, q2, q3, flat);
+    /* filter4 */
+    VP9_LPF_FILTER4_4W(p1, p0, q0, q1, mask, hev, p1_out, p0_out, q0_out,
+                       q1_out);
+
+    /* if flat is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat)) {
+        DUP2_ARG2(__lsx_vilvl_b, p0_out, p1_out, q1_out, q0_out, vec0, vec1);
+        vec2 = __lsx_vilvl_h(vec1, vec0);
+        vec3 = __lsx_vilvh_h(vec1, vec0);
+        DUP2_ARG2(__lsx_vilvh_b, p0_out, p1_out, q1_out, q0_out, vec0, vec1);
+        vec4 = __lsx_vilvl_h(vec1, vec0);
+        vec5 = __lsx_vilvh_h(vec1, vec0);
+
+        dst_org -= 2;
+        __lsx_vstelm_w(vec2, dst_org, 0, 0);
+        __lsx_vstelm_w(vec2, dst_org + stride, 0, 1);
+        __lsx_vstelm_w(vec2, dst_org + stride2, 0, 2);
+        __lsx_vstelm_w(vec2, dst_org + stride3, 0, 3);
+        dst_org += stride4;
+        __lsx_vstelm_w(vec3, dst_org, 0, 0);
+        __lsx_vstelm_w(vec3, dst_org + stride, 0, 1);
+        __lsx_vstelm_w(vec3, dst_org + stride2, 0, 2);
+        __lsx_vstelm_w(vec3, dst_org + stride3, 0, 3);
+        dst_org += stride4;
+        __lsx_vstelm_w(vec4, dst_org, 0, 0);
+        __lsx_vstelm_w(vec4, dst_org + stride, 0, 1);
+        __lsx_vstelm_w(vec4, dst_org + stride2, 0, 2);
+        __lsx_vstelm_w(vec4, dst_org + stride3, 0, 3);
+        dst_org += stride4;
+        __lsx_vstelm_w(vec5, dst_org, 0, 0);
+        __lsx_vstelm_w(vec5, dst_org + stride, 0, 1);
+        __lsx_vstelm_w(vec5, dst_org + stride2, 0, 2);
+        __lsx_vstelm_w(vec5, dst_org + stride3, 0, 3);
+
+        return 1;
+    } else {
+        DUP4_ARG2(__lsx_vilvl_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_l, p2_l, p1_l, p0_l);
+        DUP4_ARG2(__lsx_vilvl_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_l, q1_l, q2_l, q3_l);
+        VP9_FILTER8(p3_l, p2_l, p1_l, p0_l, q0_l, q1_l, q2_l, q3_l, p2_filt8_l,
+                    p1_filt8_l, p0_filt8_l, q0_filt8_l, q1_filt8_l, q2_filt8_l);
+        DUP4_ARG2(__lsx_vilvh_b, zero, p3, zero, p2, zero, p1, zero, p0,
+                  p3_h, p2_h, p1_h, p0_h);
+        DUP4_ARG2(__lsx_vilvh_b, zero, q0, zero, q1, zero, q2, zero, q3,
+                  q0_h, q1_h, q2_h, q3_h);
+        VP9_FILTER8(p3_h, p2_h, p1_h, p0_h, q0_h, q1_h, q2_h, q3_h, p2_filt8_h,
+                    p1_filt8_h, p0_filt8_h, q0_filt8_h, q1_filt8_h, q2_filt8_h);
+
+        /* convert 16 bit output data into 8 bit */
+        DUP4_ARG2(__lsx_vpickev_b, p2_filt8_h, p2_filt8_l, p1_filt8_h,
+                      p1_filt8_l, p0_filt8_h, p0_filt8_l, q0_filt8_h,
+                      q0_filt8_l, p2_filt8_l, p1_filt8_l, p0_filt8_l,
+                      q0_filt8_l);
+        DUP2_ARG2(__lsx_vpickev_b, q1_filt8_h, q1_filt8_l, q2_filt8_h,
+                  q2_filt8_l, q1_filt8_l, q2_filt8_l);
+
+        /* store pixel values */
+        p2_out = __lsx_vbitsel_v(p2, p2_filt8_l, flat);
+        p1_out = __lsx_vbitsel_v(p1_out, p1_filt8_l, flat);
+        p0_out = __lsx_vbitsel_v(p0_out, p0_filt8_l, flat);
+        q0_out = __lsx_vbitsel_v(q0_out, q0_filt8_l, flat);
+        q1_out = __lsx_vbitsel_v(q1_out, q1_filt8_l, flat);
+        q2_out = __lsx_vbitsel_v(q2, q2_filt8_l, flat);
+
+        __lsx_vst(p2_out, filter48, 0);
+        __lsx_vst(p1_out, filter48, 16);
+        __lsx_vst(p0_out, filter48, 32);
+        __lsx_vst(q0_out, filter48, 48);
+        __lsx_vst(q1_out, filter48, 64);
+        __lsx_vst(q2_out, filter48, 80);
+        __lsx_vst(flat, filter48, 96);
+
+        return 0;
+    }
+}
+
+static int32_t vp9_vt_lpf_t16_16w(uint8_t *dst, uint8_t *dst_org,
+                                  ptrdiff_t stride,
+                                  uint8_t *filter48)
+{
+    __m128i zero = __lsx_vldi(0);
+    __m128i flat, flat2, filter8;
+    __m128i p7, p6, p5, p4, p3, p2, p1, p0, q0, q1, q2, q3, q4, q5, q6, q7;
+    v8u16 p7_l_in, p6_l_in, p5_l_in, p4_l_in;
+    v8u16 p3_l_in, p2_l_in, p1_l_in, p0_l_in;
+    v8u16 q7_l_in, q6_l_in, q5_l_in, q4_l_in;
+    v8u16 q3_l_in, q2_l_in, q1_l_in, q0_l_in;
+    v8u16 p7_h_in, p6_h_in, p5_h_in, p4_h_in;
+    v8u16 p3_h_in, p2_h_in, p1_h_in, p0_h_in;
+    v8u16 q7_h_in, q6_h_in, q5_h_in, q4_h_in;
+    v8u16 q3_h_in, q2_h_in, q1_h_in, q0_h_in;
+    v8u16 tmp0_l, tmp1_l, tmp0_h, tmp1_h;
+    __m128i out_l, out_h;
+    uint8_t *dst_tmp = dst - 128;
+
+    flat = __lsx_vld(filter48, 96);
+
+    DUP4_ARG2(__lsx_vld, dst_tmp, 0, dst_tmp, 16, dst_tmp, 32,
+              dst_tmp, 48, p7, p6, p5, p4);
+    DUP4_ARG2(__lsx_vld, dst_tmp, 64, dst_tmp, 80, dst_tmp, 96,
+              dst_tmp, 112, p3, p2, p1, p0);
+    DUP4_ARG2(__lsx_vld, dst, 0, dst, 16, dst, 32, dst, 48, q0, q1, q2, q3);
+    DUP4_ARG2(__lsx_vld, dst, 64, dst, 80, dst, 96, dst, 112, q4, q5, q6, q7);
+
+    VP9_FLAT5(p7, p6, p5, p4, p0, q0, q4, q5, q6, q7, flat, flat2);
+
+    /* if flat2 is zero for all pixels, then no need to calculate other filter */
+    if (__lsx_bz_v(flat2)) {
+        __m128i vec0, vec1, vec2, vec3, vec4, vec5, vec6, vec7;
+
+        DUP4_ARG2(__lsx_vld, filter48, 0, filter48, 16, filter48, 32,
+                  filter48, 48, p2, p1, p0, q0);
+        DUP2_ARG2(__lsx_vld, filter48, 64, filter48, 80, q1, q2);
+
+        DUP2_ARG2(__lsx_vilvl_b, p1, p2, q0, p0, vec0, vec1);
+        vec3 = __lsx_vilvl_h(vec1, vec0);
+        vec4 = __lsx_vilvh_h(vec1, vec0);
+        DUP2_ARG2(__lsx_vilvh_b, p1, p2, q0, p0, vec0, vec1);
+        vec6 = __lsx_vilvl_h(vec1, vec0);
+        vec7 = __lsx_vilvh_h(vec1, vec0);
+        vec2 = __lsx_vilvl_b(q2, q1);
+        vec5 = __lsx_vilvh_b(q2, q1);
+
+        dst_org -= 3;
+        __lsx_vstelm_w(vec3, dst_org, 0, 0);
+        __lsx_vstelm_h(vec2, dst_org, 4, 0);
+        dst_org += stride;
+        __lsx_vstelm_w(vec3, dst_org, 0, 1);
+        __lsx_vstelm_h(vec2, dst_org, 4, 1);
+        dst_org += stride;
+        __lsx_vstelm_w(vec3, dst_org, 0, 2);
+        __lsx_vstelm_h(vec2, dst_org, 4, 2);
+        dst_org += stride;
+        __lsx_vstelm_w(vec3, dst_org, 0, 3);
+        __lsx_vstelm_h(vec2, dst_org, 4, 3);
+        dst_org += stride;
+        __lsx_vstelm_w(vec4, dst_org, 0, 0);
+        __lsx_vstelm_h(vec2, dst_org, 4, 4);
+        dst_org += stride;
+        __lsx_vstelm_w(vec4, dst_org, 0, 1);
+        __lsx_vstelm_h(vec2, dst_org, 4, 5);
+        dst_org += stride;
+        __lsx_vstelm_w(vec4, dst_org, 0, 2);
+        __lsx_vstelm_h(vec2, dst_org, 4, 6);
+        dst_org += stride;
+        __lsx_vstelm_w(vec4, dst_org, 0, 3);
+        __lsx_vstelm_h(vec2, dst_org, 4, 7);
+        dst_org += stride;
+        __lsx_vstelm_w(vec6, dst_org, 0, 0);
+        __lsx_vstelm_h(vec5, dst_org, 4, 0);
+        dst_org += stride;
+        __lsx_vstelm_w(vec6, dst_org, 0, 1);
+        __lsx_vstelm_h(vec5, dst_org, 4, 1);
+        dst_org += stride;
+        __lsx_vstelm_w(vec6, dst_org, 0, 2);
+        __lsx_vstelm_h(vec5, dst_org, 4, 2);
+        dst_org += stride;
+        __lsx_vstelm_w(vec6, dst_org, 0, 3);
+        __lsx_vstelm_h(vec5, dst_org, 4, 3);
+        dst_org += stride;
+        __lsx_vstelm_w(vec7, dst_org, 0, 0);
+        __lsx_vstelm_h(vec5, dst_org, 4, 4);
+        dst_org += stride;
+        __lsx_vstelm_w(vec7, dst_org, 0, 1);
+        __lsx_vstelm_h(vec5, dst_org, 4, 5);
+        dst_org += stride;
+        __lsx_vstelm_w(vec7, dst_org, 0, 2);
+        __lsx_vstelm_h(vec5, dst_org, 4, 6);
+        dst_org += stride;
+        __lsx_vstelm_w(vec7, dst_org, 0, 3);
+        __lsx_vstelm_h(vec5, dst_org, 4, 7);
+
+        return 1;
+    } else {
+        dst -= 7 * 16;
+
+        p7_l_in = (v8u16)__lsx_vilvl_b(zero, p7);
+        p6_l_in = (v8u16)__lsx_vilvl_b(zero, p6);
+        p5_l_in = (v8u16)__lsx_vilvl_b(zero, p5);
+        p4_l_in = (v8u16)__lsx_vilvl_b(zero, p4);
+        p3_l_in = (v8u16)__lsx_vilvl_b(zero, p3);
+        p2_l_in = (v8u16)__lsx_vilvl_b(zero, p2);
+        p1_l_in = (v8u16)__lsx_vilvl_b(zero, p1);
+        p0_l_in = (v8u16)__lsx_vilvl_b(zero, p0);
+        q0_l_in = (v8u16)__lsx_vilvl_b(zero, q0);
+
+        tmp0_l = p7_l_in << 3;
+        tmp0_l -= p7_l_in;
+        tmp0_l += p6_l_in;
+        tmp0_l += q0_l_in;
+        tmp1_l = p6_l_in + p5_l_in;
+        tmp1_l += p4_l_in;
+        tmp1_l += p3_l_in;
+        tmp1_l += p2_l_in;
+        tmp1_l += p1_l_in;
+        tmp1_l += p0_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+
+        p7_h_in = (v8u16)__lsx_vilvh_b(zero, p7);
+        p6_h_in = (v8u16)__lsx_vilvh_b(zero, p6);
+        p5_h_in = (v8u16)__lsx_vilvh_b(zero, p5);
+        p4_h_in = (v8u16)__lsx_vilvh_b(zero, p4);
+        p3_h_in = (v8u16)__lsx_vilvh_b(zero, p3);
+        p2_h_in = (v8u16)__lsx_vilvh_b(zero, p2);
+        p1_h_in = (v8u16)__lsx_vilvh_b(zero, p1);
+        p0_h_in = (v8u16)__lsx_vilvh_b(zero, p0);
+        q0_h_in = (v8u16)__lsx_vilvh_b(zero, q0);
+
+        tmp0_h = p7_h_in << 3;
+        tmp0_h -= p7_h_in;
+        tmp0_h += p6_h_in;
+        tmp0_h += q0_h_in;
+        tmp1_h = p6_h_in + p5_h_in;
+        tmp1_h += p4_h_in;
+        tmp1_h += p3_h_in;
+        tmp1_h += p2_h_in;
+        tmp1_h += p1_h_in;
+        tmp1_h += p0_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        p6 = __lsx_vbitsel_v(p6, out_l, flat2);
+        __lsx_vst(p6, dst, 0);
+
+        /* p5 */
+        q1_l_in = (v8u16)__lsx_vilvl_b(zero, q1);
+        tmp0_l = p5_l_in - p6_l_in;
+        tmp0_l += q1_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        q1_h_in = (v8u16)__lsx_vilvh_b(zero, q1);
+        tmp0_h = p5_h_in - p6_h_in;
+        tmp0_h += q1_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        p5 = __lsx_vbitsel_v(p5, out_l, flat2);
+        __lsx_vst(p5, dst, 16);
+
+        /* p4 */
+        q2_l_in = (v8u16)__lsx_vilvl_b(zero, q2);
+        tmp0_l = p4_l_in - p5_l_in;
+        tmp0_l += q2_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        q2_h_in = (v8u16)__lsx_vilvh_b(zero, q2);
+        tmp0_h = p4_h_in - p5_h_in;
+        tmp0_h += q2_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        p4 = __lsx_vbitsel_v(p4, out_l, flat2);
+        __lsx_vst(p4, dst, 16*2);
+
+        /* p3 */
+        q3_l_in = (v8u16)__lsx_vilvl_b(zero, q3);
+        tmp0_l = p3_l_in - p4_l_in;
+        tmp0_l += q3_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        q3_h_in = (v8u16)__lsx_vilvh_b(zero, q3);
+        tmp0_h = p3_h_in - p4_h_in;
+        tmp0_h += q3_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        p3 = __lsx_vbitsel_v(p3, out_l, flat2);
+        __lsx_vst(p3, dst, 16*3);
+
+        /* p2 */
+        q4_l_in = (v8u16)__lsx_vilvl_b(zero, q4);
+        filter8 = __lsx_vld(filter48, 0);
+        tmp0_l = p2_l_in - p3_l_in;
+        tmp0_l += q4_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        q4_h_in = (v8u16)__lsx_vilvh_b(zero, q4);
+        tmp0_h = p2_h_in - p3_h_in;
+        tmp0_h += q4_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 16*4);
+
+        /* p1 */
+        q5_l_in = (v8u16)__lsx_vilvl_b(zero, q5);
+        filter8 = __lsx_vld(filter48, 16);
+        tmp0_l = p1_l_in - p2_l_in;
+        tmp0_l += q5_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        q5_h_in = (v8u16)__lsx_vilvh_b(zero, q5);
+        tmp0_h = p1_h_in - p2_h_in;
+        tmp0_h += q5_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)(tmp1_h), 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 16*5);
+
+        /* p0 */
+        q6_l_in = (v8u16)__lsx_vilvl_b(zero, q6);
+        filter8 = __lsx_vld(filter48, 32);
+        tmp0_l = p0_l_in - p1_l_in;
+        tmp0_l += q6_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        q6_h_in = (v8u16)__lsx_vilvh_b(zero, q6);
+        tmp0_h = p0_h_in - p1_h_in;
+        tmp0_h += q6_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 16*6);
+
+        /* q0 */
+        q7_l_in = (v8u16)__lsx_vilvl_b(zero, q7);
+        filter8 = __lsx_vld(filter48, 48);
+        tmp0_l = q7_l_in - p0_l_in;
+        tmp0_l += q0_l_in;
+        tmp0_l -= p7_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        q7_h_in = (v8u16)__lsx_vilvh_b(zero, q7);
+        tmp0_h = q7_h_in - p0_h_in;
+        tmp0_h += q0_h_in;
+        tmp0_h -= p7_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 16*7);
+
+        /* q1 */
+        filter8 = __lsx_vld(filter48, 64);
+        tmp0_l = q7_l_in - q0_l_in;
+        tmp0_l += q1_l_in;
+        tmp0_l -= p6_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        tmp0_h = q7_h_in - q0_h_in;
+        tmp0_h += q1_h_in;
+        tmp0_h -= p6_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 16*8);
+
+        /* q2 */
+        filter8 = __lsx_vld(filter48, 80);
+        tmp0_l = q7_l_in - q1_l_in;
+        tmp0_l += q2_l_in;
+        tmp0_l -= p5_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        tmp0_h = q7_h_in - q1_h_in;
+        tmp0_h += q2_h_in;
+        tmp0_h -= p5_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        filter8 = __lsx_vbitsel_v(filter8, out_l, flat2);
+        __lsx_vst(filter8, dst, 16*9);
+
+        /* q3 */
+        tmp0_l = q7_l_in - q2_l_in;
+        tmp0_l += q3_l_in;
+        tmp0_l -= p4_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        tmp0_h = q7_h_in - q2_h_in;
+        tmp0_h += q3_h_in;
+        tmp0_h -= p4_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        q3 = __lsx_vbitsel_v(q3, out_l, flat2);
+        __lsx_vst(q3, dst, 16*10);
+
+        /* q4 */
+        tmp0_l = q7_l_in - q3_l_in;
+        tmp0_l += q4_l_in;
+        tmp0_l -= p3_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        tmp0_h = q7_h_in - q3_h_in;
+        tmp0_h += q4_h_in;
+        tmp0_h -= p3_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        q4 = __lsx_vbitsel_v(q4, out_l, flat2);
+        __lsx_vst(q4, dst, 16*11);
+
+        /* q5 */
+        tmp0_l = q7_l_in - q4_l_in;
+        tmp0_l += q5_l_in;
+        tmp0_l -= p2_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        tmp0_h = q7_h_in - q4_h_in;
+        tmp0_h += q5_h_in;
+        tmp0_h -= p2_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        q5 = __lsx_vbitsel_v(q5, out_l, flat2);
+        __lsx_vst(q5, dst, 16*12);
+
+        /* q6 */
+        tmp0_l = q7_l_in - q5_l_in;
+        tmp0_l += q6_l_in;
+        tmp0_l -= p1_l_in;
+        tmp1_l += tmp0_l;
+        out_l = __lsx_vsrari_h((__m128i)tmp1_l, 4);
+        tmp0_h = q7_h_in - q5_h_in;
+        tmp0_h += q6_h_in;
+        tmp0_h -= p1_h_in;
+        tmp1_h += tmp0_h;
+        out_h = __lsx_vsrari_h((__m128i)tmp1_h, 4);
+        out_l = __lsx_vpickev_b(out_h, out_l);
+        q6 = __lsx_vbitsel_v(q6, out_l, flat2);
+        __lsx_vst(q6, dst, 16*13);
+
+        return 0;
+    }
+}
+
+void ff_loop_filter_h_16_16_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int32_t b_limit_ptr,
+                                int32_t limit_ptr,
+                                int32_t thresh_ptr)
+{
+    uint8_t early_exit = 0;
+    uint8_t transposed_input[16 * 24] __attribute__ ((aligned(16)));
+    uint8_t *filter48 = &transposed_input[16 * 16];
+
+    vp9_transpose_16x16((dst - 8), stride, &transposed_input[0], 16);
+
+    early_exit = vp9_vt_lpf_t4_and_t8_16w((transposed_input + 16 * 8),
+                                          &filter48[0], dst, stride,
+                                          b_limit_ptr, limit_ptr, thresh_ptr);
+
+    if (0 == early_exit) {
+        early_exit = vp9_vt_lpf_t16_16w((transposed_input + 16 * 8), dst,
+                                         stride, &filter48[0]);
+
+        if (0 == early_exit) {
+            vp9_transpose_16x16(transposed_input, 16, (dst - 8), stride);
+        }
+    }
+}
diff --git a/libavcodec/loongarch/vp9dsp_init_loongarch.c b/libavcodec/loongarch/vp9dsp_init_loongarch.c
index c1e01b4558..e49625ad5f 100644
--- a/libavcodec/loongarch/vp9dsp_init_loongarch.c
+++ b/libavcodec/loongarch/vp9dsp_init_loongarch.c
@@ -71,6 +71,15 @@
     dsp->intra_pred[tx][TOP_DC_PRED]  = ff_dc_top_##sz##_lsx;   \
     dsp->intra_pred[tx][TM_VP8_PRED]  = ff_tm_##sz##_lsx;       \
 
+#define init_idct(tx, nm)                        \
+    dsp->itxfm_add[tx][DCT_DCT]   =              \
+    dsp->itxfm_add[tx][ADST_DCT]  =              \
+    dsp->itxfm_add[tx][DCT_ADST]  =              \
+    dsp->itxfm_add[tx][ADST_ADST] = nm##_add_lsx;
+
+#define init_itxfm(tx, sz)                                     \
+    dsp->itxfm_add[tx][DCT_DCT] = ff_idct_idct_##sz##_add_lsx;
+
 av_cold void ff_vp9dsp_init_loongarch(VP9DSPContext *dsp, int bpp)
 {
     int cpu_flags = av_get_cpu_flags();
@@ -86,8 +95,30 @@ av_cold void ff_vp9dsp_init_loongarch(VP9DSPContext *dsp, int bpp)
             init_intra_pred1_lsx(TX_32X32, 32x32);
             init_intra_pred2_lsx(TX_4X4, 4x4);
             init_intra_pred2_lsx(TX_8X8, 8x8);
+            init_itxfm(TX_8X8, 8x8);
+            init_itxfm(TX_16X16, 16x16);
+            init_idct(TX_32X32, ff_idct_idct_32x32);
+            dsp->loop_filter_8[0][0] = ff_loop_filter_h_4_8_lsx;
+            dsp->loop_filter_8[0][1] = ff_loop_filter_v_4_8_lsx;
+            dsp->loop_filter_8[1][0] = ff_loop_filter_h_8_8_lsx;
+            dsp->loop_filter_8[1][1] = ff_loop_filter_v_8_8_lsx;
+            dsp->loop_filter_8[2][0] = ff_loop_filter_h_16_8_lsx;
+            dsp->loop_filter_8[2][1] = ff_loop_filter_v_16_8_lsx;
+
+            dsp->loop_filter_16[0] = ff_loop_filter_h_16_16_lsx;
+            dsp->loop_filter_16[1] = ff_loop_filter_v_16_16_lsx;
+
+            dsp->loop_filter_mix2[0][0][0] = ff_loop_filter_h_44_16_lsx;
+            dsp->loop_filter_mix2[0][0][1] = ff_loop_filter_v_44_16_lsx;
+            dsp->loop_filter_mix2[0][1][0] = ff_loop_filter_h_48_16_lsx;
+            dsp->loop_filter_mix2[0][1][1] = ff_loop_filter_v_48_16_lsx;
+            dsp->loop_filter_mix2[1][0][0] = ff_loop_filter_h_84_16_lsx;
+            dsp->loop_filter_mix2[1][0][1] = ff_loop_filter_v_84_16_lsx;
+            dsp->loop_filter_mix2[1][1][0] = ff_loop_filter_h_88_16_lsx;
+            dsp->loop_filter_mix2[1][1][1] = ff_loop_filter_v_88_16_lsx;
         }
 }
+
 #undef init_subpel1
 #undef init_subpel2
 #undef init_subpel3
@@ -95,3 +126,5 @@ av_cold void ff_vp9dsp_init_loongarch(VP9DSPContext *dsp, int bpp)
 #undef init_fpel
 #undef init_intra_pred1_lsx
 #undef init_intra_pred2_lsx
+#undef init_idct
+#undef init_itxfm
diff --git a/libavcodec/loongarch/vp9dsp_loongarch.h b/libavcodec/loongarch/vp9dsp_loongarch.h
index b469326fdc..3cc918a18c 100644
--- a/libavcodec/loongarch/vp9dsp_loongarch.h
+++ b/libavcodec/loongarch/vp9dsp_loongarch.h
@@ -140,5 +140,43 @@ void ff_tm_16x16_lsx(uint8_t *dst, ptrdiff_t stride, const uint8_t *left,
                      const uint8_t *top);
 void ff_tm_32x32_lsx(uint8_t *dst, ptrdiff_t stride, const uint8_t *left,
                      const uint8_t *top);
+void ff_loop_filter_h_16_8_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                               int32_t i, int32_t h);
+void ff_loop_filter_v_16_8_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                               int32_t i, int32_t h);
+void ff_loop_filter_h_4_8_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                              int32_t i, int32_t h);
+void ff_loop_filter_v_4_8_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                              int32_t i, int32_t h);
+void ff_loop_filter_h_44_16_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                                int32_t i, int32_t h);
+void ff_loop_filter_v_44_16_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                                int32_t i, int32_t h);
+void ff_loop_filter_h_8_8_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                              int32_t i, int32_t h);
+void ff_loop_filter_v_8_8_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                              int32_t i, int32_t h);
+void ff_loop_filter_h_88_16_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                                int32_t i, int32_t h);
+void ff_loop_filter_v_88_16_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                                int32_t i, int32_t h);
+void ff_loop_filter_h_84_16_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                                int32_t i, int32_t h);
+void ff_loop_filter_v_84_16_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                                int32_t i, int32_t h);
+void ff_loop_filter_h_48_16_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                                int32_t i, int32_t h);
+void ff_loop_filter_v_48_16_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                                int32_t i, int32_t h);
+void ff_loop_filter_h_16_16_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                                int32_t i, int32_t h);
+void ff_loop_filter_v_16_16_lsx(uint8_t *dst, ptrdiff_t stride, int32_t e,
+                                int32_t i, int32_t h);
+void ff_idct_idct_8x8_add_lsx(uint8_t *dst, ptrdiff_t stride,
+                              int16_t *block, int eob);
+void ff_idct_idct_16x16_add_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int16_t *block, int eob);
+void ff_idct_idct_32x32_add_lsx(uint8_t *dst, ptrdiff_t stride,
+                                int16_t *block, int eob);
 
 #endif /* AVCODEC_LOONGARCH_VP9DSP_LOONGARCH_H */
-- 
2.20.1



More information about the ffmpeg-devel mailing list