From patchwork Fri Oct 28 11:34:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hubert Mazur X-Patchwork-Id: 39025 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:85a8:b0:a2:d5a7:ad9d with SMTP id s40csp729881pzd; Fri, 28 Oct 2022 04:35:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4xRIABu8O9ukLP0LMpB75xPxrU/DCmfD5/Ivgr2WYwPEvE9vmz7GxVF5/MIUMgitB1VsXP X-Received: by 2002:a05:6402:294a:b0:461:b661:d903 with SMTP id ed10-20020a056402294a00b00461b661d903mr25659184edb.407.1666956923692; Fri, 28 Oct 2022 04:35:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666956923; cv=none; d=google.com; s=arc-20160816; b=y4kRmloDUQD2qnC8Xo968eqJ++tME/hIG31mx83uWeEeH9aRhtKbEvEwUbQ2BX6Vi2 fPy8rxomSxyS02EfPGJU5tyZk+r/ot7t3atG8CPsq6HDI7MZm1E9NBduVRbSI2GkZfRe DemQjSjajkMlEiB0atWfGY4smC0EX10B7eBlw6whpmUmZBVb/32ou2HW2f3GGz53m/am J3NPu9hrjWqfZWPNKjSgdrasrpFR1HGZ8n9LGQCc1VkfAnR+2mDzIG0mc7iNYhvI7mqQ X9HBZ1OrQSD9HEbWXstYAaS2BX0jiEAjWSu2MxbSf0G85xPFA3voPuBrRN1Hbi8drE4J NWNQ== 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=Azit29Q7SPIESrvbXtuNiywxAqeJ+aWeMjDF0kJ5NKw=; b=mnVx50J65lLJxWZ4DFbzhDiEIFWf88ugNYHGug+WLSbDfvkGU9Y8oZ4K3nf8PUogee 8gJIqw/QT+d08b2g0zobMIGAmFNIPPOExUbqTsC6eCWNuUwsz8p6K2GeiypywuWr5C7T SkzklyQGQTSylAOB69hw4JWmIK0xVojHm7hcLzNfa+VXGHXW5BV232TQQ617iyKuaw9r 37W+2P1ACzXk3JO6Wsu/VmSU2Rj1g2M1rJ2Yf4bJ+V1Ko7/99T0A3aDap4Mq2LDFHNXF Z1PjdZgg5syShUvQO4LuxGQg91VRNsuke9+woHU79qxiZsNVqG9Puy1LOnvyqXwk3iv4 cX5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@semihalf.com header.s=google header.b=SwcvCuwJ; 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 hz5-20020a1709072ce500b0077a6429787dsi4750696ejc.157.2022.10.28.04.35.23; Fri, 28 Oct 2022 04:35:23 -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=SwcvCuwJ; 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 8849E68BCF5; Fri, 28 Oct 2022 14:35:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2E75D68BCED for ; Fri, 28 Oct 2022 14:34:55 +0300 (EEST) Received: by mail-wr1-f41.google.com with SMTP id j15so6237928wrq.3 for ; Fri, 28 Oct 2022 04:34:55 -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 :message-id:reply-to; bh=2NTcX7aW/MByUjPTSOEYWLmOluuIV3hV/i2Ug+Gjzso=; b=SwcvCuwJQznOg/Oh9Dxr6a3S1+OH0oIKmKevxu6o3TmZBdVMjAsLrYNMXRldJUfRK+ H6z+7pIT6q5FzHK0xeNOOYnDaWASSDbcro3hGjNHhIzGQ1/irLtiJqtwEXJxV0cbIj4H t+9yPHJecYiLHdP4o4BlE45sA6jf+NIX0tNivoP10mb2Wapeh3zbQbAiHQsiTt5ngIrJ ljmRyDDJiCvDghRpxNzEdcKQIMe438Zw8/XBO+UhjgV3LtK8YPrTxFztRgyZiT3OgAPR ESwg3URiHfUt+blVrNZ3fIyw6+rTCWtm9R/7oo21ghysF0stXKcFhF4ropaWgNTNgHiT kutg== 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:message-id:reply-to; bh=2NTcX7aW/MByUjPTSOEYWLmOluuIV3hV/i2Ug+Gjzso=; b=e0NZHXHr0YA2hZAUjc+IKztO24JCLD2W+YzSagVc9KvinuYfjUYPuMCpbRC6cOJVzV wKCv2UM2EdeYK76UYS+JNa2jP8fXPtCvCxWFqaswNcGvD1EZbQkH7ic9TTq87x5rFTQa utnQxO4o6s8Js/GUa2XOZtxeNwZEqLNpApVsBGrk/lP7PxyYOF2EZ29W8wJ2P4tQ1ts/ OfB6alSGxqmVZ1ZtMvhKedbLO8eyK5I8A3J2kgraxd+JHPhFqxhJrcd86pU+6zGGGMUl S3sEBgMjD1voSaTpYaj6fXcIe0r26e7Mfoma7rk7u6weCR5u0Raa+Qgb8ze709SvvuGW IYEA== X-Gm-Message-State: ACrzQf3qxyrXiok4tTtNtyNzzWbgRTuvo5Ft74AT/NRf9RDPvVFK4uPz q1LGlv29C8DInGqSeCqtYU7lgcImyj3XmFjU X-Received: by 2002:a5d:6c6f:0:b0:22e:3fdf:4b27 with SMTP id r15-20020a5d6c6f000000b0022e3fdf4b27mr35039305wrz.150.1666956894106; Fri, 28 Oct 2022 04:34:54 -0700 (PDT) Received: from ip-172-31-3-164.eu-west-1.compute.internal (ec2-54-154-193-154.eu-west-1.compute.amazonaws.com. [54.154.193.154]) by smtp.gmail.com with ESMTPSA id m124-20020a1ca382000000b003c70191f267sm7216852wme.39.2022.10.28.04.34.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Oct 2022 04:34:53 -0700 (PDT) From: Hubert Mazur To: ffmpeg-devel@ffmpeg.org Date: Fri, 28 Oct 2022 11:34:38 +0000 Message-Id: <20221028113439.30279-3-hum@semihalf.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20221028113439.30279-1-hum@semihalf.com> References: <20221028113439.30279-1-hum@semihalf.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] sw_scale: Add specializations for hscale 16 to 15 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: cVSicVY7OYBg Add arm64 neon implementations for hscale 16 to 15 with filter sizes 4, 8 and X4. The tests and benchmarks run on AWS Graviton 2 instances. The results from a checkasm tool are shown below. hscale_16_to_15__fs_4_dstW_512_c: 6703.5 hscale_16_to_15__fs_4_dstW_512_neon: 2298.0 hscale_16_to_15__fs_8_dstW_512_c: 10983.0 hscale_16_to_15__fs_8_dstW_512_neon: 3216.5 hscale_16_to_15__fs_12_dstW_512_c: 15526.0 hscale_16_to_15__fs_12_dstW_512_neon: 3993.0 hscale_16_to_15__fs_16_dstW_512_c: 20183.5 hscale_16_to_15__fs_16_dstW_512_neon: 5369.7 hscale_16_to_15__fs_32_dstW_512_c: 39315.2 hscale_16_to_15__fs_32_dstW_512_neon: 9511.2 hscale_16_to_15__fs_40_dstW_512_c: 48995.7 hscale_16_to_15__fs_40_dstW_512_neon: 11570.0 Signed-off-by: Hubert Mazur --- libswscale/aarch64/hscale.S | 407 +++++++++++++++++++++++++++++++++++ libswscale/aarch64/swscale.c | 61 ++++++ libswscale/swscale.c | 1 - 3 files changed, 468 insertions(+), 1 deletion(-) diff --git a/libswscale/aarch64/hscale.S b/libswscale/aarch64/hscale.S index 35e25462ce8..b571a5dc219 100644 --- a/libswscale/aarch64/hscale.S +++ b/libswscale/aarch64/hscale.S @@ -636,5 +636,412 @@ function ff_hscale8to19_X4_neon, export=1 add x4, x4, x7, lsl #2 b.gt 1b ret +endfunc + +function ff_hscale16to15_4_neon_asm, export=1 + // w0 int shift + // x1 int32_t *dst + // w2 int dstW + // x3 const uint8_t *src // treat it as uint16_t *src + // x4 const uint16_t *filter + // x5 const int32_t *filterPos + // w6 int filterSize + + movi v18.4s, #1 + movi v17.4s, #1 + shl v18.4s, v18.4s, #15 + sub v18.4s, v18.4s, v17.4s // max allowed value + dup v17.4s, w0 // read shift + neg v17.4s, v17.4s // negate it, so it can be used in sshl (effectively shift right) + + cmp w2, #16 + b.lt 2f // move to last block + + ldp w8, w9, [x5] // filterPos[0], filterPos[1] + ldp w10, w11, [x5, #8] // filterPos[2], filterPos[3] + ldp w12, w13, [x5, #16] // filterPos[4], filterPos[5] + ldp w14, w15, [x5, #24] // filterPos[6], filterPos[7] + add x5, x5, #32 + + // shift all filterPos left by one, as uint16_t will be read + lsl x8, x8, #1 + lsl x9, x9, #1 + lsl x10, x10, #1 + lsl x11, x11, #1 + lsl x12, x12, #1 + lsl x13, x13, #1 + lsl x14, x14, #1 + lsl x15, x15, #1 + + // load src with given offset + ldr x8, [x3, w8, UXTW] + ldr x9, [x3, w9, UXTW] + ldr x10, [x3, w10, UXTW] + ldr x11, [x3, w11, UXTW] + ldr x12, [x3, w12, UXTW] + ldr x13, [x3, w13, UXTW] + ldr x14, [x3, w14, UXTW] + ldr x15, [x3, w15, UXTW] + + sub sp, sp, #64 + // push src on stack so it can be loaded into vectors later + stp x8, x9, [sp] + stp x10, x11, [sp, #16] + stp x12, x13, [sp, #32] + stp x14, x15, [sp, #48] + +1: + ld4 {v0.8h, v1.8h, v2.8h, v3.8h}, [sp] + ld4 {v28.8h, v29.8h, v30.8h, v31.8h}, [x4], #64 // filter[0..7] + + // Each of blocks does the following: + // Extend src and filter to 32 bits with uxtl and sxtl + // multiply or multiply and accumulate results + // Extending to 32 bits is necessary, as unit16_t values can't + // be represented as int16_t without type promotion. + uxtl v26.4s, v0.4h + sxtl v27.4s, v28.4H + uxtl2 v0.4s, v0.8h + mul v5.4s, v26.4s, v27.4s + sxtl2 v28.4s, v28.8H + uxtl v26.4s, v1.4h + mul v6.4s, v0.4s, v28.4s + + sxtl v27.4s, v29.4H + uxtl2 v0.4s, v1.8h + mla v5.4s, v27.4s, v26.4s + sxtl2 v28.4s, v29.8H + uxtl v26.4s, v2.4h + mla v6.4s, v28.4s, v0.4s + + sxtl v27.4s, v30.4H + uxtl2 v0.4s, v2.8h + mla v5.4s, v27.4s, v26.4s + sxtl2 v28.4s, v30.8H + uxtl v26.4s, v3.4h + mla v6.4s, v28.4s, v0.4s + + sxtl v27.4s, v31.4H + uxtl2 v0.4s, v3.8h + mla v5.4s, v27.4s, v26.4s + sxtl2 v28.4s, v31.8H + sub w2, w2, #8 + mla v6.4s, v28.4s, v0.4s + + sshl v5.4s, v5.4s, v17.4s + sshl v6.4s, v6.4s, v17.4s + smin v5.4s, v5.4s, v18.4s + smin v6.4s, v6.4s, v18.4s + xtn v5.4h, v5.4s + xtn2 v5.8h, v6.4s + + st1 {v5.8h}, [x1], #16 + cmp w2, #16 + + // load filterPositions into registers for next iteration + ldp w8, w9, [x5] // filterPos[0], filterPos[1] + ldp w10, w11, [x5, #8] // filterPos[2], filterPos[3] + ldp w12, w13, [x5, #16] // filterPos[4], filterPos[5] + ldp w14, w15, [x5, #24] // filterPos[6], filterPos[7] + add x5, x5, #32 + + lsl x8, x8, #1 + lsl x9, x9, #1 + lsl x10, x10, #1 + lsl x11, x11, #1 + lsl x12, x12, #1 + lsl x13, x13, #1 + lsl x14, x14, #1 + lsl x15, x15, #1 + + ldr x8, [x3, w8, UXTW] + ldr x9, [x3, w9, UXTW] + ldr x10, [x3, w10, UXTW] + ldr x11, [x3, w11, UXTW] + ldr x12, [x3, w12, UXTW] + ldr x13, [x3, w13, UXTW] + ldr x14, [x3, w14, UXTW] + ldr x15, [x3, w15, UXTW] + + stp x8, x9, [sp] + stp x10, x11, [sp, #16] + stp x12, x13, [sp, #32] + stp x14, x15, [sp, #48] + + b.ge 1b + + // here we make last iteration, without updating the registers + ld4 {v0.8h, v1.8h, v2.8h, v3.8h}, [sp] + ld4 {v28.8h, v29.8h, v30.8h, v31.8h}, [x4], #64 + + uxtl v26.4s, v0.4h + sxtl v27.4s, v28.4H + uxtl2 v0.4s, v0.8h + mul v5.4s, v26.4s, v27.4s + sxtl2 v28.4s, v28.8H + uxtl v26.4s, v1.4h + mul v6.4s, v0.4s, v28.4s + + sxtl v27.4s, v29.4H + uxtl2 v0.4s, v1.8h + mla v5.4s, v26.4s, v27.4s + sxtl2 v28.4s, v29.8H + uxtl v26.4s, v2.4h + mla v6.4s, v0.4s, v28.4s + + sxtl v27.4s, v30.4H + uxtl2 v0.4s, v2.8h + mla v5.4s, v26.4s, v27.4s + sxtl2 v28.4s, v30.8H + uxtl v26.4s, v3.4h + mla v6.4s, v0.4s, v28.4s + + sxtl v27.4s, v31.4H + uxtl2 v0.4s, v3.8h + mla v5.4s, v26.4s, v27.4s + sxtl2 v28.4s, v31.8H + subs w2, w2, #8 + mla v6.4s, v0.4s, v28.4s + + sshl v5.4s, v5.4s, v17.4s + sshl v6.4s, v6.4s, v17.4s + smin v5.4s, v5.4s, v18.4s + smin v6.4s, v6.4s, v18.4s + xtn v5.4h, v5.4S + xtn2 v5.8h, v6.4s + + st1 {v5.8h}, [x1], #16 + add sp, sp, #64 // restore stack + cbnz w2, 2f + + ret + +2: + ldr w8, [x5], #4 // load filterPos + lsl w8, w8, #1 + add x9, x3, w8, UXTW // src + filterPos + ld1 {v0.4h}, [x9] // load 4 * uint16_t + ld1 {v31.4h}, [x4], #8 + + uxtl v0.4s, v0.4h + sxtl v31.4s, v31.4h + mul v5.4s, v0.4s, v31.4s + addv s0, v5.4S + sshl v0.4s, v0.4s, v17.4s + smin v0.4s, v0.4s, v18.4s + st1 {v0.h}[0], [x1], #2 + sub w2, w2, #1 + cbnz w2, 2b // if iterations remain jump to beginning + + ret +endfunc + +function ff_hscale16to15_X8_neon_asm, export=1 + // w0 int shift + // x1 int32_t *dst + // w2 int dstW + // x3 const uint8_t *src // treat it as uint16_t *src + // x4 const uint16_t *filter + // x5 const int32_t *filterPos + // w6 int filterSize + + movi v20.4s, #1 + movi v21.4s, #1 + shl v20.4s, v20.4s, #15 + sub v20.4s, v20.4s, v21.4s + dup v21.4s, w0 + neg v21.4s, v21.4s + + sbfiz x7, x6, #1, #32 // filterSize*2 (*2 because int16) +1: ldr w8, [x5], #4 // filterPos[idx] + lsl w8, w8, #1 + ldr w10, [x5], #4 // filterPos[idx + 1] + lsl w10, w10, #1 + ldr w11, [x5], #4 // filterPos[idx + 2] + lsl w11, w11, #1 + ldr w9, [x5], #4 // filterPos[idx + 3] + lsl w9, w9, #1 + mov x16, x4 // filter0 = filter + add x12, x16, x7 // filter1 = filter0 + filterSize*2 + add x13, x12, x7 // filter2 = filter1 + filterSize*2 + add x4, x13, x7 // filter3 = filter2 + filterSize*2 + movi v0.2D, #0 // val sum part 1 (for dst[0]) + movi v1.2D, #0 // val sum part 2 (for dst[1]) + movi v2.2D, #0 // val sum part 3 (for dst[2]) + movi v3.2D, #0 // val sum part 4 (for dst[3]) + add x17, x3, w8, UXTW // srcp + filterPos[0] + add x8, x3, w10, UXTW // srcp + filterPos[1] + add x10, x3, w11, UXTW // srcp + filterPos[2] + add x11, x3, w9, UXTW // srcp + filterPos[3] + mov w15, w6 // filterSize counter +2: ld1 {v4.8H}, [x17], #16 // srcp[filterPos[0] + {0..7}] + ld1 {v5.8H}, [x16], #16 // load 8x16-bit filter values, part 1 + ld1 {v6.8H}, [x8], #16 // srcp[filterPos[1] + {0..7}] + ld1 {v7.8H}, [x12], #16 // load 8x16-bit at filter+filterSize + uxtl v24.4s, v4.4H // extend srcp lower half to 32 bits to preserve sign + sxtl v25.4s, v5.4H // extend filter lower half to 32 bits to match srcp size + uxtl2 v4.4s, v4.8h // extend srcp upper half to 32 bits + mla v0.4s, v24.4s, v25.4s // multiply accumulate lower half of v4 * v5 + sxtl2 v5.4s, v5.8h // extend filter upper half to 32 bits + uxtl v26.4s, v6.4h // extend srcp lower half to 32 bits + mla v0.4S, v4.4s, v5.4s // multiply accumulate upper half of v4 * v5 + sxtl v27.4s, v7.4H // exted filter lower half + uxtl2 v6.4s, v6.8H // extend srcp upper half + sxtl2 v7.4s, v7.8h // extend filter upper half + ld1 {v16.8H}, [x10], #16 // srcp[filterPos[2] + {0..7}] + mla v1.4S, v26.4s, v27.4s // v1 accumulates srcp[filterPos[1] + {0..3}] * filter[{0..3}] + ld1 {v17.8H}, [x13], #16 // load 8x16-bit at filter+2*filterSize + uxtl v22.4s, v16.4H // extend srcp lower half + sxtl v23.4s, v17.4H // extend filter lower half + uxtl2 v16.4s, v16.8H // extend srcp upper half + sxtl2 v17.4s, v17.8h // extend filter upper half + mla v2.4S, v22.4s, v23.4s // v2 accumulates srcp[filterPos[2] + {0..3}] * filter[{0..3}] + mla v2.4S, v16.4s, v17.4s // v2 accumulates srcp[filterPos[2] + {4..7}] * filter[{4..7}] + ld1 {v18.8H}, [x11], #16 // srcp[filterPos[3] + {0..7}] + mla v1.4S, v6.4s, v7.4s // v1 accumulates srcp[filterPos[1] + {4..7}] * filter[{4..7}] + ld1 {v19.8H}, [x4], #16 // load 8x16-bit at filter+3*filterSize + subs w15, w15, #8 // j -= 8: processed 8/filterSize + uxtl v28.4s, v18.4H // extend srcp lower half + sxtl v29.4s, v19.4H // extend filter lower half + uxtl2 v18.4s, v18.8H // extend srcp upper half + sxtl2 v19.4s, v19.8h // extend filter upper half + mla v3.4S, v28.4s, v29.4s // v3 accumulates srcp[filterPos[3] + {0..3}] * filter[{0..3}] + mla v3.4S, v18.4s, v19.4s // v3 accumulates srcp[filterPos[3] + {4..7}] * filter[{4..7}] + b.gt 2b // inner loop if filterSize not consumed completely + addp v0.4S, v0.4S, v1.4S // part01 horizontal pair adding + addp v2.4S, v2.4S, v3.4S // part23 horizontal pair adding + addp v0.4S, v0.4S, v2.4S // part0123 horizontal pair adding + subs w2, w2, #4 // dstW -= 4 + sshl v0.4s, v0.4s, v21.4s // shift right (effectively rigth, as shift is negative); overflow expected + smin v0.4s, v0.4s, v20.4s // apply min (do not use sqshl) + xtn v0.4h, v0.4s // narrow down to 16 bits + + st1 {v0.4H}, [x1], #8 // write to destination part0123 + b.gt 1b // loop until end of line + ret +endfunc +function ff_hscale16to15_X4_neon_asm, export=1 + // w0 int shift + // x1 int16_t *dst + // w2 int dstW + // x3 const uint8_t *src + // x4 const int16_t *filter + // x5 const int32_t *filterPos + // w6 int filterSize + + stp d8, d9, [sp, #-0x20]! + stp d10, d11, [sp, #0x10] + + movi v18.4s, #1 + movi v17.4s, #1 + shl v18.4s, v18.4s, #15 + sub v21.4s, v18.4s, v17.4s // max allowed value + dup v17.4s, w0 // read shift + neg v20.4s, v17.4s // negate it, so it can be used in sshl (effectively shift right) + + lsl w7, w6, #1 +1: + ldp w8, w9, [x5] + ldp w10, w11, [x5, #8] + + movi v16.2d, #0 // initialize accumulator for idx + 0 + movi v17.2d, #0 // initialize accumulator for idx + 1 + movi v18.2d, #0 // initialize accumulator for idx + 2 + movi v19.2d, #0 // initialize accumulator for idx + 3 + + mov x12, x4 // filter + 0 + add x13, x4, x7 // filter + 1 + add x8, x3, x8, lsl #1 // srcp + filterPos 0 + add x14, x13, x7 // filter + 2 + add x9, x3, x9, lsl #1 // srcp + filterPos 1 + add x15, x14, x7 // filter + 3 + add x10, x3, x10, lsl #1 // srcp + filterPos 2 + mov w0, w6 // save the filterSize to temporary variable + add x11, x3, x11, lsl #1 // srcp + filterPos 3 + add x5, x5, #16 // advance filter position + mov x16, xzr // clear the register x16 used for offsetting the filter values + +2: + ldr q4, [x8], #16 // load src values for idx 0 + ldr q5, [x9], #16 // load src values for idx 1 + uxtl v26.4s, v4.4h + uxtl2 v4.4s, v4.8h + ldr q31, [x12, x16] // load filter values for idx 0 + ldr q6, [x10], #16 // load src values for idx 2 + sxtl v22.4s, v31.4h + sxtl2 v31.4s, v31.8h + mla v16.4s, v26.4s, v22.4s // multiplication of lower half for idx 0 + uxtl v25.4s, v5.4h + uxtl2 v5.4s, v5.8h + ldr q30, [x13, x16] // load filter values for idx 1 + ldr q7, [x11], #16 // load src values for idx 3 + mla v16.4s, v4.4s, v31.4s // multiplication of upper half for idx 0 + uxtl v24.4s, v6.4h + sxtl v8.4s, v30.4h + sxtl2 v30.4s, v30.8h + mla v17.4s, v25.4s, v8.4s // multiplication of lower half for idx 1 + ldr q29, [x14, x16] // load filter values for idx 2 + uxtl2 v6.4s, v6.8h + sxtl v9.4s, v29.4h + sxtl2 v29.4s, v29.8h + mla v17.4s, v5.4s, v30.4s // multiplication of upper half for idx 1 + mla v18.4s, v24.4s, v9.4s // multiplication of lower half for idx 2 + ldr q28, [x15, x16] // load filter values for idx 3 + uxtl v23.4s, v7.4h + sxtl v10.4s, v28.4h + mla v18.4s, v6.4s, v29.4s // multiplication of upper half for idx 2 + uxtl2 v7.4s, v7.8h + sxtl2 v28.4s, v28.8h + mla v19.4s, v23.4s, v10.4s // multiplication of lower half for idx 3 + sub w0, w0, #8 + cmp w0, #8 + mla v19.4s, v7.4s, v28.4s // multiplication of upper half for idx 3 + + add x16, x16, #16 // advance filter values indexing + + b.ge 2b + + // 4 iterations left + + sub x17, x7, #8 // step back to wrap up the filter pos for last 4 elements + + ldr d4, [x8] // load src values for idx 0 + ldr d31, [x12, x17] // load filter values for idx 0 + uxtl v4.4s, v4.4h + sxtl v31.4s, v31.4h + ldr d5, [x9] // load src values for idx 1 + mla v16.4s, v4.4s, v31.4s // multiplication of upper half for idx 0 + ldr d30, [x13, x17] // load filter values for idx 1 + uxtl v5.4s, v5.4h + sxtl v30.4s, v30.4h + ldr d6, [x10] // load src values for idx 2 + mla v17.4s, v5.4s, v30.4s // multiplication of upper half for idx 1 + ldr d29, [x14, x17] // load filter values for idx 2 + uxtl v6.4s, v6.4h + sxtl v29.4s, v29.4h + ldr d7, [x11] // load src values for idx 3 + ldr d28, [x15, x17] // load filter values for idx 3 + mla v18.4s, v6.4s, v29.4s // multiplication of upper half for idx 2 + uxtl v7.4s, v7.4h + sxtl v28.4s, v28.4h + addp v16.4s, v16.4s, v17.4s + mla v19.4s, v7.4s, v28.4s // multiplication of upper half for idx 3 + subs w2, w2, #4 + addp v18.4s, v18.4s, v19.4s + addp v16.4s, v16.4s, v18.4s + sshl v16.4s, v16.4s, v20.4s + smin v16.4s, v16.4s, v21.4s + xtn v16.4h, v16.4s + + st1 {v16.4h}, [x1], #8 + add x4, x4, x7, lsl #2 + b.gt 1b + + ldp d8, d9, [sp] + ldp d10, d11, [sp, #0x10] + + add sp, sp, #0x20 + + ret endfunc diff --git a/libswscale/aarch64/swscale.c b/libswscale/aarch64/swscale.c index 171fb51329b..5d0887cfe51 100644 --- a/libswscale/aarch64/swscale.c +++ b/libswscale/aarch64/swscale.c @@ -22,6 +22,63 @@ #include "libswscale/swscale_internal.h" #include "libavutil/aarch64/cpu.h" +void ff_hscale16to15_4_neon_asm(int shift, int16_t *_dst, int dstW, + const uint8_t *_src, const int16_t *filter, + const int32_t *filterPos, int filterSize); +void ff_hscale16to15_X8_neon_asm(int shift, int16_t *_dst, int dstW, + const uint8_t *_src, const int16_t *filter, + const int32_t *filterPos, int filterSize); +void ff_hscale16to15_X4_neon_asm(int shift, int16_t *_dst, int dstW, + const uint8_t *_src, const int16_t *filter, + const int32_t *filterPos, int filterSize); + +static void ff_hscale16to15_4_neon(SwsContext *c, int16_t *_dst, int dstW, + const uint8_t *_src, const int16_t *filter, + const int32_t *filterPos, int filterSize) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + int sh = desc->comp[0].depth - 1; + + if (sh<15) { + sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); + } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ + sh = 16 - 1; + } + ff_hscale16to15_4_neon_asm(sh, _dst, dstW, _src, filter, filterPos, filterSize); + +} + +static void ff_hscale16to15_X8_neon(SwsContext *c, int16_t *_dst, int dstW, + const uint8_t *_src, const int16_t *filter, + const int32_t *filterPos, int filterSize) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + int sh = desc->comp[0].depth - 1; + + if (sh<15) { + sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); + } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ + sh = 16 - 1; + } + ff_hscale16to15_X8_neon_asm(sh, _dst, dstW, _src, filter, filterPos, filterSize); + +} + +static void ff_hscale16to15_X4_neon(SwsContext *c, int16_t *_dst, int dstW, + const uint8_t *_src, const int16_t *filter, + const int32_t *filterPos, int filterSize) +{ + const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(c->srcFormat); + int sh = desc->comp[0].depth - 1; + + if (sh<15) { + sh = isAnyRGB(c->srcFormat) || c->srcFormat==AV_PIX_FMT_PAL8 ? 13 : (desc->comp[0].depth - 1); + } else if (desc->flags & AV_PIX_FMT_FLAG_FLOAT) { /* float input are process like uint 16bpc */ + sh = 16 - 1; + } + ff_hscale16to15_X4_neon_asm(sh, _dst, dstW, _src, filter, filterPos, filterSize); +} + #define SCALE_FUNC(filter_n, from_bpc, to_bpc, opt) \ void ff_hscale ## from_bpc ## to ## to_bpc ## _ ## filter_n ## _ ## opt( \ SwsContext *c, int16_t *data, \ @@ -56,6 +113,10 @@ void ff_yuv2plane1_8_neon( } else \ hscalefn = \ ff_hscale8to19_ ## filtersize ## _ ## opt; \ + } else { \ + if (c->dstBpc <= 14) \ + hscalefn = \ + ff_hscale16to15_ ## filtersize ## _ ## opt; \ } \ } while (0) diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 367d045a024..ad0ddc07e0d 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -109,7 +109,6 @@ static void hScale16To15_c(SwsContext *c, int16_t *dst, int dstW, int j; int srcPos = filterPos[i]; int val = 0; - for (j = 0; j < filterSize; j++) { val += src[srcPos + j] * filter[filterSize * i + j]; }