From patchwork Tue Sep 18 02:59:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyou Yin X-Patchwork-Id: 10356 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp4188120jap; Mon, 17 Sep 2018 19:59:55 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb+R0cCXO4XfVHcy23ntHKsUOMNmx2eh/yzVCxwIM0sX0PK+yg7CfHkjzJx/5JEI/LMTliX X-Received: by 2002:a1c:f0a:: with SMTP id 10-v6mr13616203wmp.58.1537239594963; Mon, 17 Sep 2018 19:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537239594; cv=none; d=google.com; s=arc-20160816; b=ealMSTNLK41mWWwtJ6rDnKQzsbi3yF17+CSoh2DBHVsyvJMHDLfehi5pQtS1mCGemf dEpq79iL6xrtTGyyo/IGVfBRnGY/4xwMnDRUEjoEUZENcGZ8PQ53VZMDnvkN1PLa1qrb h3rrECmsnMvANPO1+1HqxmSeP3LpX20tiiioVhz0zZCwPTHlSDL8yzBvDA/f+5uyT4Yx wIuz1VLELyRkjmXT6zzMkVHKPJ0G796IuOlPC1UUACFdTgOweJT3X1FNsfDvCPcA1QJq HhJdwTIov3waDyT3wb1otFOAVrryj8+iLwHyGXcj4VnbqkTTucF0KSPKG7UObX8zucFO IJ9Q== 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; bh=8XQux3fZN4M/o6D10PPbZGbLf2BMHZn59Tp7g31ZNZ0=; b=a6AREkydzKjkk0qvqv7ZU1dGUzG6kt+mwl/z/bpLUSddLZcOkCCoD0AK7QFmIaPzap PxLvv8v9OO2DPpNf+1gFbOUguSRkUOQHEJHt1Yh0c2/5ShazgRYTS2Orhn6FCXssk9cj uEyt+ZqOS3YpeR3c5uEuR6wz8p3ZkMZpOe0AYfccs5ZHGA1f2MAgr2jyav4jdozB1GTE X/LC8KwS7hG4bulo/Ym+DNjk0KnzapDDsLj0MlD48NKD1MAXWmTzZ3SOErR0Q1kQ0+XK AFhLHdZL80G8p6HgYEgQXSS9Sxaodmmb2D1gcGFbdmpTYtI18WkmhVi2CyqWD8Uv26El oIuA== 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 m12-v6si379933wrg.369.2018.09.17.19.59.54; Mon, 17 Sep 2018 19:59:54 -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 97FA168A29F; Tue, 18 Sep 2018 05:59:39 +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 227CB68A0A6 for ; Tue, 18 Sep 2018 05:59:31 +0300 (EEST) Received: from localhost (unknown [210.45.123.188]) by mail (Coremail) with SMTP id QMiowPCxSeXpaaBb_OkfAA--.10126S3; Tue, 18 Sep 2018 10:58:49 +0800 (CST) From: Shiyou Yin To: ffmpeg-devel@ffmpeg.org Date: Tue, 18 Sep 2018 10:59:41 +0800 Message-Id: <1537239581-12160-1-git-send-email-yinshiyou-hf@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: QMiowPCxSeXpaaBb_OkfAA--.10126S3 X-Coremail-Antispam: 1UD129KBjvJXoWxKF1rWr1rAFW3Jw1kWw4xXrb_yoW7Wr4fpr ykCws0k34IqFW7CFsxJF48GrnIyF40qF48GFy7K3W2yrZ8tr4rXrZ2gry8Gw1rGFykAFy3 Zr1DuFy3Ca17u3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkmb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4 vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7Cj xVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x 0267AKxVW8Jr0_Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02 F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r17McIj6I8E87Iv67AKxVW8JVWxJwAm72CE4I kC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lF7xvr2IYc2Ij64vIr40E4x8a64kEw24l c2xSY4AK67AK6r4UMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I 0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWU JVWUXwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJV W8JwCI42IY6xAIw20EY4v20xvaj40_Wr1j6rW3Jr1lIxAIcVC2z280aVAFwI0_Jr0_Gr1l IxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxUcQ6pDUUUU X-CM-SenderInfo: p1lq2x5l1r3gtki6z05rqj20fqof0/ Subject: [FFmpeg-devel] [PATCH] avcodec: [loongson] optimize get_cabac_inline. 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" This optimization improved h264 decoding performance about 4%(from 74fps to 77fps, tested on loongson 3A3000). --- 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..82cee29 --- /dev/null +++ b/libavcodec/mips/cabac.h @@ -0,0 +1,119 @@ +/* + * Loongson SIMD optimized h264chroma + * + * Copyright (c) 2018 Loongson Technology Corporation Limited + * Copyright (c) 2018 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 */