From: remi@remlab.net
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH 05/26] lavu/cpu: CPU flags for the RISC-V Vector extension
Date: Tue, 20 Sep 2022 17:39:52 +0300
Message-ID: <20220920144013.4959-5-remi@remlab.net> (raw)
In-Reply-To: <5602865.DvuYhMxLoT@basile.remlab.net>
From: Rémi Denis-Courmont <remi@remlab.net>
RVV defines a total of 12 different extensions, including:
- 5 different instruction subsets:
- Zve32x: 8-, 16- and 32-bit integers,
- Zve32f: Zve32x plus single precision floats,
- Zve64x: Zve32x plus 64-bit integers,
- Zve64f: Zve32f plus Zve64x,
- Zve64d: Zve64f plus double precision floats.
- 6 different vector lengths:
- Zvl32b (embedded only),
- Zvl64b (embedded only),
- Zvl128b,
- Zvl256b,
- Zvl512b,
- Zvl1024b,
- and the V extension proper: equivalent to Zve64f and Zvl128b.
In total, there are 6 different possible sets of supported instructions
(including the empty set), but for convenience we allocate one bit for
each type sets: up-to-32-bit ints (ZVE32X), floats (ZV32F),
64-bit ints (ZV64X) and doubles (ZVE64D).
Whence the vector size is needed, it can be retrieved by reading the
unprivileged read-only vlenb CSR. This should probably be a separate
helper macro if needed at a later point.
---
libavutil/cpu.c | 4 ++++
libavutil/cpu.h | 4 ++++
libavutil/riscv/cpu.c | 46 ++++++++++++++++++++++++++++++++++++++-
tests/checkasm/checkasm.c | 10 ++++++---
4 files changed, 60 insertions(+), 4 deletions(-)
diff --git a/libavutil/cpu.c b/libavutil/cpu.c
index 78e92a1bf6..58ae4858b4 100644
--- a/libavutil/cpu.c
+++ b/libavutil/cpu.c
@@ -187,6 +187,10 @@ int av_parse_cpu_caps(unsigned *flags, const char *s)
{ "rvi", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_RVI }, .unit = "flags" },
{ "rvf", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_RVF }, .unit = "flags" },
{ "rvd", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_RVD }, .unit = "flags" },
+ { "rvve32", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_RV_ZVE32X}, .unit = "flags" },
+ { "rvvf", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_RV_ZVE32F}, .unit = "flags" },
+ { "rvve64", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_RV_ZVE64X}, .unit = "flags" },
+ { "rvv", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AV_CPU_FLAG_RV_ZVE64D}, .unit = "flags" },
#endif
{ NULL },
};
diff --git a/libavutil/cpu.h b/libavutil/cpu.h
index 9aae2ccc7a..00698e30ef 100644
--- a/libavutil/cpu.h
+++ b/libavutil/cpu.h
@@ -82,6 +82,10 @@
#define AV_CPU_FLAG_RVI (1 << 0) ///< I (full GPR bank)
#define AV_CPU_FLAG_RVF (1 << 1) ///< F (single precision FP)
#define AV_CPU_FLAG_RVD (1 << 2) ///< D (double precision FP)
+#define AV_CPU_FLAG_RV_ZVE32X (1 << 3) ///< Vectors of 8/16/32-bit int's */
+#define AV_CPU_FLAG_RV_ZVE32F (1 << 4) ///< Vectors of float's */
+#define AV_CPU_FLAG_RV_ZVE64X (1 << 5) ///< Vectors of 64-bit int's */
+#define AV_CPU_FLAG_RV_ZVE64D (1 << 6) ///< Vectors of double's
/**
* Return the flags which specify extensions supported by the CPU.
diff --git a/libavutil/riscv/cpu.c b/libavutil/riscv/cpu.c
index fec1f7822a..6f862635b3 100644
--- a/libavutil/riscv/cpu.c
+++ b/libavutil/riscv/cpu.c
@@ -30,7 +30,32 @@
int ff_force_cpu_flags_riscv(int flags)
{
- if ((flags & AV_CPU_FLAG_RVD) && !(flags & AV_CPU_FLAG_RVF)) {
+ if ((flags & AV_CPU_FLAG_RV_ZVE64D) && !(flags & AV_CPU_FLAG_RV_ZVE64X)) {
+ av_log(NULL, AV_LOG_WARNING, "RV%s implied by specified flags\n",
+ "_ZVE64X");
+ flags |= AV_CPU_FLAG_RV_ZVE64X;
+ }
+
+ if ((flags & AV_CPU_FLAG_RV_ZVE64D) && !(flags & AV_CPU_FLAG_RV_ZVE32F)) {
+ av_log(NULL, AV_LOG_WARNING, "RV%s implied by specified flags\n",
+ "_ZVE32F");
+ flags |= AV_CPU_FLAG_RV_ZVE32F;
+ }
+
+ if ((flags & (AV_CPU_FLAG_RV_ZVE64X | AV_CPU_FLAG_RV_ZVE32F))
+ && !(flags & AV_CPU_FLAG_RV_ZVE32X)) {
+ av_log(NULL, AV_LOG_WARNING, "RV%s implied by specified flags\n",
+ "_ZVE32X");
+ flags |= AV_CPU_FLAG_RV_ZVE32X;
+ }
+
+ if ((flags & AV_CPU_FLAG_RV_ZVE64D) && !(flags & AV_CPU_FLAG_RVD)) {
+ av_log(NULL, AV_LOG_WARNING, "RV%s implied by specified flags\n", "D");
+ flags |= AV_CPU_FLAG_RVD;
+ }
+
+ if ((flags & (AV_CPU_FLAG_RVD | AV_CPU_FLAG_RV_ZVE32F))
+ && !(flags & AV_CPU_FLAG_RVF)) {
av_log(NULL, AV_LOG_WARNING, "RV%s implied by specified flags\n", "F");
flags |= AV_CPU_FLAG_RVF;
}
@@ -50,6 +75,11 @@ int ff_get_cpu_flags_riscv(void)
ret |= AV_CPU_FLAG_RVF;
if (hwcap & HWCAP_RV('D'))
ret |= AV_CPU_FLAG_RVD;
+
+ /* The V extension implies all Zve* functional subsets */
+ if (hwcap & HWCAP_RV('V'))
+ ret |= AV_CPU_FLAG_RV_ZVE32X | AV_CPU_FLAG_RV_ZVE64X
+ | AV_CPU_FLAG_RV_ZVE32F | AV_CPU_FLAG_RV_ZVE64D;
#endif
#ifdef __riscv_i
@@ -60,6 +90,20 @@ int ff_get_cpu_flags_riscv(void)
#if (__riscv_flen >= 64)
ret |= AV_CPU_FLAG_RVD;
#endif
+#endif
+
+ /* If RV-V is enabled statically at compile-time, check the details. */
+#ifdef __riscv_vectors
+ ret |= AV_CPU_FLAG_RV_ZVE32X;
+#if __riscv_v_elen >= 64
+ ret |= AV_CPU_FLAG_RV_ZVE64X;
+#endif
+#if __riscv_v_elen_fp >= 32
+ ret |= AV_CPU_FLAG_RV_ZVE32F;
+#if __riscv_v_elen_fp >= 64
+ ret |= AV_CPU_FLAG_RV_ZVE64F;
+#endif
+#endif
#endif
return ret;
diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c
index 7730b14d98..c4352f1a16 100644
--- a/tests/checkasm/checkasm.c
+++ b/tests/checkasm/checkasm.c
@@ -230,9 +230,13 @@ static const struct {
{ "VSX", "vsx", AV_CPU_FLAG_VSX },
{ "POWER8", "power8", AV_CPU_FLAG_POWER8 },
#elif ARCH_RISCV
- { "RVI", "rvi", AV_CPU_FLAG_RVI },
- { "RVF", "rvf", AV_CPU_FLAG_RVF },
- { "RVD", "rvd", AV_CPU_FLAG_RVD },
+ { "RVI", "rvi", AV_CPU_FLAG_RVI },
+ { "RVF", "rvf", AV_CPU_FLAG_RVF },
+ { "RVD", "rvd", AV_CPU_FLAG_RVD },
+ { "RV_Zve32x", "rv_zve32x", AV_CPU_FLAG_RV_ZVE32X },
+ { "RV_Zve32f", "rv_zve32f", AV_CPU_FLAG_RV_ZVE32F },
+ { "RV_Zve64x", "rv_zve64x", AV_CPU_FLAG_RV_ZVE64X },
+ { "RV_Zve64d", "rv_zve64d", AV_CPU_FLAG_RV_ZVE64D },
#elif ARCH_MIPS
{ "MMI", "mmi", AV_CPU_FLAG_MMI },
{ "MSA", "msa", AV_CPU_FLAG_MSA },
--
2.37.2
_______________________________________________
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:[~2022-09-20 14:42 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-20 14:39 [FFmpeg-devel] [PATCHv3 00/26] RISC-V CPU extensions Rémi Denis-Courmont
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 01/26] lavu/cpu: detect RISC-V base extensions remi
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 02/26] lavu/riscv: initial common header for assembler macros remi
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 03/26] lavc/audiodsp: RISC-V F vector_clipf remi
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 04/26] lavc/pixblockdsp: RISC-V I get_pixels remi
2022-09-20 14:39 ` remi [this message]
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 06/26] configure: probe RISC-V Vector extension remi
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 07/26] lavu/floatdsp: RISC-V V vector_fmul_scalar remi
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 08/26] lavu/floatdsp: RISC-V V vector_dmul_scalar remi
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 09/26] lavu/floatdsp: RISC-V V vector_fmul remi
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 10/26] lavu/floatdsp: RISC-V V vector_dmul remi
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 11/26] lavu/floatdsp: RISC-V V vector_fmac_scalar remi
2022-09-20 14:39 ` [FFmpeg-devel] [PATCH 12/26] lavu/floatdsp: RISC-V V vector_dmac_scalar remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 13/26] lavu/floatdsp: RISC-V V vector_fmul_add remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 14/26] lavu/floatdsp: RISC-V V butterflies_float remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 15/26] lavu/floatdsp: RISC-V V vector_fmul_reversed remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 16/26] lavu/floatdsp: RISC-V V vector_fmul_window remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 17/26] lavu/floatdsp: RISC-V V scalarproduct_float remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 18/26] lavu/fixeddsp: RISC-V V butterflies_fixed remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 19/26] lavc/audiodsp: RISC-V V vector_clip_int32 remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 20/26] lavc/audiodsp: RISC-V V vector_clipf remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 21/26] lavc/audiodsp: RISC-V V scalarproduct_int16 remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 22/26] lavc/fmtconvert: RISC-V V int32_to_float_fmul_scalar remi
2022-09-20 15:00 ` Andreas Rheinhardt
2022-09-20 15:12 ` Rémi Denis-Courmont
2022-09-21 14:14 ` [FFmpeg-devel] [PATCH 22 bis/26] " remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 23/26] lavc/fmtconvert: RISC-V V int32_to_float_fmul_array8 remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 24/26] lavc/vorbisdsp: RISC-V V inverse_coupling remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 25/26] lavc/aacpsdsp: RISC-V V add_squares remi
2022-09-20 14:40 ` [FFmpeg-devel] [PATCH 26/26] lavc/aacpsdsp: RISC-V V mul_pair_single remi
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=20220920144013.4959-5-remi@remlab.net \
--to=remi@remlab.net \
--cc=ffmpeg-devel@ffmpeg.org \
/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