From patchwork Fri Dec 1 22:02:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 6499 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.94 with SMTP id m30csp1683649jah; Fri, 1 Dec 2017 14:03:45 -0800 (PST) X-Google-Smtp-Source: AGs4zMasho5ui87Ik1TJV5Ml0+huCom2lBlmaIzdI8BM4JdiFw3RzOjJvKFFAmzMk9L6nWIOsYBZ X-Received: by 10.28.9.195 with SMTP id 186mr2003177wmj.122.1512165825527; Fri, 01 Dec 2017 14:03:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512165825; cv=none; d=google.com; s=arc-20160816; b=oVZu9ojYm3/eALwDmWxeKuelCU2AL18V6dSqXfZDNFakwLzo70j8h1m3UNjc1pIuq4 FpUgjSZrOSZVYrsb1S5Kvb5sS9oEnAZ4LKzBWt+t/VGw8wariaFPD4lL8IqUL79Tg/X4 O5m8LEwrpXioS5C94kDH0RYiriC1Q5QUpYjcsT35Fua91z/axAHljtWoF5ZzSVZnJjPg uKgx/RqFkjS6wzkbfnHryEotgbBV74jRQ66P9PmJUjllpOAmpz4S395aEYx4N6qIbI57 WlZU3OmswlrtqUIBh1ewd4jM9gPsHuhmwbCEmJ4PEuKj7huGufWkrZ6GogDADkv9Pk5B VCiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=BUseeyLe+mBfjtQGql7aEMXi/m5ymd/s9Avj/EmUnyg=; b=yjgEF+YBuJ2H7S0ufmkLaI75eB8t7bYHoIzo7QEN25aKtaYai4zVqs2PkygMqg2RTO H4eAXXFA0XM+pFyV5+VXUG2oHysJE1W0EZ1XjMTb2OpV8KUs8LR11bUJeVcW7lQd89ce D1j7poT8P/xt3kFTweGhdSoGSV7Z17Vc3X+5kCsldV9foFSwZrIGCsVk+y+OsVH3besb IKT0ErV+qu+X205WEAIvLz14ZZ3gurkTslPm+kyCR21ueClaG1Q32dd5GXQGyZnLpUoh pVq+qUE+nKPu3bQQrA9JkqmlGbnREQwQct7xGLI0+3vx5qQJZECRpHfFI/VEe2jR0NSd QxwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=AP5FP+ID; 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 sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z63si1332167wmz.126.2017.12.01.14.03.45; Fri, 01 Dec 2017 14:03:45 -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 header.s=20161025 header.b=AP5FP+ID; 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 sp=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 9CF4868A52C; Sat, 2 Dec 2017 00:03:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C93DA68A0FE for ; Sat, 2 Dec 2017 00:03:34 +0200 (EET) Received: by mail-wm0-f68.google.com with SMTP id n138so5913667wmg.2 for ; Fri, 01 Dec 2017 14:03:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=alYSmmMnWei3Z2NbMf1Ng8gI6q6wrCFpJYyYKLqO8d0=; b=AP5FP+IDkw9pyrl0y2mrxmE4/fH/59+00Ie8Qv4wQZDq69IoPzG1iBcTm6G9MJVDPI RZ1U3gHMrap5pQhrZSk8/ajHGYWW8f69VEkIBfVVkBm9fywTa5RCRaW4IU1ciiTfFM2z YixAc0iYiRFlCYlyEjecdFE9O00RQFXMYFcKMBXUj/yhfoJ/BtfmwWS67Il6CRtrm9rI GjZLn5AzPvut/DFE26gRY0C5ut2nuUBcnIk2dTZiKHptpMZ8Yaaq/UMvr30E4nxYXAtY wcO/Y8trYwrywgUDisG0fwkJXKZbCRhlYzV0cWGTMde/O3X7jTV23V/LLfU2v6AhskCd FVDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=alYSmmMnWei3Z2NbMf1Ng8gI6q6wrCFpJYyYKLqO8d0=; b=qVBPUH3KtZ8DYmz/iUj7sf9HfjbkvPr7WIs/uXaSwRRQ7X2I61jULs3wTppVMuuRmN 84Fv+5UQMznaJOEKQzGrl36iHUsDQ8JsVs5/iB3fiOCxvXgRjVTb4marKOYBvIBKqZSM kfPkbrQyd+71uTLkx7Ddb4dhX/pjWxX9aR3+HLXMDgXQeWtrNL+SzyCN2Houi/9F623r 2teJRDoSEnYri4WKwsQ6VGgD+fNeKSQNGQUFWYtpbndv6v6CMIreJ12ISy2FFSeWwamS 9BCX4zLn79xrvCJhczFRJsPa3873bmn4O8bTUNb4s4/LYg3Ip9dHY8klbfbxxSsk1iY/ +d3g== X-Gm-Message-State: AKGB3mIihAf+NPhreZmqN50ZNKWk7pZFQj2GQYTjWVR8pMA+MT227WO2 CmyKWQQeqH3lhd6BVyD6Pbyn+A== X-Received: by 10.28.52.207 with SMTP id b198mr2480552wma.154.1512165817856; Fri, 01 Dec 2017 14:03:37 -0800 (PST) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id 141sm2162277wmt.30.2017.12.01.14.03.35 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Dec 2017 14:03:37 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 1 Dec 2017 23:02:43 +0100 Message-Id: <20171201220243.16371-1-onemda@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] avfilter: add hflip x86 SIMD X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Paul B Mahol --- libavfilter/hflip.h | 38 +++++++++++++++++++++++++ libavfilter/vf_hflip.c | 30 ++++++++++++++------ libavfilter/x86/Makefile | 2 ++ libavfilter/x86/vf_hflip.asm | 61 +++++++++++++++++++++++++++++++++++++++++ libavfilter/x86/vf_hflip_init.c | 38 +++++++++++++++++++++++++ 5 files changed, 160 insertions(+), 9 deletions(-) create mode 100644 libavfilter/hflip.h create mode 100644 libavfilter/x86/vf_hflip.asm create mode 100644 libavfilter/x86/vf_hflip_init.c diff --git a/libavfilter/hflip.h b/libavfilter/hflip.h new file mode 100644 index 0000000000..138380427c --- /dev/null +++ b/libavfilter/hflip.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2007 Benoit Fouet + * Copyright (c) 2010 Stefano Sabatini + * + * 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 AVFILTER_HFLIP_H +#define AVFILTER_HFLIP_H + +#include "avfilter.h" + +typedef struct FlipContext { + const AVClass *class; + int max_step[4]; ///< max pixel step for each plane, expressed as a number of bytes + int planewidth[4]; ///< width of each plane + int planeheight[4]; ///< height of each plane + + void (*flip_line[4])(const uint8_t *src, uint8_t *dst, int w); +} FlipContext; + +void ff_hflip_init_x86(FlipContext *s, int step[4]); + +#endif /* AVFILTER_HFLIP_H */ diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c index cf20c193f7..65cf7c5cd1 100644 --- a/libavfilter/vf_hflip.c +++ b/libavfilter/vf_hflip.c @@ -29,6 +29,7 @@ #include "libavutil/opt.h" #include "avfilter.h" #include "formats.h" +#include "hflip.h" #include "internal.h" #include "video.h" #include "libavutil/pixdesc.h" @@ -36,13 +37,6 @@ #include "libavutil/intreadwrite.h" #include "libavutil/imgutils.h" -typedef struct FlipContext { - const AVClass *class; - int max_step[4]; ///< max pixel step for each plane, expressed as a number of bytes - int planewidth[4]; ///< width of each plane - int planeheight[4]; ///< height of each plane -} FlipContext; - static const AVOption hflip_options[] = { { NULL } }; @@ -67,12 +61,21 @@ static int query_formats(AVFilterContext *ctx) return ff_set_common_formats(ctx, pix_fmts); } +static void hflip_byte_c(const uint8_t *src, uint8_t *dst, int w) +{ + int j; + + for (j = 0; j < w; j++) + dst[j] = src[-j]; +} + static int config_props(AVFilterLink *inlink) { FlipContext *s = inlink->dst->priv; const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(inlink->format); const int hsub = pix_desc->log2_chroma_w; const int vsub = pix_desc->log2_chroma_h; + int i; av_image_fill_max_pixsteps(s->max_step, NULL, pix_desc); s->planewidth[0] = s->planewidth[3] = inlink->w; @@ -80,6 +83,16 @@ static int config_props(AVFilterLink *inlink) s->planeheight[0] = s->planeheight[3] = inlink->h; s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, vsub); + for (i = 0; i < 4; i++) { + switch (s->max_step[i]) { + case 1: + s->flip_line[i] = hflip_byte_c; + } + } + + if (ARCH_X86) + ff_hflip_init_x86(s, s->max_step); + return 0; } @@ -109,8 +122,7 @@ static int filter_slice(AVFilterContext *ctx, void *arg, int job, int nb_jobs) for (i = start; i < end; i++) { switch (step) { case 1: - for (j = 0; j < width; j++) - outrow[j] = inrow[-j]; + s->flip_line[plane](inrow, outrow, width); break; case 2: diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile index 3431625883..1420954f62 100644 --- a/libavfilter/x86/Makefile +++ b/libavfilter/x86/Makefile @@ -5,6 +5,7 @@ OBJS-$(CONFIG_COLORSPACE_FILTER) += x86/colorspacedsp_init.o OBJS-$(CONFIG_EQ_FILTER) += x86/vf_eq.o OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp_init.o OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun_init.o +OBJS-$(CONFIG_HFLIP_FILTER) += x86/vf_hflip_init.o OBJS-$(CONFIG_HQDN3D_FILTER) += x86/vf_hqdn3d_init.o OBJS-$(CONFIG_IDET_FILTER) += x86/vf_idet_init.o OBJS-$(CONFIG_INTERLACE_FILTER) += x86/vf_interlace_init.o @@ -31,6 +32,7 @@ X86ASM-OBJS-$(CONFIG_BWDIF_FILTER) += x86/vf_bwdif.o X86ASM-OBJS-$(CONFIG_COLORSPACE_FILTER) += x86/colorspacedsp.o X86ASM-OBJS-$(CONFIG_FSPP_FILTER) += x86/vf_fspp.o X86ASM-OBJS-$(CONFIG_GRADFUN_FILTER) += x86/vf_gradfun.o +X86ASM-OBJS-$(CONFIG_HFLIP_FILTER) += x86/vf_hflip.o X86ASM-OBJS-$(CONFIG_HQDN3D_FILTER) += x86/vf_hqdn3d.o X86ASM-OBJS-$(CONFIG_IDET_FILTER) += x86/vf_idet.o X86ASM-OBJS-$(CONFIG_INTERLACE_FILTER) += x86/vf_interlace.o diff --git a/libavfilter/x86/vf_hflip.asm b/libavfilter/x86/vf_hflip.asm new file mode 100644 index 0000000000..bc52a16ad8 --- /dev/null +++ b/libavfilter/x86/vf_hflip.asm @@ -0,0 +1,61 @@ +;***************************************************************************** +;* x86-optimized functions for hflip filter +;* +;* Copyright (C) 2017 Paul B Mahol +;* +;* 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/x86/x86util.asm" + +SECTION_RODATA + +pb_flip: times 16 db 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 + +SECTION .text + +INIT_XMM ssse3 +%if ARCH_X86_64 +cglobal hflip_byte, 5, 5, 8, src, dst, w, x, v + mova m0, [pb_flip] + mov xq, 0 + sub wq, mmsize + cmp wq, mmsize + jl .skip + + .loop0: + neg xq + movu m1, [srcq + xq - mmsize + 1] + pshufb m1, m0 + neg xq + movu [dstq + xq], m1 + add xq, mmsize + cmp xq, wq + jl .loop0 + +.skip: + add wq, mmsize + .loop1: + neg xq + mov vb, [srcq + xq] + neg xq + mov [dstq + xq], vb + add xq, 1 + cmp xq, wq + jl .loop1 +RET +%endif diff --git a/libavfilter/x86/vf_hflip_init.c b/libavfilter/x86/vf_hflip_init.c new file mode 100644 index 0000000000..cd0e18f7ee --- /dev/null +++ b/libavfilter/x86/vf_hflip_init.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017 Paul B Mahol + * + * 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/attributes.h" +#include "libavutil/cpu.h" +#include "libavutil/x86/cpu.h" +#include "libavfilter/hflip.h" + +void ff_hflip_byte_ssse3(const uint8_t *src, uint8_t *dst, int w); + +av_cold void ff_hflip_init_x86(FlipContext *s, int step[4]) +{ + int cpu_flags = av_get_cpu_flags(); + int i; + + for (i = 0; i < 4; i++) { + if (EXTERNAL_SSSE3(cpu_flags) && step[i] == 1) { + s->flip_line[i] = ff_hflip_byte_ssse3; + } + } +}