From patchwork Mon Aug 22 15:26:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Mazur X-Patchwork-Id: 37397 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp1361361pzh; Mon, 22 Aug 2022 08:26:58 -0700 (PDT) X-Google-Smtp-Source: AA6agR4iw0p486T0/nlYYVnlsRbponLoDfovFG5KvJOE24/gA8wSFI7/wt8eoYREKcxnVesgjAI9 X-Received: by 2002:a17:907:970b:b0:73d:5a29:959 with SMTP id jg11-20020a170907970b00b0073d5a290959mr9193700ejc.183.1661182018484; Mon, 22 Aug 2022 08:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661182018; cv=none; d=google.com; s=arc-20160816; b=KvpYjvCYpUdRqwHrLG+GSyaDd9p8mqZ0NaW4gSP6nMKgfIpN/yslO8SwjZIz8FJmcN /k4tHH3q3VY6DsSoqhHDeCD0yphujdnUG9aAFmnKTYq+g2CzgU3T0ZsbNQOZZXbGMWHr QkjmdrZGmJrvyAqs5JtVRMEvVQqJiEZwJUt47rKidOY+poAdvdEm/IFeTr8oYrTglbMf S/Oe47NRvYoLkKeoMSG3XnqmVDhxjGVml0TIGj7jLAWwXnBVXMEprlbOG7hFe+WnB9lr Z7BI0CsGunHUAA0VInavc8nf9FjLLsg3E8h7lOLZ96QulkQt+DK09utnxfT+3k/TyRZR H6+A== 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:dkim-signature:delivered-to; bh=9c1i/Y42hKJCCL0HyBnJezNJMaI8sbh1KNEvjSosbX4=; b=AbpXCe5DHX0pkIeUN5hTJZVUezmHq2ZJr/fQbSZePnU7NLgW1D4rXWCuJj3Ny0v+/D Z9f+9WA5MbivsrFb1pghajqjGWUOEXWP1Rr7AiEVrno8UxI0mmiGE/V2wG+nKJgkjc7h 3A3FZqmHIAmGIh5j/SyjvmyCM+xdm1UMnxHUl+Z1/oOcbjW8pLC3FAaeGPAvzGXTeQuZ KXjO74DhLmIeQeJjbmq/saizpEbYjQlXk/QqX8ufIyfTIIX+sqx18enyQG1CBZItW48Z S1eJy3xoL81ut6N2oeLy1617gEsQq88L9VoOOhd1yWtpGFq76uMKxJEXgDiz+3YEePuR 38oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b=ICYibZCH; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id cw16-20020a170906479000b0073d8a8fedbfsi1237932ejc.386.2022.08.22.08.26.58; Mon, 22 Aug 2022 08:26:58 -0700 (PDT) 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=@semihalf.com header.s=google header.b=ICYibZCH; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=semihalf.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DF27368BA1E; Mon, 22 Aug 2022 18:26:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6D1C468BA14 for ; Mon, 22 Aug 2022 18:26:41 +0300 (EEST) Received: by mail-lj1-f178.google.com with SMTP id l19so7804288ljg.8 for ; Mon, 22 Aug 2022 08:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=3nwFqcPHpNtl9QykgLjikZYEeqOHyj+nJSfRlC42xTM=; b=ICYibZCHNEu+VpL571B9wb+4hwaVNNnYy3ZJjNIEvqHoYPqo0PC4WCT0KmvbGToagJ 1xyCgPL0ns9syzHoODqw57lRRPvBsIAfJORO0ktPkjyHwaPW3jIcATMhC5dXVkB/Psbr QYjwm3tCbslEuLZIc8zTbHFctw2qqkUU08+cwUYmRT+SP0AFHoR9UewvAMI4LprqhtKf z/cmh+t3vL4NUMpUEiiIybRKQmUpyuZRjXYt+ZWpcloq9RF+SXoRXZkU52l3rc/StV5r j9si0pAXu5fukSOyqasyv3x+IfwCL14dYNUqlpb6kFZhp7m/l9q92hv4ySYiEKLtUMqx F4xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=3nwFqcPHpNtl9QykgLjikZYEeqOHyj+nJSfRlC42xTM=; b=iVWbZCMDXdkHL44GkP1HGpLvv0/59gSTW9Ui3j7mZyDr6/eVnl34+D4z3Gmcwh7+J2 hzo+bdCiUNpnvdqnOzoTFhjOFl7nr2u6z25GRBTc73Bf5f7Z5C/heaRi1zgeuLEfunRv QfXbbboG4A77Z44+7YimBjTChoNd9feXD3g8020wQ4Nl6YjDSXGVmtT3x8sLrwxYnJlf IlwMv+R9Y0LxqWkfNP5hXZF8HjYWLTR3AX/JZknvvQQAmZYEw9AXGEj7Ef7SFWUEHL9x rVIM93IrdtB8ZaVI/rSIVFE5DaP/Mq3BmNkA1ac5Y0imqm6eCiPviaWQ1QFcgDYSv43t rt0w== X-Gm-Message-State: ACgBeo1XzkZd8J9PK1OqiRy3u4fB5hy1yKhDH8Ckg1p1DMtQNmLqw7n6 NPF2MR2TGGIHCNRO2azZ/4xjcMYSmJpuQA== X-Received: by 2002:a05:651c:507:b0:25e:73af:1661 with SMTP id o7-20020a05651c050700b0025e73af1661mr6363111ljp.195.1661182000386; Mon, 22 Aug 2022 08:26:40 -0700 (PDT) Received: from hum-HP-ProBook-440-G7.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id z13-20020a056512370d00b00492f21c161esm2921lfr.123.2022.08.22.08.26.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 08:26:40 -0700 (PDT) From: Hubert Mazur To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Aug 2022 17:26:23 +0200 Message-Id: <20220822152627.1992008-2-hum@semihalf.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220822152627.1992008-1-hum@semihalf.com> References: <20220822152627.1992008-1-hum@semihalf.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] lavc/aarch64: Add neon implementation for vsad16 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: gjb@semihalf.com, upstream@semihalf.com, jswinney@amazon.com, Hubert Mazur , martin@martin.st, mw@semihalf.com, spop@amazon.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Af0I2hxaWgjB Provide optimized implementation of vsad16 function for arm64. Performance comparison tests are shown below. - vsad_0_c: 285.0 - vsad_0_neon: 42.5 Benchmarks and tests are run with checkasm tool on AWS Graviton 3. Signed-off-by: Hubert Mazur --- libavcodec/aarch64/me_cmp_init_aarch64.c | 5 ++ libavcodec/aarch64/me_cmp_neon.S | 75 ++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index fb7c3f5059..ddc5d05611 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -41,6 +41,9 @@ int sse8_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, int sse4_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); +int vsad16_neon(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, + ptrdiff_t stride, int h); + av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) { int cpu_flags = av_get_cpu_flags(); @@ -57,5 +60,7 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) c->sse[0] = sse16_neon; c->sse[1] = sse8_neon; c->sse[2] = sse4_neon; + + c->vsad[0] = vsad16_neon; } } diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index 4198985c6c..d4c0099854 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -584,3 +584,78 @@ function sse4_neon, export=1 ret endfunc + +function vsad16_neon, export=1 + // x0 unused + // x1 uint8_t *pix1 + // x2 uint8_t *pix2 + // x3 ptrdiff_t stride + // w4 int h + + sub w4, w4, #1 // we need to make h-1 iterations + movi v16.8h, #0 + + cmp w4, #3 // check if we can make 3 iterations at once + add x5, x1, x3 // pix1 + stride + add x6, x2, x3 // pix2 + stride + b.le 2f + +1: + // abs(pix1[0] - pix2[0] - pix1[0 + stride] + pix2[0 + stride]) + // abs(x) = (x < 0 ? (-x) : (x)) + ld1 {v0.16b}, [x1], x3 // Load pix1[0], first iteration + ld1 {v1.16b}, [x2], x3 // Load pix2[0], first iteration + ld1 {v2.16b}, [x5], x3 // Load pix1[0 + stride], first iteration + usubl v31.8h, v0.8b, v1.8b // Signed difference pix1[0] - pix2[0], first iteration + ld1 {v3.16b}, [x6], x3 // Load pix2[0 + stride], first iteration + usubl2 v30.8h, v0.16b, v1.16b // Signed difference pix1[0] - pix2[0], first iteration + usubl v29.8h, v2.8b, v3.8b // Signed difference pix1[0 + stride] - pix2[0 + stride], first iteration + ld1 {v4.16b}, [x1], x3 // Load pix1[0], second iteration + usubl2 v28.8h, v2.16b, v3.16b // Signed difference pix1[0 + stride] - pix2[0 + stride], first iteration + ld1 {v5.16b}, [x2], x3 // Load pix2[0], second iteration + saba v16.8h, v31.8h, v29.8h // Signed absolute difference and accumulate the result. first iteration + ld1 {v6.16b}, [x5], x3 // Load pix1[0 + stride], second iteration + saba v16.8h, v30.8h, v28.8h // Signed absolute difference and accumulate the result. first iteration + usubl v27.8h, v4.8b, v5.8b // Signed difference pix1[0] - pix2[0], second iteration + ld1 {v7.16b}, [x6], x3 // Load pix2[0 + stride], second iteration + usubl2 v26.8h, v4.16b, v5.16b // Signed difference pix1[0] - pix2[0], second iteration + usubl v25.8h, v6.8b, v7.8b // Signed difference pix1[0 + stride] - pix2[0 + stride], second iteration + ld1 {v17.16b}, [x1], x3 // Load pix1[0], third iteration + usubl2 v24.8h, v6.16b, v7.16b // Signed difference pix1[0 + stride] - pix2[0 + stride], second iteration + ld1 {v18.16b}, [x2], x3 // Load pix2[0], second iteration + saba v16.8h, v27.8h, v25.8h // Signed absolute difference and accumulate the result. second iteration + ld1 {v19.16b}, [x5], x3 // Load pix1[0 + stride], third iteration + saba v16.8h, v26.8h, v24.8h // Signed absolute difference and accumulate the result. second iteration + usubl v23.8h, v17.8b, v18.8b // Signed difference pix1[0] - pix2[0], third iteration + ld1 {v20.16b}, [x6], x3 // Load pix2[0 + stride], third iteration + usubl2 v22.8h, v17.16b, v18.16b // Signed difference pix1[0] - pix2[0], third iteration + usubl v21.8h, v19.8b, v20.8b // Signed difference pix1[0 + stride] - pix2[0 + stride], third iteration + sub w4, w4, #3 // h -= 3 + saba v16.8h, v23.8h, v21.8h // Signed absolute difference and accumulate the result. third iteration + usubl2 v31.8h, v19.16b, v20.16b // Signed difference pix1[0 + stride] - pix2[0 + stride], third iteration + cmp w4, #3 + saba v16.8h, v22.8h, v31.8h // Signed absolute difference and accumulate the result. third iteration + + b.ge 1b + cbz w4, 3f +2: + + ld1 {v0.16b}, [x1], x3 + ld1 {v1.16b}, [x2], x3 + ld1 {v2.16b}, [x5], x3 + usubl v30.8h, v0.8b, v1.8b + ld1 {v3.16b}, [x6], x3 + usubl2 v29.8h, v0.16b, v1.16b + usubl v28.8h, v2.8b, v3.8b + usubl2 v27.8h, v2.16b, v3.16b + saba v16.8h, v30.8h, v28.8h + subs w4, w4, #1 + saba v16.8h, v29.8h, v27.8h + + b.ne 2b +3: + uaddlv s17, v16.8h + fmov w0, s17 + + ret +endfunc