Bug 504648 - Add support for RISC-V Zfh extension instructions
Summary: Add support for RISC-V Zfh extension instructions
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: vex (other bugs)
Version First Reported In: unspecified
Platform: Other Other
: NOR normal
Target Milestone: ---
Assignee: Mark Wielaard
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-05-22 06:12 UTC by JojoR
Modified: 2025-10-24 15:52 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
0001-riscv64-Add-zfh-extension-support-VEX-modifications.patch (10.26 KB, text/plain)
2025-05-22 06:18 UTC, JojoR
Details
0002-riscv64-Add-zfh-extension-support-test-modifications.patch (5.19 KB, text/plain)
2025-05-22 06:19 UTC, JojoR
Details
0003-riscv64-Add-zfh-extension-support-new-port-specific-.patch (65.28 KB, text/plain)
2025-05-22 06:20 UTC, JojoR
Details
0004-riscv64-Add-zfh-extension-support-new-port-specific-.patch (156.22 KB, text/plain)
2025-05-22 06:21 UTC, JojoR
Details
0005-riscv64-Add-zfh-extension-support-determine-hardware.patch (4.74 KB, text/plain)
2025-06-09 09:33 UTC, JojoR
Details
0004-riscv64-Add-zfh-extension-support-new-port-specific-.patch (158.33 KB, text/plain)
2025-07-02 06:54 UTC, JojoR
Details
0005-riscv64-Add-zfh-extension-support-determine-hardware.patch (6.31 KB, text/plain)
2025-07-02 06:56 UTC, JojoR
Details

