From patchwork Tue May 26 09:48:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 19871 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 E0D504495FF for ; Tue, 26 May 2020 12:49:27 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C878E68A4D4; Tue, 26 May 2020 12:49:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from sender2-op-o12.zoho.com.cn (sender2-op-o12.zoho.com.cn [163.53.93.243]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 37C55680ADB for ; Tue, 26 May 2020 12:49:18 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; t=1590486541; cv=none; d=zoho.com.cn; s=zohoarc; b=NVWKuXHiynILToReVUHIFwCJ4fa/exKQfEghyKLLYHqRwzmmN2AcifUyWBgOS0hHNzQzB6MdKa1LLHH3JASU2MNvLfn+KjH0O0Q7A9fT+STke3pI7jA2NP/FJSSJxyfiJi0dEvX+DXV7K4g1S4jRDxeulhkZqWCFUYAXRhWgyT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com.cn; s=zohoarc; t=1590486541; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=776ABoDI53Smb3q6iebMTjxBWz7lUS6GqHbxsewqaNc=; b=i1y4VNsTY2fKq5PASUldo1+3EqMQLTQdyShjxBRCGx5URFkAYCXpb+Pxq7vQDjFkGUYrOombjBr/F+iRkvbaCxLu8A6wJZkDaeerCx/Hog2KiJTqCinqzcS/VZz2NXek3180piyJOmcujOw2quOvtHWdDz6XzqxQmr7ffUBuoDw= ARC-Authentication-Results: i=1; mx.zoho.com.cn; dkim=pass header.i=flygoat.com; spf=pass smtp.mailfrom=jiaxun.yang@flygoat.com; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1590486541; s=mail; d=flygoat.com; i=jiaxun.yang@flygoat.com; h=From:To:Cc:Message-ID:Subject:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type; bh=776ABoDI53Smb3q6iebMTjxBWz7lUS6GqHbxsewqaNc=; b=epVBAXn3nLw8FHze3fm0N5Ahxt1fmkfMfZH38wYEju/ItodaaykLqeDfiI7qTpWF ipQntY/iycXdgoIMNsNqfxec99fYPpK6ZvnDTuBqUH1gvmQOuALkp7E51bb8eKkqPv7 32wcNmAKbPxK+qNMyQOIFJx45hwCj8sXccwob/ng= Received: from halation.202.net.flygoat.com (60.177.188.90 [60.177.188.90]) by mx.zoho.com.cn with SMTPS id 159048653926717.736906608589834; Tue, 26 May 2020 17:48:59 +0800 (CST) From: Jiaxun Yang To: ffmpeg-devel@ffmpeg.org Message-ID: <20200526094822.72855-2-jiaxun.yang@flygoat.com> Date: Tue, 26 May 2020 17:48:20 +0800 X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526094822.72855-1-jiaxun.yang@flygoat.com> References: <20200526094822.72855-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 X-ZohoCNMailClient: External Subject: [FFmpeg-devel] [PATCH 1/3] ffbuild: Refine MIPS handling 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: yinshiyou@loongson.cn, Jiaxun Yang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" To enable runtime detection for MIPS, we need to refine ffbuild part to support buildding these feature together. Firstly, we fixed configure, let it probe native ability of toolchain to decide wether a feature can to be enabled, also clearly marked the conflictions between loongson2 & loongson3 and Release 6 & rest. Secondly, we compile MMI and MSA C sources with their own flags to ensure their flags won't pollute the whole program and generate illegal code. Signed-off-by: Jiaxun Yang --- configure | 179 +++++++++++++++++++++++---------------- ffbuild/common.mak | 10 ++- libavcodec/mips/Makefile | 3 +- 3 files changed, 117 insertions(+), 75 deletions(-) diff --git a/configure b/configure index f97cad0298..8dc3874642 100755 --- a/configure +++ b/configure @@ -1113,6 +1113,26 @@ void foo(void){ __asm__ volatile($code); } EOF } +check_extra_inline_asm_flags(){ + log check_extra_inline_asm_flags "$@" + name="$1" + extra=$2 + code="$3" + flags='' + shift 3 + while [ "$1" != "" ]; do + append flags $1 + shift + done; + disable $name + cat > $TMPC < X-Patchwork-Id: 19873 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 CC0884495FF for ; Tue, 26 May 2020 12:49:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AE23B68A777; Tue, 26 May 2020 12:49:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from sender2-op-o12.zoho.com.cn (sender2-op-o12.zoho.com.cn [163.53.93.243]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 613E86898BD for ; Tue, 26 May 2020 12:49:32 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; t=1590486541; cv=none; d=zoho.com.cn; s=zohoarc; b=k8BuuzHTfmenYitqIjI6Fm2CbA8NF94G/L+9EWb0s0/Z1wYQtQisYK1qAZ/1V+2nm6oUhrXEH69CQmuAjRaNhIL/uxqVoez1Jz2mzNvW6p94gYKQTPBrK+zGyzaW7G0Jic0GkhD1yOa7WTEluTQY1aU3Bl4WiVbc79fsrUkrhw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com.cn; s=zohoarc; t=1590486541; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=ywQEGvHrvFmBEX/IyiBJiw52O5FAvd/vXhqPVpj3Jqw=; b=c6NFqEup/jhBfRFPw5MeZvjukjoHLWrg1uR5qPXPmjgtVkYn6Sv1pyrB8m62KNJ/1M6FKyGeJv9puzuZts6ECZ3uzvKf0+1GWTXGBVMPEbs2gUL0VKdTiLjQ3SjNLkxB/G6gGFnkJNLOETgRln5lc5Ge3m6ZDlnJsHrpUwdkLO4= ARC-Authentication-Results: i=1; mx.zoho.com.cn; dkim=pass header.i=flygoat.com; spf=pass smtp.mailfrom=jiaxun.yang@flygoat.com; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1590486541; s=mail; d=flygoat.com; i=jiaxun.yang@flygoat.com; h=From:To:Cc:Message-ID:Subject:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type; bh=ywQEGvHrvFmBEX/IyiBJiw52O5FAvd/vXhqPVpj3Jqw=; b=XYZvcd3W+ZFYqpySEr9luSUECptJP7kubmApyriEW99v1ZqAE2szzHhCfg8QaXam BED9v/tYv+a2gMM7upEUKxtP5We22TqxIYJDTTWeMjGABD7sgnBzUVjhI7uSy3Xeues zm6RjNAU56FubtU08EFkds4bUEz/E20LWdGhiar0= Received: from halation.202.net.flygoat.com (60.177.188.90 [60.177.188.90]) by mx.zoho.com.cn with SMTPS id 1590486539712131.7551760499813; Tue, 26 May 2020 17:48:59 +0800 (CST) From: Jiaxun Yang To: ffmpeg-devel@ffmpeg.org Message-ID: <20200526094822.72855-3-jiaxun.yang@flygoat.com> Date: Tue, 26 May 2020 17:48:21 +0800 X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526094822.72855-1-jiaxun.yang@flygoat.com> References: <20200526094822.72855-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 X-ZohoCNMailClient: External Subject: [FFmpeg-devel] [PATCH 2/3] libavutil: Detect MMI and MSA flags for 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 Cc: yinshiyou@loongson.cn, Jiaxun Yang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Add MMI & MSA runtime detection for MIPS. Currently it's based on cpuinfo but in future we should consider to use CPUCFG instruction. Signed-off-by: Jiaxun Yang --- libavutil/cpu.c | 10 +++++ libavutil/cpu.h | 3 ++ libavutil/cpu_internal.h | 2 + libavutil/mips/Makefile | 2 +- libavutil/mips/cpu.c | 78 +++++++++++++++++++++++++++++++++++++++ libavutil/mips/cpu.h | 28 ++++++++++++++ libavutil/tests/cpu.c | 3 ++ tests/checkasm/checkasm.c | 3 ++ 8 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 libavutil/mips/cpu.c create mode 100644 libavutil/mips/cpu.h diff --git a/libavutil/cpu.c b/libavutil/cpu.c index 6548cc3042..52f6b9a3bf 100644 --- a/libavutil/cpu.c +++ b/libavutil/cpu.c @@ -51,6 +51,8 @@ static atomic_int cpu_flags = ATOMIC_VAR_INIT(-1); static int get_cpu_flags(void) { + if (ARCH_MIPS) + return ff_get_cpu_flags_mips(); if (ARCH_AARCH64) return ff_get_cpu_flags_aarch64(); if (ARCH_ARM) @@ -169,6 +171,9 @@ int av_parse_cpu_flags(const char *s) { "armv8", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV8 }, .unit = "flags" }, { "neon", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON }, .unit = "flags" }, { "vfp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP }, .unit = "flags" }, +#elif ARCH_MIPS + { "mmi", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMI }, .unit = "flags" }, + { "msa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MSA }, .unit = "flags" }, #endif { NULL }, }; @@ -250,6 +255,9 @@ int av_parse_cpu_caps(unsigned *flags, const char *s) { "armv8", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_ARMV8 }, .unit = "flags" }, { "neon", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_NEON }, .unit = "flags" }, { "vfp", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_VFP }, .unit = "flags" }, +#elif ARCH_MIPS + { "mmi", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MMI }, .unit = "flags" }, + { "msa", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_MSA }, .unit = "flags" }, #endif { NULL }, }; @@ -308,6 +316,8 @@ int av_cpu_count(void) size_t av_cpu_max_align(void) { + if (ARCH_MIPS) + return ff_get_cpu_max_align_mips(); if (ARCH_AARCH64) return ff_get_cpu_max_align_aarch64(); if (ARCH_ARM) diff --git a/libavutil/cpu.h b/libavutil/cpu.h index 8bb9eb606b..83099dd969 100644 --- a/libavutil/cpu.h +++ b/libavutil/cpu.h @@ -71,6 +71,9 @@ #define AV_CPU_FLAG_VFP_VM (1 << 7) ///< VFPv2 vector mode, deprecated in ARMv7-A and unavailable in various CPUs implementations #define AV_CPU_FLAG_SETEND (1 <<16) +#define AV_CPU_FLAG_MMI (1 << 0) +#define AV_CPU_FLAG_MSA (1 << 1) + /** * Return the flags which specify extensions supported by the CPU. * The returned value is affected by av_force_cpu_flags() if that was used diff --git a/libavutil/cpu_internal.h b/libavutil/cpu_internal.h index 37122d1c5f..889764320b 100644 --- a/libavutil/cpu_internal.h +++ b/libavutil/cpu_internal.h @@ -41,11 +41,13 @@ #define CPUEXT_FAST(flags, cpuext) CPUEXT_SUFFIX_FAST(flags, , cpuext) #define CPUEXT_SLOW(flags, cpuext) CPUEXT_SUFFIX_SLOW(flags, , cpuext) +int ff_get_cpu_flags_mips(void); int ff_get_cpu_flags_aarch64(void); int ff_get_cpu_flags_arm(void); int ff_get_cpu_flags_ppc(void); int ff_get_cpu_flags_x86(void); +size_t ff_get_cpu_max_align_mips(void); size_t ff_get_cpu_max_align_aarch64(void); size_t ff_get_cpu_max_align_arm(void); size_t ff_get_cpu_max_align_ppc(void); diff --git a/libavutil/mips/Makefile b/libavutil/mips/Makefile index dbfa5aa341..5f8c9b64e9 100644 --- a/libavutil/mips/Makefile +++ b/libavutil/mips/Makefile @@ -1 +1 @@ -OBJS += mips/float_dsp_mips.o +OBJS += mips/float_dsp_mips.o mips/cpu.o diff --git a/libavutil/mips/cpu.c b/libavutil/mips/cpu.c new file mode 100644 index 0000000000..83f7322132 --- /dev/null +++ b/libavutil/mips/cpu.c @@ -0,0 +1,78 @@ +/* + * 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 "libavutil/cpu.h" +#include "libavutil/cpu_internal.h" +#include "config.h" +#if defined __linux__ || defined __ANDROID__ +#include +#include +#include +#include "libavutil/avstring.h" +#endif + +int ff_get_cpu_flags_mips(void) +{ +#if defined __linux__ || defined __ANDROID__ + FILE *f = fopen("/proc/cpuinfo", "r"); + char buf[200]; + int flags = 0; + + if (!f) + return -1; + + while (fgets(buf, sizeof(buf), f)) { + /* Legacy kernel may not export MMI in ASEs implemented */ + if (av_strstart(buf, "cpu model", NULL)) { + if (strstr(buf, "Loongson-3 ")) + flags |= AV_CPU_FLAG_MMI; + } + + if (av_strstart(buf, "ASEs implemented", NULL)) { + if (strstr(buf, " loongson-mmi")) + flags |= AV_CPU_FLAG_MMI; + if (strstr(buf, " msa")) + flags |= AV_CPU_FLAG_MSA; + + break; + } + } + fclose(f); + return flags; +#else + /* Assume no SIMD ASE supported */ + return 0; +#endif +} + +size_t ff_get_cpu_max_align_mips(void) +{ + int flags = av_get_cpu_flags(); + + if (flags & AV_CPU_FLAG_MSA) + return 16; + + /* + * MMI itself is 64-bit but quad word load & store + * needs 128-bit align. + */ + if (flags & AV_CPU_FLAG_MMI) + return 16; + + return 8; +} diff --git a/libavutil/mips/cpu.h b/libavutil/mips/cpu.h new file mode 100644 index 0000000000..615dc49759 --- /dev/null +++ b/libavutil/mips/cpu.h @@ -0,0 +1,28 @@ +/* + * 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 AVUTIL_MIPS_CPU_H +#define AVUTIL_MIPS_CPU_H + +#include "libavutil/cpu.h" +#include "libavutil/cpu_internal.h" + +#define have_mmi(flags) CPUEXT(flags, MMI) +#define have_msa(flags) CPUEXT(flags, MSA) + +#endif /* AVUTIL_MIPS_CPU_H */ diff --git a/libavutil/tests/cpu.c b/libavutil/tests/cpu.c index ce45b715a0..c853371fb3 100644 --- a/libavutil/tests/cpu.c +++ b/libavutil/tests/cpu.c @@ -49,6 +49,9 @@ static const struct { { AV_CPU_FLAG_SETEND, "setend" }, #elif ARCH_PPC { AV_CPU_FLAG_ALTIVEC, "altivec" }, +#elif ARCH_MIPS + { AV_CPU_FLAG_MMI, "mmi" }, + { AV_CPU_FLAG_MSA, "msa" }, #elif ARCH_X86 { AV_CPU_FLAG_MMX, "mmx" }, { AV_CPU_FLAG_MMXEXT, "mmxext" }, diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index 899f68bb32..b3ac76c325 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -213,6 +213,9 @@ static const struct { { "ALTIVEC", "altivec", AV_CPU_FLAG_ALTIVEC }, { "VSX", "vsx", AV_CPU_FLAG_VSX }, { "POWER8", "power8", AV_CPU_FLAG_POWER8 }, +#elif ARCH_MIPS + { "MMI", "mmi", AV_CPU_FLAG_MMI }, + { "MSA", "msa", AV_CPU_FLAG_MSA }, #elif ARCH_X86 { "MMX", "mmx", AV_CPU_FLAG_MMX|AV_CPU_FLAG_CMOV }, { "MMXEXT", "mmxext", AV_CPU_FLAG_MMXEXT }, From patchwork Tue May 26 09:48:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 19872 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 0DB1E4495FF for ; Tue, 26 May 2020 12:49:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EB4A568A9F0; Tue, 26 May 2020 12:49:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from sender2-op-o12.zoho.com.cn (sender2-op-o12.zoho.com.cn [163.53.93.243]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9E75668A71D for ; Tue, 26 May 2020 12:49:24 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; t=1590486542; cv=none; d=zoho.com.cn; s=zohoarc; b=fA++xTfCyzVbkJJp5BpU01o9JzDKr1Wl0w2MQba+9qI8xYd1y1PnfR8kKbC+zCr/C16I8Cgn017XC6BQVPQWOweL86vXKIZIjab7eM+9Myd6kY998NFfwcxyhYUWDnsIlxyigSv9koe5Xf4RHZBuz8B9yDNv7w4Vne75huzxcak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com.cn; s=zohoarc; t=1590486542; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=RfI5Ha/O6IPf/Z37z+qRYQASDfPbEo7vsUfJmWCa5DY=; b=G2RIAarm41FTVULw9DWBi3o5Phc2ex4ZnVvYDMPQK0yZ9NPRZaOvZ5f7G99Pg437zAvYmm9KZHExmA3PpzYkEriG9zdx+AqzYDvfEXFwrtUn6uaFAmGDJIl2vX0K3YWntQtep1j/8vMS6+6dnjCg1jVehqlRiwtCTyjeSzKFB/w= ARC-Authentication-Results: i=1; mx.zoho.com.cn; dkim=pass header.i=flygoat.com; spf=pass smtp.mailfrom=jiaxun.yang@flygoat.com; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1590486542; s=mail; d=flygoat.com; i=jiaxun.yang@flygoat.com; h=From:To:Cc:Message-ID:Subject:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type; bh=RfI5Ha/O6IPf/Z37z+qRYQASDfPbEo7vsUfJmWCa5DY=; b=OGGXCjNBMQSOMVgwIyNUKCUActaITrK5hdUwTBnqrhyxSUs2sVPwxt8f/w0Lq6ss eDTuGj6sc+yxQhzcudLdlTfV0DT8yp34pOYxduUL2OPznPzibilqcoUh6pzEKH0rG+g Sj2jybAO31I2G0Aq2fxjTeOGUE2uaooGNUD95IbE= Received: from halation.202.net.flygoat.com (60.177.188.90 [60.177.188.90]) by mx.zoho.com.cn with SMTPS id 159048654010597.65316090623651; Tue, 26 May 2020 17:49:00 +0800 (CST) From: Jiaxun Yang To: ffmpeg-devel@ffmpeg.org Message-ID: <20200526094822.72855-4-jiaxun.yang@flygoat.com> Date: Tue, 26 May 2020 17:48:22 +0800 X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200526094822.72855-1-jiaxun.yang@flygoat.com> References: <20200526094822.72855-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 X-ZohoCNMailClient: External Subject: [FFmpeg-devel] [PATCH 3/3] libavcodec: Enable runtime detection for MIPS MMI & MSA 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: yinshiyou@loongson.cn, Jiaxun Yang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Apply optimized functions according to cpuflags. MSA is always put after MMI as it's usually faster than MMI. Signed-off-by: Jiaxun Yang --- libavcodec/mips/blockdsp_init_mips.c | 22 +++++++++++++----- libavcodec/mips/cabac.h | 2 +- libavcodec/mips/h263dsp_init_mips.c | 12 +++++++--- libavcodec/mips/h264chroma_init_mips.c | 22 +++++++++++++----- libavcodec/mips/h264dsp_init_mips.c | 25 ++++++++++++++++----- libavcodec/mips/h264pred_init_mips.c | 25 ++++++++++++++++----- libavcodec/mips/h264qpel_init_mips.c | 22 +++++++++++++----- libavcodec/mips/hevcdsp_init_mips.c | 24 +++++++++++++++----- libavcodec/mips/hevcpred_init_mips.c | 12 +++++++--- libavcodec/mips/hpeldsp_init_mips.c | 22 +++++++++++++----- libavcodec/mips/idctdsp_init_mips.c | 24 +++++++++++++++----- libavcodec/mips/me_cmp_init_mips.c | 12 +++++++--- libavcodec/mips/mpegvideo_init_mips.c | 22 +++++++++++++----- libavcodec/mips/mpegvideoencdsp_init_mips.c | 13 ++++++++--- libavcodec/mips/pixblockdsp_init_mips.c | 25 ++++++++++++++++----- libavcodec/mips/qpeldsp_init_mips.c | 12 +++++++--- libavcodec/mips/vc1dsp_init_mips.c | 22 +++++++++++++----- libavcodec/mips/videodsp_init.c | 12 +++++++--- libavcodec/mips/vp3dsp_init_mips.c | 22 +++++++++++++----- libavcodec/mips/vp8dsp_init_mips.c | 22 +++++++++++++----- libavcodec/mips/vp9dsp_init_mips.c | 22 +++++++++++++----- libavcodec/mips/wmv2dsp_init_mips.c | 12 +++++++--- libavcodec/mips/xvididct_init_mips.c | 13 ++++++++--- 23 files changed, 312 insertions(+), 109 deletions(-) diff --git a/libavcodec/mips/blockdsp_init_mips.c b/libavcodec/mips/blockdsp_init_mips.c index 55ac1c3e99..47170c17ef 100644 --- a/libavcodec/mips/blockdsp_init_mips.c +++ b/libavcodec/mips/blockdsp_init_mips.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "blockdsp_mips.h" #if HAVE_MSA @@ -30,6 +31,10 @@ static av_cold void blockdsp_init_msa(BlockDSPContext *c) c->fill_block_tab[0] = ff_fill_block16_msa; c->fill_block_tab[1] = ff_fill_block8_msa; } +#else +static av_cold void blockdsp_init_msa(BlockDSPContext *c) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -41,14 +46,19 @@ static av_cold void blockdsp_init_mmi(BlockDSPContext *c) c->fill_block_tab[0] = ff_fill_block16_mmi; c->fill_block_tab[1] = ff_fill_block8_mmi; } +#else +static av_cold void blockdsp_init_mmi(BlockDSPContext *c) +{ +} #endif /* HAVE_MMI */ void ff_blockdsp_init_mips(BlockDSPContext *c) { -#if HAVE_MMI - blockdsp_init_mmi(c); -#endif /* HAVE_MMI */ -#if HAVE_MSA - blockdsp_init_msa(c); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + blockdsp_init_mmi(c); + + if (have_msa(cpu_flags)) + blockdsp_init_msa(c); } diff --git a/libavcodec/mips/cabac.h b/libavcodec/mips/cabac.h index 03b5010edc..c595915eda 100644 --- a/libavcodec/mips/cabac.h +++ b/libavcodec/mips/cabac.h @@ -25,7 +25,7 @@ #define AVCODEC_MIPS_CABAC_H #include "libavcodec/cabac.h" -#include "libavutil/mips/mmiutils.h" +#include "libavutil/mips/asmdefs.h" #include "config.h" #define get_cabac_inline get_cabac_inline_mips diff --git a/libavcodec/mips/h263dsp_init_mips.c b/libavcodec/mips/h263dsp_init_mips.c index 09bd93707d..b88b76368b 100644 --- a/libavcodec/mips/h263dsp_init_mips.c +++ b/libavcodec/mips/h263dsp_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "h263dsp_mips.h" #if HAVE_MSA @@ -26,11 +27,16 @@ static av_cold void h263dsp_init_msa(H263DSPContext *c) c->h263_h_loop_filter = ff_h263_h_loop_filter_msa; c->h263_v_loop_filter = ff_h263_v_loop_filter_msa; } +#else +static av_cold void h263dsp_init_msa(H263DSPContext *c) +{ +} #endif // #if HAVE_MSA av_cold void ff_h263dsp_init_mips(H263DSPContext *c) { -#if HAVE_MSA - h263dsp_init_msa(c); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_msa(cpu_flags)) + h263dsp_init_msa(c); } diff --git a/libavcodec/mips/h264chroma_init_mips.c b/libavcodec/mips/h264chroma_init_mips.c index ae817e47ae..84d335da59 100644 --- a/libavcodec/mips/h264chroma_init_mips.c +++ b/libavcodec/mips/h264chroma_init_mips.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "h264chroma_mips.h" #if HAVE_MSA @@ -36,6 +37,10 @@ static av_cold void h264chroma_init_msa(H264ChromaContext *c, int bit_depth) c->avg_h264_chroma_pixels_tab[2] = ff_avg_h264_chroma_mc2_msa; } } +#else +static av_cold void h264chroma_init_msa(H264ChromaContext *c, int bit_depth) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -50,14 +55,19 @@ static av_cold void h264chroma_init_mmi(H264ChromaContext *c, int bit_depth) c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_mmi; } } +#else +static av_cold void h264chroma_init_mmi(H264ChromaContext *c, int bit_depth) +{ +} #endif /* HAVE_MMI */ av_cold void ff_h264chroma_init_mips(H264ChromaContext *c, int bit_depth) { -#if HAVE_MMI - h264chroma_init_mmi(c, bit_depth); -#endif /* HAVE_MMI */ -#if HAVE_MSA - h264chroma_init_msa(c, bit_depth); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + h264chroma_init_mmi(c, bit_depth); + + if (have_msa(cpu_flags)) + h264chroma_init_msa(c, bit_depth); } diff --git a/libavcodec/mips/h264dsp_init_mips.c b/libavcodec/mips/h264dsp_init_mips.c index dc08a25800..7b89cfc393 100644 --- a/libavcodec/mips/h264dsp_init_mips.c +++ b/libavcodec/mips/h264dsp_init_mips.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "h264dsp_mips.h" #if HAVE_MSA @@ -79,6 +80,12 @@ static av_cold void h264dsp_init_msa(H264DSPContext *c, c->h264_luma_dc_dequant_idct = ff_h264_deq_idct_luma_dc_msa; } // if (8 == bit_depth) } +#else +static av_cold void h264dsp_init_msa(H264DSPContext *c, + const int bit_depth, + const int chroma_format_idc) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -133,15 +140,21 @@ static av_cold void h264dsp_init_mmi(H264DSPContext * c, const int bit_depth, c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_mmi; } } +#else +static av_cold void h264dsp_init_mmi(H264DSPContext * c, const int bit_depth, + const int chroma_format_idc) +{ +} #endif /* HAVE_MMI */ av_cold void ff_h264dsp_init_mips(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) { -#if HAVE_MMI - h264dsp_init_mmi(c, bit_depth, chroma_format_idc); -#endif /* HAVE_MMI */ -#if HAVE_MSA - h264dsp_init_msa(c, bit_depth, chroma_format_idc); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + h264dsp_init_mmi(c, bit_depth, chroma_format_idc); + + if (have_msa(cpu_flags)) + h264dsp_init_msa(c, bit_depth, chroma_format_idc); } diff --git a/libavcodec/mips/h264pred_init_mips.c b/libavcodec/mips/h264pred_init_mips.c index e537ad8bd4..633d157b50 100644 --- a/libavcodec/mips/h264pred_init_mips.c +++ b/libavcodec/mips/h264pred_init_mips.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "config.h" #include "h264dsp_mips.h" #include "h264pred_mips.h" @@ -91,6 +92,12 @@ static av_cold void h264_pred_init_msa(H264PredContext *h, int codec_id, h->pred16x16[DC_128_PRED8x8] = ff_h264_intra_pred_dc_128_16x16_msa; } } +#else +static av_cold void h264_pred_init_msa(H264PredContext *h, int codec_id, + const int bit_depth, + const int chroma_format_idc) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -137,16 +144,22 @@ static av_cold void h264_pred_init_mmi(H264PredContext *h, int codec_id, } } } +#else +static av_cold void h264_pred_init_mmi(H264PredContext *h, int codec_id, + const int bit_depth, const int chroma_format_idc) +{ +} #endif /* HAVE_MMI */ av_cold void ff_h264_pred_init_mips(H264PredContext *h, int codec_id, int bit_depth, const int chroma_format_idc) { -#if HAVE_MMI - h264_pred_init_mmi(h, codec_id, bit_depth, chroma_format_idc); -#endif /* HAVE_MMI */ -#if HAVE_MSA - h264_pred_init_msa(h, codec_id, bit_depth, chroma_format_idc); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + h264_pred_init_mmi(h, codec_id, bit_depth, chroma_format_idc); + + if (have_msa(cpu_flags)) + h264_pred_init_msa(h, codec_id, bit_depth, chroma_format_idc); } diff --git a/libavcodec/mips/h264qpel_init_mips.c b/libavcodec/mips/h264qpel_init_mips.c index 33bae3093a..c1d584b14b 100644 --- a/libavcodec/mips/h264qpel_init_mips.c +++ b/libavcodec/mips/h264qpel_init_mips.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "h264dsp_mips.h" #if HAVE_MSA @@ -127,6 +128,10 @@ static av_cold void h264qpel_init_msa(H264QpelContext *c, int bit_depth) c->avg_h264_qpel_pixels_tab[2][15] = ff_avg_h264_qpel4_mc33_msa; } } +#else +static av_cold void h264qpel_init_msa(H264QpelContext *c, int bit_depth) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -236,14 +241,19 @@ static av_cold void h264qpel_init_mmi(H264QpelContext *c, int bit_depth) c->avg_h264_qpel_pixels_tab[2][15] = ff_avg_h264_qpel4_mc33_mmi; } } +#else +static av_cold void h264qpel_init_mmi(H264QpelContext *c, int bit_depth) +{ +} #endif /* HAVE_MMI */ av_cold void ff_h264qpel_init_mips(H264QpelContext *c, int bit_depth) { -#if HAVE_MMI - h264qpel_init_mmi(c, bit_depth); -#endif /* HAVE_MMI */ -#if HAVE_MSA - h264qpel_init_msa(c, bit_depth); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + h264qpel_init_mmi(c, bit_depth); + + if (have_msa(cpu_flags)) + h264qpel_init_msa(c, bit_depth); } diff --git a/libavcodec/mips/hevcdsp_init_mips.c b/libavcodec/mips/hevcdsp_init_mips.c index 88337f462e..246d71b74e 100644 --- a/libavcodec/mips/hevcdsp_init_mips.c +++ b/libavcodec/mips/hevcdsp_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "libavcodec/mips/hevcdsp_mips.h" #if HAVE_MMI @@ -90,6 +91,11 @@ static av_cold void hevc_dsp_init_mmi(HEVCDSPContext *c, c->put_hevc_qpel_uni[9][1][1] = ff_hevc_put_hevc_qpel_uni_hv64_8_mmi; } } +#else +static av_cold void hevc_dsp_init_mmi(HEVCDSPContext *c, + const int bit_depth) +{ +} #endif // #if HAVE_MMI #if HAVE_MSA @@ -516,14 +522,20 @@ static av_cold void hevc_dsp_init_msa(HEVCDSPContext *c, c->transform_4x4_luma = ff_hevc_idct_luma_4x4_msa; } } +#else +static av_cold void hevc_dsp_init_msa(HEVCDSPContext *c, + const int bit_depth) +{ +} #endif // #if HAVE_MSA void ff_hevc_dsp_init_mips(HEVCDSPContext *c, const int bit_depth) { -#if HAVE_MMI - hevc_dsp_init_mmi(c, bit_depth); -#endif // #if HAVE_MMI -#if HAVE_MSA - hevc_dsp_init_msa(c, bit_depth); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + hevc_dsp_init_mmi(c, bit_depth); + + if (have_msa(cpu_flags)) + hevc_dsp_init_msa(c, bit_depth); } diff --git a/libavcodec/mips/hevcpred_init_mips.c b/libavcodec/mips/hevcpred_init_mips.c index e987698d66..f829561ddf 100644 --- a/libavcodec/mips/hevcpred_init_mips.c +++ b/libavcodec/mips/hevcpred_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "config.h" #include "libavutil/attributes.h" #include "libavcodec/mips/hevcpred_mips.h" @@ -39,11 +40,16 @@ static av_cold void hevc_pred_init_msa(HEVCPredContext *c, const int bit_depth) c->pred_angular[3] = ff_pred_intra_pred_angular_3_msa; } } +#else +static av_cold void hevc_pred_init_msa(HEVCPredContext *c, const int bit_depth) +{ +} #endif // #if HAVE_MSA void ff_hevc_pred_init_mips(HEVCPredContext *c, const int bit_depth) { -#if HAVE_MSA - hevc_pred_init_msa(c, bit_depth); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_msa(cpu_flags)) + hevc_pred_init_msa(c, bit_depth); } diff --git a/libavcodec/mips/hpeldsp_init_mips.c b/libavcodec/mips/hpeldsp_init_mips.c index d6f7a9793d..9e12bde547 100644 --- a/libavcodec/mips/hpeldsp_init_mips.c +++ b/libavcodec/mips/hpeldsp_init_mips.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "../hpeldsp.h" #include "libavcodec/mips/hpeldsp_mips.h" @@ -64,6 +65,10 @@ static void ff_hpeldsp_init_msa(HpelDSPContext *c, int flags) c->avg_pixels_tab[2][2] = ff_avg_pixels4_y2_msa; c->avg_pixels_tab[2][3] = ff_avg_pixels4_xy2_msa; } +#else +static void ff_hpeldsp_init_msa(HpelDSPContext *c, int flags) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -109,14 +114,19 @@ static void ff_hpeldsp_init_mmi(HpelDSPContext *c, int flags) c->avg_pixels_tab[2][2] = ff_avg_pixels4_y2_8_mmi; c->avg_pixels_tab[2][3] = ff_avg_pixels4_xy2_8_mmi; } +#else +static void ff_hpeldsp_init_mmi(HpelDSPContext *c, int flags) +{ +} #endif // #if HAVE_MMI void ff_hpeldsp_init_mips(HpelDSPContext *c, int flags) { -#if HAVE_MMI - ff_hpeldsp_init_mmi(c, flags); -#endif // #if HAVE_MMI -#if HAVE_MSA - ff_hpeldsp_init_msa(c, flags); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + ff_hpeldsp_init_mmi(c, flags); + + if (have_msa(cpu_flags)) + ff_hpeldsp_init_msa(c, flags); } diff --git a/libavcodec/mips/idctdsp_init_mips.c b/libavcodec/mips/idctdsp_init_mips.c index 85b76ca478..a1a5ad5449 100644 --- a/libavcodec/mips/idctdsp_init_mips.c +++ b/libavcodec/mips/idctdsp_init_mips.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "idctdsp_mips.h" #include "xvididct_mips.h" @@ -40,6 +41,11 @@ static av_cold void idctdsp_init_msa(IDCTDSPContext *c, AVCodecContext *avctx, c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_msa; c->add_pixels_clamped = ff_add_pixels_clamped_msa; } +#else +static av_cold void idctdsp_init_msa(IDCTDSPContext *c, AVCodecContext *avctx, + unsigned high_bit_depth) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -60,15 +66,21 @@ static av_cold void idctdsp_init_mmi(IDCTDSPContext *c, AVCodecContext *avctx, c->add_pixels_clamped = ff_add_pixels_clamped_mmi; c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmi; } +#else +static av_cold void idctdsp_init_mmi(IDCTDSPContext *c, AVCodecContext *avctx, + unsigned high_bit_depth) +{ +} #endif /* HAVE_MMI */ av_cold void ff_idctdsp_init_mips(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth) { -#if HAVE_MMI - idctdsp_init_mmi(c, avctx, high_bit_depth); -#endif /* HAVE_MMI */ -#if HAVE_MSA - idctdsp_init_msa(c, avctx, high_bit_depth); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + idctdsp_init_mmi(c, avctx, high_bit_depth); + + if (have_msa(cpu_flags)) + idctdsp_init_msa(c, avctx, high_bit_depth); } diff --git a/libavcodec/mips/me_cmp_init_mips.c b/libavcodec/mips/me_cmp_init_mips.c index 219a0dc00c..3b5c01ecd4 100644 --- a/libavcodec/mips/me_cmp_init_mips.c +++ b/libavcodec/mips/me_cmp_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "me_cmp_mips.h" #if HAVE_MSA @@ -46,11 +47,16 @@ static av_cold void me_cmp_msa(MECmpContext *c, AVCodecContext *avctx) c->sse[2] = ff_sse4_msa; #endif } +#else +static av_cold void me_cmp_msa(MECmpContext *c, AVCodecContext *avctx) +{ +} #endif // #if HAVE_MSA av_cold void ff_me_cmp_init_mips(MECmpContext *c, AVCodecContext *avctx) { -#if HAVE_MSA - me_cmp_msa(c, avctx); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_msa(cpu_flags)) + me_cmp_msa(c, avctx); } diff --git a/libavcodec/mips/mpegvideo_init_mips.c b/libavcodec/mips/mpegvideo_init_mips.c index be77308140..cc6d4b1785 100644 --- a/libavcodec/mips/mpegvideo_init_mips.c +++ b/libavcodec/mips/mpegvideo_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "h263dsp_mips.h" #include "mpegvideo_mips.h" @@ -29,6 +30,10 @@ static av_cold void dct_unquantize_init_msa(MpegEncContext *s) if (!s->q_scale_type) s->dct_unquantize_mpeg2_inter = ff_dct_unquantize_mpeg2_inter_msa; } +#else +static av_cold void dct_unquantize_init_msa(MpegEncContext *s) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -45,14 +50,19 @@ static av_cold void dct_unquantize_init_mmi(MpegEncContext *s) s->denoise_dct= ff_denoise_dct_mmi; } +#else +static av_cold void dct_unquantize_init_mmi(MpegEncContext *s) +{ +} #endif /* HAVE_MMI */ av_cold void ff_mpv_common_init_mips(MpegEncContext *s) { -#if HAVE_MMI - dct_unquantize_init_mmi(s); -#endif /* HAVE_MMI */ -#if HAVE_MSA - dct_unquantize_init_msa(s); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + dct_unquantize_init_mmi(s); + + if (have_msa(cpu_flags)) + dct_unquantize_init_msa(s); } diff --git a/libavcodec/mips/mpegvideoencdsp_init_mips.c b/libavcodec/mips/mpegvideoencdsp_init_mips.c index 9bfe94e4cd..543f429aa4 100644 --- a/libavcodec/mips/mpegvideoencdsp_init_mips.c +++ b/libavcodec/mips/mpegvideoencdsp_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "libavcodec/bit_depth_template.c" #include "h263dsp_mips.h" @@ -29,12 +30,18 @@ static av_cold void mpegvideoencdsp_init_msa(MpegvideoEncDSPContext *c, c->pix_sum = ff_pix_sum_msa; #endif } +#else +static av_cold void mpegvideoencdsp_init_msa(MpegvideoEncDSPContext *c, + AVCodecContext *avctx) +{ +} #endif // #if HAVE_MSA av_cold void ff_mpegvideoencdsp_init_mips(MpegvideoEncDSPContext *c, AVCodecContext *avctx) { -#if HAVE_MSA - mpegvideoencdsp_init_msa(c, avctx); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_msa(cpu_flags)) + mpegvideoencdsp_init_msa(c, avctx); } diff --git a/libavcodec/mips/pixblockdsp_init_mips.c b/libavcodec/mips/pixblockdsp_init_mips.c index fd0238d79b..cf4f986ba7 100644 --- a/libavcodec/mips/pixblockdsp_init_mips.c +++ b/libavcodec/mips/pixblockdsp_init_mips.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "pixblockdsp_mips.h" #if HAVE_MSA @@ -43,6 +44,12 @@ static av_cold void pixblockdsp_init_msa(PixblockDSPContext *c, break; } } +#else +static av_cold void pixblockdsp_init_msa(PixblockDSPContext *c, + AVCodecContext *avctx, + unsigned high_bit_depth) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -55,15 +62,21 @@ static av_cold void pixblockdsp_init_mmi(PixblockDSPContext *c, c->get_pixels = ff_get_pixels_8_mmi; } } +#else +static av_cold void pixblockdsp_init_mmi(PixblockDSPContext *c, + AVCodecContext *avctx, unsigned high_bit_depth) +{ +} #endif /* HAVE_MMI */ void ff_pixblockdsp_init_mips(PixblockDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth) { -#if HAVE_MMI - pixblockdsp_init_mmi(c, avctx, high_bit_depth); -#endif /* HAVE_MMI */ -#if HAVE_MSA - pixblockdsp_init_msa(c, avctx, high_bit_depth); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + pixblockdsp_init_mmi(c, avctx, high_bit_depth); + + if (have_msa(cpu_flags)) + pixblockdsp_init_msa(c, avctx, high_bit_depth); } diff --git a/libavcodec/mips/qpeldsp_init_mips.c b/libavcodec/mips/qpeldsp_init_mips.c index 140e8f89c9..2d136f5d6f 100644 --- a/libavcodec/mips/qpeldsp_init_mips.c +++ b/libavcodec/mips/qpeldsp_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "qpeldsp_mips.h" #if HAVE_MSA @@ -157,11 +158,16 @@ static av_cold void qpeldsp_init_msa(QpelDSPContext *c) c->avg_qpel_pixels_tab[1][14] = ff_hv_mc_qpel_avg_dst_aver_v_src1_8x8_msa; c->avg_qpel_pixels_tab[1][15] = ff_hv_mc_qpel_avg_dst_aver_hv_src11_8x8_msa; } +#else +static av_cold void qpeldsp_init_msa(QpelDSPContext *c) +{ +} #endif // #if HAVE_MSA void ff_qpeldsp_init_mips(QpelDSPContext *c) { -#if HAVE_MSA - qpeldsp_init_msa(c); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_msa(cpu_flags)) + qpeldsp_init_msa(c); } diff --git a/libavcodec/mips/vc1dsp_init_mips.c b/libavcodec/mips/vc1dsp_init_mips.c index c0007ff650..09840c6b83 100644 --- a/libavcodec/mips/vc1dsp_init_mips.c +++ b/libavcodec/mips/vc1dsp_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "libavutil/attributes.h" #include "libavcodec/vc1dsp.h" #include "vc1dsp_mips.h" @@ -98,6 +99,10 @@ static av_cold void vc1dsp_init_mmi(VC1DSPContext *dsp) dsp->put_no_rnd_vc1_chroma_pixels_tab[1] = ff_put_no_rnd_vc1_chroma_mc4_mmi; dsp->avg_no_rnd_vc1_chroma_pixels_tab[1] = ff_avg_no_rnd_vc1_chroma_mc4_mmi; } +#else +static av_cold void vc1dsp_init_mmi(VC1DSPContext *dsp) +{ +} #endif /* HAVE_MMI */ #if HAVE_MSA @@ -117,14 +122,19 @@ static av_cold void vc1dsp_init_msa(VC1DSPContext *dsp) FN_ASSIGN(put_, 3, 2, _msa); FN_ASSIGN(put_, 3, 3, _msa); } +#else +static av_cold void vc1dsp_init_msa(VC1DSPContext *dsp) +{ +} #endif /* HAVE_MSA */ av_cold void ff_vc1dsp_init_mips(VC1DSPContext *dsp) { -#if HAVE_MMI - vc1dsp_init_mmi(dsp); -#endif /* HAVE_MMI */ -#if HAVE_MSA - vc1dsp_init_msa(dsp); -#endif /* HAVE_MSA */ + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + vc1dsp_init_mmi(dsp); + + if (have_msa(cpu_flags)) + vc1dsp_init_msa(dsp); } diff --git a/libavcodec/mips/videodsp_init.c b/libavcodec/mips/videodsp_init.c index 817040420b..9d64d88a48 100644 --- a/libavcodec/mips/videodsp_init.c +++ b/libavcodec/mips/videodsp_init.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "config.h" #include "libavutil/attributes.h" #include "libavutil/mips/asmdefs.h" @@ -41,11 +42,16 @@ static void prefetch_mips(uint8_t *mem, ptrdiff_t stride, int h) : [stride] "r" (stride) ); } +#else +static void prefetch_mips(uint8_t *mem, ptrdiff_t stride, int h) +{ +} #endif // #if HAVE_MSA av_cold void ff_videodsp_init_mips(VideoDSPContext *ctx, int bpc) { -#if HAVE_MSA - ctx->prefetch = prefetch_mips; -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_msa(cpu_flags)) + ctx->prefetch = prefetch_mips; } diff --git a/libavcodec/mips/vp3dsp_init_mips.c b/libavcodec/mips/vp3dsp_init_mips.c index e183db35b6..fcbd7e8332 100644 --- a/libavcodec/mips/vp3dsp_init_mips.c +++ b/libavcodec/mips/vp3dsp_init_mips.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "config.h" #include "libavutil/attributes.h" #include "libavcodec/avcodec.h" @@ -36,6 +37,10 @@ static av_cold void vp3dsp_init_msa(VP3DSPContext *c, int flags) c->v_loop_filter = ff_vp3_v_loop_filter_msa; c->h_loop_filter = ff_vp3_h_loop_filter_msa; } +#else +static av_cold void vp3dsp_init_msa(VP3DSPContext *c, int flags) +{ +} #endif /* HAVE_MSA */ #if HAVE_MMI @@ -47,14 +52,19 @@ static av_cold void vp3dsp_init_mmi(VP3DSPContext *c, int flags) c->idct_put = ff_vp3_idct_put_mmi; c->idct_dc_add = ff_vp3_idct_dc_add_mmi; } +#else +static av_cold void vp3dsp_init_mmi(VP3DSPContext *c, int flags) +{ +} #endif /* HAVE_MMI */ av_cold void ff_vp3dsp_init_mips(VP3DSPContext *c, int flags) { -#if HAVE_MMI - vp3dsp_init_mmi(c, flags); -#endif /* HAVE_MMI */ -#if HAVE_MSA - vp3dsp_init_msa(c, flags); -#endif /* HAVE_MSA */ + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + vp3dsp_init_mmi(c, flags); + + if (have_msa(cpu_flags)) + vp3dsp_init_msa(c, flags); } diff --git a/libavcodec/mips/vp8dsp_init_mips.c b/libavcodec/mips/vp8dsp_init_mips.c index 7fd8fb0d32..73f172b64f 100644 --- a/libavcodec/mips/vp8dsp_init_mips.c +++ b/libavcodec/mips/vp8dsp_init_mips.c @@ -24,6 +24,7 @@ * VP8 compatible video decoder */ +#include "libavutil/mips/cpu.h" #include "config.h" #include "libavutil/attributes.h" #include "libavcodec/vp8dsp.h" @@ -104,6 +105,10 @@ static av_cold void vp8dsp_init_msa(VP8DSPContext *dsp) dsp->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter_simple_msa; dsp->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter_simple_msa; } +#else +static av_cold void vp8dsp_init_msa(VP8DSPContext *dsp) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -189,14 +194,19 @@ static av_cold void vp8dsp_init_mmi(VP8DSPContext *dsp) dsp->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter_simple_mmi; dsp->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter_simple_mmi; } +#else +static av_cold void vp8dsp_init_mmi(VP8DSPContext *dsp) +{ +} #endif /* HAVE_MMI */ av_cold void ff_vp8dsp_init_mips(VP8DSPContext *dsp) { -#if HAVE_MMI - vp8dsp_init_mmi(dsp); -#endif /* HAVE_MMI */ -#if HAVE_MSA - vp8dsp_init_msa(dsp); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + vp8dsp_init_mmi(dsp); + + if (have_msa(cpu_flags)) + vp8dsp_init_msa(dsp); } diff --git a/libavcodec/mips/vp9dsp_init_mips.c b/libavcodec/mips/vp9dsp_init_mips.c index 5990fa6952..ddbbd9f838 100644 --- a/libavcodec/mips/vp9dsp_init_mips.c +++ b/libavcodec/mips/vp9dsp_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "config.h" #include "libavutil/common.h" #include "libavcodec/vp9dsp.h" @@ -166,6 +167,10 @@ static av_cold void vp9dsp_init_msa(VP9DSPContext *dsp, int bpp) vp9dsp_mc_init_msa(dsp, bpp); vp9dsp_loopfilter_init_msa(dsp, bpp); } +#else +static av_cold void vp9dsp_init_msa(VP9DSPContext *dsp, int bpp) +{ +} #endif // #if HAVE_MSA #if HAVE_MMI @@ -205,14 +210,19 @@ static av_cold void vp9dsp_init_mmi(VP9DSPContext *dsp, int bpp) vp9dsp_mc_init_mmi(dsp); } } +#else +static av_cold void vp9dsp_init_mmi(VP9DSPContext *dsp, int bpp) +{ +} #endif // #if HAVE_MMI av_cold void ff_vp9dsp_init_mips(VP9DSPContext *dsp, int bpp) { -#if HAVE_MMI - vp9dsp_init_mmi(dsp, bpp); -#endif // #if HAVE_MMI -#if HAVE_MSA - vp9dsp_init_msa(dsp, bpp); -#endif // #if HAVE_MSA + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + vp9dsp_init_mmi(dsp, bpp); + + if (have_msa(cpu_flags)) + vp9dsp_init_msa(dsp, bpp); } diff --git a/libavcodec/mips/wmv2dsp_init_mips.c b/libavcodec/mips/wmv2dsp_init_mips.c index 51dd2078d9..9dc3aeb29a 100644 --- a/libavcodec/mips/wmv2dsp_init_mips.c +++ b/libavcodec/mips/wmv2dsp_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "config.h" #include "libavutil/attributes.h" #include "wmv2dsp_mips.h" @@ -28,11 +29,16 @@ static av_cold void wmv2dsp_init_mmi(WMV2DSPContext *c) c->idct_add = ff_wmv2_idct_add_mmi; c->idct_put = ff_wmv2_idct_put_mmi; } +#else +static av_cold void wmv2dsp_init_mmi(WMV2DSPContext *c) +{ +} #endif /* HAVE_MMI */ av_cold void ff_wmv2dsp_init_mips(WMV2DSPContext *c) { -#if HAVE_MMI - wmv2dsp_init_mmi(c); -#endif /* HAVE_MMI */ + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + wmv2dsp_init_mmi(c); } diff --git a/libavcodec/mips/xvididct_init_mips.c b/libavcodec/mips/xvididct_init_mips.c index c1d82cc30c..9193cbb401 100644 --- a/libavcodec/mips/xvididct_init_mips.c +++ b/libavcodec/mips/xvididct_init_mips.c @@ -18,6 +18,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/mips/cpu.h" #include "xvididct_mips.h" #if HAVE_MMI @@ -34,12 +35,18 @@ static av_cold void xvid_idct_init_mmi(IDCTDSPContext *c, AVCodecContext *avctx, } } } +#else +static av_cold void xvid_idct_init_mmi(IDCTDSPContext *c, AVCodecContext *avctx, + unsigned high_bit_depth) +{ +} #endif /* HAVE_MMI */ av_cold void ff_xvid_idct_init_mips(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth) { -#if HAVE_MMI - xvid_idct_init_mmi(c, avctx, high_bit_depth); -#endif /* HAVE_MMI */ + int cpu_flags = av_get_cpu_flags(); + + if (have_mmi(cpu_flags)) + xvid_idct_init_mmi(c, avctx, high_bit_depth); }