From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <ffmpeg-devel-bounces@ffmpeg.org>
Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100])
	by master.gitmailbox.com (Postfix) with ESMTPS id D91104B524
	for <ffmpegdev@gitmailbox.com>; Fri, 25 Apr 2025 08:25:40 +0000 (UTC)
Received: from [127.0.1.1] (localhost [127.0.0.1])
	by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 410B6687DB9;
	Fri, 25 Apr 2025 11:25:36 +0300 (EEST)
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 09E58687C94
 for <ffmpeg-devel@ffmpeg.org>; Fri, 25 Apr 2025 11:25:29 +0300 (EEST)
Received: by mail-lf1-f45.google.com with SMTP id
 2adb3069b0e04-5499614d3d2so2037666e87.3
 for <ffmpeg-devel@ffmpeg.org>; Fri, 25 Apr 2025 01:25:29 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=martin-st.20230601.gappssmtp.com; s=20230601; t=1745569528; x=1746174328;
 darn=ffmpeg.org; 
 h=mime-version:references:message-id:in-reply-to:subject:cc:to:from
 :date:from:to:cc:subject:date:message-id:reply-to;
 bh=MlM/KdB54k0c5AS5/69PSCGHoCPmw3fL7tgs1Sbb3vI=;
 b=1L3Y4RW4lX4haQY3RhXrnKwBNAM2OKutmAGqmojNqeTsE1CCyNKhX69kgDLi8f8XHO
 x6NdBsclh06e8uTSL4QDCmJwBPGgg+mgz0RIhdZVi7DFwABVMcq22W5P2lek3wFBdT+P
 2b1jj+ENVSAY0eZiaix60KdcdYRd8AELgmNAs72GjJ3EnVIC2RJeFf4CiAq2vgdSddaL
 hcsLCC1ViVxLTH82Wj4eFEJgjM9MyEiDqBMyeX3BYyTFbspRH6OSjwttsTyQ1btb+kJz
 HqZXSzky/3rmQiMzL/0eNECpZikU076CQGr4RERM/CDypjTcEZlA14xCvr6lsBDDyOcF
 8gyw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1745569528; x=1746174328;
 h=mime-version:references:message-id:in-reply-to:subject:cc:to:from
 :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=MlM/KdB54k0c5AS5/69PSCGHoCPmw3fL7tgs1Sbb3vI=;
 b=J6bf0WmxFc3aUm/8s5pMobU71uZ9xz3g4KNV1CKnfqjlgGBtnvSBe0diGe91as009j
 XG33Hl3MLWFGjpFJt6np4Z+UkEabk91W4xUnMSTkUkbCfUuvqJVYgv1R/HArOaWbcr5s
 wq3vm0uniuGJykRciK5GJL9g5hLiKiR/EEMiz6zE5PvmBU6asqhmGhMGcJz3TOPD16lY
 yBBSBta6DSiClduIvSj7La6f0AP2+v+NQwJ02mO6NtuGsFc3fvFQ88bTpM+31QeZyAV0
 ufcekbOc5IxT7JQ1LaFcCc5Dj/WFKoHvzYtV4BaonBtgGoicTCEp3HgcCRCr9Jplwxto
 8f7A==
X-Gm-Message-State: AOJu0YyHkrpZd9epKAVzpzJ+4qAYUCgB3oayquHocXiLMh1aCMJ0upE1
 CaufJ+DKYBacF5GgVjOA12+FaqROLGMplIBSLuyfNjpfbafJ7hbgfDMUN0hLPLXc7ZgBjcg/NxS
 Zfw==
X-Gm-Gg: ASbGnctootBTB0pMPgOlki/aY6zkoYJxU1SzVOJETdsDDsSGr/c8xrOvvV9LDOD/yr8
 cKdfm5Kmz+P7cN2VO03KBqJ6d8MVA+yRncApUsWSTzuFacQQgRCvsWaGu38dhyhr5fMHZByLi7B
 iZlmsdNtIk4QbLA5oytQQQ0oAuV9KjZjBk+hyqSLZqMjoYYEjjt9BBm2c2nCXxIhJzpIRC333al
 zd/aey42vmU5rPMZfmFLhjfaI/9ptzaLVgjozc8Sys7x5St9txS/7EHl6+e1TS1wWWsa56XJJbg
 FXguQVdQutrZqLg8Li6m7MnNrXOzpa5WP51bQoxc4BRighYdggh1OjC38NZb0LNJyagcXV+gkLh
 1PaTudh++fqEx2uiMcfwe8FzHlRmzyaIOK1+z
