From patchwork Mon Oct 21 15:45:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 15890 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 DEB59448094 for ; Mon, 21 Oct 2019 18:45:20 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B9D3668B0F5; Mon, 21 Oct 2019 18:45:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0553968B0B5 for ; Mon, 21 Oct 2019 18:45:14 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id q13so3838586wmj.0 for ; Mon, 21 Oct 2019 08:45:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=O9zz1j06wTwPOBK0TjVhzbLjC/LMBltDQzHYd8BTtzQ=; b=GA+2bFBo7kiNrL/0rhOAN9RYu+zT812cLtEbV3tKz6mpE4oI0zkm2mXzKgVJ4UfQQ+ nyPM+CLspjQ4QqCYeY0/T2uUloHGIzKp8JCrNbjOA0BLDjr04ExVfCK8m0H2pZZU54IU nRo5UNMXL7k9re1ilZ0NWhybenE2d9xyMpYueuqs6urmI+4QMAVfqE1DtmQtULN33Kk5 ybVtv015ATqfVGuxC1icE087Ps8Vx1o/SUddXFXUXV+oWzyoJSjjTUfXz4h0ADRidG+7 RrtsHmGnVhncdr7F5zyAaZpRYf0zn02B8c6tQAmTFdJNBSlOxPNWLVwjDCJ7qxEH59v1 11vg== 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=O9zz1j06wTwPOBK0TjVhzbLjC/LMBltDQzHYd8BTtzQ=; b=ESGhlj6zyNngbQlG5eq8/z/DoiFOcf2h0BQVizYmOvyzwUNmUK4nCy37IzkvK5LaW2 /q+GmBqUQxVhY4YgWgc71R1yGJJX80G2ErHfqNhm1VZcIYeu2iqGByTTvYCmpskRQsZ4 VuVC6kSkezxpD8BwzbP4SNQLBABxl8+dRQprrap/B6iR6Oe/dZOvMUSrxVYFlAY209Ep 6MADoVfjSPovyAFKav6Ul3+0yP6qkupXgpSVy3GBeCJMnop27mXllJU1NAsJco5iBCdv BP4XwdZKb8OL0+4faBayvDMJ3DTJZTRerUId+ezfO+6Isrw9lChKUcFMubEKn3kleG8O 4XNg== X-Gm-Message-State: APjAAAWOxiiFXlr+9KKJREOP9tp91TDQfuo5qwgRX+C9TQF1IrSmX8R7 JE4MC5BSnYygbV+SfCorchJe/x4dBjU= X-Google-Smtp-Source: APXvYqwjCu1vocEJY+yqCo5mTCMQlvLIn5Xu9O2sDfmYs6X1KbGgPHlKea6WeWea+88rFQjgPg7LRg== X-Received: by 2002:a7b:c049:: with SMTP id u9mr19386434wmc.12.1571672713000; Mon, 21 Oct 2019 08:45:13 -0700 (PDT) Received: from localhost.localdomain ([212.15.160.218]) by smtp.gmail.com with ESMTPSA id b22sm16132574wmj.36.2019.10.21.08.45.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 08:45:12 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Mon, 21 Oct 2019 17:45:04 +0200 Message-Id: <20191021154504.14753-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_transpose: add 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/transpose.h | 10 +++ libavfilter/vf_transpose.c | 18 ++--- libavfilter/x86/Makefile | 2 + libavfilter/x86/vf_transpose.asm | 104 ++++++++++++++++++++++++++++ libavfilter/x86/vf_transpose_init.c | 49 +++++++++++++ 5 files changed, 174 insertions(+), 9 deletions(-) create mode 100644 libavfilter/x86/vf_transpose.asm create mode 100644 libavfilter/x86/vf_transpose_init.c diff --git a/libavfilter/transpose.h b/libavfilter/transpose.h index aa262b9487..f73a42864f 100644 --- a/libavfilter/transpose.h +++ b/libavfilter/transpose.h @@ -34,4 +34,14 @@ enum TransposeDir { TRANSPOSE_VFLIP, }; +typedef struct TransVtable { + void (*transpose_8x8)(uint8_t *src, ptrdiff_t src_linesize, + uint8_t *dst, ptrdiff_t dst_linesize); + void (*transpose_block)(uint8_t *src, ptrdiff_t src_linesize, + uint8_t *dst, ptrdiff_t dst_linesize, + int w, int h); +} TransVtable; + +void ff_transpose_init_x86(TransVtable *v, int pixstep); + #endif diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c index dd54947bd9..16ac6c311a 100644 --- a/libavfilter/vf_transpose.c +++ b/libavfilter/vf_transpose.c @@ -40,14 +40,6 @@ #include "video.h" #include "transpose.h" -typedef struct TransVtable { - void (*transpose_8x8)(uint8_t *src, ptrdiff_t src_linesize, - uint8_t *dst, ptrdiff_t dst_linesize); - void (*transpose_block)(uint8_t *src, ptrdiff_t src_linesize, - uint8_t *dst, ptrdiff_t dst_linesize, - int w, int h); -} TransVtable; - typedef struct TransContext { const AVClass *class; int hsub, vsub; @@ -243,7 +235,15 @@ static int config_props_output(AVFilterLink *outlink) } } - av_log(ctx, AV_LOG_VERBOSE, + if (ARCH_X86) { + for (int i = 0; i < 4; i++) { + TransVtable *v = &s->vtables[i]; + + ff_transpose_init_x86(v, s->pixsteps[i]); + } + } + + av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d dir:%d -> w:%d h:%d rotation:%s vflip:%d\n", inlink->w, inlink->h, s->dir, outlink->w, outlink->h, s->dir == 1 || s->dir == 3 ? "clockwise" : "counterclockwise", diff --git a/libavfilter/x86/Makefile b/libavfilter/x86/Makefile index 06f832e36c..8d97e46c3f 100644 --- a/libavfilter/x86/Makefile +++ b/libavfilter/x86/Makefile @@ -31,6 +31,7 @@ OBJS-$(CONFIG_STEREO3D_FILTER) += x86/vf_stereo3d_init.o OBJS-$(CONFIG_TBLEND_FILTER) += x86/vf_blend_init.o OBJS-$(CONFIG_THRESHOLD_FILTER) += x86/vf_threshold_init.o OBJS-$(CONFIG_TINTERLACE_FILTER) += x86/vf_tinterlace_init.o +OBJS-$(CONFIG_TRANSPOSE_FILTER) += x86/vf_transpose_init.o OBJS-$(CONFIG_VOLUME_FILTER) += x86/af_volume_init.o OBJS-$(CONFIG_V360_FILTER) += x86/vf_v360_init.o OBJS-$(CONFIG_W3FDIF_FILTER) += x86/vf_w3fdif_init.o @@ -69,6 +70,7 @@ X86ASM-OBJS-$(CONFIG_STEREO3D_FILTER) += x86/vf_stereo3d.o X86ASM-OBJS-$(CONFIG_TBLEND_FILTER) += x86/vf_blend.o X86ASM-OBJS-$(CONFIG_THRESHOLD_FILTER) += x86/vf_threshold.o X86ASM-OBJS-$(CONFIG_TINTERLACE_FILTER) += x86/vf_interlace.o +X86ASM-OBJS-$(CONFIG_TRANSPOSE_FILTER) += x86/vf_transpose.o X86ASM-OBJS-$(CONFIG_VOLUME_FILTER) += x86/af_volume.o X86ASM-OBJS-$(CONFIG_V360_FILTER) += x86/vf_v360.o X86ASM-OBJS-$(CONFIG_W3FDIF_FILTER) += x86/vf_w3fdif.o diff --git a/libavfilter/x86/vf_transpose.asm b/libavfilter/x86/vf_transpose.asm new file mode 100644 index 0000000000..6d925d5d97 --- /dev/null +++ b/libavfilter/x86/vf_transpose.asm @@ -0,0 +1,104 @@ +;***************************************************************************** +;* x86-optimized functions for transpose filter +;* +;* Copyright (C) 2019 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 .text + +;------------------------------------------------------------------------------ +; void ff_transpose_8x8(uint8_t *src, ptrdiff_t src_linesize, +; uint8_t *dst, ptrdiff_t dst_linesize) +;------------------------------------------------------------------------------ + +INIT_XMM sse4 +cglobal transpose_8x8_8, 4,4,8, src, src_linesize, dst, dst_linesize + movu m0, [srcq] + add srcq, src_linesizeq + movu m1, [srcq] + add srcq, src_linesizeq + movu m2, [srcq] + add srcq, src_linesizeq + movu m3, [srcq] + add srcq, src_linesizeq + movu m4, [srcq] + add srcq, src_linesizeq + movu m5, [srcq] + add srcq, src_linesizeq + movu m6, [srcq] + add srcq, src_linesizeq + movu m7, [srcq] + + TRANSPOSE_8X8B 0, 1, 2, 3, 4, 5, 6, 7 + + movq [dstq], m0 + add dstq, dst_linesizeq + movq [dstq], m1 + add dstq, dst_linesizeq + movq [dstq], m2 + add dstq, dst_linesizeq + movq [dstq], m3 + add dstq, dst_linesizeq + movq [dstq], m4 + add dstq, dst_linesizeq + movq [dstq], m5 + add dstq, dst_linesizeq + movq [dstq], m6 + add dstq, dst_linesizeq + movq [dstq], m7 + RET + +INIT_XMM sse4 +cglobal transpose_8x8_16, 4,4,9, src, src_linesize, dst, dst_linesize + movu m0, [srcq] + add srcq, src_linesizeq + movu m1, [srcq] + add srcq, src_linesizeq + movu m2, [srcq] + add srcq, src_linesizeq + movu m3, [srcq] + add srcq, src_linesizeq + movu m4, [srcq] + add srcq, src_linesizeq + movu m5, [srcq] + add srcq, src_linesizeq + movu m6, [srcq] + add srcq, src_linesizeq + movu m7, [srcq] + + TRANSPOSE8x8W 0, 1, 2, 3, 4, 5, 6, 7, 8 + + movu [dstq], m0 + add dstq, dst_linesizeq + movu [dstq], m1 + add dstq, dst_linesizeq + movu [dstq], m2 + add dstq, dst_linesizeq + movu [dstq], m3 + add dstq, dst_linesizeq + movu [dstq], m4 + add dstq, dst_linesizeq + movu [dstq], m5 + add dstq, dst_linesizeq + movu [dstq], m6 + add dstq, dst_linesizeq + movu [dstq], m7 + RET diff --git a/libavfilter/x86/vf_transpose_init.c b/libavfilter/x86/vf_transpose_init.c new file mode 100644 index 0000000000..4f5acd5e56 --- /dev/null +++ b/libavfilter/x86/vf_transpose_init.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2019 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/mem.h" +#include "libavutil/x86/asm.h" +#include "libavutil/x86/cpu.h" +#include "libavfilter/transpose.h" + +void ff_transpose_8x8_8_sse4(uint8_t *src, + ptrdiff_t src_linesize, + uint8_t *dst, + ptrdiff_t dst_linesize); + +void ff_transpose_8x8_16_sse4(uint8_t *src, + ptrdiff_t src_linesize, + uint8_t *dst, + ptrdiff_t dst_linesize); + +av_cold void ff_transpose_init_x86(TransVtable *v, int pixstep) +{ + int cpu_flags = av_get_cpu_flags(); + + if (EXTERNAL_SSE4(cpu_flags) && pixstep == 1) { + v->transpose_8x8 = ff_transpose_8x8_8_sse4; + } + + if (EXTERNAL_SSE4(cpu_flags) && pixstep == 2) { + v->transpose_8x8 = ff_transpose_8x8_16_sse4; + } +}