From patchwork Thu Jul 12 12:45:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyou Yin X-Patchwork-Id: 9697 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:104:0:0:0:0:0 with SMTP id c4-v6csp1618593jad; Thu, 12 Jul 2018 05:45:28 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcZACmxM6OWER4sPjoQDOF/d/IChWBvrseb8lwgmsDqeIy7Ox/HP1TgP8g6aN5mluZx7jFj X-Received: by 2002:adf:ee4e:: with SMTP id w14-v6mr1750794wro.63.1531399528381; Thu, 12 Jul 2018 05:45:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531399528; cv=none; d=google.com; s=arc-20160816; b=dvuSMv0/3PTuyoWLWGuIG1idoEsZR4L9TPO4zkPLZVabGqmNGYUqGsw+otarMO7djz BgajRf6JYXji1XvzaxqaUWNYazk66p0Lpj7bQJ82rl1fEnqsCCw1l+iv/1fB5LmXX5uT 0mJu8ko2JyviqBiCdKr82CIlxAKj2Q6F9wMzr7g3j48ZtcpC2+lOLfqFRSWRLvuS9/oK u7qRaICmtBkqTzQV3BEuGfXwtqNuYBcxWsZp+bfzoCM6mJiFUhunEesRfgpfwLbPJR+S ZPe/G+8SAoNqrsN+WOaNvtroYeCpzIyc/R0hJbHAbhuDUkZg6EnzF4E4cAUVtqQWmmnX +uXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to :arc-authentication-results; bh=fgHMysDOEpX5SQfqKk+mSMuaA43SPqVkMiEpV8wkK54=; b=y6qeVClRTdy6rhaClyL8rvUSknTpj8mAoZ9nyrvGTJiY6vY1UCND2OPtrMas1VZY1l QSZluiwJtB4EwOSP16YJnoS5BJCRDR5xEr75dZeerXNlKEOjM+NZZcbzab0TtDRftob+ gk7q7airstxpJ4G1othr7M8kCN1DakHzWQSZ+vwgE3lxc4QeGF0paJz+Qtna5vdXcc9K FGaPkCrDTWpHlPGP/OHrD987R+RihWo89tzQz65V4PoYNoSQT3/sxfjccmJr/XYb0mpW YgK+ZQJ/UHOStZ5+C72/4X36K96aYrwdzjR0vJ5VTJACpDd95CFrmpKDgnNCb3S8F4OY En0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g47-v6si1042115wra.332.2018.07.12.05.45.27; Thu, 12 Jul 2018 05:45:28 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C11768A6D1; Thu, 12 Jul 2018 15:44:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 57D3268A683 for ; Thu, 12 Jul 2018 15:44:55 +0300 (EEST) Received: from localhost (unknown [202.141.160.96]) by mail (Coremail) with SMTP id QMiowPDxj2MsTEdbDZuTAA--.26239S3; Thu, 12 Jul 2018 20:40:12 +0800 (CST) From: Shiyou Yin To: ffmpeg-devel@ffmpeg.org Date: Thu, 12 Jul 2018 20:45:02 +0800 Message-Id: <1531399502-14903-1-git-send-email-yinshiyou-hf@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: QMiowPDxj2MsTEdbDZuTAA--.26239S3 X-Coremail-Antispam: 1UD129KBjvJXoWxKF1rWr1rAFW3Jw1kWw4xXrb_yoW7AF4kpr ykCws0kw1IqFW7CFsxJF48GrnIyF40qF48GFy7K3W2yrZ8tr4rXrZ2gry8Gw1rGFykAFy3 Zr1DuFy3Ca17u3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkIb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWxJr0_GcWl84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv67AKxVW8JVWxJwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7xvr2IYc2Ij64vIr40E4x8a64kEw24lc2xS Y4AK67AK6ryUMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I 8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUJVWU XwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8Jw CI42IY6xAIw20EY4v20xvaj40_JFI_Gr1lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2 z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU0b_-PUUUUU== X-CM-SenderInfo: p1lq2x5l1r3gtki6z05rqj20fqof0/ Subject: [FFmpeg-devel] [PATCH 6/9] avcodec: [loongson] optimize get_cabac_inline with asm. 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" Optimize function get_cabac_inline with asm. This optimization improved h264 decoding performance about 3fps(from 74fps to 77fps, tested on loongson 3A3000). Change-Id: Ia06381d3b820b6abdeef6af257d7b64b43f08a4b Signed-off-by: Shiyou Yin --- libavcodec/cabac_functions.h | 3 ++ libavcodec/mips/cabac.h | 119 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 libavcodec/mips/cabac.h diff --git a/libavcodec/cabac_functions.h b/libavcodec/cabac_functions.h index fe72a82..bb2b421 100644 --- a/libavcodec/cabac_functions.h +++ b/libavcodec/cabac_functions.h @@ -45,6 +45,9 @@ #if ARCH_X86 # include "x86/cabac.h" #endif +#if ARCH_MIPS +# include "mips/cabac.h" +#endif static const uint8_t * const ff_h264_norm_shift = ff_h264_cabac_tables + H264_NORM_SHIFT_OFFSET; static const uint8_t * const ff_h264_lps_range = ff_h264_cabac_tables + H264_LPS_RANGE_OFFSET; diff --git a/libavcodec/mips/cabac.h b/libavcodec/mips/cabac.h new file mode 100644 index 0000000..a22c1ea --- /dev/null +++ b/libavcodec/mips/cabac.h @@ -0,0 +1,119 @@ +/* + * Loongson SIMD optimized h264chroma + * + * Copyright (c) 2015 Loongson Technology Corporation Limited + * Copyright (c) 2015 Shiyou Yin + * + * 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 + */ + +#ifndef AVCODEC_MIPS_CABAC_H +#define AVCODEC_MIPS_CABAC_H + +#include "libavcodec/cabac.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(CABACContext *c, + 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_ADDU "%[tmp0], %[tmp0], %[tables] \n\t" + PTR_ADDU "%[tmp0], %[tmp0], %[bit] \n\t" + /* tmp1: RangeLPS */ + "lbu %[tmp1], %[lps_off](%[tmp0]) \n\t" + + 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*/ + "beqz %[tmp2], 1f \n\t" + PTR_SLL "%[tmp0], %[c_range], 0x11 \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 */ + PTR_ADDU "%[tmp0], %[tables], %[bit] \n\t" + "lbu %[tmp1], %[mlps_off](%[tmp0]) \n\t" + /* tmp2: lps_mask */ + PTR_ADDU "%[tmp0], %[tables], %[c_range] \n\t" + "lbu %[tmp2], %[norm_off](%[tmp0]) \n\t" + + "sb %[tmp1], 0(%[state]) \n\t" + "and %[bit], %[bit], 0x01 \n\t" + 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_ADDI "%[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" + "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" + PTR_SLL "%[tmp0], %[tmp0], 0x01 \n\t" +#endif + PTR_SUBU "%[tmp0], %[tmp0], %[cabac_mask] \n\t" + + "li %[tmp1], 0x07 \n\t" + PTR_SUBU "%[tmp1], %[tmp1], %[tmp2] \n\t" + 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" +#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), + [c_bytestream]"+&r"(c->bytestream) + : [state]"r"(state), [tables]"r"(ff_h264_cabac_tables), +#if !UNCHECKED_BITSTREAM_READER + [c_bytestream_end]"r"(c->bytestream_end), +#endif + [lps_off]"i"(H264_LPS_RANGE_OFFSET), + [mlps_off]"i"(H264_MLPS_STATE_OFFSET + 128), + [norm_off]"i"(H264_NORM_SHIFT_OFFSET), + [cabac_mask]"i"(CABAC_MASK) + : "memory" + ); + + return bit; +} + +#endif /* AVCODEC_MIPS_CABAC_H */