From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 0A8ED4433B for ; Tue, 6 Sep 2022 10:28:53 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6564568BB13; Tue, 6 Sep 2022 13:28:13 +0300 (EEST) Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D76A468BB0C for ; Tue, 6 Sep 2022 13:28:06 +0300 (EEST) Received: by mail-lf1-f42.google.com with SMTP id z6so16617467lfu.9 for ; Tue, 06 Sep 2022 03:28:06 -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=rUl5JfNcOwShI+Fu8hWPsymuo0HaPRTGsANyMm/6gJI=; b=N4gniW3nFa5VDyummgLnJuKR68t1fU8h8RffHsuXsbXjri7Yp5YgAb2N++bqJWQNJG fsa+WOeI7lxXvtXou+qbbW2RAXQn10Cz2s7MKDYOGLfpnbFOrdT6kRVUIlvqm6jLEc4D fHncWoBU8jcWO4jutX5AKaW4kxmBkNgkhIUnTvaw+gj/RTLjtQ1YdMGlLosLWs9yhbwF EtfumefS+UcmrXxVcgY4/BzBHfWzo/qHo8p5kFo0EKqRoR4DLRMpVAoBqEUaVO40EHPV kxWYNWBBfPqeu9i4jlYZ4wIM2gaiDpMYSP6e07xs3ahSFB4BUySKY923P23mky8v5SLq n70Q== 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=rUl5JfNcOwShI+Fu8hWPsymuo0HaPRTGsANyMm/6gJI=; b=xhkeCA0IzARGMGnk98a4B/JWMqOPTWHZSgaWYQ7CSarRwUIGK/1FSb47zYEShOjT2M 8pyNeZ1S/KofwRJt3t4DJqzyQuBGC0Kufkfe6r1BoaSFU3FAugGCMML547WdwOeL70zK vYSAfnOfxmPlkr8NnuMw1hJMQfW1Hl6+IJMCoJXHUfXriZ4ZgqPZ8gWHBFWxEtI0nlkb n4KWJzeC2qVbEX10pXV2b7kO3kWCTod7ZFHm5EDegRaRhZNPeP8T7RFuj2QlTnmiCpfO Z0qjfCdTqqhYyX4lZrZvXotT24iqKl88gtno1VvvzvwY/WVAg7PQne3nCKLAQOPV1lOJ QW6Q== X-Gm-Message-State: ACgBeo1Pe0oiMEdZHKgH7T3Jm0lSEL8uuBSNs7tsc57TdaVPedKzrR+A zksbKGEGATd410X25wqCgjo4Ust+79IJnw== X-Google-Smtp-Source: AA6agR7slaIZrtTZYFEc+QtIEsWaql9r84qMFqf47JJ2cGS5tXpHp0qSaHZSLE9SDG5hE8ZiaMfEXw== X-Received: by 2002:a19:6706:0:b0:494:b2d0:3b3e with SMTP id b6-20020a196706000000b00494b2d03b3emr4602118lfc.179.1662460085999; Tue, 06 Sep 2022 03:28:05 -0700 (PDT) Received: from hum-HP-ProBook-440-G7.wifi.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id q5-20020a2eb4a5000000b0025e59f125fbsm1822751ljm.53.2022.09.06.03.28.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 03:28:05 -0700 (PDT) From: Hubert Mazur To: ffmpeg-devel@ffmpeg.org Date: Tue, 6 Sep 2022 12:27:22 +0200 Message-Id: <20220906102722.53266-6-hum@semihalf.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220906102722.53266-1-hum@semihalf.com> References: <20220906102722.53266-1-hum@semihalf.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 5/5] lavc/aarch64: Provide neon implementation of nsse16 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Add vectorized implementation of nsse16 function. Performance comparison tests are shown below. - nsse_0_c: 707.0 - nsse_0_neon: 120.0 Benchmarks and tests run with checkasm tool on AWS Graviton 3. Signed-off-by: Hubert Mazur --- libavcodec/aarch64/me_cmp_init_aarch64.c | 15 +++ libavcodec/aarch64/me_cmp_neon.S | 124 +++++++++++++++++++++++ 2 files changed, 139 insertions(+) diff --git a/libavcodec/aarch64/me_cmp_init_aarch64.c b/libavcodec/aarch64/me_cmp_init_aarch64.c index 8c295d5457..ea7f295373 100644 --- a/libavcodec/aarch64/me_cmp_init_aarch64.c +++ b/libavcodec/aarch64/me_cmp_init_aarch64.c @@ -49,6 +49,10 @@ int vsse16_neon(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, ptrdiff_t stride, int h); int vsse_intra16_neon(MpegEncContext *c, const uint8_t *s, const uint8_t *dummy, ptrdiff_t stride, int h); +int nsse16_neon(int multiplier, const uint8_t *s, const uint8_t *s2, + ptrdiff_t stride, int h); +int nsse16_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) { @@ -72,5 +76,16 @@ av_cold void ff_me_cmp_init_aarch64(MECmpContext *c, AVCodecContext *avctx) c->vsse[0] = vsse16_neon; c->vsse[4] = vsse_intra16_neon; + + c->nsse[0] = nsse16_neon_wrapper; } } + +int nsse16_neon_wrapper(MpegEncContext *c, const uint8_t *s1, const uint8_t *s2, + ptrdiff_t stride, int h) +{ + if (c) + return nsse16_neon(c->avctx->nsse_weight, s1, s2, stride, h); + else + return nsse16_neon(8, s1, s2, stride, h); +} diff --git a/libavcodec/aarch64/me_cmp_neon.S b/libavcodec/aarch64/me_cmp_neon.S index cf2b8da425..bd21122a21 100644 --- a/libavcodec/aarch64/me_cmp_neon.S +++ b/libavcodec/aarch64/me_cmp_neon.S @@ -847,3 +847,127 @@ function vsse_intra16_neon, export=1 ret endfunc + +function nsse16_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(sse16_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.16b}, [x1], x3 + subs w4, w4, #1 // we need to make h-1 iterations + ext v1.16b, v0.16b, v0.16b, #1 // x1 + 1 + ld1 {v2.16b}, [x2], x3 + cmp w4, #2 + ext v3.16b, v2.16b, v2.16b, #1 // x2 + 1 + + b.lt 2f + +// make 2 iterations at once +1: + ld1 {v4.16b}, [x1], x3 + ld1 {v20.16b}, [x1], x3 + ext v5.16b, v4.16b, v4.16b, #1 // x1 + stride + 1 + ext v21.16b, v20.16b, v20.16b, #1 + ld1 {v6.16b}, [x2], x3 + ld1 {v22.16b}, [x2], x3 + ext v7.16b, v6.16b, v6.16b, #1 // x2 + stride + 1 + ext v23.16b, v22.16b, v22.16b, #1 + + usubl v31.8h, v0.8b, v4.8b + usubl2 v30.8h, v0.16b, v4.16b + usubl v29.8h, v1.8b, v5.8b + usubl2 v28.8h, v1.16b, v5.16b + saba v16.8h, v31.8h, v29.8h + saba v17.8h, v30.8h, v28.8h + usubl v27.8h, v2.8b, v6.8b + usubl2 v26.8h, v2.16b, v6.16b + usubl v25.8h, v3.8b, v7.8b + usubl2 v24.8h, v3.16b, v7.16b + saba v18.8h, v27.8h, v25.8h + saba v19.8h, v26.8h, v24.8h + + usubl v31.8h, v4.8b, v20.8b + usubl2 v30.8h, v4.16b, v20.16b + usubl v29.8h, v5.8b, v21.8b + usubl2 v28.8h, v5.16b, v21.16b + saba v16.8h, v31.8h, v29.8h + saba v17.8h, v30.8h, v28.8h + usubl v27.8h, v6.8b, v22.8b + usubl2 v26.8h, v6.16b, v22.16b + usubl v25.8h, v7.8b, v23.8b + usubl2 v24.8h, v7.16b, v23.16b + saba v18.8h, v27.8h, v25.8h + saba v19.8h, v26.8h, v24.8h + + mov v0.16b, v20.16b + mov v1.16b, v21.16b + mov v2.16b, v22.16b + mov v3.16b, v23.16b + + sub w4, w4, #2 + cmp w4, #2 + + b.ge 1b + cbz w4, 3f + +// iterate by one +2: + ld1 {v4.16b}, [x1], x3 + subs w4, w4, #1 + ext v5.16b, v4.16b, v4.16b, #1 // x1 + stride + 1 + ld1 {v6.16b}, [x2], x3 + usubl v31.8h, v0.8b, v4.8b + ext v7.16b, v6.16b, v6.16b, #1 // x2 + stride + 1 + + usubl2 v30.8h, v0.16b, v4.16b + usubl v29.8h, v1.8b, v5.8b + usubl2 v28.8h, v1.16b, v5.16b + saba v16.8h, v31.8h, v29.8h + saba v17.8h, v30.8h, v28.8h + usubl v27.8h, v2.8b, v6.8b + usubl2 v26.8h, v2.16b, v6.16b + usubl v25.8h, v3.8b, v7.8b + usubl2 v24.8h, v3.16b, v7.16b + saba v18.8h, v27.8h, v25.8h + saba v19.8h, v26.8h, v24.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 + sqsub v17.8h, v17.8h, v19.8h + ins v17.h[7], wzr + sqadd v16.8h, v16.8h, v17.8h + saddlv s16, v16.8h + sqabs s16, s16 + fmov w0, s16 + + mul w0, w0, w5 + add w0, w0, w9 + + ret +endfunc -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".