From patchwork Mon Sep 7 10:54:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyou Yin X-Patchwork-Id: 22147 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 8F02844AF93 for ; Mon, 7 Sep 2020 13:55:15 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 753C868AB96; Mon, 7 Sep 2020 13:55: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 B896268A107 for ; Mon, 7 Sep 2020 13:55:04 +0300 (EEST) Received: from localhost (unknown [36.33.26.144]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxGMaEEVZfuVMSAA--.1404S3; Mon, 07 Sep 2020 18:55:01 +0800 (CST) From: Shiyou Yin To: ffmpeg-devel@ffmpeg.org Date: Mon, 7 Sep 2020 18:54:54 +0800 Message-Id: <1599476095-2865-3-git-send-email-yinshiyou-hf@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1599476095-2865-1-git-send-email-yinshiyou-hf@loongson.cn> References: <1599476095-2865-1-git-send-email-yinshiyou-hf@loongson.cn> X-CM-TRANSID: AQAAf9DxGMaEEVZfuVMSAA--.1404S3 X-Coremail-Antispam: 1UD129KBjvJXoWxtr15Gw4xZw13XFWrKr17ZFb_yoWxKF1fpr y8Grs0yrWavFW7CFZxJF4xGrnxZF48tw18WFyUtF18Ars0vr1rurZ7GryxWw1rGFykuFWa vF1UZFy3CF17Zw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkYb7Iv0xC_KF4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Cr0_Gr1UM28EF7xvwVC2z280aVAFwI0_Cr1j6rxdM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Gr0_Cr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxEwVAFwVW8twCF04k2 0xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI 8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jr0_JrylIxkGc2Ij64vIr41l IxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIx AIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IU8K9aPUUUUU== X-CM-SenderInfo: p1lq2x5l1r3gtki6z05rqj20fqof0/ Subject: [FFmpeg-devel] [PATCH v2 2/3] avcodec/mips: Refine get_cabac_inline_mips. 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 1. Refined function get_cabac_inline_mips. 2. Optimize function get_cabac_bypass and get_cabac_bypass_sign. Speed of decoding h264: 5.23x ==> 5.45x(tested on 3A4000). --- libavcodec/mips/cabac.h | 131 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 102 insertions(+), 29 deletions(-) diff --git a/libavcodec/mips/cabac.h b/libavcodec/mips/cabac.h index 3d09e93..0ee7594 100644 --- a/libavcodec/mips/cabac.h +++ b/libavcodec/mips/cabac.h @@ -2,7 +2,8 @@ * Loongson SIMD optimized h264chroma * * Copyright (c) 2018 Loongson Technology Corporation Limited - * Copyright (c) 2018 Shiyou Yin + * Contributed by Shiyou Yin + * Gu Xiwei(guxiwei-hf@loongson.cn) * * This file is part of FFmpeg. * @@ -25,18 +26,18 @@ #define AVCODEC_MIPS_CABAC_H #include "libavcodec/cabac.h" -#include "libavutil/mips/asmdefs.h" +#include "libavutil/mips/mmiutils.h" #include "config.h" #define get_cabac_inline get_cabac_inline_mips static av_always_inline int get_cabac_inline_mips(CABACContext *c, - uint8_t * const state){ + uint8_t * const state){ mips_reg tmp0, tmp1, tmp2, bit; __asm__ volatile ( "lbu %[bit], 0(%[state]) \n\t" "and %[tmp0], %[c_range], 0xC0 \n\t" - PTR_ADDU "%[tmp0], %[tmp0], %[tmp0] \n\t" + PTR_SLL "%[tmp0], %[tmp0], 0x01 \n\t" PTR_ADDU "%[tmp0], %[tmp0], %[tables] \n\t" PTR_ADDU "%[tmp0], %[tmp0], %[bit] \n\t" /* tmp1: RangeLPS */ @@ -44,18 +45,11 @@ static av_always_inline int get_cabac_inline_mips(CABACContext *c, PTR_SUBU "%[c_range], %[c_range], %[tmp1] \n\t" PTR_SLL "%[tmp0], %[c_range], 0x11 \n\t" - PTR_SUBU "%[tmp0], %[tmp0], %[c_low] \n\t" - - /* tmp2: lps_mask */ - PTR_SRA "%[tmp2], %[tmp0], 0x1F \n\t" - /* If tmp0 < 0, lps_mask == 0xffffffff*/ - /* If tmp0 >= 0, lps_mask == 0x00000000*/ + "slt %[tmp2], %[tmp0], %[c_low] \n\t" "beqz %[tmp2], 1f \n\t" - PTR_SLL "%[tmp0], %[c_range], 0x11 \n\t" + "move %[c_range], %[tmp1] \n\t" + "not %[bit], %[bit] \n\t" PTR_SUBU "%[c_low], %[c_low], %[tmp0] \n\t" - PTR_SUBU "%[tmp0], %[tmp1], %[c_range] \n\t" - PTR_ADDU "%[c_range], %[c_range], %[tmp0] \n\t" - "xor %[bit], %[bit], %[tmp2] \n\t" "1: \n\t" /* tmp1: *state */ @@ -70,23 +64,18 @@ static av_always_inline int get_cabac_inline_mips(CABACContext *c, PTR_SLL "%[c_range], %[c_range], %[tmp2] \n\t" PTR_SLL "%[c_low], %[c_low], %[tmp2] \n\t" - "and %[tmp0], %[c_low], %[cabac_mask] \n\t" - "bnez %[tmp0], 1f \n\t" - PTR_ADDIU "%[tmp0], %[c_low], -0x01 \n\t" + "and %[tmp1], %[c_low], %[cabac_mask] \n\t" + "bnez %[tmp1], 1f \n\t" + PTR_ADDIU "%[tmp0], %[c_low], -0X01 \n\t" "xor %[tmp0], %[c_low], %[tmp0] \n\t" PTR_SRA "%[tmp0], %[tmp0], 0x0f \n\t" PTR_ADDU "%[tmp0], %[tmp0], %[tables] \n\t" + /* tmp2: ff_h264_norm_shift[x >> (CABAC_BITS - 1)] */ "lbu %[tmp2], %[norm_off](%[tmp0]) \n\t" -#if CABAC_BITS == 16 - "lbu %[tmp0], 0(%[c_bytestream]) \n\t" - "lbu %[tmp1], 1(%[c_bytestream]) \n\t" - PTR_SLL "%[tmp0], %[tmp0], 0x09 \n\t" - PTR_SLL "%[tmp1], %[tmp1], 0x01 \n\t" - PTR_ADDU "%[tmp0], %[tmp0], %[tmp1] \n\t" -#else - "lbu %[tmp0], 0(%[c_bytestream]) \n\t" + + "lhu %[tmp0], 0(%[c_bytestream]) \n\t" + "wsbh %[tmp0], %[tmp0] \n\t" PTR_SLL "%[tmp0], %[tmp0], 0x01 \n\t" -#endif PTR_SUBU "%[tmp0], %[tmp0], %[cabac_mask] \n\t" "li %[tmp1], 0x07 \n\t" @@ -94,10 +83,13 @@ static av_always_inline int get_cabac_inline_mips(CABACContext *c, PTR_SLL "%[tmp0], %[tmp0], %[tmp1] \n\t" PTR_ADDU "%[c_low], %[c_low], %[tmp0] \n\t" -#if !UNCHECKED_BITSTREAM_READER - "bge %[c_bytestream], %[c_bytestream_end], 1f \n\t" +#if UNCHECKED_BITSTREAM_READER + PTR_ADDIU "%[c_bytestream], %[c_bytestream], 0x02 \n\t" +#else + "slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t" + PTR_ADDIU "%[tmp2], %[c_bytestream], 0x02 \n\t" + "movn %[c_bytestream], %[tmp2], %[tmp0] \n\t" #endif - PTR_ADDIU "%[c_bytestream], %[c_bytestream], 0X02 \n\t" "1: \n\t" : [bit]"=&r"(bit), [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [tmp2]"=&r"(tmp2), [c_range]"+&r"(c->range), [c_low]"+&r"(c->low), @@ -116,4 +108,85 @@ static av_always_inline int get_cabac_inline_mips(CABACContext *c, return bit; } +#define get_cabac_bypass get_cabac_bypass_mips +static av_always_inline int get_cabac_bypass_mips(CABACContext *c) +{ + mips_reg tmp0, tmp1; + int res = 0; + __asm__ volatile( + PTR_SLL "%[c_low], %[c_low], 0x01 \n\t" + "and %[tmp0], %[c_low], %[cabac_mask] \n\t" + "bnez %[tmp0], 1f \n\t" + "lhu %[tmp1], 0(%[c_bytestream]) \n\t" + "wsbh %[tmp1], %[tmp1] \n\t" + PTR_SLL "%[tmp1], %[tmp1], 0x01 \n\t" + PTR_SUBU "%[tmp1], %[tmp1], %[cabac_mask] \n\t" + PTR_ADDU "%[c_low], %[c_low], %[tmp1] \n\t" +#if UNCHECKED_BITSTREAM_READER + PTR_ADDIU "%[c_bytestream], %[c_bytestream], 0x02 \n\t" +#else + "slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t" + PTR_ADDIU "%[tmp1], %[c_bytestream], 0x02 \n\t" + "movn %[c_bytestream], %[tmp1], %[tmp0] \n\t" +#endif + "1: \n\t" + PTR_SLL "%[tmp1], %[c_range], 0x11 \n\t" + "slt %[tmp0], %[c_low], %[tmp1] \n\t" + PTR_SUBU "%[tmp1], %[c_low], %[tmp1] \n\t" + "movz %[res], %[one], %[tmp0] \n\t" + "movz %[c_low], %[tmp1], %[tmp0] \n\t" + : [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [res]"+&r"(res), + [c_range]"+&r"(c->range), [c_low]"+&r"(c->low), + [c_bytestream]"+&r"(c->bytestream) + : [cabac_mask]"r"(CABAC_MASK), +#if !UNCHECKED_BITSTREAM_READER + [c_bytestream_end]"r"(c->bytestream_end), +#endif + [one]"r"(0x01) + : "memory" + ); + return res; +} + +#define get_cabac_bypass_sign get_cabac_bypass_sign_mips +static av_always_inline int get_cabac_bypass_sign_mips(CABACContext *c, int val) +{ + mips_reg tmp0, tmp1; + int res = val; + __asm__ volatile( + PTR_SLL "%[c_low], %[c_low], 0x01 \n\t" + "and %[tmp0], %[c_low], %[cabac_mask] \n\t" + "bnez %[tmp0], 1f \n\t" + "lhu %[tmp1], 0(%[c_bytestream]) \n\t" + "wsbh %[tmp1], %[tmp1] \n\t" + PTR_SLL "%[tmp1], %[tmp1], 0x01 \n\t" + PTR_SUBU "%[tmp1], %[tmp1], %[cabac_mask] \n\t" + PTR_ADDU "%[c_low], %[c_low], %[tmp1] \n\t" +#if UNCHECKED_BITSTREAM_READER + PTR_ADDIU "%[c_bytestream], %[c_bytestream], 0x02 \n\t" +#else + "slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t" + PTR_ADDIU "%[tmp1], %[c_bytestream], 0x02 \n\t" + "movn %[c_bytestream], %[tmp1], %[tmp0] \n\t" +#endif + "1: \n\t" + PTR_SLL "%[tmp1], %[c_range], 0x11 \n\t" + "slt %[tmp0], %[c_low], %[tmp1] \n\t" + PTR_SUBU "%[tmp1], %[c_low], %[tmp1] \n\t" + "movz %[c_low], %[tmp1], %[tmp0] \n\t" + PTR_SUBU "%[tmp1], %[zero], %[res] \n\t" + "movn %[res], %[tmp1], %[tmp0] \n\t" + : [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [res]"+&r"(res), + [c_range]"+&r"(c->range), [c_low]"+&r"(c->low), + [c_bytestream]"+&r"(c->bytestream) + : [cabac_mask]"r"(CABAC_MASK), +#if !UNCHECKED_BITSTREAM_READER + [c_bytestream_end]"r"(c->bytestream_end), +#endif + [zero]"r"(0x0) + : "memory" + ); + + return res; +} #endif /* AVCODEC_MIPS_CABAC_H */