From patchwork Mon Sep 26 09:15:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Bernacki X-Patchwork-Id: 38326 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp2122567pzh; Mon, 26 Sep 2022 02:15:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM45jqjS/3mb5y2TEcjmXwvuVH+xUTmfifdcJXn3b2uxpaCG+dKdKvSFvqp49IiYesWjbaar X-Received: by 2002:a05:6402:3591:b0:451:8397:3e9 with SMTP id y17-20020a056402359100b00451839703e9mr20981946edc.409.1664183759345; Mon, 26 Sep 2022 02:15:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664183759; cv=none; d=google.com; s=arc-20160816; b=w5I6pZz4QsxzwJuyI+9xSlosdOe8uPdq27x1Zwhgcy4un1w3mznMhwp0tVkB/hi8xP Fjhi9/qyJPQSQEecgqbjIxF4dPsVBgFJPS9uN2Cr5LPO65KTzrA1RG3KvFlvHKm89p1X FeTfJHGVYoTw1O/T7H/J6NCK55QHX5qyi7bJDsA6PSdsfQwlUaZRvZJjA9fvdEi3Dh3k Ie/gIrw53XEb8oHKJpX8qGBdFf0pltbSwLteU5OojZx0fSo+/xTx8tbTG99F+DBMjpJk 297c/isqTk35APGU62/A/eX25p67zjt3/GfiyfnrqqYeRoe//WrqaxlZQ4WR2cuMZQ4A jREg== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=wGQjNRHEamGOJi9D71FVgPOFjmgbsc/gm9Y5AROvgZs=; b=iXKw5iTsEUam0Ly7DDrLFQaoepAQfS8mkH0lBzepAkl0U7VuOerwaZ+MUO7dlfm0CG oFTF/2uEaPPHuIQczthPH7P2FWyMycLpOXIyFbX74xLov7Ev34XaKiA8QGaLkYUiuyv3 Sb/s+0mBS2bS20ynI18I7SXjPbBA9XimcKvnmxnzBeK3eoDZA/B2j+/2pTbdSWuRhvd/ DUuwVji5XLdVHG/sDd1ucV1b4UKm2U9XYRe+BP+5HEXVzZo5MKBSHw9uER2Wp9Liv8Ff nkbe3BN44QGebVCpbeLS2ZRGNycLGd5gEnOxqhV0Pqiz6BojGnGPQqu57yGW2txbX7Yv bnwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b=qhiOYo59; 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 i8-20020a1709061e4800b00730ed690a72si12682356ejj.630.2022.09.26.02.15.36; Mon, 26 Sep 2022 02:15:59 -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=qhiOYo59; 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 2FB3768B9CA; Mon, 26 Sep 2022 12:15:33 +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 7A63E68B515 for ; Mon, 26 Sep 2022 12:15:26 +0300 (EEST) Received: by mail-lj1-f178.google.com with SMTP id j24so6693385lja.4 for ; Mon, 26 Sep 2022 02:15:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date; bh=L6JYCTQ0p9AW2Ky22OM4I9RWxdkXGsF1BdBKWQ/3o+U=; b=qhiOYo59CZ4s9P5bXAis1bZnsyVj4fI+VXTkWCDw9visXx9ouDEuycez4vH7YYoZ9+ vavrSYv7wQtbVddJbet5xG1+hdKK2a9ZVnCK8eFebEaVojgLImYzOO3xAl+ywVDoZJej vbCeqd19Bk9EjXH/nrpXDKWP5X6/XQBREMMx6DqoECY8fI0Qj0FnH+fCy6SdxD7isQWZ DWbqG8hgcRGecPo8i5S9TlcKDhX41WwM25/MtZQP5qNhciigTzCvIkS9pdPKOKNBkjA2 SNyWqLO/j56O70zO7OZMGIFbjlCawhPa63PYknZegDQ2CLDdie2D8um3yir+ZvNPjowH /fNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date; bh=L6JYCTQ0p9AW2Ky22OM4I9RWxdkXGsF1BdBKWQ/3o+U=; b=mbT5JoJ5MlXa10PAjDNCcVvQSQvn7tbpPRd6r/Aj7obp15lHcY5rNN4ZU9fDlmPRXU lXoKWpTQA7MbFZ5b4SCprT2Au/F08tm8remOKzwi2Qz4oSg1ZR3aP79rKow59loZ011D TF1gkvAV15A4ngf/Z4CmebrTq6aV82xYcy6gHGIvIaphtGD1Zw+thQ0IJQ/fbAKCbA7o 4f73Qhn+BeAGb4TkX3qe7yzaOqyiN1jevGXYi8jCoQWmxpAnZlcQDfOHKjQE1/+khse1 3WsP39apl6HjJ6MXwT6hGEM7ykx5J3ReRGGZxXN+P6+e3ZT7Y9MhA5Tq56akUeCS+5l6 mQSQ== X-Gm-Message-State: ACrzQf20olZewClQYy0WnVW/HPz9WvSpX/4HTuWynx4VQvxQF6bk6D+s bfP+jE4xvVdZI7/G5TT6woOOGEjsJLYQ4A== X-Received: by 2002:a2e:9018:0:b0:26b:defc:2a19 with SMTP id h24-20020a2e9018000000b0026bdefc2a19mr7180881ljg.470.1664183725321; Mon, 26 Sep 2022 02:15:25 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:15:24 -0700 (PDT) From: Grzegorz Bernacki To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Sep 2022 11:15:01 +0200 Message-Id: <20220926091504.3459110-1-gjb@semihalf.com> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] lavc/aarch64: Add neon implementation for pix_abs8 functions. 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: LE5062L8YmEB Provide optimized implementation of pix_abs8 function for arm64. Performance comparison tests are shown below: pix_abs_1_1_c: 162.5 pix_abs_1_1_neon: 27.0 pix_abs_1_2_c: 174.0 pix_abs_1_2_neon: 23.5 pix_abs_1_3_c: 203.2 pix_abs_1_3_neon: 34.7 Benchmarks and tests are run with checkasm tool on AWS Graviton 3. Signed-off-by: Grzegorz Bernacki --- libavcodec/aarch64/me_cmp_init_aarch64.c | 9 ++ libavcodec/aarch64/me_cmp_neon.S | 193 +++++++++++++++++++++++ 2 files changed, 202 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index e143f0816e..3459403ee5 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -59,6 +59,12 @@ int pix_median_abs16_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t ptrdiff_t stride, int h); int pix_median_abs8_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, ptrdiff_t stride, int h); +int ff_pix_abs8_x2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, + ptrdiff_t stride, int h); +int ff_pix_abs8_y2_neon(MpegEncContext *v, const uint8_t *pix1, const uint8_t *pix2, + ptrdiff_t stride, int h); +int ff_pix_abs8_xy2_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) { @@ -70,6 +76,9 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) 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->pix_abs[1][1] = ff_pix_abs8_x2_neon; + c->pix_abs[1][2] = ff_pix_abs8_y2_neon; + c->pix_abs[1][3] = ff_pix_abs8_xy2_neon; c->sad[0] = ff_pix_abs16_neon; c->sad[1] = ff_pix_abs8_neon; diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index 11af4849f9..e03c0c26cd 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -119,6 +119,199 @@ function ff_pix_abs8_neon, export=1 ret endfunc +function ff_pix_abs8_x2_neon, export=1 + // x0 unused + // x1 uint8_t *pix1 + // x2 uint8_t *pix2 + // x3 ptrdiff_t stride + // w4 int h + + cmp w4, #4 + movi v26.8h, #0 + add x5, x2, #1 // pix2 + 1 + b.lt 2f + +// make 4 iterations at once +1: + ld1 {v1.8b}, [x2], x3 + ld1 {v2.8b}, [x5], x3 + ld1 {v0.8b}, [x1], x3 + ld1 {v4.8b}, [x2], x3 + urhadd v30.8b, v1.8b, v2.8b + ld1 {v5.8b}, [x5], x3 + uabal v26.8h, v0.8b, v30.8b + ld1 {v6.8b}, [x1], x3 + urhadd v29.8b, v4.8b, v5.8b + ld1 {v7.8b}, [x2], x3 + ld1 {v20.8b}, [x5], x3 + uabal v26.8h, v6.8b, v29.8b + ld1 {v21.8b}, [x1], x3 + urhadd v28.8b, v7.8b, v20.8b + ld1 {v22.8b}, [x2], x3 + ld1 {v23.8b}, [x5], x3 + uabal v26.8h, v21.8b, v28.8b + sub w4, w4, #4 + ld1 {v24.8b}, [x1], x3 + urhadd v27.8b, v22.8b, v23.8b + cmp w4, #4 + uabal v26.8h, v24.8b, v27.8b + + b.ge 1b + cbz w4, 3f + +// iterate by one +2: + ld1 {v1.8b}, [x2], x3 + ld1 {v2.8b}, [x5], x3 + ld1 {v0.8b}, [x1], x3 + urhadd v30.8b, v1.8b, v2.8b + subs w4, w4, #1 + uabal v26.8h, v0.8b, v30.8b + + b.ne 2b +3: + uaddlv s20, v26.8h + fmov w0, s20 + + ret + +endfunc + +function ff_pix_abs8_y2_neon, export=1 + // x0 unused + // x1 uint8_t *pix1 + // x2 uint8_t *pix2 + // x3 ptrdiff_t stride + // w4 int h + + cmp w4, #4 + movi v26.8h, #0 + ld1 {v1.8b}, [x2], x3 + b.lt 2f + +// make 4 iterations at once +1: + ld1 {v2.8b}, [x2], x3 + ld1 {v0.8b}, [x1], x3 + ld1 {v6.8b}, [x1], x3 + urhadd v30.8b, v1.8b, v2.8b + ld1 {v5.8b}, [x2], x3 + ld1 {v21.8b}, [x1], x3 + uabal v26.8h, v0.8b, v30.8b + urhadd v29.8b, v2.8b, v5.8b + ld1 {v20.8b}, [x2], x3 + ld1 {v24.8b}, [x1], x3 + uabal v26.8h, v6.8b, v29.8b + urhadd v28.8b, v5.8b, v20.8b + uabal v26.8h, v21.8b, v28.8b + ld1 {v23.8b}, [x2], x3 + mov v1.8b, v23.8b + sub w4, w4, #4 + urhadd v27.8b, v20.8b, v23.8b + cmp w4, #4 + uabal v26.8h, v24.8b, v27.8b + + b.ge 1b + cbz w4, 3f + +// iterate by one +2: + ld1 {v0.8b}, [x1], x3 + ld1 {v2.8b}, [x2], x3 + urhadd v30.8b, v1.8b, v2.8b + subs w4, w4, #1 + uabal v26.8h, v0.8b, v30.8b + mov v1.8b, v2.8b + + b.ne 2b +3: + uaddlv s20, v26.8h + fmov w0, s20 + + ret + +endfunc + +function ff_pix_abs8_xy2_neon, export=1 + // x0 unused + // x1 uint8_t *pix1 + // x2 uint8_t *pix2 + // x3 ptrdiff_t stride + // w4 int h + + movi v31.8h, #0 + add x0, x2, 1 // pix2 + 1 + + add x5, x2, x3 // pix2 + stride = pix3 + cmp w4, #4 + add x6, x5, 1 // pix3 + stride + 1 + + b.lt 2f + + ld1 {v0.8b}, [x2], x3 + ld1 {v1.8b}, [x0], x3 + uaddl v2.8h, v0.8b, v1.8b + +// make 4 iterations at once +1: + ld1 {v4.8b}, [x5], x3 + ld1 {v5.8b}, [x6], x3 + ld1 {v7.8b}, [x5], x3 + uaddl v0.8h, v4.8b, v5.8b + ld1 {v16.8b}, [x6], x3 + add v4.8h, v0.8h, v2.8h + ld1 {v5.8b}, [x1], x3 + rshrn v4.8b, v4.8h, #2 + uaddl v7.8h, v7.8b, v16.8b + uabal v31.8h, v5.8b, v4.8b + add v2.8h, v0.8h, v7.8h + ld1 {v17.8b}, [x1], x3 + rshrn v2.8b, v2.8h, #2 + ld1 {v20.8b}, [x5], x3 + uabal v31.8h, v17.8b, v2.8b + ld1 {v21.8b}, [x6], x3 + ld1 {v25.8b}, [x5], x3 + uaddl v20.8h, v20.8b, v21.8b + ld1 {v26.8b}, [x6], x3 + add v7.8h, v7.8h, v20.8h + uaddl v25.8h, v25.8b, v26.8b + rshrn v7.8b, v7.8h, #2 + ld1 {v22.8b}, [x1], x3 + mov v2.16b, v25.16b + uabal v31.8h, v22.8b, v7.8b + add v20.8h, v20.8h, v25.8h + ld1 {v27.8b}, [x1], x3 + sub w4, w4, #4 + rshrn v20.8b, v20.8h, #2 + cmp w4, #4 + uabal v31.8h, v27.8b, v20.8b + + b.ge 1b + + cbz w4, 3f + +// iterate by one +2: + ld1 {v0.8b}, [x5], x3 + ld1 {v1.8b}, [x6], x3 + ld1 {v4.8b}, [x1], x3 + uaddl v21.8h, v0.8b, v1.8b + subs w4, w4, #1 + add v3.8h, v2.8h, v21.8h + mov v2.16b, v21.16b + rshrn v3.8b, v3.8h, #2 + uabal v31.8h, v4.8b, v3.8b + b.ne 2b + +3: + uaddlv s18, v31.8h + fmov w0, s18 + + ret + +endfunc + + function ff_pix_abs16_xy2_neon, export=1 // x0 unused // x1 uint8_t *pix1 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 From patchwork Mon Sep 26 09:15:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Bernacki X-Patchwork-Id: 38329 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp2122724pzh; Mon, 26 Sep 2022 02:16:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6M+ssPKcFkuNC8LdShjj+vQyE+dH7zjufMT5VOSI88072kF9QiE263lxNl4DMmQkxegmdJ X-Received: by 2002:a17:907:a40e:b0:783:4d41:a159 with SMTP id sg14-20020a170907a40e00b007834d41a159mr4932093ejc.212.1664183778149; Mon, 26 Sep 2022 02:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664183778; cv=none; d=google.com; s=arc-20160816; b=vJMAoWtpgLgHv+o6oyswP/tK6hdIcFK5Sm9wdvRGiQxvEy9hG6qjbGnS88ubpH+goA ENtIaaJWcBtL2HkGeSxa7zeaeZUEMf+KvzeHe5z87x8BniCRXt+vcG5Vtj91D/EfoKX0 +lnKHeJn9S/dPyQ9XxPbUyDNAdq5qeorwoUHgCTZZHQWcQWpu6skhpCYGHhJ35QgOJND tFe+U7rSrDyegwej1ulyZy5UJHor/tuw1xK4YcZtg7j+M07PQYirlhT9wAmlZ4dMNRLP 2TY/Y/pCHXo4tQboqdhUecfk1LxslX2ulrWQuj5+yFKmk4an8WOgg9p0Dam2OgY9mdBB a5jQ== 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=PCXMVji4ilyGbtj1Mv+aQLT7f3CR51OmEUPqjGPKDY4=; b=elaQZmTH43dUI2XrBgLjc4ZzvzDN02l/HzH/bQtceBkR4z7n9hf6h0ogkLWbQwXWPW uTSapJJSXquaUaGB0l8niF6s7Nbn6/8Y9ZMVsDWNvK1EPJ62rPvImnhHPUdmmL6Z7t4h Tb+CWuvDSj6XxGefjkzp2kJ0kCwrGwznH22TuV0UydEkxkA0rtvAC6ZOcO0NYEg9Wnlx xYW/eY2xQOLqzUQTewvazttcfUp/VWuHKLXuuW9MKFJx67kCcs+S9/94qAvr7Jl+Q52G mwoYJHqf7mu2yK5CqVqqDCp9F9FlSHX2S0zBFzJA+FvRMg58IPGAz2E9zNWUhUqQN2qS FDyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b=eEAWY1Nl; 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 dn8-20020a17090794c800b0078358970513si3386430ejc.367.2022.09.26.02.15.55; Mon, 26 Sep 2022 02:16:18 -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=eEAWY1Nl; 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 2A58368BA62; Mon, 26 Sep 2022 12:15:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E2B168BA0C for ; Mon, 26 Sep 2022 12:15:28 +0300 (EEST) Received: by mail-lj1-f169.google.com with SMTP id c7so6648827ljm.12 for ; Mon, 26 Sep 2022 02:15:28 -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=Jrx+pHOh5VlywFbdDD67DyRM2lg4D99yezbr1/V1bOM=; b=eEAWY1NlYRn1unUvgsB1C2SWDWD4KoMnJqil5QYp2leNZR8QzsgeDfcg519GuNdoVT 7jLibvMhM7zHNBu+B86UKZNkVJ/C1zErkthIH/M5LH/QOOlpiN6f5R8J9x58ntxmWwjv aix9DphJT6TVU6SPQib51Sj3QHEMNEoK9KrLHpWRtCLFhe1CnqQiEZ55Hqm8UbQf6KzK 2ORa+9TvSJPBUcbOkFZaqflq1kSFz+9ccNoXUFoY/ADFGvq2nDYkQePiK8hf9SBJkBZF Owu5wpIukph2AzO1TevRaL4QsHMyjlzx5SVXrA257X8Yx5OdO/m/C97/cbkXtq/fAMsL UgKw== 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=Jrx+pHOh5VlywFbdDD67DyRM2lg4D99yezbr1/V1bOM=; b=M/EJgk2Z9zWVE5nsySYZ8zM4qDCwBZ47ImSGKs09CF4dTU4rtwgZv8fZQPO6hdHvHq tutf9gHsTeQXop0I2zsDkXwGT5EjN8VcUrbRaiSxVdjWWje1j1KjjNnrKEo9Y9Tc4s8V NzMPUccqPjPHsJSxWBFmYVwMOwpyRLdry165gXG0L2AZ5nWpB01hiWSoN6t/U7zFcz04 WnYxKAp++1SKwMcDJ0HYeoKTc6X0rZkdwL46aSjE6kwjsnWb3mVpkn/StAwBEIyuALEQ m2OXBsGOhu4KcvoADUrxhLIj7RXINAmBLFHuKH/gDISW6rKpw7QKL6xwHbm/RDgPA9mA lj6A== X-Gm-Message-State: ACrzQf0QXNdJGA+FAWYTuaciJLVJs+sgVQ3RHPDi99WbjUoSGGHOjHi0 qD1HAuPu5o6XAW1sNLn2rQqYLUk8Nwn4gQ== X-Received: by 2002:a2e:8904:0:b0:26b:e97e:d85b with SMTP id d4-20020a2e8904000000b0026be97ed85bmr7209400lji.7.1664183727520; Mon, 26 Sep 2022 02:15:27 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:15:27 -0700 (PDT) From: Grzegorz Bernacki To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Sep 2022 11:15:03 +0200 Message-Id: <20220926091504.3459110-3-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 3/4] lavc/aarch64: Provide optimized implementation of vsse8 for arm64. 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: +t9NWOE5C7Ad Provide optimized implementation of vsse8 for arm64. Performance comparison tests are shown below. - vsse_1_c: 141.5 - vsse_1_neon: 32.5 Benchmarks and tests are run with checkasm tool on AWS Graviton 3. Signed-off-by: Grzegorz Bernacki --- libavcodec/aarch64/me_cmp_init_aarch64.c | 5 ++ libavcodec/aarch64/me_cmp_neon.S | 70 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index 2c61cfcf63..f247372c94 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -71,6 +71,9 @@ int nsse8_neon(int multiplier, const uint8_t *s, const uint8_t *s2, int nsse8_neon_wrapper(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h); +int vsse8_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(); @@ -96,6 +99,8 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) c->vsad[5] = vsad_intra8_neon; c->vsse[0] = vsse16_neon; + c->vsse[1] = vsse8_neon; + c->vsse[4] = vsse_intra16_neon; c->nsse[0] = nsse16_neon_wrapper; diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index 6f7c7c1690..386d2de0c5 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -843,6 +843,76 @@ function vsad16_neon, export=1 ret endfunc +function vsse8_neon, export=1 + // x0 unused + // x1 uint8_t *pix1 + // x2 uint8_t *pix2 + // x3 ptrdiff_t stride + // w4 int h + + ld1 {v0.8b}, [x1], x3 // Load pix1[0], first iteration + ld1 {v1.8b}, [x2], x3 // Load pix2[0], first iteration + + sub w4, w4, #1 // we need to make h-1 iterations + movi v16.4s, #0 + movi v17.4s, #0 + + cmp w4, #3 // check if we can make 3 iterations at once + usubl v31.8h, v0.8b, v1.8b // Signed difference of pix1[0] - pix2[0], first iteration + b.le 2f + + +1: + // x = abs(pix1[0] - pix2[0] - pix1[0 + stride] + pix2[0 + stride]) + // res = (x) * (x) + ld1 {v0.8b}, [x1], x3 // Load pix1[0 + stride], first iteration + ld1 {v1.8b}, [x2], x3 // Load pix2[0 + stride], first iteration + ld1 {v2.8b}, [x1], x3 // Load pix1[0 + stride], second iteration + ld1 {v3.8b}, [x2], x3 // Load pix2[0 + stride], second iteration + usubl v29.8h, v0.8b, v1.8b + usubl2 v28.8h, v0.16b, v1.16b + ld1 {v4.8b}, [x1], x3 // Load pix1[0 + stride], third iteration + ld1 {v5.8b}, [x2], x3 // Load pix1[0 + stride], third iteration + sabd v31.8h, v31.8h, v29.8h + usubl v27.8h, v2.8b, v3.8b + usubl v25.8h, v4.8b, v5.8b + sabd v29.8h, v29.8h, v27.8h + sabd v27.8h, v27.8h, v25.8h + umlal v16.4s, v31.4h, v31.4h + umlal2 v17.4s, v31.8h, v31.8h + mov v31.16b, v25.16b + umlal v16.4s, v29.4h, v29.4h + umlal2 v17.4s, v29.8h, v29.8h + sub w4, w4, #3 + umlal v16.4s, v27.4h, v27.4h + umlal2 v17.4s, v27.8h, v27.8h + cmp w4, #3 + + b.ge 1b + + cbz w4, 3f + +// iterate by once +2: + ld1 {v0.8b}, [x1], x3 + ld1 {v1.8b}, [x2], x3 + subs w4, w4, #1 + usubl v29.8h, v0.8b, v1.8b + sabd v31.8h, v31.8h, v29.8h + umlal v16.4s, v31.4h, v31.4h + umlal2 v17.4s, v31.8h, v31.8h + mov v31.16b, v29.16b + b.ne 2b + +3: + add v16.4s, v16.4s, v17.4s + uaddlv d17, v16.4s + fmov w0, s17 + + ret +endfunc + + function vsse16_neon, export=1 // x0 unused // x1 uint8_t *pix1 From patchwork Mon Sep 26 09:15:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grzegorz Bernacki X-Patchwork-Id: 38327 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp2122627pzh; Mon, 26 Sep 2022 02:16:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5P9MR9yHVsQSRtlDW7LyXO0fuROSlMrnwirg60rtMl7aRXa8u4pMoaj6k9b4d1sxlF+Xem X-Received: by 2002:a05:6402:1e8d:b0:454:79a9:201f with SMTP id f13-20020a0564021e8d00b0045479a9201fmr21601114edf.176.1664183766350; Mon, 26 Sep 2022 02:16:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664183766; cv=none; d=google.com; s=arc-20160816; b=BH4ERTO7mBlGu4UP8yHO68GcDRRBfsOWmb99a/sbq8GcrwQRIuh5zPT8Y92hONmmxi YmoLPuiaQC4GjFo/xFE9WQIX1Q6RhGzCKOIZbPTxElDeojpJhjTHy6lDA4WrXU1L0scD V2QRySV52j0Hmm1hwlN/PQ76EGbGevjeanB0SZZEB7t+cQWHjc8BXUdXJ/DCJQ8R+DrN Vycj7Ut8CGC30ZJ5NuvDu1BBOiM7RSjyGOYQ9waYQmksR8WakzKUHlfunr+35FmY0XYi Cq6EivozmVNnTJUYlBrwBHjOf7quvvxlsXWbQPo2oeHpvHaEQDpcAzz3xsT5W+n6kNXL eDcQ== 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=3FrZO7OP++/aTeKDQTrfawgk/rJVZidKDXR7NW+jprs=; b=oQOaCer7oG9b6+MWNR1eRURqBGWPyxzlAEZQaFWUZLoxL9d9lDr98YCHaH43/4nXJP fV/iOCs5wpuBcxF86fPVjQREKG5U/5YSa6V7fZVCH07N+GiEJBUZs6cmzVI9fidSbyWP W/J0frLeFCJEo8SZIPcTSVx78GLb//6/7UammD8QPqMf4F40dUPOAmrhRhZ6n37Wl48I GR3KPa7LAQKUa2DYwU3FtsArBCbi5mJbwkSGzt8E83kFniLDdXuzBX0Y7u6T5N5n4kgj YagLDcn15UkWSJopIDhjbU/ZxzBncyFpavCccZj4A4wY2O3i/EFmD64GwsonrpDEr4wh vzcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b="DvE/yJM/"; 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 hr38-20020a1709073fa600b007824b85978asi12114277ejc.81.2022.09.26.02.16.05; Mon, 26 Sep 2022 02:16:06 -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="DvE/yJM/"; 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 348BA68BA89; Mon, 26 Sep 2022 12:15:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2DC5C680105 for ; Mon, 26 Sep 2022 12:15:30 +0300 (EEST) Received: by mail-lf1-f51.google.com with SMTP id a8so9780116lff.13 for ; Mon, 26 Sep 2022 02:15:30 -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=IU2SHa5I6ClTspEFUtyFpWXXN6Vl5g6893brwwXZTH4=; b=DvE/yJM/oRTL1mXb3+WHWdJiR51RdDQs6PJEDlbgPmddbrcMoE2El8sxptQmOaxpDg MqD96tCwNgadTqehwml5EwKk2umDvaSSQTP02tnJ8AnLgnNaqYEC7SyOHutNYWnSE3T/ /wzMWXZcqrl3FAr5qzxzPR212L1hfyLYQ8MlOtpWcBI0g/yxYD67urJV6D9CRXFKGkwR a72gqVTXpCTaFbdHGmOv+AjPybSWFyI90ZHxbuuKCA9Zm1gebUvGm30hmGV9ULdmK6HD 3/POjE4mG6+jFTn0jr1BMZ69JfTQIh35IoPftuOHFWY/Egtukwfy89iA6WuDznQlzsRr /BcQ== 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=IU2SHa5I6ClTspEFUtyFpWXXN6Vl5g6893brwwXZTH4=; b=8NjiACHAkogyV6HecfRpWXTXCg20tc+Finzin/wYBf2acFzZBBfIY+c2WbURMWeTRt hzzRqFfeJk02Ub2dY7ytCrnFwgUnzmkETTpj4UmYw6X4zXAkhOqzbJ7/kNLZs4AXg6FR YM+CBoKPgd3y67qgyE3aAr1pYmzJLkDYjjV0fUxQ8FgCTpON/76F70CFlAD1BsKVGRo0 1lCoGHl0an+CB2W/0dwN7u0YIp/2wCb6a+bxXdSPMt0iYGdEKuYX8XtX8IhaOXAKFhbu D5HPpMjLtOsHorTdY4qkAGktJKOoZy0do23yx/sj6+uyrlSGhlrya61i/4EH+e7S0oH1 FuYw== X-Gm-Message-State: ACrzQf0sa40y3eG87lANPnOB0tJPhQwqPfdqAui/ZZbTKB6vqvQX1WGH hFtjb0AMonfH30vPMuN/fFzJvk0hJBAshg== X-Received: by 2002:a05:6512:3d94:b0:49d:144c:9667 with SMTP id k20-20020a0565123d9400b0049d144c9667mr8614555lfv.50.1664183728601; Mon, 26 Sep 2022 02:15:28 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Sep 2022 02:15:28 -0700 (PDT) From: Grzegorz Bernacki To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Sep 2022 11:15:04 +0200 Message-Id: <20220926091504.3459110-4-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 4/4] lavc/aarch64: Add neon implementation for vsse_intra8 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: 7ztG47Bqb+4w Provide optimized implementation for vsse_intra8 for arm64. Performance tests are shown below. - vsse_5_c: 87.7 - vsse_5_neon: 26.2 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 | 53 ++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index f247372c94..defec37478 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -74,6 +74,9 @@ int nsse8_neon_wrapper(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, int vsse8_neon(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h); +int vsse_intra8_neon(MpegEncContext *c, const uint8_t *s, const uint8_t *dummy, + ptrdiff_t stride, int h); + av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) { int cpu_flags = av_get_cpu_flags(); @@ -102,6 +105,7 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) c->vsse[1] = vsse8_neon; c->vsse[4] = vsse_intra16_neon; + c->vsse[5] = vsse_intra8_neon; c->nsse[0] = nsse16_neon_wrapper; c->nsse[1] = nsse8_neon_wrapper; diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index 386d2de0c5..82ff05d3f0 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -1111,6 +1111,59 @@ function vsse_intra16_neon, export=1 ret endfunc +function vsse_intra8_neon, export=1 + // x0 unused + // x1 uint8_t *pix1 + // x2 uint8_t *dummy + // x3 ptrdiff_t stride + // w4 int h + + ld1 {v0.8b}, [x1], x3 + movi v16.4s, #0 + + sub w4, w4, #1 // we need to make h-1 iterations + cmp w4, #3 + b.lt 2f + +1: + // v = abs( pix1[0] - pix1[0 + stride] ) + // score = sum( v * v ) + ld1 {v1.8b}, [x1], x3 + ld1 {v2.8b}, [x1], x3 + uabd v30.8b, v0.8b, v1.8b + ld1 {v3.8b}, [x1], x3 + umull v29.8h, v30.8b, v30.8b + uabd v27.8b, v1.8b, v2.8b + uadalp v16.4s, v29.8h + umull v26.8h, v27.8b, v27.8b + uabd v25.8b, v2.8b, v3.8b + uadalp v16.4s, v26.8h + umull v24.8h, v25.8b, v25.8b + sub w4, w4, #3 + uadalp v16.4s, v24.8h + cmp w4, #3 + mov v0.8b, v3.8b + + b.ge 1b + cbz w4, 3f + +// iterate by one +2: + ld1 {v1.8b}, [x1], x3 + subs w4, w4, #1 + uabd v30.8b, v0.8b, v1.8b + mov v0.8b, v1.8b + umull v29.8h, v30.8b, v30.8b + uadalp v16.4s, v29.8h + cbnz w4, 2b + +3: + uaddlv d17, v16.4s + fmov w0, s17 + + ret +endfunc + function nsse16_neon, export=1 // x0 multiplier // x1 uint8_t *pix1