X-Google-Smtp-Source: AGHT+IHzZ8NDH7wN9rw2cbPsY4JiGdNOMxFDaS8dQz0kqQxMmcLaNVYRyUnQm4vy1Zkj/PSS3mR47Q==
X-Received: by 2002:a05:6512:1321:b0:54d:67d7:c530 with SMTP id
 2adb3069b0e04-54e8cc10e76mr410508e87.56.1745569527906; 
 Fri, 25 Apr 2025 01:25:27 -0700 (PDT)
Received: from tunnel335574-pt.tunnel.tserv24.sto1.ipv6.he.net
 (tunnel335574-pt.tunnel.tserv24.sto1.ipv6.he.net. [2001:470:27:11::2])
 by smtp.gmail.com with ESMTPSA id
 2adb3069b0e04-54e7ccaa959sm520226e87.200.2025.04.25.01.25.27
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Fri, 25 Apr 2025 01:25:27 -0700 (PDT)
Date: Fri, 25 Apr 2025 11:25:25 +0300 (EEST)
From: =?ISO-8859-15?Q?Martin_Storsj=F6?= <martin@martin.st>
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
In-Reply-To: <tencent_B6A71838849627CD75A00E4DBC4FBA556B07@qq.com>
Message-ID: <c405429-f2b4-3764-4e-fdef3aa91795@martin.st>
References: <tencent_B6A71838849627CD75A00E4DBC4FBA556B07@qq.com>
MIME-Version: 1.0
Subject: Re: [FFmpeg-devel] [PATCH] aarch64/h26x: optimize sao_band_filter
X-BeenThere: ffmpeg-devel@ffmpeg.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: FFmpeg development discussions and patches <ffmpeg-devel.ffmpeg.org>
List-Unsubscribe: <https://ffmpeg.org/mailman/options/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=unsubscribe>
List-Archive: <https://ffmpeg.org/pipermail/ffmpeg-devel>
List-Post: <mailto:ffmpeg-devel@ffmpeg.org>
List-Help: <mailto:ffmpeg-devel-request@ffmpeg.org?subject=help>
List-Subscribe: <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>,
 <mailto:ffmpeg-devel-request@ffmpeg.org?subject=subscribe>
Reply-To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Zhao Zhili <zhilizhao@tencent.com>
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="us-ascii"; Format="flowed"
Errors-To: ffmpeg-devel-bounces@ffmpeg.org
Sender: "ffmpeg-devel" <ffmpeg-devel-bounces@ffmpeg.org>
Archived-At: <https://master.gitmailbox.com/ffmpegdev/c405429-f2b4-3764-4e-fdef3aa91795@martin.st/>
List-Archive: <https://master.gitmailbox.com/ffmpegdev/>
List-Post: <mailto:ffmpegdev@gitmailbox.com>

On Tue, 15 Apr 2025, Zhao Zhili wrote:

