From patchwork Tue Aug 16 12:20:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Mazur X-Patchwork-Id: 37308 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1829249pzi; Tue, 16 Aug 2022 05:21:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR6sOeVWTz5tiCJRIG422Nop7OGuBlQUtx5TkCRSw5NHJj5j744w6X4enQYYC333WV1yvLrL X-Received: by 2002:a17:907:7284:b0:731:82a3:16e3 with SMTP id dt4-20020a170907728400b0073182a316e3mr13636856ejc.30.1660652472967; Tue, 16 Aug 2022 05:21:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660652472; cv=none; d=google.com; s=arc-20160816; b=e1D+8HXPcZC4AJ1fNUQeiVOA1NjUvRm+E8u8/0dmruKEWxp6cLqtx/+kPbw4YabhpN ju8FBBqGfsmjFkepqG2ljbJrmJUbKRkYmsfMfPS8XB2Y+VE6ZDkyr04zAHBUr46zR1rC 5CK8i3l+AfJEG4+AznXSWYMVLc1cqL5OICWRk85AWZ6tQzSkTvPmjqKDc1ZNSNFkXNXT wRfZh+jf43of1qtLQEnnYda9DIXtnxmkIaoVME/MmTRAoqN5jZDkMpgTQzGzo5a6veF1 KLlzb1l7/6eYOKsT2x2fOKTbrwtSsU5b8IE87RVIoWFix92ksVjTg5Bc83HAba7+cIQZ d7rQ== 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=Ez+pIqD6gAD3F1VaypHFvZLGzOKKUzLOTNkDFQ6HA4w=; b=kCfJ4pGq64GHrlju3fmwR3dvtXbZhr6mhzFMnhavBPxK5NMMNW2LmJHkgx/f1J5ht/ Z7zFSCIaxz7fh5zdy0l9vLI/4oQJZmldtUDlrWuifSOfeXPq9H19cc6+JL/unPfF381C ohXws1dF9COMVt/AVA9vZnYpJ25DTSnUhdBYpW0PMK9pPW3qaZy3VUzqo26m/BS7ARY4 fB0qf2qi7RGRh8NQI+FInCKQ2GAPlTDQ2G18+PK6GvHueDJAYVUGxDHWyvmsIf0NrJoV 8f7M9Zl07Vj5jVtISmzHVYZ+53DPUb6b+5FKExXJK04id2ML13e+9rTqJD6jfNre4omJ FxkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b=pssuMzo0; 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 u8-20020a50eac8000000b0043e6a16bca1si9539898edp.475.2022.08.16.05.21.11; Tue, 16 Aug 2022 05:21:12 -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=pssuMzo0; 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 303BF68B8FD; Tue, 16 Aug 2022 15:21:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f45.google.com (mail-lf1-f45.google.com [209.85.167.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 27F2968B41C for ; Tue, 16 Aug 2022 15:20:56 +0300 (EEST) Received: by mail-lf1-f45.google.com with SMTP id c28so10614753lfh.3 for ; Tue, 16 Aug 2022 05:20:56 -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=VHOgVR5mQm9FMmGWvgy7zxQXWSDL5yO+yk9z1W9gNhk=; b=pssuMzo0Q6Ge9cb1fJmZ1nnqqcXFUmRxCEI1CnW0C2mS5wbIKNmiR7BeB5QV9xnwjJ gAPRfaRLWCZf6xTHfSfBa12Fc47OXm1NW3kecBq6KvPqyNhOGslt10xtCMYoIuamipgP 64AByoszHBafluwnrpYbNQsXoX9VHJaLoQDoMs0NFWTLg+xUzPqdNZpQ9PsN2oj0oiRm lpECeu9W1jbcCNkOfCMuAfYDuwxUAbn/UK7Oi6YoCfz4GM7HO+O30wSfO4++ygI5nygr 6baHxhMeK2ORpsgFPDhouiid5CFNyBSUUkAog58RT8k8HA9zWMz8zAu1/hKkYKxerUvJ HZuA== 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=VHOgVR5mQm9FMmGWvgy7zxQXWSDL5yO+yk9z1W9gNhk=; b=nvUR0uXJ9Tc2DiWxT3uFilE5PaG2+JBQyJL7wfPR/ntMUTPy69U/GfKJ2AE30H5Ib3 ZwXPUBLIBRRoJWFiC1VR5hopSbdbdq9lcVc6fQynTmG0Y0WHdH0Hvf43UR/dFBcztvMJ fuG+WtlQLMo/WvLqiVWchK3uj2j2Oh1qAJU19lwNsos5MIbOnC8BBXW+mQtB+DVgL3UW StFWmuZ29Dy/LyugULLTkBMflqj361+5wbzpFTEQxHL809PB5/hcQAsamTL+gk3DsPSY xGDI82I0bS4QXv/xtZdALwbMvIaLZNXPlK69910nC+ZEjpRGkNFy8TZr9DaO7TUuozlp TILw== X-Gm-Message-State: ACgBeo2563X6XCAj9Xvo221PgzaEgFU+hdzxXoNaCgjnQfPbSz1CWmn2 VrSbh/JYZUCvTgy17vnICVAqErYohhAb1eVt X-Received: by 2002:ac2:5bc4:0:b0:48b:1be:f02d with SMTP id u4-20020ac25bc4000000b0048b01bef02dmr7083289lfn.486.1660652455235; Tue, 16 Aug 2022 05:20:55 -0700 (PDT) Received: from hum-HP-ProBook-440-G7.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id p20-20020ac24ed4000000b0048b998be041sm1365707lfr.309.2022.08.16.05.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 05:20:54 -0700 (PDT) From: Hubert Mazur To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2022 14:20:12 +0200 Message-Id: <20220816122016.64929-2-hum@semihalf.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816122016.64929-1-hum@semihalf.com> References: <20220816122016.64929-1-hum@semihalf.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/5] lavc/aarch64: Add neon implementation for sse16 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: erYe3Hon+5Mn Provide neon implementation for sse16 function. Performance comparison tests are shown below. - sse_0_c: 268.2 - sse_0_neon: 43.5 Benchmarks and tests run with checkasm tool on AWS Graviton 3. Signed-off-by: Hubert Mazur --- libavcodec/aarch64/me_cmp_init_aarch64.c | 4 ++ libavcodec/aarch64/me_cmp_neon.S | 76 ++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index 79c739914f..7780009d41 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -30,6 +30,9 @@ int ff_pix_abs16_xy2_neon(MpegEncContext *s, const uint8_t *blk1, const uint8_t int ff_pix_abs16_x2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); +int sse16_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, + ptrdiff_t stride, int h); + av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) { int cpu_flags = av_get_cpu_flags(); @@ -40,5 +43,6 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) c->pix_abs[0][3] = ff_pix_abs16_xy2_neon; c->sad[0] = ff_pix_abs16_neon; + c->sse[0] = sse16_neon; } } diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index cda7ce0408..825ce45d13 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -270,3 +270,79 @@ function ff_pix_abs16_x2_neon, export=1 ret endfunc + +function sse16_neon, export=1 + // x0 - unused + // x1 - pix1 + // x2 - pix2 + // x3 - stride + // w4 - h + + cmp w4, #4 + movi d18, #0 + movi v17.4s, #0 + b.lt 2f + +// Make 4 iterations at once +1: + + // res = abs(pix1[0] - pix2[0]) + // res * res + + ld1 {v0.16b}, [x1], x3 // Load pix1 vector for first iteration + ld1 {v1.16b}, [x2], x3 // Load pix2 vector for first iteration + ld1 {v2.16b}, [x1], x3 // Load pix1 vector for second iteration + uabd v30.16b, v0.16b, v1.16b // Absolute difference, first iteration + ld1 {v3.16b}, [x2], x3 // Load pix2 vector for second iteration + umull v29.8h, v30.8b, v30.8b // Multiply lower half of vectors, first iteration + umull2 v28.8h, v30.16b, v30.16b // Multiply upper half of vectors, first iteration + uabd v27.16b, v2.16b, v3.16b // Absolute difference, second iteration + uadalp v17.4s, v29.8h // Pairwise add, first iteration + ld1 {v4.16b}, [x1], x3 // Load pix1 for third iteration + umull v26.8h, v27.8b, v27.8b // Mulitply lower half, second iteration + umull2 v25.8h, v27.16b, v27.16b // Multiply upper half, second iteration + ld1 {v5.16b}, [x2], x3 // Load pix2 for third iteration + uadalp v17.4s, v26.8h // Pairwise add and accumulate, second iteration + uabd v24.16b, v4.16b, v5.16b // Absolute difference, third iteration + ld1 {v6.16b}, [x1], x3 // Load pix1 for fourth iteration + uadalp v17.4s, v25.8h // Pairwise add andd accumulate, second iteration + umull v23.8h, v24.8b, v24.8b // Multiply lower half, third iteration + umull2 v22.8h, v24.16b, v24.16b // Multiply upper half, third iteration + uadalp v17.4s, v23.8h // Pairwise add and accumulate, third iteration + ld1 {v7.16b}, [x2], x3 // Load pix2 for fouth iteration + uadalp v17.4s, v22.8h // Pairwise add and accumulate, third iteration + uabd v21.16b, v6.16b, v7.16b // Absolute difference, fourth iteration + uadalp v17.4s, v28.8h // Pairwise add and accumulate, first iteration + umull v20.8h, v21.8b, v21.8b // Multiply lower half, fourth iteration + sub w4, w4, #4 // h -= 4 + umull2 v19.8h, v21.16b, v21.16b // Multiply upper half, fourth iteration + uadalp v17.4s, v20.8h // Pairwise add and accumulate, fourth iteration + cmp w4, #4 + uadalp v17.4s, v19.8h // Pairwise add and accumulate, fourth iteration + b.ge 1b + + cbz w4, 3f + +// iterate by one +2: + + ld1 {v0.16b}, [x1], x3 // Load pix1 + ld1 {v1.16b}, [x2], x3 // Load pix2 + + uabd v30.16b, v0.16b, v1.16b + umull v29.8h, v30.8b, v30.8b + umull2 v28.8h, v30.16b, v30.16b + uadalp v17.4s, v29.8h + subs w4, w4, #1 + uadalp v17.4s, v28.8h + + b.ne 2b + +3: + uaddlv d16, v17.4s // add up accumulator vector + add d18, d18, d16 + + fmov w0, s18 + + ret +endfunc From patchwork Tue Aug 16 12:20:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Mazur X-Patchwork-Id: 37310 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1829393pzi; Tue, 16 Aug 2022 05:21:31 -0700 (PDT) X-Google-Smtp-Source: AA6agR499SIV26f5IFx0A6OPjvrerFqCRrQbkS3tx2mT/8tJUFd+qFQh2ZTQmeD4JUg1b4rchvZ0 X-Received: by 2002:a05:6402:5203:b0:43d:444b:9f99 with SMTP id s3-20020a056402520300b0043d444b9f99mr19016240edd.343.1660652480855; Tue, 16 Aug 2022 05:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660652480; cv=none; d=google.com; s=arc-20160816; b=T7zSr0wjoX9aX6Nf/xzceGLqom1CaVvbsYvDepjXXbOKVoCtcONMIxYFEPCrvZEsbH EL6wU9/1vDzsCPoc2VWzZ17jjH/nnGyDljpRDBN5kKiURvI9edM0fFfdlfJdNQowKwHX mUOo9fdc4oUquNJWl46tV2XXMCQiGcmLHaEs99lfHVv9C7yLIr19tXt/slkdX8GZrpvO n1QseFj8nDGx5mGlrcOpKaRU6vVN22YrfY7GzDdCD+BfJelcP4cvnphlnPctkPXEFqv7 SFwTNAMsvrUxuczFniUiN5FtmgAVD97copIF5Bg1r0AxaE+aUAItVLaGFrbah1xVxbnG rWhw== 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=OQ+Z51WiLduPFeRp7if87fL97/JfKwEd9mZk3qnS4wE=; b=0wXPTP1aNEUroN4fDEwnZUzdXxVdh74gVUHEDiwUrd/U6Q85GC29HpqtM51qlbrmLV yKK2GXmTRWNh/GW0sf7Vk7kMoXu23LMhhll3jUnZnsyknZmjnIDLimz1ORFvcQVwmEzL 8EJ/u8dvz8kwsX2jPA2Nkvn8EedgfCg0VKmY+bEWVYhnQeFXS98MwDwImKz8vOKi2kw6 rDAwxSst2PGSvjJDjglCPBXVd2aHrEoE8pvMB6niDswFfjPITf+LKJf1qttcwULyKKmN /xLLjMSx5eFIlB17g+BGDcgL5/ihjL1y47ZEsn0C0Z/GqaOfIrWDIC6oK71ptB9bqCQs pwbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b=Qmh5gqsX; 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 jg21-20020a170907971500b00733002330edsi9911985ejc.342.2022.08.16.05.21.20; Tue, 16 Aug 2022 05:21:20 -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=Qmh5gqsX; 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 3E1EF68B92B; Tue, 16 Aug 2022 15:21:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2F9A868B8F0 for ; Tue, 16 Aug 2022 15:20:59 +0300 (EEST) Received: by mail-lf1-f49.google.com with SMTP id v2so14670112lfi.6 for ; Tue, 16 Aug 2022 05:20:59 -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=fUY7SGKEq38K8vvA4cdcrVp3TtbAL+6QhVSEp4yFh4I=; b=Qmh5gqsXEs0z+0os/3PIKP71Zdy/HFYLYuHOWAP844YzN6V5n21xhoD3PJgBCKVQv4 8+EBebjI7ug9B9iHSS/ABgKrpteTiX2zhtbkuqX+gVy96Bm5Y2VPFgU99ZKI8fPSrQrd 2BD5A8JzwEZEkuuCH6w5JUz9QeF5955eCcymZ0geeas2ZOj87undd5m9NXYsmOgVDY3V +p68I3Xym7/x7+ajyTJfSKob1rkS2wIG8u2x1jkQ6zSaQfTIDKOqtSJP4L+a0i2mAYRY ryXR7Lto1P6mvXhk/HbCa7wB4oJkrxkypPlI5kUZnix2pggx/IcDVzY/G69/hPF0LA01 sLxQ== 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=fUY7SGKEq38K8vvA4cdcrVp3TtbAL+6QhVSEp4yFh4I=; b=z2sGknjHUp2xjym+gwct8eVXtlcRcgKj8V/ASxkpjsuhGgz1YFzKFky6dU0XlMPVAL kCPZuDkn/iUted1lTl8/DbixDOGXk8AOEEJn5mYF1hMNAe+PnO7B88YH9k1NvBq9Qm9s ZnJ9a7L8jP/ok5/gXuooWcUB33zhXXeDDX8h3+Ind/unhDfzFtO7KJW+4Qfk4UvSjxsA UOTYmAbY468JzjvmFVjfqNT/sPmfAzg/7tJv53Fbpjm3gTADAExXcm9eyMtd9MyPnjFz C3lsTaKYmdVJvmwpN2kRr/LsS8GdLr8NboNy/3D/p0vJ1lKTuRNHFKj64O68ShdAfDR6 ExoQ== X-Gm-Message-State: ACgBeo2U8nH/78ADzfrKQOd7AYu3qTyWeZgRskHtIdCaYODzrVOjZDwH NS24cnjZTYbt2wjv8lcLMNe3LWLfp//tkLnk X-Received: by 2002:a05:6512:b85:b0:48c:db16:1b27 with SMTP id b5-20020a0565120b8500b0048cdb161b27mr7124306lfv.87.1660652458144; Tue, 16 Aug 2022 05:20:58 -0700 (PDT) Received: from hum-HP-ProBook-440-G7.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id p20-20020ac24ed4000000b0048b998be041sm1365707lfr.309.2022.08.16.05.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 05:20:57 -0700 (PDT) From: Hubert Mazur To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2022 14:20:13 +0200 Message-Id: <20220816122016.64929-3-hum@semihalf.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816122016.64929-1-hum@semihalf.com> References: <20220816122016.64929-1-hum@semihalf.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/5] lavc/aarch64: Add neon implementation for sse4 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: qEcUKkkCVA5F Provide neon implementation for sse4 function. Performance comparison tests are shown below. - sse_2_c: 80.7 - sse_2_neon: 31.0 Benchmarks and tests are run with checkasm tool on AWS Graviton 3. Signed-off-by: Hubert Mazur --- libavcodec/aarch64/me_cmp_init_aarch64.c | 3 ++ libavcodec/aarch64/me_cmp_neon.S | 58 ++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index 7780009d41..955592625a 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -32,6 +32,8 @@ int ff_pix_abs16_x2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t * int sse16_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); +int sse4_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, + ptrdiff_t stride, int h); av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) { @@ -44,5 +46,6 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) c->sad[0] = ff_pix_abs16_neon; c->sse[0] = sse16_neon; + c->sse[2] = sse4_neon; } } diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index 825ce45d13..367924b3c2 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -346,3 +346,61 @@ function sse16_neon, export=1 ret endfunc + +function sse4_neon, export=1 + // x0 - unused + // x1 - pix1 + // x2 - pix2 + // x3 - stride + // w4 - h + + movi d18, #0 + movi v16.4s, #0 // clear the result accumulator + cmp w4, #4 + b.le 2f + +// make 4 iterations at once +1: + + // res = abs(pix1[0] - pix2[0]) + // res * res + + ld1 {v0.s}[0], [x1], x3 // Load pix1, first iteration + ld1 {v1.s}[0], [x2], x3 // Load pix2, first iteration + ld1 {v2.s}[0], [x1], x3 // Load pix1, second iteration + ld1 {v3.s}[0], [x2], x3 // Load pix2, second iteration + uabdl v30.8h, v0.8b, v1.8b // Absolute difference, first iteration + ld1 {v4.s}[0], [x1], x3 // Load pix1, third iteration + ld1 {v5.s}[0], [x2], x3 // Load pix2, third iteration + uabdl v29.8h, v2.8b, v3.8b // Absolute difference, second iteration + umlal v16.4s, v30.4h, v30.4h // Multiply vectors, first iteration + ld1 {v6.s}[0], [x1], x3 // Load pix1, fourth iteration + ld1 {v7.s}[0], [x2], x3 // Load pix2, fourth iteration + uabdl v28.8h, v4.8b, v5.8b // Absolute difference, third iteration + umlal v16.4s, v29.4h, v29.4h // Multiply and accumulate, second iteration + sub w4, w4, #4 + uabdl v27.8h, v6.8b, v7.8b // Absolue difference, fourth iteration + umlal v16.4s, v28.4h, v28.4h // Multiply and accumulate, third iteration + cmp w4, #4 + umlal v16.4s, v27.4h, v27.4h // Multiply and accumulate, fourth iteration + b.ge 1b + + cbz w4, 3f + +// iterate by one +2: + ld1 {v0.s}[0], [x1], x3 // Load pix1 + ld1 {v1.s}[0], [x2], x3 // Load pix2 + uabdl v30.8h, v0.8b, v1.8b + subs w4, w4, #1 + umlal v16.4s, v30.4h, v30.4h + + b.ne 2b + +3: + uaddlv d17, v16.4s // Add vector + add d18, d18, d17 + fmov w0, s18 + + ret +endfunc From patchwork Tue Aug 16 12:20:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Mazur X-Patchwork-Id: 37309 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1829390pzi; Tue, 16 Aug 2022 05:21:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR7XI/f4eZ8U3NNzrzfd3fXCqXb1i+pXGP3TSERQiw5oNZFzwyiLTIvCclWtZ8JVh+uZOuNV X-Received: by 2002:a17:907:2da6:b0:730:8b30:e517 with SMTP id gt38-20020a1709072da600b007308b30e517mr13443277ejc.291.1660652490252; Tue, 16 Aug 2022 05:21:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660652490; cv=none; d=google.com; s=arc-20160816; b=ERTrj3t7MLrogbD8GazK/VGjDObqySYTn5Xz9FgpAUwgwAMgGj+PaReB71I2TsbhZp 6ckYW92BcAXJ2sRABYMcAPa5WtxG+CPVwH/b8/PQMAOX8NGTAzSZXXOEvesXcnCOiV2y QifYhCyIacu8o988Ylklv1en3C189uoCEPiBkYlNjIglgz/5J5vYH2naHsloIe34JUdy cero9zs7IK7IOpck5ImEbDT9OWBRwXm6oxMh+Y6S9T4V+ivAFhS0BxYI42hyFHpmmKSC qbSOQk7U2WfLdQtE9Wq3jZu+KF2O0XvER16IRb/tehjd8eeYVGAenehXjzjxt+IKfUJf gdhQ== 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=tE1jCLSFpGvObBSRszYoFxQQot+BLz/fkRt9fg1ue1M=; b=L483ZNpkjADP0PvJ/Wp6JIS0Qde2QExUTcOkFVTvm4HU4Rrhs9KGweB9HNfYsHV12I vncK42ocx0ePjGAVV2GJayY6ucwbauERfd/WJd2wZbSvYWfSfAXSOp122dJ/PLuGCre8 4/H0xNeFR0xroV6ZLHbb39wDqX5SJuvmcMoDXt0pjVdXULgHIPd9qyiRVAKT8m+1Nl88 5PcsQmrWX46guTWl0oJwdg7xDEJfQUBhU6FYovKSTCtNS7Q3DkJfdTtleOHquD8ElHSV dEshlE1lw0DJaVcJjeCQa2pv7TlXBBWUe1uAnb8tynZ6A+Bfntefr8Uj6eoTGblFU5Rn iXag== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b=mU4MkueU; 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 f19-20020a170906139300b007303646197csi7880194ejc.596.2022.08.16.05.21.29; Tue, 16 Aug 2022 05:21:30 -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=mU4MkueU; 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 3F2D668B913; Tue, 16 Aug 2022 15:21:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0823F68B900 for ; Tue, 16 Aug 2022 15:21:01 +0300 (EEST) Received: by mail-lf1-f54.google.com with SMTP id z25so14673930lfr.2 for ; Tue, 16 Aug 2022 05:21:01 -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=Jyf3BnAxmt3GS20+5LX75T5kI6P/GR6SZahTzjlpTdU=; b=mU4MkueU1t7XUX5UrBdoGeU1sWT9rYlJQdX5rEyxvyJYwGdnF9N4G93pHeKP1mjymx XYe0QC7nR0Uzzr98BP/hHVCgrDa4h3pcbFeVOwahnbhCTS8y6HU3BAoPMk5Yhl5LRQLI yz4sm3H9k96KA1IIEWMbZfretNkWObZRkC25UGE77Nijgg2bgGukoPgJsljMuF/mm4MV Ae6G+7pL+EU2mA/JM7cuezPYQZjyCfaX6Vsaus3iEHmrmIXj/sb7zM7YouuQBGsXIIqQ 1xM4m9hyTFghtdc+dywDCUZ9WzVj6kCDhOtshawEjsaBpg5uCuHjt/QZfbqKPk1gFVEP GUnQ== 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=Jyf3BnAxmt3GS20+5LX75T5kI6P/GR6SZahTzjlpTdU=; b=dY7Xcp+Trw8TStjOgB360b4yB19MwJzIVL0vUp2iz2ZbjpAR4E+Ej8Mi67JJbVGaTy 1A9nVbBDTcWa6jiwsJ3UPG+hC8fG8YPnzSTLkpVrXMPaZNrlyVFj1DFjTyYHuK9RU5LD n6O4Klkt/W5ekrv6GpwtxvSGZMvX1volyOhiNGwAJ60/O1XZLcgRzGxkDhr/ifzP/W49 DePYsGxAnROZLmb//G/NNLheudg96T6u1NeSR8B8QH3j4C5FQc2+aa6Dth8e5Tj2fXQY /h8jadUc39Ci/MmfZK0OReuKFfqNVXrJFEZE2pdQglu2o2Yc/YuVSQGcEn7H9FrV6MWH hyiA== X-Gm-Message-State: ACgBeo0vfPP44WbU0SUP+TEbpcZAGaiO0NQkdcZ9sLVMJ0vNkn8fYZio LyfiS6I+9y5vpdRWz8LfVNLPhhR9/2e1mK7n X-Received: by 2002:a05:6512:3c82:b0:48b:1844:2840 with SMTP id h2-20020a0565123c8200b0048b18442840mr6925897lfv.406.1660652460028; Tue, 16 Aug 2022 05:21:00 -0700 (PDT) Received: from hum-HP-ProBook-440-G7.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id p20-20020ac24ed4000000b0048b998be041sm1365707lfr.309.2022.08.16.05.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 05:20:59 -0700 (PDT) From: Hubert Mazur To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2022 14:20:14 +0200 Message-Id: <20220816122016.64929-4-hum@semihalf.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816122016.64929-1-hum@semihalf.com> References: <20220816122016.64929-1-hum@semihalf.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/5] lavc/aarch64: Add neon implementation for pix_abs16_y2 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: rSYSca0yNsOM Provide optimized implementation of pix_abs16_y2 function for arm64. Performance comparison tests are shown below. pix_abs_0_2_c: 317.2 pix_abs_0_2_neon: 37.5 Benchmarks and tests run with checkasm tool on AWS Graviton 3. Signed-off-by: Hubert Mazur --- libavcodec/aarch64/me_cmp_init_aarch64.c | 3 + libavcodec/aarch64/me_cmp_neon.S | 75 ++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index 955592625a..1c36d3d7cb 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -29,6 +29,8 @@ int ff_pix_abs16_xy2_neon(MpegEncContext *s, const uint8_t *blk1, const uint8_t ptrdiff_t stride, int h); int ff_pix_abs16_x2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); +int ff_pix_abs16_y2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, + ptrdiff_t stride, int h); int sse16_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); @@ -42,6 +44,7 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) if (have_neon(cpu_flags)) { c->pix_abs[0][0] = ff_pix_abs16_neon; c->pix_abs[0][1] = ff_pix_abs16_x2_neon; + c->pix_abs[0][2] = ff_pix_abs16_y2_neon; c->pix_abs[0][3] = ff_pix_abs16_xy2_neon; c->sad[0] = ff_pix_abs16_neon; diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index 367924b3c2..0ec9c0465b 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -404,3 +404,78 @@ function sse4_neon, export=1 ret endfunc + +function ff_pix_abs16_y2_neon, export=1 + // x0 unused + // x1 uint8_t *pix1 + // x2 uint8_t *pix2 + // x3 ptrdiff_t stride + // x4 int h + + // initialize buffers + movi v29.8h, #0 // clear the accumulator + movi v28.8h, #0 // clear the accumulator + movi d18, #0 + add x5, x2, x3 // pix2 + stride + cmp w4, #4 + b.lt 2f + +// make 4 iterations at once +1: + + // abs(pix1[0], avg2(pix2[0], pix2[0 + stride])) + // avg2(a, b) = (((a) + (b) + 1) >> 1) + // abs(x) = (x < 0 ? (-x) : (x)) + + ld1 {v1.16b}, [x2], x3 // Load pix2 for first iteration + ld1 {v2.16b}, [x5], x3 // Load pix3 for first iteration + urhadd v30.16b, v1.16b, v2.16b // Rounding halving add, first iteration + ld1 {v0.16b}, [x1], x3 // Load pix1 for first iteration + uabal v29.8h, v0.8b, v30.8b // Absolute difference of lower half, first iteration + ld1 {v4.16b}, [x2], x3 // Load pix2 for second iteration + uabal2 v28.8h, v0.16b, v30.16b // Absolute difference of upper half, first iteration + ld1 {v5.16b}, [x5], x3 // Load pix3 for second iteartion + urhadd v27.16b, v4.16b, v5.16b // Rounding halving add, second iteration + ld1 {v3.16b}, [x1], x3 // Load pix1 for second iteration + uabal v29.8h, v3.8b, v27.8b // Absolute difference of lower half for second iteration + ld1 {v7.16b}, [x2], x3 // Load pix2 for third iteration + ld1 {v20.16b}, [x5], x3 // Load pix3 for third iteration + uabal2 v28.8h, v3.16b, v27.16b // Absolute difference of upper half for second iteration + ld1 {v6.16b}, [x1], x3 // Load pix1 for third iteration + urhadd v26.16b, v7.16b, v20.16b // Rounding halving add, third iteration + uabal v29.8h, v6.8b, v26.8b // Absolute difference of lower half for third iteration + ld1 {v22.16b}, [x2], x3 // Load pix2 for fourth iteration + uabal2 v28.8h, v6.16b, v26.16b // Absolute difference of upper half for third iteration + ld1 {v23.16b}, [x5], x3 // Load pix3 for fourth iteration + sub w4, w4, #4 // h-= 4 + urhadd v25.16b, v22.16b, v23.16b // Rounding halving add + ld1 {v21.16b}, [x1], x3 // Load pix1 for fourth iteration + cmp w4, #4 + uabal v29.8h, v21.8b, v25.8b // Absolute difference of lower half for fourth iteration + uabal2 v28.8h, v21.16b, v25.16b // Absolute difference of upper half for fourth iteration + + b.ge 1b + cbz w4, 3f + +// iterate by one +2: + + ld1 {v1.16b}, [x2], x3 // Load pix2 + ld1 {v2.16b}, [x5], x3 // Load pix3 + subs w4, w4, #1 + urhadd v30.16b, v1.16b, v2.16b // Rounding halving add + ld1 {v0.16b}, [x1], x3 // Load pix1 + uabal v29.8h, v30.8b, v0.8b + uabal2 v28.8h, v30.16b, v0.16b + + b.ne 2b + +3: + add v29.8h, v29.8h, v28.8h // Add vectors together + uaddlv s16, v29.8h // Add up vector values + add d18, d18, d16 + + fmov w0, s18 + + ret +endfunc From patchwork Tue Aug 16 12:20:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Mazur X-Patchwork-Id: 37311 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1829506pzi; Tue, 16 Aug 2022 05:21:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR5rhXCYNBxqLwcrSYUiu7nwfH+9SqCspzNuTOsP8sV/WUtiLG2TKCbbAxn1Oek44IPGvUm2 X-Received: by 2002:a17:906:4787:b0:737:2a03:6dd6 with SMTP id cw7-20020a170906478700b007372a036dd6mr9492457ejc.476.1660652500401; Tue, 16 Aug 2022 05:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660652500; cv=none; d=google.com; s=arc-20160816; b=piX9HBTW1dfWjK3A5ZmnDKpj49Wwefs2xAkpHHXG14n8OyftYWWYqO++s8nOWYR2Z+ LDaE/1aczxjEou7oyjoz3a5x/SsJmtUm/DTObiYTOOOrmTNFnmhSNiZ5ZpNBHiBfzvwh clKBTHZm62HpLwD/mhMu2oEi3Fn79taGdylebdHNk2hT6b3TTuUHkvhnMJC/QvP9Zfl7 0F9MxwAQs8ceSuhX/q8ehB7hYlz+qcEV4sf1fGhWp1LVAD4MWbbzAQBIo/IKfb4YEajM X6IwLrAA+KihqLoiqYhL6VhjgRVR072yamNEOANyhum+ZQr5d55BdiZcbgbJqIDrHgyg KzWg== 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=jcE+PW7lxLEeGPS3rf0sBs8Df3bRjj/NHiEC0QLRCBw=; b=d0Ok9HJizid+CLkzdjUjzM4tppfBlbIv3uN92h1TpC/vm7oEXpbUhNHkGkUlpmMsW4 v7bQx56mjCDc45wnV3nvJmnJARIUEI8d7Gc3jB6z8I18p2qkvs4klPb2LzDvxl4AI35V LiU60weQ85iWtDjWqllI67QlzbsIUhVsxeCxgdbKCR618jKa5dnaYVjhS9iNdYY3sVTT xk9OawSISTD06AsyOXcrAc9TzK97eQmPWT81L+D6/NfT+dhLXDQ04E0cO1KxxOm+pADw LuT4/Iyei8VW2lv1mpEc2b+bWrl9a8dZG8bXPAon3e+ENV4mI+j8t0IpVWU7qduqqsJ7 pvYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b=l2PzeD61; 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 15-20020a170906208f00b00732fa13e848si7837523ejq.597.2022.08.16.05.21.39; Tue, 16 Aug 2022 05:21:40 -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=l2PzeD61; 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 4249168B900; Tue, 16 Aug 2022 15:21:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AA37E68B945 for ; Tue, 16 Aug 2022 15:21:02 +0300 (EEST) Received: by mail-lj1-f176.google.com with SMTP id x10so10342844ljq.4 for ; Tue, 16 Aug 2022 05:21:02 -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=SmMZFii3d3EQIhkoH12Err/nmwGBYbli+L7MX3q9rjo=; b=l2PzeD61YytcYO25mVx2DF67w4E0V3NdeFw/GO6g/xCalrho/1BjA2ZxBtziC9wovn QuvT2kXiUc1H+2ggozfH97jpJuZJ04dLEFOKr6hji6WwkxcKMZ29UU0APtz9oExbscUb EiXZnhuztuCJ5W9Aol4p3oTK4f0aX38ZgYBbMchd3YBEwvOEuDhMgt+BcCMsxSiuZVhy 2VsblXxK7IFLu3ziQljfqbCGdc2RK4XL9XmzptxW/AUSwwgjYVuUn451+HMjFS3HkaMY ZH9EIDyCjz43OFyVL9a2VC6r2vWbYhVMUPx8jpz0qwdNyt/H5Z/2U7MUOL+7TH5pLOfn DCdQ== 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=SmMZFii3d3EQIhkoH12Err/nmwGBYbli+L7MX3q9rjo=; b=8Icz7kriHUaOaWDs2iD+55I88hik+RMROsgD2U4hM8y/PDFTMT1QmI8XywEVc/RYr9 bauyTdYj+Bu5gPDg4WY2weyPWk/QMkVsAlL5325poaopdHxaoHXthtY2yH7fqPKroI2E fYaFo2JF7QuFb5ufi38q7oiLyIvz1iETCdF54/Gd712qSFnj1jZRwFDs0C2NbV1C+4lw 8HH2CtTLE+844DJjr/EOKByYlEScjh/26sw0A6EQ2zSMwQh97N6Qy9UCVtiDQfAaFkMi z3A/tA9auGS1LEsHJfflxObD+RwpDDoZC6NVy+yT0MbQBhQCbl+Bu64Neo3TBGCwaQgb olAw== X-Gm-Message-State: ACgBeo0CkjrPDqUf4CZOgxQgxOe59UuQR+81otJ3cYZTJMa/fu3XOazJ V+wvPXVk7c6S3PXM1VIAsKwek86VsBnJi3Ax X-Received: by 2002:a2e:b01a:0:b0:25e:5a3f:ecd6 with SMTP id y26-20020a2eb01a000000b0025e5a3fecd6mr6727774ljk.209.1660652461722; Tue, 16 Aug 2022 05:21:01 -0700 (PDT) Received: from hum-HP-ProBook-440-G7.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id p20-20020ac24ed4000000b0048b998be041sm1365707lfr.309.2022.08.16.05.21.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 05:21:01 -0700 (PDT) From: Hubert Mazur To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2022 14:20:15 +0200 Message-Id: <20220816122016.64929-5-hum@semihalf.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816122016.64929-1-hum@semihalf.com> References: <20220816122016.64929-1-hum@semihalf.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] lavc/aarch64: Add neon implementation for sse8 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: GhOW+h6jSEjm Provide optimized implementation of sse8 function for arm64. Performance comparison tests are shown below. - sse_1_c: 130.7 - sse_1_neon: 29.7 Benchmarks and tests run with checkasm tool on AWS Graviton 3. Signed-off-by: Hubert Mazur --- libavcodec/aarch64/me_cmp_init_aarch64.c | 4 ++ libavcodec/aarch64/me_cmp_neon.S | 66 ++++++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index 1c36d3d7cb..2f51f0497e 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -34,9 +34,12 @@ int ff_pix_abs16_y2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t * int sse16_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); +int sse8_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, + ptrdiff_t stride, int h); int sse4_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); + av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) { int cpu_flags = av_get_cpu_flags(); @@ -49,6 +52,7 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) c->sad[0] = ff_pix_abs16_neon; c->sse[0] = sse16_neon; + c->sse[1] = sse8_neon; c->sse[2] = sse4_neon; } } diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index 0ec9c0465b..3f4266d4d5 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -347,6 +347,72 @@ function sse16_neon, export=1 ret endfunc +function sse8_neon, export=1 + // x0 - unused + // x1 - pix1 + // x2 - pix2 + // x3 - stride + // w4 - h + + movi d18, #0 + movi v21.4s, #0 + movi v20.4s, #0 + cmp w4, #4 + b.le 2f + +// make 4 iterations at once +1: + + // res = abs(pix1[0] - pix2[0]) + // res * res + + ld1 {v0.8b}, [x1], x3 // Load pix1 for first iteration + ld1 {v1.8b}, [x2], x3 // Load pix2 for second iteration + ld1 {v2.8b}, [x1], x3 // Load pix1 for second iteration + ld1 {v3.8b}, [x2], x3 // Load pix2 for second iteration + uabdl v30.8h, v0.8b, v1.8b // Absolute difference, first iteration + ld1 {v4.8b}, [x1], x3 // Load pix1 for third iteration + ld1 {v5.8b}, [x2], x3 // Load pix2 for third iteration + uabdl v29.8h, v2.8b, v3.8b // Absolute difference, second iteration + umlal v21.4s, v30.4h, v30.4h // Multiply lower half, first iteration + ld1 {v6.8b}, [x1], x3 // Load pix1 for fourth iteration + ld1 {v7.8b}, [x2], x3 // Load pix2 for fourth iteration + uabdl v28.8h, v4.8b, v5.8b // Absolute difference, third iteration + umlal v21.4s, v29.4h, v29.4h // Multiply lower half, second iteration + umlal2 v20.4s, v30.8h, v30.8h // Multiply upper half, second iteration + uabdl v27.8h, v6.8b, v7.8b // Absolute difference, fourth iteration + umlal v21.4s, v28.4h, v28.4h // Multiply lower half, third iteration + umlal2 v20.4s, v29.8h, v29.8h // Multiply upper half, second iteration + sub w4, w4, #4 // h -= 4 + umlal2 v20.4s, v28.8h, v28.8h // Multiply upper half, third iteration + umlal v21.4s, v27.4h, v27.4h // Multiply lower half, fourth iteration + cmp w4, #4 + umlal2 v20.4s, v27.8h, v27.8h // Multiply upper half, fourth iteration + b.ge 1b + + cbz w4, 3f + +// iterate by one +2: + ld1 {v0.8b}, [x1], x3 // Load pix1 + ld1 {v1.8b}, [x2], x3 // Load pix2 + subs w4, w4, #1 + uabdl v30.8h, v0.8b, v1.8b + umlal v21.4s, v30.4h, v30.4h + umlal2 v20.4s, v30.8h, v30.8h + + b.ne 2b + +3: + add v21.4s, v21.4s, v20.4s // Add accumulator vectors together + uaddlv d17, v21.4s // Add up vector + add d18, d18, d17 + + fmov w0, s18 + ret + +endfunc + function sse4_neon, export=1 // x0 - unused // x1 - pix1 From patchwork Tue Aug 16 12:20:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Mazur X-Patchwork-Id: 37312 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1829578pzi; Tue, 16 Aug 2022 05:21:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR7Ws9JfSaAiTVP9dXjyu8ZmF2SgHz/7ZTL+qin3nvWGqZXyt5qidOretmYA+pyGcNqQWxuo X-Received: by 2002:a17:907:7f9f:b0:733:76c:44c9 with SMTP id qk31-20020a1709077f9f00b00733076c44c9mr13304040ejc.642.1660652509496; Tue, 16 Aug 2022 05:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660652509; cv=none; d=google.com; s=arc-20160816; b=ylnoFyJNOET/V6NU5sYaxjMrmO4nGuH+rX/WVf+w+OTABJwvLJWWMZMw8LZMvLU7QM c44qAzIkbNCn5sw8zCZCAnEqaAO8MlDmDggGDCHsxiu8FMIoCyJvKE8pjzTo8wDIMWev XTloYHbN44bJuYyJ/hpc/GTX1wCcaKPgdsWN4CCUG+UR1K/mNkILVwdtcQ0x6BrY2yQa x1IXmrpmxnX2Aoc21pXbtyTrTr/jurlOKmmKGUHyd6eHTU8pSL+Vqgia7e8jYcvsa/6/ VGVkYNswnIz2aEniW83t/6OE3VmDfyL70c1lk8ly61/Vu9rR35s/3SR6LyBRvNQfSizZ T6Ww== 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=/yEEgEB9NayIbJGGsQKOV2iaBzl8i8Vg3d8Az0/FK1o=; b=mFOJzz2B9Uoh8Gah0MA/jTAzu00lUtGN1Hqg29L0aYpp62eAZOT35Mu98KP4gsW9z4 ALjrjVrp7wjnReBu3tDfydgqdzU3/WhuCE/y3849YnF0/aPxzAeiWeCHl/yuHed2rMGo lvUf8gMSup1LUBRUulD8mm0Ry6HR5Gf6QF5iewqSGS5yTlTbM6BgCpjRFd4C7A/efL73 5bTMhMV8Gf/bJ1V+iEtuOgmmMgtXMMIcFv5P2tv/1VdVZiHfHnWeKjBA1k1EQH/7qf9t OpmjvjZD9tiDfu03FTHEQ7zYrXawFZAHkfEnxgf3KC/MEbr560W7EG31Gq9Ayxbd7IV2 DK2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b=LQDjxbzU; 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 rs8-20020a170907036800b00722fc335c77si8780154ejb.213.2022.08.16.05.21.49; Tue, 16 Aug 2022 05:21:49 -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=LQDjxbzU; 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 3E1A068B92F; Tue, 16 Aug 2022 15:21:12 +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 6782668B876 for ; Tue, 16 Aug 2022 15:21:04 +0300 (EEST) Received: by mail-lj1-f178.google.com with SMTP id y23so10316075ljh.12 for ; Tue, 16 Aug 2022 05:21:04 -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=xs6JcHObQznf2rviOnBCgthrq/WUGqzD1ob6pzVidwk=; b=LQDjxbzU6Z58UC8ei+xNHL/2XAsR9Hqsyi8uySF4t3pF+1broAIZmhAVKgbnv4igS6 QGuWk67xCIkeqPIVUG5MVuEGnFLUZYXoJbpTQzOHz+JKvhpR37qy+ju0ZTRJPy1cnwMe d5oGkpy+f/nR2ZJ3ZO314Bx6dmeQjYTc8XR7gAwQzl4UMbv/rI31zMcQ2PDd+9PmXRpl yEAnaL5F1GID2R7Z7FBNbiJsXwoC6n75w2Y8vN2OMnrtAU8zvDCr1YoYMovUoQTOEML0 n27StODPH4M/mcbHO2Jya3UnmVkgyRRG2kZr5JRzBXVUCMmAihKKPFcbAC7E6hU1/PxI kvCg== 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=xs6JcHObQznf2rviOnBCgthrq/WUGqzD1ob6pzVidwk=; b=0kajo1C+VLuypJHiJa4OEGf/LLId09mOSjcm0qc7DmuGIlcFCV8GsmS8ozrRbfh+jT Y10/lZ8QPl3ftZQypvkczCY7uQ2a1HTonh5qZ2hVnTYnjSKHRhL5g93K+gug0zAuR3P5 ZVF/i/x7UIWzRV53g3qL1DArmccgtO7Dx4gokdVkZXzSoPGUhUBjD13xkks+Y9vgoK+k QVj7IDhmE9lEoKqWqDvp/sJ0Qyz0e927kMZoeeGHE7vSyGEjYMwxm9uDMTvny8Did9Zd C+AFMorSGErWqQvYj4dfkNXPyyQM5Lf1pfkEWvreZMW3XA18dpB3ls66+6H6S5ZC5Fo+ pxTw== X-Gm-Message-State: ACgBeo0M2r+jU551umS06xGAcD/dhPYdccvmPgbCmLyvY0QKE0mjzYym LhV7J7aPDpc6A5jys9ZcBX9piNsSB7SqC9DX X-Received: by 2002:a05:651c:a04:b0:25e:753b:db42 with SMTP id k4-20020a05651c0a0400b0025e753bdb42mr6312060ljq.529.1660652463549; Tue, 16 Aug 2022 05:21:03 -0700 (PDT) Received: from hum-HP-ProBook-440-G7.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id p20-20020ac24ed4000000b0048b998be041sm1365707lfr.309.2022.08.16.05.21.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 05:21:03 -0700 (PDT) From: Hubert Mazur To: ffmpeg-devel@ffmpeg.org Date: Tue, 16 Aug 2022 14:20:16 +0200 Message-Id: <20220816122016.64929-6-hum@semihalf.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220816122016.64929-1-hum@semihalf.com> References: <20220816122016.64929-1-hum@semihalf.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] lavc/aarch64: Add neon implementation for pix_abs8 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: 6HL4V8O9bUCn Provide optimized implementation of pix_abs8 function for arm64. Performance comparison tests are shown below. - pix_abs_1_0_c: 101.2 - pix_abs_1_0_neon: 22.5 - sad_1_c: 101.2 - sad_1_neon: 22.5 Benchmarks and tests are run with checkasm tool on AWS Graviton 3. --- libavcodec/aarch64/me_cmp_init_aarch64.c | 4 ++ libavcodec/aarch64/me_cmp_neon.S | 49 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index 2f51f0497e..e7dbd4cbc5 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -31,6 +31,8 @@ int ff_pix_abs16_x2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t * ptrdiff_t stride, int h); int ff_pix_abs16_y2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); +int ff_pix_abs8_neon(MpegEncContext *s, const uint8_t *blk1, const uint8_t *blk2, + ptrdiff_t stride, int h); int sse16_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); @@ -49,8 +51,10 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) c->pix_abs[0][1] = ff_pix_abs16_x2_neon; c->pix_abs[0][2] = ff_pix_abs16_y2_neon; c->pix_abs[0][3] = ff_pix_abs16_xy2_neon; + c->pix_abs[1][0] = ff_pix_abs8_neon; c->sad[0] = ff_pix_abs16_neon; + c->sad[1] = ff_pix_abs8_neon; c->sse[0] = sse16_neon; c->sse[1] = sse8_neon; c->sse[2] = sse4_neon; diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index 3f4266d4d5..8c396cad21 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -72,6 +72,55 @@ function ff_pix_abs16_neon, export=1 ret endfunc +function ff_pix_abs8_neon, export=1 + // x0 unused + // x1 uint8_t *pix1 + // x2 uint8_t *pix2 + // x3 ptrdiff_t stride + // x4 int h + + movi d18, #0 + movi v30.8h, #0 + cmp w4, #4 + b.lt 2f + +// make 4 iterations at once +1: + ld1 {v0.8b}, [x1], x3 // Load pix1 for first iteration + ld1 {v1.8b}, [x2], x3 // Load pix2 for first iteration + ld1 {v2.8b}, [x1], x3 // Load pix1 for second iteration + uabal v30.8h, v0.8b, v1.8b // Absolute difference, first iteration + ld1 {v3.8b}, [x2], x3 // Load pix2 for second iteration + ld1 {v4.8b}, [x1], x3 // Load pix1 for third iteration + uabal v30.8h, v2.8b, v3.8b // Absolute difference, second iteration + ld1 {v5.8b}, [x2], x3 // Load pix2 for third iteration + sub w4, w4, #4 // h -= 4 + uabal v30.8h, v4.8b, v5.8b // Absolute difference, third iteration + ld1 {v6.8b}, [x1], x3 // Load pix1 for foruth iteration + ld1 {v7.8b}, [x2], x3 // Load pix2 for fourth iteration + cmp w4, #4 + uabal v30.8h, v6.8b, v7.8b // Absolute difference, foruth iteration + b.ge 1b + + cbz w4, 3f + +// iterate by one +2: + ld1 {v0.8b}, [x1], x3 // Load pix1 + ld1 {v1.8b}, [x2], x3 // Load pix2 + + subs w4, w4, #1 + uabal v30.8h, v0.8b, v1.8b + b.ne 2b + +3: + uaddlv s20, v30.8h // Add up vector + add d18, d18, d20 + fmov w0, s18 + + ret +endfunc + function ff_pix_abs16_xy2_neon, export=1 // x0 unused // x1 uint8_t *pix1