From patchwork Wed Dec 1 03:52:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyou Yin X-Patchwork-Id: 31858 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp8672838iob; Tue, 30 Nov 2021 19:52:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVtmXb0BwNlzL/9bcm3Gvwg2fW/32ZrLoT+RzAFGhUFRFaYwciqKiz0H/VCf/PB4BdIFyZ X-Received: by 2002:a17:906:794e:: with SMTP id l14mr4164938ejo.64.1638330778944; Tue, 30 Nov 2021 19:52:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638330778; cv=none; d=google.com; s=arc-20160816; b=Z6N1UnQIli5ZZU1OSHQT9eaD5eg+devNg4yjfpoKyFCwmihBDsbZeyexhthjNVd2vB r19vikQGp34QmXHhmYlZ2z85LK5WEEuu1sAKB44uxmGY8dO4R5iynRQoW6sO2acW24eJ dqI/CAfxOpPiouCDLar7q/Dyw1B37PWnxgb5hh7dTDg7x1P7Wi7wedlLkyLuixroZZ6Z /da14wUNhCugdL4hWroleW2+LrqOsyK8HvsAyep46dTTS/+Vj+F2TG3VEZvyKDxKS5/u jR7om1EIPOs+lX1rKvYEhDzxaiwfQEmP3lUga16QHqGmJ9h+CdukZodBlBSiZRqLzTgr sB8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=m5x+4hBXXxfJ8vx+ecTcdDumjWVqPsrjtD4mZVCIL/Y=; b=uMMnmNtWomLaWiWn26dJl/ZvV4YxAT/9XF1GOJQTLreDx64oVCI8+jy0vhMn2WkEwN fmsYGKowqKLtWawvcF6bqSEBCxvl8bBuwiGEwYdXVvQTyuZ0r65mZYZPAHxxHVshqZBh BPLXbiYet0GU5XaAg571VqFQXg0YDuFEeKsq35bCovB70Huxhx6ZTX5bIrgoEx1Cltp3 2a+J8hwgOeoYlBXux4g4O7SmSWBO8Ni2Yq7l8PDYQPA8YNNyPyUD+tYeEIagTehs8y+D v1y1jtZ9xYsAoQFviDMjBPllQO4GccJlwdBgRpuCuRPe2F84u07t8XFuhH59Eg5c31dU cQNA== 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 d11si30192921edn.463.2021.11.30.19.52.58; Tue, 30 Nov 2021 19:52:58 -0800 (PST) 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 55FC768AE71; Wed, 1 Dec 2021 05:52:39 +0200 (EET) 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 9437668A2D8 for ; Wed, 1 Dec 2021 05:52:28 +0200 (EET) Received: from localhost (unknown [36.33.26.144]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dx78p58aZh8_ABAA--.4785S3; Wed, 01 Dec 2021 11:52:25 +0800 (CST) From: Shiyou Yin To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Dec 2021 11:52:19 +0800 Message-Id: <20211201035221.18817-2-yinshiyou-hf@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211201035221.18817-1-yinshiyou-hf@loongson.cn> References: <20211201035221.18817-1-yinshiyou-hf@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf9Dx78p58aZh8_ABAA--.4785S3 X-Coremail-Antispam: 1UD129KBjvJXoW7AFyrKFy8ur1kGry8Jw4rGrg_yoW8Wry5pr 97ZrWfKr48JryfGFsIqas5WFn8JrZ7WFy2qF13Kw1rCa1UAryDZr18GFyqgF1DXan8Cr4Y qr4rG3WUuF4UAFUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkYb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAFwI0_Gr0_Cr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxEwVAFwVW8GwCF04k2 0xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI 8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jr0_JrylIxkGc2Ij64vIr41l IxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIx AIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IUY83ktUUUUU== X-CM-SenderInfo: p1lq2x5l1r3gtki6z05rqj20fqof0/ Subject: [FFmpeg-devel] [PATCH v2 1/3] configure: Add support for loongarch. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: xGlnfTrR57n3 For la464 cpu: ./configure --cpu=la464 With cross-compiler: ./configure --cross-prefix=loongarch64-linux-gnu- \ --enable-cross-compile --arch=loongarch64 \ --target-os=linux --cpu=la464 --- Changelog | 1 + configure | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Changelog b/Changelog index 56faa7f9f5..648079ab64 100644 --- a/Changelog +++ b/Changelog @@ -35,6 +35,7 @@ version : - bitpacked encoder - VideoToolbox VP9 hwaccel - VideoToolbox ProRes hwaccel +- support loongarch. version 4.4: diff --git a/configure b/configure index d8b5be8bbb..aa94c39419 100755 --- a/configure +++ b/configure @@ -2032,6 +2032,9 @@ ARCH_LIST=" avr32_uc bfin ia64 + loongarch + loongarch32 + loongarch64 m68k mips mips64 @@ -4959,6 +4962,9 @@ case "$arch" in arm*|iPad*|iPhone*) arch="arm" ;; + loongarch*) + arch="loongarch" + ;; mips*|IP*) case "$arch" in *el) @@ -5106,6 +5112,18 @@ elif enabled bfin; then cpuflags="-mcpu=$cpu" +elif enabled loongarch; then + + enable local_aligned + enable simd_align_32 + enable fast_64bit + enable fast_clz + enable fast_unaligned + case $cpu in + la464) + cpuflags="-march=$cpu" + ;; + esac elif enabled mips; then if [ "$cpu" != "generic" ]; then @@ -5362,6 +5380,11 @@ case "$arch" in aarch64|alpha|ia64) enabled shared && enable_weak pic ;; + loongarch) + check_64bit loongarch32 loongarch64 + enabled loongarch64 && disable loongarch32 + enabled shared && enable_weak pic + ;; mips) check_64bit mips mips64 '_MIPS_SIM > 1' enabled shared && enable_weak pic From patchwork Wed Dec 1 03:52:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyou Yin X-Patchwork-Id: 31856 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp8672563iob; Tue, 30 Nov 2021 19:52:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyKsNfMan8vGevsiAnXrAKASL7yrFGiNqjfUQsmkras/WT7JCwFP3M8LkV6QSuT3olEue99 X-Received: by 2002:a17:907:2d12:: with SMTP id gs18mr3955882ejc.126.1638330760599; Tue, 30 Nov 2021 19:52:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638330760; cv=none; d=google.com; s=arc-20160816; b=LYycXS8azmp/ESKMLdUAz3S1y+/J+veBXLMS+lSxDCFqrj9jU+N8E+ZEBhKDgoiDDD karQ7F/xJm1Ztep56hBKl65QCU7K1DqgVbn1Zd33WRDdtUxmKJt/dOctJVFvaSmNgxTa MQ/LS1H6cK1dDHHAGSq62HnQzLSKVJaWOf/qoeiOPJ1hWtYPDurj+SIzG9/ZEyPloZYV Rg3nesrp8N1i8nQmrfVmaTf+4JbLh5FpS7MXZu+4dgYGK01u6BlPIBy6oWHiLWrdmDCy 6YdAU6kwHRJxU+SBd71Auj7Hq7lfHXXXkoyHOceTMVpJ4uAXO1PnRNAIpB/Ei4QFQnzP LEcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=cWLq+uytpubalhPA7EySDxzmdyKmroQCiJLLnYupObc=; b=L/3VFFhOcYonh/2uXe01waOFnZDqQv78ZBSUbiBWAdNBrrfEiX913GlSSa5XJTVZ/u X0l6M0m7Y4R6/JntvRSGWbWi7Dw3v2vf3TYcJUsRgc2hl5DO0j//le7ZANW0np2lOXLj lNPrUbIo1+huS9DMx5zoWAQ9F/HvmMCyEU0K4WxJrcQS7EANJ/snJKTTL8ZewhTwTENz oZKPNE5hK6m+9ulBdkmpLNR6H797BAEfBazeq4PvrUwc9Sd9S5qX3S/+C7Ir/Ui1RHgN RalyA5pLBR3psO+aGX5JYwI/w8/f5REyALS82n+KfuZfseWqae8dQHuXzXrVMLv5YsHl yRAg== 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 p20si26712261edt.513.2021.11.30.19.52.40; Tue, 30 Nov 2021 19:52:40 -0800 (PST) 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 B929768A2D8; Wed, 1 Dec 2021 05:52:36 +0200 (EET) 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 9DEA968AD0A for ; Wed, 1 Dec 2021 05:52:28 +0200 (EET) Received: from localhost (unknown [36.33.26.144]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxGsl58aZh9PABAA--.3935S3; Wed, 01 Dec 2021 11:52:25 +0800 (CST) From: Shiyou Yin To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Dec 2021 11:52:20 +0800 Message-Id: <20211201035221.18817-3-yinshiyou-hf@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211201035221.18817-1-yinshiyou-hf@loongson.cn> References: <20211201035221.18817-1-yinshiyou-hf@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf9AxGsl58aZh9PABAA--.3935S3 X-Coremail-Antispam: 1UD129KBjvJXoW3Gr47Aw1fXF17GF1DAF48tFb_yoWftF1kpF y8KrsYyr4SqF47ursxGF48Kr97CF40qr18GFy5tF1jvrs8tr48urWkGryxGF15GFykuFya vF1UZFy3CF17XaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkYb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwV C2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC 0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUAVWUtwAv7VC2z280aVAFwI0_Gr0_Cr 1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxkIecxEwVAFwVW8GwCF04k2 0xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI 8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_Jr0_JrylIxkGc2Ij64vIr41l IxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIx AIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2 jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7IUY83ktUUUUU== X-CM-SenderInfo: p1lq2x5l1r3gtki6z05rqj20fqof0/ Subject: [FFmpeg-devel] [PATCH v2 2/3] avcodec: [loongarch] optimize get_cabac. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HyJXppCh7t/t Decoding 1080P H264 on 2.5Ghz 3A5000: 165fps==>168fps. Testing command: ffmpeg -i ***.mp4 -f rawvideo -y /dev/null -an --- libavcodec/cabac_functions.h | 3 + libavcodec/loongarch/cabac.h | 238 +++++++++++++++++++++++++++++++++++ 2 files changed, 241 insertions(+) create mode 100644 libavcodec/loongarch/cabac.h diff --git a/libavcodec/cabac_functions.h b/libavcodec/cabac_functions.h index 46af921822..2f2d48a8f8 100644 --- a/libavcodec/cabac_functions.h +++ b/libavcodec/cabac_functions.h @@ -49,6 +49,9 @@ #if ARCH_MIPS # include "mips/cabac.h" #endif +#if ARCH_LOONGARCH64 +# include "loongarch/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/loongarch/cabac.h b/libavcodec/loongarch/cabac.h new file mode 100644 index 0000000000..e1c946fe16 --- /dev/null +++ b/libavcodec/loongarch/cabac.h @@ -0,0 +1,238 @@ +/* + * Loongson optimized cabac + * + * Copyright (c) 2020 Loongson Technology Corporation Limited + * Contributed by Shiyou Yin + * Gu Xiwei(guxiwei-hf@loongson.cn) + * + * 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_LOONGARCH_CABAC_H +#define AVCODEC_LOONGARCH_CABAC_H + +#include "libavcodec/cabac.h" +#include "config.h" + +#define GET_CABAC_LOONGARCH_UNCBSR \ + "ld.bu %[bit], %[state], 0x0 \n\t" \ + "andi %[tmp0], %[c_range], 0xC0 \n\t" \ + "slli.d %[tmp0], %[tmp0], 0x01 \n\t" \ + "add.d %[tmp0], %[tmp0], %[tables] \n\t" \ + "add.d %[tmp0], %[tmp0], %[bit] \n\t" \ + /* tmp1: RangeLPS */ \ + "ld.bu %[tmp1], %[tmp0], %[lps_off] \n\t" \ + \ + "sub.d %[c_range], %[c_range], %[tmp1] \n\t" \ + "slli.d %[tmp0], %[c_range], 0x11 \n\t" \ + "bge %[tmp0], %[c_low], 1f \n\t" \ + "move %[c_range], %[tmp1] \n\t" \ + "nor %[bit], %[bit], %[bit] \n\t" \ + "sub.d %[c_low], %[c_low], %[tmp0] \n\t" \ + \ + "1: \n\t" \ + /* tmp1: *state */ \ + "add.d %[tmp0], %[tables], %[bit] \n\t" \ + "ld.bu %[tmp1], %[tmp0], %[mlps_off] \n\t" \ + /* tmp2: lps_mask */ \ + "add.d %[tmp0], %[tables], %[c_range] \n\t" \ + "ld.bu %[tmp2], %[tmp0], %[norm_off] \n\t" \ + \ + "andi %[bit], %[bit], 0x01 \n\t" \ + "st.b %[tmp1], %[state], 0x0 \n\t" \ + "sll.d %[c_range], %[c_range], %[tmp2] \n\t" \ + "sll.d %[c_low], %[c_low], %[tmp2] \n\t" \ + \ + "and %[tmp1], %[c_low], %[cabac_mask] \n\t" \ + "bnez %[tmp1], 1f \n\t" \ + "ld.hu %[tmp1], %[c_bytestream], 0x0 \n\t" \ + "ctz.d %[tmp0], %[c_low] \n\t" \ + "addi.d %[tmp2], %[tmp0], -16 \n\t" \ + "revb.2h %[tmp0], %[tmp1] \n\t" \ + "slli.d %[tmp0], %[tmp0], 0x01 \n\t" \ + "sub.d %[tmp0], %[tmp0], %[cabac_mask] \n\t" \ + "sll.d %[tmp0], %[tmp0], %[tmp2] \n\t" \ + "add.d %[c_low], %[c_low], %[tmp0] \n\t" \ + "addi.d %[c_bytestream], %[c_bytestream], 0x02 \n\t" \ + "1: \n\t" \ + +#define GET_CABAC_LOONGARCH \ + "ld.bu %[bit], %[state], 0x0 \n\t" \ + "andi %[tmp0], %[c_range], 0xC0 \n\t" \ + "slli.d %[tmp0], %[tmp0], 0x01 \n\t" \ + "add.d %[tmp0], %[tmp0], %[tables] \n\t" \ + "add.d %[tmp0], %[tmp0], %[bit] \n\t" \ + /* tmp1: RangeLPS */ \ + "ld.bu %[tmp1], %[tmp0], %[lps_off] \n\t" \ + \ + "sub.d %[c_range], %[c_range], %[tmp1] \n\t" \ + "slli.d %[tmp0], %[c_range], 0x11 \n\t" \ + "bge %[tmp0], %[c_low], 1f \n\t" \ + "move %[c_range], %[tmp1] \n\t" \ + "nor %[bit], %[bit], %[bit] \n\t" \ + "sub.d %[c_low], %[c_low], %[tmp0] \n\t" \ + \ + "1: \n\t" \ + /* tmp1: *state */ \ + "add.d %[tmp0], %[tables], %[bit] \n\t" \ + "ld.bu %[tmp1], %[tmp0], %[mlps_off] \n\t" \ + /* tmp2: lps_mask */ \ + "add.d %[tmp0], %[tables], %[c_range] \n\t" \ + "ld.bu %[tmp2], %[tmp0], %[norm_off] \n\t" \ + \ + "andi %[bit], %[bit], 0x01 \n\t" \ + "st.b %[tmp1], %[state], 0x0 \n\t" \ + "sll.d %[c_range], %[c_range], %[tmp2] \n\t" \ + "sll.d %[c_low], %[c_low], %[tmp2] \n\t" \ + \ + "and %[tmp1], %[c_low], %[cabac_mask] \n\t" \ + "bnez %[tmp1], 1f \n\t" \ + "ld.hu %[tmp1], %[c_bytestream], 0x0 \n\t" \ + "ctz.d %[tmp0], %[c_low] \n\t" \ + "addi.d %[tmp2], %[tmp0], -16 \n\t" \ + "revb.2h %[tmp0], %[tmp1] \n\t" \ + "slli.d %[tmp0], %[tmp0], 0x01 \n\t" \ + "sub.d %[tmp0], %[tmp0], %[cabac_mask] \n\t" \ + "sll.d %[tmp0], %[tmp0], %[tmp2] \n\t" \ + \ + "add.d %[c_low], %[c_low], %[tmp0] \n\t" \ + \ + "slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t" \ + "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t" \ + "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t" \ + "1: \n\t" \ + +#define get_cabac_inline get_cabac_inline_loongarch +static av_always_inline +int get_cabac_inline_loongarch(CABACContext *c, uint8_t * const state) +{ + int64_t tmp0, tmp1, tmp2, bit; + + __asm__ volatile ( +#if UNCHECKED_BITSTREAM_READER + GET_CABAC_LOONGARCH_UNCBSR +#else + GET_CABAC_LOONGARCH +#endif + : [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]"r"(CABAC_MASK) + : "memory" + ); + + return bit; +} + +#define get_cabac_bypass get_cabac_bypass_loongarch +static av_always_inline int get_cabac_bypass_loongarch(CABACContext *c) +{ + int64_t tmp0, tmp1, tmp2; + int res = 0; + __asm__ volatile( + "slli.d %[c_low], %[c_low], 0x01 \n\t" + "and %[tmp0], %[c_low], %[cabac_mask] \n\t" + "bnez %[tmp0], 1f \n\t" + "ld.hu %[tmp1], %[c_bytestream], 0x0 \n\t" +#if UNCHECKED_BITSTREAM_READER + "addi.d %[c_bytestream], %[c_bytestream], 0x02 \n\t" +#else + "slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t" + "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t" + "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t" +#endif + "revb.2h %[tmp1], %[tmp1] \n\t" + "slli.d %[tmp1], %[tmp1], 0x01 \n\t" + "sub.d %[tmp1], %[tmp1], %[cabac_mask] \n\t" + "add.d %[c_low], %[c_low], %[tmp1] \n\t" + "1: \n\t" + "slli.d %[tmp1], %[c_range], 0x11 \n\t" + "slt %[tmp0], %[c_low], %[tmp1] \n\t" + "sub.d %[tmp1], %[c_low], %[tmp1] \n\t" + "masknez %[tmp2], %[one], %[tmp0] \n\t" + "maskeqz %[res], %[res], %[tmp0] \n\t" + "or %[res], %[res], %[tmp2] \n\t" + "masknez %[tmp2], %[tmp1], %[tmp0] \n\t" + "maskeqz %[c_low], %[c_low], %[tmp0] \n\t" + "or %[c_low], %[c_low], %[tmp2] \n\t" + : [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [tmp2]"=&r"(tmp2), + [c_range]"+&r"(c->range), [c_low]"+&r"(c->low), + [c_bytestream]"+&r"(c->bytestream), [res]"+&r"(res) + : [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_loongarch +static av_always_inline +int get_cabac_bypass_sign_loongarch(CABACContext *c, int val) +{ + int64_t tmp0, tmp1; + int res = val; + __asm__ volatile( + "slli.d %[c_low], %[c_low], 0x01 \n\t" + "and %[tmp0], %[c_low], %[cabac_mask] \n\t" + "bnez %[tmp0], 1f \n\t" + "ld.hu %[tmp1], %[c_bytestream], 0x0 \n\t" +#if UNCHECKED_BITSTREAM_READER + "addi.d %[c_bytestream], %[c_bytestream], 0x02 \n\t" +#else + "slt %[tmp0], %[c_bytestream], %[c_bytestream_end] \n\t" + "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t" + "add.d %[c_bytestream], %[c_bytestream], %[tmp0] \n\t" +#endif + "revb.2h %[tmp1], %[tmp1] \n\t" + "slli.d %[tmp1], %[tmp1], 0x01 \n\t" + "sub.d %[tmp1], %[tmp1], %[cabac_mask] \n\t" + "add.d %[c_low], %[c_low], %[tmp1] \n\t" + "1: \n\t" + "slli.d %[tmp1], %[c_range], 0x11 \n\t" + "slt %[tmp0], %[c_low], %[tmp1] \n\t" + "sub.d %[tmp1], %[c_low], %[tmp1] \n\t" + "masknez %[tmp1], %[tmp1], %[tmp0] \n\t" + "maskeqz %[c_low], %[c_low], %[tmp0] \n\t" + "or %[c_low], %[c_low], %[tmp1] \n\t" + "sub.d %[tmp1], %[zero], %[res] \n\t" + "maskeqz %[tmp1], %[tmp1], %[tmp0] \n\t" + "masknez %[res], %[res], %[tmp0] \n\t" + "or %[res], %[res], %[tmp1] \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_LOONGARCH_CABAC_H */ From patchwork Wed Dec 1 03:52:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyou Yin X-Patchwork-Id: 31857 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp8672946iob; Tue, 30 Nov 2021 19:53:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/V4g9yFtMJfgfPKIpKEcWkKPP0iqrClLpMrnDHO6jMgoQka6Wx7/Ea+E3FU1KCAAJrr17 X-Received: by 2002:a17:906:478e:: with SMTP id cw14mr3949232ejc.46.1638330788514; Tue, 30 Nov 2021 19:53:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638330788; cv=none; d=google.com; s=arc-20160816; b=LKfTXXUDWp81RRAeuAeGU6ve3Q3FdUe0+lrZ9M9+lksNMrsa/f3E28nym4vLd4DDRJ sc1lZXOEl1GZVKBvVTHxjVhjGxmRi5v8+qJOd7RL7LgHRIYWXNvViaU5FwL1CW8WiIlQ 91ibfi13bJ0H+UVaIaAf1Bw+WxO3wOYwKBDg901QfSszP/vOTF5ydI8jfIEEwKuFnVf3 MFuFeGrp6xe/Mqiq4kvZ2yuKZc3tU8Y6GRePwLkIvmaeItETpTaqrUZ836jMNbiUt1Mg K+DTVNuU79r7AvNgYZvynYp6CcrwrFC8kQ+IkjvbXcbjgrzrnb/2Suydsh6rhRFsNVK0 oRUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=sduGCcAbMSufCMHGfFgJRx8R0agZZETRU/TJlTHmfEU=; b=gvKNuJPW6GCUBTdVk8rOQjvhrsraDgQfhNLt2FC8kf4APDF6scJUICwe10fbe0Strs 6OoYnd6l5WPtfS8MmfHy1AopO9duv8r9lGeL5oe/nOpKcgsHRfyrp8D35nOm6psD9RIV OdWQr8eFFXVUxtluDfXeNE687r7v00bf1o7KPNty9V3yELBqLoSU1f+dXmFEpmxGLDqL 3jsEBxgjWcO6+sARo+9GTkHgS8jjEFTlQxP79j8pFNCDO9lZFUq/N6sD3Ai5+xTnZMmh teAKlnI0ZSU2f/Df2oJ8zpn5p7XDqZfwikt0ffZLy9SnmxCZ97TyGzHfnfFhXmmatE6n K/8Q== 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 h23si26253248edw.73.2021.11.30.19.53.08; Tue, 30 Nov 2021 19:53:08 -0800 (PST) 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 3A23A68AE87; Wed, 1 Dec 2021 05:52:40 +0200 (EET) 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 ECD0B68AA83 for ; Wed, 1 Dec 2021 05:52:29 +0200 (EET) Received: from localhost (unknown [36.33.26.144]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxv8t78aZh9fABAA--.4592S3; Wed, 01 Dec 2021 11:52:27 +0800 (CST) From: Shiyou Yin To: ffmpeg-devel@ffmpeg.org Date: Wed, 1 Dec 2021 11:52:21 +0800 Message-Id: <20211201035221.18817-4-yinshiyou-hf@loongson.cn> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20211201035221.18817-1-yinshiyou-hf@loongson.cn> References: <20211201035221.18817-1-yinshiyou-hf@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf9Dxv8t78aZh9fABAA--.4592S3 X-Coremail-Antispam: 1UD129KBjvJXoW3JrWUuF18uF47ZF45uw4fAFb_yoWxJF4Dpr WkGws3tw18ta17Cr97GF48GrnrCanYqr15Ka13tFW2k3yDJ3y8WFZF9FyxWFyrGF97Cry3 ur1jk3Wa9F17Xr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkq14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc2xSY4AK67AK6r48 MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr 0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUXVWUAwCIc40Y0x0E wIxGrwCI42IY6xIIjxv20xvE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJV W8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAI cVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUUhID5UUUUU== X-CM-SenderInfo: p1lq2x5l1r3gtki6z05rqj20fqof0/ Subject: [FFmpeg-devel] [PATCH v2 3/3] avcodec: [loongarch] Optimize decode_significance/_8x8_loongarch. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Hao Chen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: noANCeR1jFP9 From: Hao Chen Decoding 1080P H264 from 168fps to 170fps. Signed-off-by: Shiyou Yin --- libavcodec/h264_cabac.c | 2 + libavcodec/loongarch/h264_cabac.c | 140 ++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 libavcodec/loongarch/h264_cabac.c diff --git a/libavcodec/h264_cabac.c b/libavcodec/h264_cabac.c index 973b3419c4..040fa0a257 100644 --- a/libavcodec/h264_cabac.c +++ b/libavcodec/h264_cabac.c @@ -42,6 +42,8 @@ #if ARCH_X86 #include "x86/h264_cabac.c" +#elif ARCH_LOONGARCH64 +#include "loongarch/h264_cabac.c" #endif /* Cabac pre state table */ diff --git a/libavcodec/loongarch/h264_cabac.c b/libavcodec/loongarch/h264_cabac.c new file mode 100644 index 0000000000..d88743bed7 --- /dev/null +++ b/libavcodec/loongarch/h264_cabac.c @@ -0,0 +1,140 @@ +/* + * Loongson optimized cabac + * + * Copyright (c) 2021 Loongson Technology Corporation Limited + * Contributed by Hao Chen + * + * 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/cabac.h" +#include "cabac.h" + +#define decode_significance decode_significance_loongarch +static int decode_significance_loongarch(CABACContext *c, int max_coeff, + uint8_t *significant_coeff_ctx_base, int *index, int64_t last_off) +{ + void *end = significant_coeff_ctx_base + max_coeff - 1; + int64_t minusstart = -(int64_t)significant_coeff_ctx_base; + int64_t minusindex = 4 - (int64_t)index; + int64_t bit, tmp0, tmp1, tmp2, one = 1; + uint8_t *state = significant_coeff_ctx_base; + + __asm__ volatile( + "3:" +#if UNCHECKED_BITSTREAM_READER + GET_CABAC_LOONGARCH_UNCBSR +#else + GET_CABAC_LOONGARCH +#endif + "blt %[bit], %[one], 4f \n\t" + "add.d %[state], %[state], %[last_off] \n\t" +#if UNCHECKED_BITSTREAM_READER + GET_CABAC_LOONGARCH_UNCBSR +#else + GET_CABAC_LOONGARCH +#endif + "sub.d %[state], %[state], %[last_off] \n\t" + "add.d %[tmp0], %[state], %[minusstart] \n\t" + "st.w %[tmp0], %[index], 0 \n\t" + "bge %[bit], %[one], 5f \n\t" + "addi.d %[index], %[index], 4 \n\t" + "4: \n\t" + "addi.d %[state], %[state], 1 \n\t" + "blt %[state], %[end], 3b \n\t" + "add.d %[tmp0], %[state], %[minusstart] \n\t" + "st.w %[tmp0], %[index], 0 \n\t" + "5: \n\t" + "add.d %[tmp0], %[index], %[minusindex] \n\t" + "srli.d %[tmp0], %[tmp0], 2 \n\t" + : [bit]"=&r"(bit), [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), [tmp2]"=&r"(tmp2), + [c_range]"+&r"(c->range), [c_low]"+&r"(c->low), [state]"+&r"(state), + [c_bytestream]"+&r"(c->bytestream), [index]"+&r"(index) + : [tables]"r"(ff_h264_cabac_tables), [end]"r"(end), [one]"r"(one), + [minusstart]"r"(minusstart), [minusindex]"r"(minusindex), + [last_off]"r"(last_off), +#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]"r"(CABAC_MASK) + : "memory" + ); + + return (int)tmp0; +} + +#define decode_significance_8x8 decode_significance_8x8_loongarch +static int decode_significance_8x8_loongarch( + CABACContext *c, uint8_t *significant_coeff_ctx_base, + int *index, uint8_t *last_coeff_ctx_base, const uint8_t *sig_off) +{ + int64_t minusindex = 4 - (int64_t)index; + int64_t bit, tmp0, tmp1, tmp2, one = 1, end = 63, last = 0; + uint8_t *state = 0; + int64_t flag_offset = H264_LAST_COEFF_FLAG_OFFSET_8x8_OFFSET; + + __asm__ volatile( + "3: \n\t" + "ldx.bu %[tmp0], %[sig_off], %[last] \n\t" + "add.d %[state], %[tmp0], %[significant_coeff_ctx_base] \n\t" +#if UNCHECKED_BITSTREAM_READER + GET_CABAC_LOONGARCH_UNCBSR +#else + GET_CABAC_LOONGARCH +#endif + "blt %[bit], %[one], 4f \n\t" + "add.d %[tmp0], %[tables], %[flag_offset] \n\t" + "ldx.bu %[tmp1], %[tmp0], %[last] \n\t" + "add.d %[state], %[tmp1], %[last_coeff_ctx_base] \n\t" +#if UNCHECKED_BITSTREAM_READER + GET_CABAC_LOONGARCH_UNCBSR +#else + GET_CABAC_LOONGARCH +#endif + "st.w %[last], %[index], 0 \n\t" + "bge %[bit], %[one], 5f \n\t" + "addi.d %[index], %[index], 4 \n\t" + "4: \n\t" + "addi.d %[last], %[last], 1 \n\t" + "blt %[last], %[end], 3b \n\t" + "st.w %[last], %[index], 0 \n\t" + "5: \n\t" + "add.d %[tmp0], %[index], %[minusindex] \n\t" + "srli.d %[tmp0], %[tmp0], 2 \n\t" + : [bit]"=&r"(bit), [tmp0]"=&r"(tmp0), [tmp1]"=&r"(tmp1), + [tmp2]"=&r"(tmp2), [c_range]"+&r"(c->range), + [c_low]"+&r"(c->low), [state]"+&r"(state), [last]"+&r"(last), + [c_bytestream]"+&r"(c->bytestream), [index]"+&r"(index) + : [tables]"r"(ff_h264_cabac_tables), [end]"r"(end), + [one]"r"(one), [minusindex]"r"(minusindex), + [last_coeff_ctx_base]"r"(last_coeff_ctx_base), + [flag_offset]"r"(flag_offset), +#if !UNCHECKED_BITSTREAM_READER + [c_bytestream_end]"r"(c->bytestream_end), +#endif + [lps_off]"i"(H264_LPS_RANGE_OFFSET), [sig_off]"r"(sig_off), + [mlps_off]"i"(H264_MLPS_STATE_OFFSET + 128), + [norm_off]"i"(H264_NORM_SHIFT_OFFSET), + [cabac_mask]"r"(CABAC_MASK), + [significant_coeff_ctx_base]"r"(significant_coeff_ctx_base) + ); + + return (int)tmp0; +}