From: Lynne via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Lynne <dev@lynne.ee>
Subject: Re: [FFmpeg-devel] [PATCH 4/4] lavu/riscv: use Zbb CLZ/CTZ/CLZW/CTZW at run-time
Date: Sat, 8 Jun 2024 20:01:08 +0200
Message-ID: <c3b1238c-54f3-4c27-aac6-7b41c8790ddc@lynne.ee> (raw)
In-Reply-To: <20240608113717.1677043-4-remi@remlab.net>
[-- Attachment #1.1.1.1: Type: text/plain, Size: 3782 bytes --]
On 08/06/2024 13:37, Rémi Denis-Courmont wrote:
> Zbb static Zbb dynamic I baseline
> clz 0.668032642 1.336072283 19.552376803
> clzl 0.668092643 1.336181786 26.110855571
> ctz 1.336208533 3.340209702 26.054869008
> ctzl 1.336247784 3.340362457 26.055266290
> (seconds for 1 billion iterations on a SiFive-U74 core)
> ---
> libavutil/riscv/intmath.h | 101 ++++++++++++++++++++++++++++++++++++++
> 1 file changed, 101 insertions(+)
>
> diff --git a/libavutil/riscv/intmath.h b/libavutil/riscv/intmath.h
> index 1f0afbc81d..3e7ab864c5 100644
> --- a/libavutil/riscv/intmath.h
> +++ b/libavutil/riscv/intmath.h
> @@ -73,6 +73,107 @@ static av_always_inline av_const int av_clip_intp2_rvi(int a, int p)
> }
>
> #if defined (__GNUC__) || defined (__clang__)
> +static inline av_const int ff_ctz_rv(int x)
> +{
> +#if HAVE_RV && !defined(__riscv_zbb)
> + if (!__builtin_constant_p(x) &&
> + __builtin_expect(ff_rv_zbb_support(), true)) {
> + int y;
> +
> + __asm__ (
> + ".option push\n"
> + ".option arch, +zbb\n"
> +#if __riscv_xlen >= 64
> + "ctzw %0, %1\n"
> +#else
> + "ctz %0, %1\n"
> +#endif
> + ".option pop" : "=r" (y) : "r" (x));
> + if (y > 32)
> + __builtin_unreachable();
> + return y;
> + }
> +#endif
> + return __builtin_ctz(x);
> +}
> +#define ff_ctz ff_ctz_rv
> +
> +static inline av_const int ff_ctzll_rv(long long x)
> +{
> +#if HAVE_RV && !defined(__riscv_zbb) && __riscv_xlen == 64
> + if (!__builtin_constant_p(x) &&
> + __builtin_expect(ff_rv_zbb_support(), true)) {
> + int y;
> +
> + __asm__ (
> + ".option push\n"
> + ".option arch, +zbb\n"
> + "ctz %0, %1\n"
> + ".option pop" : "=r" (y) : "r" (x));
> + if (y > 64)
> + __builtin_unreachable();
> + return y;
> + }
> +#endif
> + return __builtin_ctzll(x);
> +}
> +#define ff_ctzll ff_ctzll_rv
> +
> +static inline av_const int ff_clz_rv(int x)
> +{
> +#if HAVE_RV && !defined(__riscv_zbb)
> + if (!__builtin_constant_p(x) &&
> + __builtin_expect(ff_rv_zbb_support(), true)) {
> + int y;
> +
> + __asm__ (
> + ".option push\n"
> + ".option arch, +zbb\n"
> +#if __riscv_xlen >= 64
> + "clzw %0, %1\n"
> +#else
> + "clz %0, %1\n"
> +#endif
> + ".option pop" : "=r" (y) : "r" (x));
> + if (y > 32)
> + __builtin_unreachable();
> + return y;
> + }
> +#endif
> + return __builtin_clz(x);
> +}
> +#define ff_clz ff_clz_rv
> +
> +#if __riscv_xlen == 64
> +static inline av_const int ff_clzll_rv(long long x)
> +{
> +#if HAVE_RV && !defined(__riscv_zbb)
> + if (!__builtin_constant_p(x) &&
> + __builtin_expect(ff_rv_zbb_support(), true)) {
> + int y;
> +
> + __asm__ (
> + ".option push\n"
> + ".option arch, +zbb\n"
> + "clz %0, %1\n"
> + ".option pop" : "=r" (y) : "r" (x));
> + if (y > 64)
> + __builtin_unreachable();
> + return y;
> + }
> +#endif
> + return __builtin_clzll(x);
> +}
> +#define ff_clz ff_clz_rv
> +#endif
> +
> +static inline av_const int ff_log2_rv(unsigned int x)
> +{
> + return 31 - ff_clz_rv(x | 1);
> +}
> +#define ff_log2 ff_log2_rv
> +#define ff_log2_16bit ff_log2_rv
> +
> static inline av_const int av_popcount_rv(unsigned int x)
> {
> #if HAVE_RV && !defined(__riscv_zbb)
Could you add a ./configure flag or a check for enabling non-dynamic Zbb?
[-- Attachment #1.1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 637 bytes --]
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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".
next prev parent reply other threads:[~2024-06-08 18:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-08 11:37 [FFmpeg-devel] [PATCH 1/4] riscv: probe for Zbb extension at load time Rémi Denis-Courmont
2024-06-08 11:37 ` [FFmpeg-devel] [PATCH 2/4] lavu/riscv: use Zbb REV8 at run-time Rémi Denis-Courmont
2024-06-08 11:37 ` [FFmpeg-devel] [PATCH 3/4] lavu/riscv: use Zbb CPOP/CPOPW " Rémi Denis-Courmont
2024-06-08 11:37 ` [FFmpeg-devel] [PATCH 4/4] lavu/riscv: use Zbb CLZ/CTZ/CLZW/CTZW " Rémi Denis-Courmont
2024-06-08 18:01 ` Lynne via ffmpeg-devel [this message]
2024-06-08 18:17 ` Rémi Denis-Courmont
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c3b1238c-54f3-4c27-aac6-7b41c8790ddc@lynne.ee \
--to=ffmpeg-devel@ffmpeg.org \
--cc=dev@lynne.ee \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git