> From: Zhao Zhili <zhilizhao@tencent.com>
>
> int8_t[] is enough for offset_table of 8 bit streams.
>
> On rpi5:
>                             Before               After
> hevc_sao_band_8_8_c:          252.3 ( 1.00x)     252.3 ( 1.00x)
> hevc_sao_band_8_8_neon:        95.8 ( 2.63x)      61.0 ( 4.14x)
> hevc_sao_band_16_8_c:         875.2 ( 1.00x)     864.9 ( 1.00x)
> hevc_sao_band_16_8_neon:      317.5 ( 2.76x)     150.0 ( 5.76x)
> hevc_sao_band_32_8_c:        3853.5 ( 1.00x)    3871.6 ( 1.00x)
> hevc_sao_band_32_8_neon:     1222.3 ( 3.15x)     550.6 ( 7.03x)
> hevc_sao_band_48_8_c:        8203.6 ( 1.00x)    8182.6 ( 1.00x)
> hevc_sao_band_48_8_neon:     2685.7 ( 3.05x)    1185.8 ( 6.90x)
> hevc_sao_band_64_8_c:       14023.0 ( 1.00x)   14038.9 ( 1.00x)
> hevc_sao_band_64_8_neon:     4783.2 ( 2.93x)    2078.4 ( 6.75x)
> ---
> libavcodec/aarch64/h26x/dsp.h             |  4 +
> libavcodec/aarch64/h26x/sao_neon.S        | 93 ++++++++++++++---------
> libavcodec/aarch64/hevcdsp_init_aarch64.c |  4 +-
> libavcodec/aarch64/vvc/dsp_init.c         |  5 +-
> 4 files changed, 65 insertions(+), 41 deletions(-)
>
> diff --git a/libavcodec/aarch64/h26x/dsp.h b/libavcodec/aarch64/h26x/dsp.h
> index 0fefb4d70f..6ea6a8d36a 100644
> --- a/libavcodec/aarch64/h26x/dsp.h
> +++ b/libavcodec/aarch64/h26x/dsp.h
> @@ -28,6 +28,10 @@ void ff_h26x_sao_band_filter_8x8_8_neon(uint8_t *_dst, const uint8_t *_src,
>                                         ptrdiff_t stride_dst, ptrdiff_t stride_src,
>                                         const int16_t *sao_offset_val, int sao_left_class,
>                                         int width, int height);
> +void ff_h26x_sao_band_filter_16x16_8_neon(uint8_t *_dst, const uint8_t *_src,
> +                                        ptrdiff_t stride_dst, ptrdiff_t stride_src,
> +                                        const int16_t *sao_offset_val, int sao_left_class,
> +                                        int width, int height);
> void ff_hevc_sao_edge_filter_16x16_8_neon(uint8_t *dst, const uint8_t *src, ptrdiff_t stride_dst,
>                                           const int16_t *sao_offset_val, int eo, int width, int height);
> void ff_hevc_sao_edge_filter_8x8_8_neon(uint8_t *dst, const uint8_t *src, ptrdiff_t stride_dst,
> diff --git a/libavcodec/aarch64/h26x/sao_neon.S b/libavcodec/aarch64/h26x/sao_neon.S
> index c43820135e..60c026fe95 100644
> --- a/libavcodec/aarch64/h26x/sao_neon.S
> +++ b/libavcodec/aarch64/h26x/sao_neon.S
> @@ -35,48 +35,67 @@
> //                      int16_t *sao_offset_val, int sao_left_class,
> //                      int width, int height)
> function ff_h26x_sao_band_filter_8x8_8_neon, export=1
> -        stp             xzr, xzr, [sp, #-64]!
> +        stp             xzr, xzr, [sp, #-32]!
>         stp             xzr, xzr, [sp, #16]
> -        stp             xzr, xzr, [sp, #32]
> -        stp             xzr, xzr, [sp, #48]
>         mov             w8,  #4
> -0:      ldrsh           x9, [x4,  x8, lsl #1]      // sao_offset_val[k+1]
> -        subs            w8,  w8,  #1
> -        add             w10, w8,  w5               // k + sao_left_class
> +0:
> +        ldrsh           x9, [x4, x8, lsl #1]        // sao_offset_val[k+1]
> +        subs            w8, w8, #1
> +        add             w10, w8, w5                 // k + sao_left_class
>         and             w10, w10, #0x1F
> -        strh            w9, [sp, x10, lsl #1]
> +        strb            w9, [sp, x10]
>         bne             0b
> -        add             w6,  w6,  #7
> -        bic             w6,  w6,  #7
> -        ld1             {v16.16b-v19.16b}, [sp], #64
> -        sub             x2,  x2,  x6
> -        sub             x3,  x3,  x6
> -        movi            v20.8h,   #1
> -1:      mov             w8,  w6                    // beginning of line
> -2:      // Simple layout for accessing 16bit values
> -        // with 8bit LUT.
> -        //
> -        //   00  01  02  03  04  05  06  07
> -        // +----------------------------------->
> -        // |xDE#xAD|xCA#xFE|xBE#xEF|xFE#xED|....
> -        // +----------------------------------->
> -        //    i-0     i-1     i-2     i-3
> -        ld1             {v2.8b}, [x1], #8          // dst[x] = av_clip_pixel(src[x] + offset_table[src[x] >> shift]);
> -        subs            w8, w8,  #8
> -        uxtl            v0.8h,  v2.8b              // load src[x]
> -        ushr            v2.8h,  v0.8h, #3          // >> BIT_DEPTH - 3
> -        shl             v1.8h,  v2.8h, #1          // low (x2, accessing short)
> -        add             v3.8h,  v1.8h, v20.8h      // +1 access upper short
> -        sli             v1.8h,  v3.8h, #8          // shift insert index to upper byte
> -        tbx             v2.16b, {v16.16b-v19.16b}, v1.16b // table
> -        add             v1.8h,  v0.8h, v2.8h       // src[x] + table
> -        sqxtun          v4.8b,  v1.8h              // clip + narrow
> -        st1             {v4.8b}, [x0], #8          // store
> -        // done 8 pixels
> +        ldp             q16, q17, [sp], #32
> +1:
> +        ld1             {v2.8b}, [x1], x3
> +        subs            w7, w7, #1
> +        uxtl            v0.8h, v2.8b
> +        ushr            v3.8b, v2.8b, #3          // >> BIT_DEPTH - 3

Nitpick: The comment on this line seems to be misaligned with the other 
comments below - please check.

> +        tbx             v3.8b, {v16.16b-v17.16b}, v3.8b

Is there any specific reason for preferring tbx over tbl here? (I know the 
existing code used tbx.) Without having studied cycle tables, I would 
expect tbl to maybe be slightly simpler, but perhaps there's no difference 
(or tbx is faster)?


Other than these comments, this patch looks good to me, thanks - feel free 
to push.

// Martin

_______________________________________________
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".