From patchwork Mon Jan 9 16:45:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Bouron X-Patchwork-Id: 2142 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp7135124vsb; Mon, 9 Jan 2017 08:54:10 -0800 (PST) X-Received: by 10.194.57.230 with SMTP id l6mr4776715wjq.54.1483980849952; Mon, 09 Jan 2017 08:54:09 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cn7si300659wjb.46.2017.01.09.08.54.09; Mon, 09 Jan 2017 08:54:09 -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; dkim=neutral (body hash did not verify) header.i=@gmail.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; dmarc=fail (p=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3FDE068A6B4; Mon, 9 Jan 2017 18:54:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wj0-f195.google.com (mail-wj0-f195.google.com [209.85.210.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A314468A570 for ; Mon, 9 Jan 2017 18:53:53 +0200 (EET) Received: by mail-wj0-f195.google.com with SMTP id kp2so85152657wjc.0 for ; Mon, 09 Jan 2017 08:54:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5RXvKWbTLxEEkl2XKDVWxgcfaAqfGNQrzgVa1T+EHe8=; b=XpUEgqeUSCieEC43Q/ns8XUNMuekPSYCk+LVAnChEK/roKsmotm8Zadh3/4/RrwZeY Gi+lbO73l6JpHjEKDh0qM1yFvFq/szbaNWUCZbkoB8gzcx4mHVUEm8Xuej3Bf5Z2YXLh sk9214Gz4sZTsnN4VzlGxuVrVa++9KMAZqOW5Zl3JWMaBfERz9TViW27ohz45BUJ1h1E yFbP+FfQzfAiahIu7vmr9milG5Ytmv5P/EkabK+HzU0wNFWDWEm0eoVYFkPgsrRqf3tE r4d6I9pjsKppNR+77QGVpQ1ya1TjA33DV9LWkSETor36VbcGb7bk++/lmRrgp4IcHp9S u90g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5RXvKWbTLxEEkl2XKDVWxgcfaAqfGNQrzgVa1T+EHe8=; b=dJt0tD/6VcASo+PsvD16GUlLj8E5DWQ4epWgxw1EbjJ6CUDhNGyEPtVzH8EHJbx4xX j99E3zdxJb/WReQQ7yOHSQtisUqi0oFhjhYM0HMEs01cXlYTW4peTXkglGFC+UEXOMpO XIJ/WA65q4eSDc57OofuVMxjgroJPgReuZ8uh09xbHAym48pkJP/0z+oG9nopqApxLiq 2t/bK2jKLRQMSYtoOSvIJg0jScN2hH33MpAGC2W4JYCqjE8O7UMZ9G2S2mB6snSEJFui EgFA/Qd4OBVfF/qgLkW2LSGdheemI9VraW2zPQU4yBqMLxnWtrPpMOIBK8Qy3wb7vEFY Y3Cg== X-Gm-Message-State: AIkVDXK/7sU6IJ3tozNnPBT0W0JjBOZy6tiAzBfrcSMZn6JN6YdVMLS3R7gqf96ztclWrw== X-Received: by 10.194.175.169 with SMTP id cb9mr4011671wjc.73.1483980341745; Mon, 09 Jan 2017 08:45:41 -0800 (PST) Received: from localhost.localdomain (AMontsouris-653-1-175-40.w92-128.abo.wanadoo.fr. [92.128.46.40]) by smtp.gmail.com with ESMTPSA id d85sm19805650wmd.17.2017.01.09.08.45.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jan 2017 08:45:41 -0800 (PST) From: Matthieu Bouron To: ffmpeg-devel@ffmpeg.org Date: Mon, 9 Jan 2017 17:45:30 +0100 Message-Id: <20170109164531.12603-2-matthieu.bouron@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170109164531.12603-1-matthieu.bouron@gmail.com> References: <20170109164531.12603-1-matthieu.bouron@gmail.com> Subject: [FFmpeg-devel] [PATCH 1/2] swresample/aarch64: add ff_resample_common_apply_filter_{x4, x8}_{float, s16}_neon 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: Matthieu Bouron MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libswresample/aarch64/Makefile | 6 +- libswresample/aarch64/resample.S | 76 +++++++++++++++++++++ libswresample/aarch64/resample_init.c | 120 ++++++++++++++++++++++++++++++++++ libswresample/resample.h | 1 + libswresample/resample_dsp.c | 1 + 5 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 libswresample/aarch64/resample.S create mode 100644 libswresample/aarch64/resample_init.c diff --git a/libswresample/aarch64/Makefile b/libswresample/aarch64/Makefile index 320ed67e82..5c34f8d949 100644 --- a/libswresample/aarch64/Makefile +++ b/libswresample/aarch64/Makefile @@ -1,5 +1,7 @@ -OBJS += aarch64/audio_convert_init.o +OBJS += aarch64/audio_convert_init.o \ + aarch64/resample_init.o OBJS-$(CONFIG_NEON_CLOBBER_TEST) += aarch64/neontest.o -NEON-OBJS += aarch64/audio_convert_neon.o +NEON-OBJS += aarch64/audio_convert_neon.o \ + aarch64/resample.o diff --git a/libswresample/aarch64/resample.S b/libswresample/aarch64/resample.S new file mode 100644 index 0000000000..b3b1bb9fe1 --- /dev/null +++ b/libswresample/aarch64/resample.S @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2017 Matthieu Bouron + * + * 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/aarch64/asm.S" + +function ff_resample_common_apply_filter_x4_float_neon, export=1 + movi v0.4S, #0 // accumulator +1: ld1 {v1.4S}, [x1], #16 // src[0..3] + ld1 {v2.4S}, [x2], #16 // filter[0..3] + fmla v0.4S, v1.4S, v2.4S // accumulator += src[0..3] * filter[0..3] + subs w3, w3, #4 // filter_length -= 4 + b.gt 1b // loop until filter_length + faddp v0.4S, v0.4S, v0.4S // pair adding of the 4x32-bit accumulated values + faddp v0.4S, v0.4S, v0.4S // pair adding of the 4x32-bit accumulated values + st1 {v0.S}[0], [x0], #4 // write accumulator + ret +endfunc + +function ff_resample_common_apply_filter_x8_float_neon, export=1 + movi v0.4S, #0 // accumulator +1: ld1 {v1.4S}, [x1], #16 // src[0..3] + ld1 {v2.4S}, [x2], #16 // filter[0..3] + ld1 {v3.4S}, [x1], #16 // src[4..7] + ld1 {v4.4S}, [x2], #16 // filter[4..7] + fmla v0.4S, v1.4S, v2.4S // accumulator += src[0..3] * filter[0..3] + fmla v0.4S, v3.4S, v4.4S // accumulator += src[4..7] * filter[4..7] + subs w3, w3, #8 // filter_length -= 8 + b.gt 1b // loop until filter_length + faddp v0.4S, v0.4S, v0.4S // pair adding of the 4x32-bit accumulated values + faddp v0.4S, v0.4S, v0.4S // pair adding of the 4x32-bit accumulated values + st1 {v0.S}[0], [x0], #4 // write accumulator +endfunc + +function ff_resample_common_apply_filter_x4_s16_neon, export=1 + movi v0.4S, #0 // accumulator +1: ld1 {v1.4H}, [x1], #8 // src[0..3] + ld1 {v2.4H}, [x2], #8 // filter[0..3] + smlal v0.4S, v1.4H, v2.4H // accumulator += src[0..3] * filter[0..3] + subs w3, w3, #4 // filter_length -= 4 + b.gt 1b // loop until filter_length + addp v0.4S, v0.4S, v0.4S // pair adding of the 4x32-bit accumulated values + addp v0.4S, v0.4S, v0.4S // pair adding of the 4x32-bit accumulated values + st1 {v0.S}[0], [x0], #4 // write accumulator + ret +endfunc + +function ff_resample_common_apply_filter_x8_s16_neon, export=1 + movi v0.4S, #0 // accumulator +1: ld1 {v1.8H}, [x1], #16 // src[0..7] + ld1 {v2.8H}, [x2], #16 // filter[0..7] + smlal v0.4S, v1.4H, v2.4H // accumulator += src[0..3] * filter[0..3] + smlal2 v0.4S, v1.8H, v2.8H // accumulator += src[4..7] * filter[4..7] + subs w3, w3, #8 // filter_length -= 8 + b.gt 1b // loop until filter_length + addp v0.4S, v0.4S, v0.4S // pair adding of the 4x32-bit accumulated values + addp v0.4S, v0.4S, v0.4S // pair adding of the 4x32-bit accumulated values + st1 {v0.S}[0], [x0], #4 // write accumulator + ret +endfunc diff --git a/libswresample/aarch64/resample_init.c b/libswresample/aarch64/resample_init.c new file mode 100644 index 0000000000..84581d5b71 --- /dev/null +++ b/libswresample/aarch64/resample_init.c @@ -0,0 +1,120 @@ +/* + * Audio resampling + * + * Copyright (c) 2004-2012 Michael Niedermayer + * + * 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 "config.h" + +#include "libavutil/cpu.h" +#include "libavutil/avassert.h" + +#include "libavutil/aarch64/cpu.h" +#include "libswresample/resample.h" + +#define DECLARE_RESAMPLE_COMMON_TEMPLATE(TYPE, DELEM, FELEM, FELEM2, OUT) \ + \ +void ff_resample_common_apply_filter_x4_##TYPE##_neon(FELEM2 *acc, const DELEM *src, \ + const FELEM *filter, int length); \ + \ +void ff_resample_common_apply_filter_x8_##TYPE##_neon(FELEM2 *acc, const DELEM *src, \ + const FELEM *filter, int length); \ + \ +static int ff_resample_common_##TYPE##_neon(ResampleContext *c, void *dest, const void *source, \ + int n, int update_ctx) \ +{ \ + DELEM *dst = dest; \ + const DELEM *src = source; \ + int dst_index; \ + int index = c->index; \ + int frac = c->frac; \ + int sample_index = 0; \ + int x4_aligned_filter_length = c->filter_length & ~3; \ + int x8_aligned_filter_length = c->filter_length & ~7; \ + \ + while (index >= c->phase_count) { \ + sample_index++; \ + index -= c->phase_count; \ + } \ + \ + for (dst_index = 0; dst_index < n; dst_index++) { \ + FELEM *filter = ((FELEM *) c->filter_bank) + c->filter_alloc * index; \ + \ + FELEM2 val=0; \ + int i = 0; \ + if (x8_aligned_filter_length >= 8) { \ + ff_resample_common_apply_filter_x8_##TYPE##_neon(&val, &src[sample_index], \ + filter, x8_aligned_filter_length); \ + i += x8_aligned_filter_length; \ + \ + } else if (x4_aligned_filter_length >= 4) { \ + ff_resample_common_apply_filter_x4_##TYPE##_neon(&val, &src[sample_index], \ + filter, x4_aligned_filter_length); \ + i += x4_aligned_filter_length; \ + } \ + for (; i < c->filter_length; i++) { \ + val += src[sample_index + i] * (FELEM2)filter[i]; \ + } \ + OUT(dst[dst_index], val); \ + \ + frac += c->dst_incr_mod; \ + index += c->dst_incr_div; \ + if (frac >= c->src_incr) { \ + frac -= c->src_incr; \ + index++; \ + } \ + \ + while (index >= c->phase_count) { \ + sample_index++; \ + index -= c->phase_count; \ + } \ + } \ + \ + if (update_ctx) { \ + c->frac = frac; \ + c->index = index; \ + } \ + \ + return sample_index; \ +} \ + +#define OUT(d, v) d = v +DECLARE_RESAMPLE_COMMON_TEMPLATE(float, float, float, float, OUT) +#undef OUT + +#define OUT(d, v) (v) = ((v) + (1<<(14)))>>15; (d) = av_clip_int16(v) +DECLARE_RESAMPLE_COMMON_TEMPLATE(s16, int16_t, int16_t, int32_t, OUT) +#undef OUT + +av_cold void swri_resample_dsp_aarch64_init(ResampleContext *c) +{ + int cpu_flags = av_get_cpu_flags(); + + if (!have_neon(cpu_flags)) + return; + + switch(c->format) { + case AV_SAMPLE_FMT_FLTP: + c->dsp.resample_common = ff_resample_common_float_neon; + break; + case AV_SAMPLE_FMT_S16P: + c->dsp.resample_common = ff_resample_common_s16_neon; + break; + } +} diff --git a/libswresample/resample.h b/libswresample/resample.h index 946f5cc8e3..1731dad3cf 100644 --- a/libswresample/resample.h +++ b/libswresample/resample.h @@ -63,5 +63,6 @@ typedef struct ResampleContext { void swri_resample_dsp_init(ResampleContext *c); void swri_resample_dsp_x86_init(ResampleContext *c); void swri_resample_dsp_arm_init(ResampleContext *c); +void swri_resample_dsp_aarch64_init(ResampleContext *c); #endif /* SWRESAMPLE_RESAMPLE_H */ diff --git a/libswresample/resample_dsp.c b/libswresample/resample_dsp.c index 6ffbb87766..b2424eb6f7 100644 --- a/libswresample/resample_dsp.c +++ b/libswresample/resample_dsp.c @@ -70,4 +70,5 @@ void swri_resample_dsp_init(ResampleContext *c) if (ARCH_X86) swri_resample_dsp_x86_init(c); else if (ARCH_ARM) swri_resample_dsp_arm_init(c); + else if (ARCH_AARCH64) swri_resample_dsp_aarch64_init(c); }