Note You need to log in before you can comment on or make changes to this bug.
Description JojoR 2025-05-22 06:12:29 UTC
These patches support RISCV ISA float16.
ref: https://github.com/riscv/riscv-isa-manual/blob/main/src/zfh.adoc
Comment 1 JojoR 2025-05-22 06:18:48 UTC
Created attachment 181637 [details]
0001-riscv64-Add-zfh-extension-support-VEX-modifications.patch
Comment 2 JojoR 2025-05-22 06:19:53 UTC
Created attachment 181638 [details]
0002-riscv64-Add-zfh-extension-support-test-modifications.patch
Comment 3 JojoR 2025-05-22 06:20:28 UTC
Created attachment 181639 [details]
0003-riscv64-Add-zfh-extension-support-new-port-specific-.patch
Comment 4 JojoR 2025-05-22 06:21:19 UTC
Created attachment 181640 [details]
0004-riscv64-Add-zfh-extension-support-new-port-specific-.patch
Comment 5 Mark Wielaard 2025-05-22 12:18:05 UTC
We probably need a real implementation of riscv_hwprobe see https://bugs.kde.org/show_bug.cgi?id=503253
Are there other ways programs check the availability of riscv extensions?
Are there auxval settings for example?
Or do programs probe by just trying to execute some extension instruction?
Comment 6 JojoR 2025-05-27 06:12:45 UTC
(In reply to Mark Wielaard from comment #5)
> We probably need a real implementation of riscv_hwprobe see
> https://bugs.kde.org/show_bug.cgi?id=503253
> Are there other ways programs check the availability of riscv extensions?
> Are there auxval settings for example?
> Or do programs probe by just trying to execute some extension instruction?

This patch need to compile Valgrind with compiler's option "-march=xxx_zfh"
to enable Zfh extension by now, it does not smart to detect host CPU ISA features dynamically :)
Comment 7 JojoR 2025-06-09 09:33:26 UTC
Created attachment 182112 [details]
0005-riscv64-Add-zfh-extension-support-determine-hardware.patch
Comment 8 JojoR 2025-06-09 09:37:31 UTC
(In reply to Mark Wielaard from comment #5)
> We probably need a real implementation of riscv_hwprobe see
> https://bugs.kde.org/show_bug.cgi?id=503253
> Are there other ways programs check the availability of riscv extensions?
> Are there auxval settings for example?
> Or do programs probe by just trying to execute some extension instruction?

I make a patch for determining hardware capability 
by trying to execute extension instruction.

Please review these :)
Comment 9 Mark Wielaard 2025-06-25 21:47:10 UTC
(In reply to JojoR from comment #8)
> (In reply to Mark Wielaard from comment #5)
> > We probably need a real implementation of riscv_hwprobe see
> > https://bugs.kde.org/show_bug.cgi?id=503253
> > Are there other ways programs check the availability of riscv extensions?
> > Are there auxval settings for example?
> > Or do programs probe by just trying to execute some extension instruction?
> 
> I make a patch for determining hardware capability 
> by trying to execute extension instruction.
> 
> Please review these :)

[PATCH 5/5] riscv64: Add zfh extension support: determine hardware
 capability

Looks good. So now valgrind can detect if the hardware supports and we need to change the #ifdef __riscv_zfh checks in libvex with checks against having VEX_HWCAPS_RISCV_Zfh in hwcaps.

Then if a program uses the same kind of illegal instruction check this should work. But if the program uses the riscv_hwprobe syscall it won't. So we still need an implementation of https://bugs.kde.org/show_bug.cgi?id=503253

For the testcases you will have to add something like ./tests/x86_amd64_features.c so you can add it to the vgtests as e.g.
prereq: test -x float16 && ../../../tests/riscv64_features riscv64-Zfh

And you should really check for __riscv_zfh in a configure check, so that you only build the tests if the compiler knows about it.
Comment 10 JojoR 2025-07-02 06:54:59 UTC
Created attachment 182851 [details]
0004-riscv64-Add-zfh-extension-support-new-port-specific-.patch
Comment 11 JojoR 2025-07-02 06:56:17 UTC
Created attachment 182852 [details]
0005-riscv64-Add-zfh-extension-support-determine-hardware.patch
Comment 12 JojoR 2025-07-02 07:08:06 UTC
(In reply to Mark Wielaard from comment #9)
> (In reply to JojoR from comment #8)
> > (In reply to Mark Wielaard from comment #5)
> > > We probably need a real implementation of riscv_hwprobe see
> > > https://bugs.kde.org/show_bug.cgi?id=503253
> > > Are there other ways programs check the availability of riscv extensions?
> > > Are there auxval settings for example?
> > > Or do programs probe by just trying to execute some extension instruction?
> > 
> > I make a patch for determining hardware capability 
> > by trying to execute extension instruction.
> > 
> > Please review these :)
> 
> [PATCH 5/5] riscv64: Add zfh extension support: determine hardware
>  capability
> 
> Looks good. So now valgrind can detect if the hardware supports and we need
> to change the #ifdef __riscv_zfh checks in libvex with checks against having
> VEX_HWCAPS_RISCV_Zfh in hwcaps.
> 

Updated patch "0005-riscv64-Add-zfh-extension-support-determine-hardware.patch"
I will check Zfh feature before calling disassembler function "dis_RV64Zfh"

> Then if a program uses the same kind of illegal instruction check this
> should work. But if the program uses the riscv_hwprobe syscall it won't. So
> we still need an implementation of
> https://bugs.kde.org/show_bug.cgi?id=503253
> 

It looks like an independent feature ?
I will see that later.

> For the testcases you will have to add something like
> ./tests/x86_amd64_features.c so you can add it to the vgtests as e.g.
> prereq: test -x float16 && ../../../tests/riscv64_features riscv64-Zfh
> 
> And you should really check for __riscv_zfh in a configure check, so that
> you only build the tests if the compiler knows about it.

Updated patch "0004-riscv64-Add-zfh-extension-support-new-port-specific-.patch"
Like other arch, I add "prereq" condition in execution for Zfh feature.
Comment 13 JojoR 2025-07-21 02:23:44 UTC
@Mark

Any other suggestions for these patches ?
Comment 14 JojoR 2025-08-12 02:45:01 UTC
Any maintainer help to review or submit RISCV patches ?
Comment 15 JojoR 2025-09-29 06:37:04 UTC
hello ?
Comment 16 Mark Wielaard 2025-10-24 15:52:30 UTC
(In reply to JojoR from comment #15)
> hello ?

Hi! Sorry, I didn't forget. But I just ran out of time for the v3.26.0 release.