From patchwork Tue Mar 30 12:51:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyou Yin X-Patchwork-Id: 26663 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 0E78B44BD83 for ; Tue, 30 Mar 2021 15:52:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E82FE68A17B; Tue, 30 Mar 2021 15:52:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 09F6868973D for ; Tue, 30 Mar 2021 15:52:06 +0300 (EEST) Received: from localhost (unknown [36.33.26.144]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxHcj0HmNgA2QCAA--.2529S3; Tue, 30 Mar 2021 20:52:04 +0800 (CST) From: Shiyou Yin To: ffmpeg-devel@ffmpeg.org Date: Tue, 30 Mar 2021 20:51:53 +0800 Message-Id: <1617108715-24232-4-git-send-email-yinshiyou-hf@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1617108715-24232-1-git-send-email-yinshiyou-hf@loongson.cn> References: <1617108715-24232-1-git-send-email-yinshiyou-hf@loongson.cn> X-CM-TRANSID: AQAAf9AxHcj0HmNgA2QCAA--.2529S3 X-Coremail-Antispam: 1UD129KBjvJXoW3Jr1UKr1xAF1DAFWUJFy7ZFb_yoW3KFW8p3 WUu3W3Gr18J3ya9as3Jr4kC3WayF95tFy8AFyUXw1UX39rX348ZFZ3KFZ3X3WkWr9FqF13 Ww1Fg347A3W7C3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkq14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26F4j 6r4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUtVWrXwAv7VC2z280aVAFwI0_Cr0_Gr1UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK6ryU MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUXVWUAwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JV WxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAI cVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUb1SoPUUUUU== X-CM-SenderInfo: p1lq2x5l1r3gtki6z05rqj20fqof0/ Subject: [FFmpeg-devel] [PATCH v3 3/5] avcodec/mips: Optimize function ff_h264_loop_filter_strength_msa. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: gxw MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: gxw Speed of decoding H264 1080P: 5.05x ==> 5.13x Signed-off-by: Shiyou Yin --- libavcodec/mips/Makefile | 3 +- libavcodec/mips/h264_deblock_msa.c | 153 ++++++++++++++++++++++++++++++++++++ libavcodec/mips/h264dsp_init_mips.c | 2 + libavcodec/mips/h264dsp_mips.h | 4 + 4 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 libavcodec/mips/h264_deblock_msa.c diff --git a/libavcodec/mips/Makefile b/libavcodec/mips/Makefile index 2be4d9b..81a73a4 100644 --- a/libavcodec/mips/Makefile +++ b/libavcodec/mips/Makefile @@ -57,7 +57,8 @@ MSA-OBJS-$(CONFIG_VP8_DECODER) += mips/vp8_mc_msa.o \ mips/vp8_lpf_msa.o MSA-OBJS-$(CONFIG_VP3DSP) += mips/vp3dsp_idct_msa.o MSA-OBJS-$(CONFIG_H264DSP) += mips/h264dsp_msa.o \ - mips/h264idct_msa.o + mips/h264idct_msa.o \ + mips/h264_deblock_msa.o MSA-OBJS-$(CONFIG_H264QPEL) += mips/h264qpel_msa.o MSA-OBJS-$(CONFIG_H264CHROMA) += mips/h264chroma_msa.o MSA-OBJS-$(CONFIG_H264PRED) += mips/h264pred_msa.o diff --git a/libavcodec/mips/h264_deblock_msa.c b/libavcodec/mips/h264_deblock_msa.c new file mode 100644 index 0000000..4fed55c --- /dev/null +++ b/libavcodec/mips/h264_deblock_msa.c @@ -0,0 +1,153 @@ +/* + * MIPS SIMD optimized H.264 deblocking code + * + * Copyright (c) 2020 Loongson Technology Corporation Limited + * Gu Xiwei + * + * 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/bit_depth_template.c" +#include "h264dsp_mips.h" +#include "libavutil/mips/generic_macros_msa.h" +#include "libavcodec/mips/h264dsp_mips.h" + +#define h264_loop_filter_strength_iteration_msa(edges, step, mask_mv, dir, \ + d_idx, mask_dir) \ +do { \ + int b_idx = 0; \ + int step_x4 = step << 2; \ + int d_idx_12 = d_idx + 12; \ + int d_idx_52 = d_idx + 52; \ + int d_idx_x4 = d_idx << 2; \ + int d_idx_x4_48 = d_idx_x4 + 48; \ + int dir_x32 = dir * 32; \ + uint8_t *ref_t = (uint8_t*)ref; \ + uint8_t *mv_t = (uint8_t*)mv; \ + uint8_t *nnz_t = (uint8_t*)nnz; \ + uint8_t *bS_t = (uint8_t*)bS; \ + mask_mv <<= 3; \ + for (; b_idx < edges; b_idx += step) { \ + out &= mask_dir; \ + if (!(mask_mv & b_idx)) { \ + if (bidir) { \ + ref_2 = LD_SB(ref_t + d_idx_12); \ + ref_3 = LD_SB(ref_t + d_idx_52); \ + ref_0 = LD_SB(ref_t + 12); \ + ref_1 = LD_SB(ref_t + 52); \ + ref_2 = (v16i8)__msa_ilvr_w((v4i32)ref_3, (v4i32)ref_2); \ + ref_0 = (v16i8)__msa_ilvr_w((v4i32)ref_0, (v4i32)ref_0); \ + ref_1 = (v16i8)__msa_ilvr_w((v4i32)ref_1, (v4i32)ref_1); \ + ref_3 = (v16i8)__msa_shf_h((v8i16)ref_2, 0x4e); \ + ref_0 -= ref_2; \ + ref_1 -= ref_3; \ + ref_0 = (v16i8)__msa_or_v((v16u8)ref_0, (v16u8)ref_1); \ +\ + tmp_2 = LD_SH(mv_t + d_idx_x4_48); \ + tmp_3 = LD_SH(mv_t + 48); \ + tmp_4 = LD_SH(mv_t + 208); \ + tmp_5 = tmp_2 - tmp_3; \ + tmp_6 = tmp_2 - tmp_4; \ + SAT_SH2_SH(tmp_5, tmp_6, 7); \ + tmp_0 = __msa_pckev_b((v16i8)tmp_6, (v16i8)tmp_5); \ + tmp_0 += cnst_1; \ + tmp_0 = (v16i8)__msa_subs_u_b((v16u8)tmp_0, (v16u8)cnst_0);\ + tmp_0 = (v16i8)__msa_sat_s_h((v8i16)tmp_0, 7); \ + tmp_0 = __msa_pckev_b(tmp_0, tmp_0); \ + out = (v16i8)__msa_or_v((v16u8)ref_0, (v16u8)tmp_0); \ +\ + tmp_2 = LD_SH(mv_t + 208 + d_idx_x4); \ + tmp_5 = tmp_2 - tmp_3; \ + tmp_6 = tmp_2 - tmp_4; \ + SAT_SH2_SH(tmp_5, tmp_6, 7); \ + tmp_1 = __msa_pckev_b((v16i8)tmp_6, (v16i8)tmp_5); \ + tmp_1 += cnst_1; \ + tmp_1 = (v16i8)__msa_subs_u_b((v16u8)tmp_1, (v16u8)cnst_0); \ + tmp_1 = (v16i8)__msa_sat_s_h((v8i16)tmp_1, 7); \ + tmp_1 = __msa_pckev_b(tmp_1, tmp_1); \ +\ + tmp_1 = (v16i8)__msa_shf_h((v8i16)tmp_1, 0x4e); \ + out = (v16i8)__msa_or_v((v16u8)out, (v16u8)tmp_1); \ + tmp_0 = (v16i8)__msa_shf_h((v8i16)out, 0x4e); \ + out = (v16i8)__msa_min_u_b((v16u8)out, (v16u8)tmp_0); \ + } else { \ + ref_0 = LD_SB(ref_t + d_idx_12); \ + ref_3 = LD_SB(ref_t + 12); \ + tmp_2 = LD_SH(mv_t + d_idx_x4_48); \ + tmp_3 = LD_SH(mv_t + 48); \ + tmp_4 = tmp_3 - tmp_2; \ + tmp_1 = (v16i8)__msa_sat_s_h(tmp_4, 7); \ + tmp_1 = __msa_pckev_b(tmp_1, tmp_1); \ + tmp_1 += cnst_1; \ + out = (v16i8)__msa_subs_u_b((v16u8)tmp_1, (v16u8)cnst_0); \ + out = (v16i8)__msa_sat_s_h((v8i16)out, 7); \ + out = __msa_pckev_b(out, out); \ + ref_0 = ref_3 - ref_0; \ + out = (v16i8)__msa_or_v((v16u8)out, (v16u8)ref_0); \ + } \ + } \ + tmp_0 = LD_SB(nnz_t + 12); \ + tmp_1 = LD_SB(nnz_t + d_idx_12); \ + tmp_0 = (v16i8)__msa_or_v((v16u8)tmp_0, (v16u8)tmp_1); \ + tmp_0 = (v16i8)__msa_min_u_b((v16u8)tmp_0, (v16u8)cnst_2); \ + out = (v16i8)__msa_min_u_b((v16u8)out, (v16u8)cnst_2); \ + tmp_0 = (v16i8)((v8i16)tmp_0 << 1); \ + tmp_0 = (v16i8)__msa_max_u_b((v16u8)out, (v16u8)tmp_0); \ + tmp_0 = __msa_ilvr_b(zero, tmp_0); \ + ST_D1(tmp_0, 0, bS_t + dir_x32); \ + ref_t += step; \ + mv_t += step_x4; \ + nnz_t += step; \ + bS_t += step; \ + } \ +} while(0) + +void ff_h264_loop_filter_strength_msa(int16_t bS[2][4][4], uint8_t nnz[40], + int8_t ref[2][40], int16_t mv[2][40][2], + int bidir, int edges, int step, + int mask_mv0, int mask_mv1, int field) +{ + v16i8 out; + v16i8 ref_0, ref_1, ref_2, ref_3; + v16i8 tmp_0, tmp_1; + v8i16 tmp_2, tmp_3, tmp_4, tmp_5, tmp_6; + v16i8 cnst_0, cnst_1, cnst_2; + v16i8 zero = { 0 }; + v16i8 one = __msa_fill_b(0xff); + if (field) { + cnst_0 = (v16i8)__msa_fill_h(0x206); + cnst_1 = (v16i8)__msa_fill_h(0x103); + cnst_2 = (v16i8)__msa_fill_h(0x101); + } else { + cnst_0 = __msa_fill_b(0x6); + cnst_1 = __msa_fill_b(0x3); + cnst_2 = __msa_fill_b(0x1); + } + step <<= 3; + edges <<= 3; + + h264_loop_filter_strength_iteration_msa(edges, step, mask_mv1, 1, -8, zero); + h264_loop_filter_strength_iteration_msa(32, 8, mask_mv0, 0, -1, one); + + LD_SB2((int8_t*)bS, 16, tmp_0, tmp_1); + tmp_2 = (v8i16)__msa_ilvl_d((v2i64)tmp_0, (v2i64)tmp_0); + tmp_3 = (v8i16)__msa_ilvl_d((v2i64)tmp_1, (v2i64)tmp_1); + TRANSPOSE4x4_SH_SH(tmp_0, tmp_2, tmp_1, tmp_3, tmp_2, tmp_3, tmp_4, tmp_5); + tmp_0 = (v16i8)__msa_ilvr_d((v2i64)tmp_3, (v2i64)tmp_2); + tmp_1 = (v16i8)__msa_ilvr_d((v2i64)tmp_5, (v2i64)tmp_4); + ST_SB2(tmp_0, tmp_1, (int8_t*)bS, 16); +} diff --git a/libavcodec/mips/h264dsp_init_mips.c b/libavcodec/mips/h264dsp_init_mips.c index 9cd05e0..f822c38 100644 --- a/libavcodec/mips/h264dsp_init_mips.c +++ b/libavcodec/mips/h264dsp_init_mips.c @@ -78,6 +78,8 @@ av_cold void ff_h264dsp_init_mips(H264DSPContext *c, const int bit_depth, } if (have_msa(cpu_flags)) { + if (chroma_format_idc <= 1) + c->h264_loop_filter_strength = ff_h264_loop_filter_strength_msa; if (bit_depth == 8) { c->h264_v_loop_filter_luma = ff_h264_v_lpf_luma_inter_msa; c->h264_h_loop_filter_luma = ff_h264_h_lpf_luma_inter_msa; diff --git a/libavcodec/mips/h264dsp_mips.h b/libavcodec/mips/h264dsp_mips.h index 35e16c4..5847ef3 100644 --- a/libavcodec/mips/h264dsp_mips.h +++ b/libavcodec/mips/h264dsp_mips.h @@ -319,6 +319,10 @@ void ff_vp8_pred8x8_129_dc_8_msa(uint8_t *src, ptrdiff_t stride); void ff_vp8_pred16x16_127_dc_8_msa(uint8_t *src, ptrdiff_t stride); void ff_vp8_pred16x16_129_dc_8_msa(uint8_t *src, ptrdiff_t stride); +void ff_h264_loop_filter_strength_msa(int16_t bS[2][4][4], uint8_t nnz[40], + int8_t ref[2][40], int16_t mv[2][40][2], int bidir, int edges, + int step, int mask_mv0, int mask_mv1, int field); + void ff_h264_add_pixels4_8_mmi(uint8_t *_dst, int16_t *_src, int stride); void ff_h264_idct_add_8_mmi(uint8_t *dst, int16_t *block, int stride); void ff_h264_idct8_add_8_mmi(uint8_t *dst, int16_t *block, int stride);