From patchwork Mon Sep 26 09:15:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Bernacki X-Patchwork-Id: 38328 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp2122653pzh; Mon, 26 Sep 2022 02:16:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6su0sG5LW0/2Gu4Jc82mNnfRTZJRUZ/cC1RP2Az11rbMyToVPkJnBs3MqrBxOJSUSvKrum X-Received: by 2002:a17:907:6288:b0:72f:90ba:f0b2 with SMTP id nd8-20020a170907628800b0072f90baf0b2mr16486101ejc.696.1664183768614; Mon, 26 Sep 2022 02:16:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664183768; cv=none; d=google.com; s=arc-20160816; b=QOiCIyNql95itzTlZVqiKlG7dOa2ki2FmjR4liH7/Qai7lYyR5p3O4cczVdcrAAWcZ piXWPW6/Nw1v05GNcVrp+WwBEIR5RMijg7QZrNqp7UoEe6M2w3vhqHC/g61QVDHgCKQJ g6t3jfyX0bn9YfamEyCTQOy/+tiOngQM7me99CaKxAl9v85JqPAPkKKx+twc97S7gmXL w23fb1xwDqH5p6JUrpjVUWmhjWweMNvrb1j0jBQMFS+z3hyys/UiUXsNw4xiJerQUwyH cJMBsFO40cMNPBj+QpDHDt3SAAeosUVpLYp014DFZ7AdVSPed4wsyBdaQePDe2UpFCq7 GkNQ== 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=ML67oZgWlnTLuBozVBdiaDG8OY6WhkSWrQv2uuXGarY=; b=VvywZi5ai4hWzPM1h4aWHIlGDqBx2BCeCPNdDRRM6ow/zTSq6mmRlKp67cZzTSzB1C E73jZTKYzR4Ii/EbTPEkF1NkBiJI3ODLuo1fajGGQdnVrifMRKq2iNCMfHzUeAxZcno1 2xDOSzCelfZPfHBJC7hw1b02efkvGXQMsndQ1o3jdXtvbkDUWKo7koN1PdXFHmQN6GBS S4/yjZmHOIads5TszUd+vnVSk9H1j9uAeMDqOTnbKumllvOLbVwFANhVL6/KrSHZx7ju 88kQx15YwWBiLhGKcpR0lndxAnxdrC58k0/dszZ12AMYtf8MCrgkaLXsabgvSvgfMkyp mxNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b=QwJErgqI; 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 c20-20020a05640227d400b004548c49ef4csi17156862ede.504.2022.09.26.02.15.45; Mon, 26 Sep 2022 02:16:08 -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=QwJErgqI; 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 4289568BA4A; Mon, 26 Sep 2022 12:15:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9319F68B5B9 for ; Mon, 26 Sep 2022 12:15:27 +0300 (EEST) Received: by mail-lj1-f182.google.com with SMTP id a10so6758093ljq.0 for ; Mon, 26 Sep 2022 02:15:27 -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:subject:date; bh=MIUz8XOrqfARp/PJyPst3PCe8oS/fN7z3dzgh4vccS0=; b=QwJErgqI1iuOd42RMHxw7FPokUEmYAuBY6HSiquil0QwFjQUTBp8cFc46m4+7TwOCS Heg7NvJPEHmLy30b0aedTFmubAzVnvrzNt/ksBYMPhOfq80zuYoohE73JEW0yJRQ2Ksn ZIT+89dMY0rkYFbgIRTf43UnuavyK+zfPfXJXprO7uJv2vq60R18Sby+jMdrrgld4plL kQ/oDFSogj6o7Nu0ft4N7ltQ1wPE66v8Xae5QVjkXrYnB1trvi/4i13DyJtGH6cv/Tuo WeB7LlDgnfJcKOt6onB8a2CrHTptAkSddf8lrZmyxiIgCcX+ZecNX7MArF8wc1NaNOqe UmMw== 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 :subject:date; bh=MIUz8XOrqfARp/PJyPst3PCe8oS/fN7z3dzgh4vccS0=; b=tyd9/9OWG8aNVMIOhRZFEttkEzcy0U08s/6t5kTLtHUhdflMi8qbFxm4E+L7TCe9w0 KaNeyjFMHJ5SID62lrK+E/V+KgJ621gl04IWJlQNtnNo0W0j/3ZDeqwxyeEbXVtXxcPF 4Gh07SHPvVgC3Iw7kVIH9T55gXa4QHL0MVxcz8UKIUD+29dOjdy3UJg8ehcrXAMAKENE CBAqvgjL2BDEWYK53STdUjL43usmY/6FUvIRnZrrarTGeHZB/eZ+4Jjwdk1XxvWUwkK3 Ht1T5rabDyDG7bPYx0NodF9vwUFAsqfBA/WpZPv6FlF3OkhzwfXher/+l+PzA+SlFQRD H+IA== X-Gm-Message-State: ACrzQf3JhyssZl4RW0djXR/pLPR2RoOTO8fYd6NFG3IHVvhGHGncuHy2 aw9nZK5XjCS/wreU5PjQB02KFIhDfF/o+A== X-Received: by 2002:a2e:50b:0:b0:26a:b7ec:59ea with SMTP id 11-20020a2e050b000000b0026ab7ec59eamr7486528ljf.312.1664183726431; Mon, 26 Sep 2022 02:15:26 -0700 (PDT) Received: from gilgamesh.lab.semihalf.net ([83.142.187.85]) by smtp.gmail.com with ESMTPSA id b14-20020a056512070e00b004949f7cbb6esm2472942lfs.79.2022.09.26.02.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:15:26 -0700 (PDT) From: Grzegorz Bernacki To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Sep 2022 11:15:02 +0200 Message-Id: <20220926091504.3459110-2-gjb@semihalf.com> X-Mailer: git-send-email 2.29.0 In-Reply-To: <20220926091504.3459110-1-gjb@semihalf.com> References: <20220926091504.3459110-1-gjb@semihalf.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] lavc/aarch64: Provide neon implementation of nsse8 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, hum@semihalf.com, martin@martin.st, mw@semihalf.com, spop@amazon.com Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: HZtpZB95x9yX Add vectorized implementation of nsse8 function. Performance comparison tests are shown below. - nsse_1_c: 256.0 - nsse_1_neon: 82.7 Benchmarks and tests run with checkasm tool on AWS Graviton 3. Signed-off-by: Grzegorz Bernacki --- libavcodec/aarch64/me_cmp_init_aarch64.c | 15 ++++ libavcodec/aarch64/me_cmp_neon.S | 99 ++++++++++++++++++++++++ 2 files changed, 114 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index 3459403ee5..2c61cfcf63 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -66,6 +66,11 @@ int ff_pix_abs8_y2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *p int ff_pix_abs8_xy2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); +int nsse8_neon(int multiplier, const uint8_t *s, const uint8_t *s2, + ptrdiff_t stride, int h); +int nsse8_neon_wrapper(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(); @@ -94,6 +99,7 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) c->vsse[4] = vsse_intra16_neon; c->nsse[0] = nsse16_neon_wrapper; + c->nsse[1] = nsse8_neon_wrapper; c->median_sad[0] = pix_median_abs16_neon; c->median_sad[1] = pix_median_abs8_neon; @@ -108,3 +114,12 @@ int nsse16_neon_wrapper(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, else return nsse16_neon(8, s1, s2, stride, h); } + +int nsse8_neon_wrapper(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, + ptrdiff_t stride, int h) +{ + if (c) + return nsse8_neon(c->avctx->nsse_weight, s1, s2, stride, h); + else + return nsse8_neon(8, s1, s2, stride, h); +} diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index e03c0c26cd..6f7c7c1690 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -1163,6 +1163,105 @@ function nsse16_neon, export=1 ret endfunc +function nsse8_neon, export=1 + // x0 multiplier + // x1 uint8_t *pix1 + // x2 uint8_t *pix2 + // x3 ptrdiff_t stride + // w4 int h + + str x0, [sp, #-0x40]! + stp x1, x2, [sp, #0x10] + stp x3, x4, [sp, #0x20] + str x30, [sp, #0x30] + bl X(sse8_neon) + ldr x30, [sp, #0x30] + mov w9, w0 // here we store score1 + ldr x5, [sp] + ldp x1, x2, [sp, #0x10] + ldp x3, x4, [sp, #0x20] + add sp, sp, #0x40 + + movi v16.8h, #0 + movi v17.8h, #0 + movi v18.8h, #0 + movi v19.8h, #0 + + ld1 {v0.8b}, [x1], x3 + subs w4, w4, #1 // we need to make h-1 iterations + ext v1.8b, v0.8b, v0.8b, #1 // x1 + 1 + ld1 {v2.8b}, [x2], x3 + cmp w4, #2 + ext v3.8b, v2.8b, v2.8b, #1 // x2 + 1 + + b.lt 2f + +// make 2 iterations at once +1: + ld1 {v4.8b}, [x1], x3 + ld1 {v20.8b}, [x1], x3 + ld1 {v6.8b}, [x2], x3 + ext v5.8b, v4.8b, v4.8b, #1 // x1 + stride + 1 + ext v21.8b, v20.8b, v20.8b, #1 + ld1 {v22.8b}, [x2], x3 + ext v7.8b, v6.8b, v6.8b, #1 // x2 + stride + 1 + usubl v31.8h, v0.8b, v4.8b + ext v23.8b, v22.8b, v22.8b, #1 + usubl v29.8h, v1.8b, v5.8b + usubl v27.8h, v2.8b, v6.8b + usubl v25.8h, v3.8b, v7.8b + saba v16.8h, v31.8h, v29.8h + usubl v31.8h, v4.8b, v20.8b + saba v18.8h, v27.8h, v25.8h + sub w4, w4, #2 + usubl v29.8h, v5.8b, v21.8b + mov v0.16b, v20.16b + mov v1.16b, v21.16b + saba v16.8h, v31.8h, v29.8h + usubl v27.8h, v6.8b, v22.8b + usubl v25.8h, v7.8b, v23.8b + mov v2.16b, v22.16b + mov v3.16b, v23.16b + cmp w4, #2 + saba v18.8h, v27.8h, v25.8h + b.ge 1b + cbz w4, 3f + +// iterate by one +2: + ld1 {v4.8b}, [x1], x3 + subs w4, w4, #1 + ext v5.8b, v4.8b, v4.8b, #1 // x1 + stride + 1 + ld1 {v6.8b}, [x2], x3 + usubl v31.8h, v0.8b, v4.8b + ext v7.8b, v6.8b, v6.8b, #1 // x2 + stride + 1 + + usubl v29.8h, v1.8b, v5.8b + saba v16.8h, v31.8h, v29.8h + usubl v27.8h, v2.8b, v6.8b + usubl v25.8h, v3.8b, v7.8b + saba v18.8h, v27.8h, v25.8h + + mov v0.16b, v4.16b + mov v1.16b, v5.16b + mov v2.16b, v6.16b + mov v3.16b, v7.16b + + cbnz w4, 2b + +3: + sqsub v16.8h, v16.8h, v18.8h + ins v16.h[7], wzr + saddlv s16, v16.8h + sqabs s16, s16 + fmov w0, s16 + + mul w0, w0, w5 + add w0, w0, w9 + + ret +endfunc + function pix_median_abs16_neon, export=1 // x0 unused // x1 uint8_t *pix1