From patchwork Thu Jun 14 07:19:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyou Yin X-Patchwork-Id: 9402 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp1578775jad; Thu, 14 Jun 2018 00:19:40 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKPjiiEkPWTIdOleyryDkpd2vgIfLnmxomy632GUxqS6nQUkg8s0L6JeIkLtHR+5iOGctXA X-Received: by 2002:a1c:64c5:: with SMTP id y188-v6mr844487wmb.45.1528960780646; Thu, 14 Jun 2018 00:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528960780; cv=none; d=google.com; s=arc-20160816; b=xVvgOKnrxPBzoqcVdMeXuCJcPUqJ32Zm9oz1JfDFT79OSZ//zt8t1CLhWzIIUCMYSp kI4be/KAdMfmVB653YWeu3Oh3hdgPFIdG9cDL3iLV1XyudA1JdjceWcB2RpHjqyd5/Bf hgOivj4RxIK4ZivxYrYLf0CctwMlAn+Awv7WrZVB11Xt77RmDqBbs5bwa7apcItX1OOH C52/euSN394zAD0uOkEIsI1bPrCIxVO12Ao5pABmf+FU5B2TqBr6l2ZjLx3cP5CT6EE+ zYTx6R+5cZhWHTKAjVpWXavljbi/Rtz2tKGjOkvk03a04jJxXcBEjk429xx1HCo5a2ip g3cg== 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:cc: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=gJye9yXKO9EP8MyWmV+AHcdK2ejGXEyzENjD/pahybs=; b=eUfoL7t8duZxOU3b/b0j0tuFhAVm+R/DorKPRxo14N1wafRgFt+JpyRPiq313vL/Ka c/nfWXVPQ9c82CMeh0H/j06b0pnPlGcoalGb21R3VXOb3w3Wi7JYMDHTpyUNd/A24ywS l+gDCvLJdjE4xXnJnvkWXoGXXrobZszBBCQVcw96kf5DLYxrkJW1Ssgr3qQge901H02o 6VVf3B7/E/PqIiyAeQESGYA2pvHBOLqZE53a6GRAVhImdwhPz3m7ypcAGYiTpf8T2D7R 5y81YGnlcIW6mhj5H9ahHlbn+CC8nMs8kWx5NmO8tq5/UWX5xhq3O9l38JTggqG1I4xW OL+w== 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 127-v6si3554551wmu.162.2018.06.14.00.19.40; Thu, 14 Jun 2018 00:19:40 -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 78FB868AEE5; Thu, 14 Jun 2018 10:18:48 +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 8369068AEEC for ; Thu, 14 Jun 2018 10:18:45 +0300 (EEST) Received: from localhost (unknown [202.141.160.96]) by mail (Coremail) with SMTP id QMiowPAxmOEWFiJbbX13AA--.59367S3; Thu, 14 Jun 2018 15:15:34 +0800 (CST) From: Shiyou Yin To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 Jun 2018 15:19:26 +0800 Message-Id: <1528960766-17196-1-git-send-email-yinshiyou-hf@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: QMiowPAxmOEWFiJbbX13AA--.59367S3 X-Coremail-Antispam: 1UD129KBjvJXoWxKF1rWr1rAFW3Jw1kWw4xXrb_yoW7WFy8pr ykCrs0kw1IqFW7CFsxJF48GrnIyF40qF48GFy7KF12yrZ8tr4rXrZ2gry8G3WrGFykCFy3 Zr1DuFy3Ca17u3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvI14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr 1j6rxdM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj 6xIIjxv20xvE14v26r126r1DMcIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr 0_Gr1lF7xvr2IYc2Ij64vIr41lF7xvr2IYc2Ij64vIr40E4x8a64kEw24lF7I21c0EjII2 zVCS5cI20VAGYxC7MxkIecxEwVAFwVW8CwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7x kEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E 67AF67kF1VAFwI0_Jrv_JF1lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20x vEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r4j6FyUMIIF0xvEx4A2jsIE 14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf 9x0JU2-eOUUUUU= X-CM-SenderInfo: p1lq2x5l1r3gtki6z05rqj20fqof0/ Subject: [FFmpeg-devel] [PATCH 5/7] 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 Cc: Shiyou Yin MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Optimize function get_cabac_inline with asm. Change-Id: I67f5e96b30589d925fa13c5a4595f1f2924f17e1 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 */