Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the Zfa ISA extension #330

Merged
merged 4 commits into from
May 7, 2024

Conversation

cmuellner
Copy link
Contributor

@cmuellner cmuellner commented Apr 6, 2023

This patch introduces the RISC-V Zfa extension, which introduces additional floating-point extensions:

  • fli (load-immediate) with pre-defined immediates
  • fminm/fmaxm (like fmin/fmax but with different NaN behaviour)
  • fround/froundmx (round to integer)
  • fcvtmod.w.d (Modular Convert-to-Integer)
  • fmv* to access high bits of float register bigger than XLEN
  • Quiet comparison instructions (fleq/fltq)

Zfa defines its instructions in combination with the following extensions:

  • single-precision floating-point (F)
  • double-precision floating-point (D)
  • quad-precision floating-point (Q)
  • half-precision floating-point (Zfh)

Since the RISC-V architecture test framework does not support the RISC-V quad-precision floating-point ISA extension (Q) and the RISC-V half-precision floating-point ISA extension (Zfh), this patch does not include tests for instructions that depend on these extensions.

Given missing infrastructure support, the fli.* instruction tests are hand written and not generated.
All other test files are generated using riscv-ctg.

The generated test files have been generated using the following command (with $BASEISA={rv32i,rv64i}, $FLEN={32,64}), and CFG=$INSN:
riscv_ctg.py
--cgf sample_cgfs/dataset.cgf
--cgf sample_cgfs/zfa/$INSN.cfg
--base-isa $BASEISA
--flen $FLEN
-d tests_$BASEISA_$FLEN/

Exceptions are:

  • fcvtmod.w.d.cgf is for FLEN=64 only
  • fmvh.x.d and fmvp.d.x are for BASEISA=rv32i only

The resulting tests have been copied to the target directory.

The generation of the Zfa test cases depends on a PR in the riscv-ctg repository:
riscv-software-src/riscv-ctg#60

The Zfa specification is ratified and can be found here:
https://github.com/riscv/riscv-isa-manual/blob/main/src/zfa.adoc

Description

Provide a detailed description of the changes performed by the PR.

Related Issues

Please list all the issues related to this PR. Use NA if no issues exist

Ratified/Unratified Extensions

  • Ratified
  • Unratified

List Extensions

List the extensions that your PR affects. In case of unratified extensions, please provide a link to the spec draft that was referred to make this PR.

Reference Model Used

  • SAIL
  • Spike
  • Other - < SPECIFY HERE >

Mandatory Checklist:

  • All tests are compliant with the test-format spec present in this repo ?
  • Ran the new tests on RISCOF with SAIL/Spike as reference model successfully ?
  • Ran the new tests on RISCOF in coverage mode
  • Link to Google-Drive folder containing the new coverage reports (See this for more info): < SPECIFY HERE >
  • Link to PR in RISCV-ISAC from which the reports were generated : < SPECIFY HERE >
  • Changelog entry created with a minor patch

Optional Checklist:

  • RISCV-V CTG PR link if tests were generated using it : < SPECIFY HERE >
  • Were the tests hand-written/modified ?
  • Have you run these on any hard DUT model ? Please specify name and provide link if possible in the description
  • If you have modified arch_test.h Please provide a detailed description of the changes in the Description section above.

@charmitro
Copy link

Link for test results using RISCOF can be found here.

@pawks
Copy link
Collaborator

pawks commented Apr 10, 2023

This PR also lacks the coverage reports and the CGF files. Please include them in the drive folder.

@cmuellner
Copy link
Contributor Author

The CGF files are in the linked riscv-ctg PR.

The coverage report is blocked by #331.

@cmuellner
Copy link
Contributor Author

Updated the PR: fixed the rounding modes for fcvtmod.w.d, which must be rtz (all other modes are reserved).

@cmuellner
Copy link
Contributor Author

cmuellner commented May 23, 2023

Updated PR:

@jscheid-ventana
Copy link

Now that Zfa is ratified (https://wiki.riscv.org/display/HOME/Specification+Status#SpecificationStatus-Zfa_Row) what is next?

@davidharrishmc
Copy link
Contributor

davidharrishmc commented Jan 13, 2024

The fcvtmod tests need to replace dynamic with rtz. See the riscv-zfa spec at Section 264:

"The assembly syntax requires the RTZ rounding mode to be explicitly specified, i.e., fcvtmod.w.d rd, rs1, rtz"

Looks like this is mentioned above, but I don't see the rtz in the file.

@davidharrishmc
Copy link
Contributor

Also, note that one of the tests (in both rv32i_m and rv64i_m) produces a discrepancy between Sail and Spike.

ERROR | /home/harris/cvw/addins/riscv-arch-test/riscv-test-suite/rv32i_m/D_Zfa/src/fcvtmod.w.d_b22-01.S : - : Failed

I believe Sail is setting the wrong flag. I have submitted the issue to
riscv/sail-riscv#388

@davidharrishmc
Copy link
Contributor

davidharrishmc commented Jan 16, 2024

I don't see froundnx tests in the repository even though they are in the ctg.

@davidharrishmc
Copy link
Contributor

Why are there more fleq.s tests in D_Zfa/src/fleq_b1-01.S than in F_Zfa/src/fleq_b1-01.S? Why doesn't D_Zfa just add double-precision tests that aren't in F_Zfa?

@davidharrishmc
Copy link
Contributor

The patch documentation above says that fcvtmod.w.d is for FLEN=32 only. I think that is a typo and should say for FLEN=64 only.

@cmuellner
Copy link
Contributor Author

When attempting to regenerate the tests, I found riscv-ctg broken (triggering a code-path that always fires an exception). I've addressed this in riscv-software-src/riscv-ctg#102.

The fcvtmod tests need to replace dynamic with rtz. See the riscv-zfa spec at Section 264:

"The assembly syntax requires the RTZ rounding mode to be explicitly specified, i.e., fcvtmod.w.d rd, rs1, rtz"

Looks like this is mentioned above, but I don't see the rtz in the file.

fter looking into riscv-ctg, it becomes obvious why the 'dyn' rounding mode is still in this PR:
The Zfa riscv-ctg PR restricts the rounding modes as follows:

  rm_val_data: '[1]'

However, the field rm_val_data, which was expected to provide a mechanism to restrict the rounding mode, is completely ignored because the only referencing code has been removed in riscv-software-src/riscv-ctg@1d108e7.

So, this feature was dropped, and I can't see a replacement in CTG atm.

Also, note that one of the tests (in both rv32i_m and rv64i_m) produces a discrepancy between Sail and Spike.

ERROR | /home/harris/cvw/addins/riscv-arch-test/riscv-test-suite/rv32i_m/D_Zfa/src/fcvtmod.w.d_b22-01.S : - : Failed

I believe Sail is setting the wrong flag. I have submitted the issue to riscv/sail-riscv#388

Thanks for reporting!

I don't see froundnx tests in the repository even though they are in the ctg.

Thanks! This was caused by a typo in the CTG PR, which has been addressed.

Why are there more fleq.s tests in D_Zfa/src/fleq_b1-01.S than in F_Zfa/src/fleq_b1-01.S? Why doesn't D_Zfa just add double-precision tests that aren't in F_Zfa?

I don't see anything odd in the CTG PR so that it might be the intended behavior of CTG.

The patch documentation above says that fcvtmod.w.d is for FLEN=32 only. I think that is a typo and should say for FLEN=64 only.

Thanks! I've updated the description accordingly.

Thanks for reviewing the PR!
I've rebased and updated it as mentioned above.

@davidharrishmc
Copy link
Contributor

Thanks for looking into all of these. I'm trying to test CORE-V Wally Zfa and discovering things as I go.
rv32i_m/D_Zfa is missing fmvp.d.x tests.

The regular D tests are exclusive of the cases already covered by F tests. For example, rv32i_m/D contains fadd.d but not fadd.s. By the same reasoning, it would seem that rv32i_m/D_Zfa should contain fltq.d but not fltq. Similarly, I don't think it needs to have fleq, fmaxm, fminm, or fround.

@davidharrishmc
Copy link
Contributor

The CORE-V Wally team would love to try the remaining tests when possible. We're happy to help if there's something we can do.

@davidharrishmc
Copy link
Contributor

Is it easy to add the missing fmvp.d.x tests?

rv32i_m/D_Zfa/fmvp.d.x

@cmuellner
Copy link
Contributor Author

Is it easy to add the missing fmvp.d.x tests?

rv32i_m/D_Zfa/fmvp.d.x

I just checked and there are two issues why this test does not exist:

  1. There is a typo in the riscv-ctg PR (riscv_ctg/data/fd.yaml): s/fmvh.d.x/fmvp.d.x
  2. After fixing the typo the test generation fails, because riscv-isac can't handle that instruction

I have not analyzed this further so far.

@davidharrishmc
Copy link
Contributor

Something happened to fcvtmod.w.d when the tests were regenerated. The rounding modes were changed from rz to dyn. This is incorrect - the instruction should always use rz per the spec: "It is encoded like FCVT.W.D, but with the rs2 field set to 8 and the rm field set to 1 (RTZ). Other rm values are reserved."

Here is the May 22, 2023 version of fcvtmod.w.d_b22 using rz.

inst_0:// rs1==f31, rd==x31,fs1 == 0 and fe1 == 0x3fc and fm1 == 0x08577924770d3 and fcsr == 0x0 and rm_val == 7
/* opcode: fcvtmod.w.d ; op1:f31; dest:x31; op1val:0x3fc08577924770d3; valaddr_reg:x3;
val_offset:0FLEN/8; rmval:rtz; correctval:??; testreg:x2;
fcsr_val:0
/
TEST_FPID_OP(fcvtmod.w.d, x31, f31, rtz, 0, 0, x3, 0*FLEN/8, x4, x1, x2,FLREG)

The version currently in the PR has dyn instead of rz.

Could you regenerate the fcvtmod.w.d tests with rz?

@allenjbaum
Copy link
Collaborator

This is a bit weird. Presumably the test on this latest was run and passed, yet the instructions as defined should not have even assembled without errors; I didn't think the toolchain would allow it if the spec required rtz

This patch introduces the RISC-V Zfa extension, which introduces
additional floating-point extensions:
* fli (load-immediate) with pre-defined immediates
* fminm/fmaxm (like fmin/fmax but with different NaN behaviour)
* fround/froundmx (round to integer)
* fcvtmod.w.d (Modular Convert-to-Integer)
* fmv* to access high bits of float register bigger than XLEN
* Quiet comparison instructions (fleq/fltq)

Zfa defines its instructions in combination with the following
extensions:
* single-precision floating-point (F)
* double-precision floating-point (D)
* quad-precision floating-point (Q)
* half-precision floating-point (Zfh)

Since the RISC-V architecture test framework does not support
the RISC-V quad-precision floating-point ISA extension (Q) and
the RISC-V half-precision floating-point ISA extension (Zfh),
this patch does not include tests for instructions that depend
on these extensions.

Given missing infrastructure support, the fli.* instruction tests
are hand written and not generated.
All other test files are generated using riscv-ctg.

The generated test files have been generated using the following
command (with $BASEISA={rv32i,rv64i}, $FLEN={32,64}), and CFG=$INSN:
      riscv_ctg.py \
        --cgf sample_cgfs/dataset.cgf \
        --cgf sample_cgfs/zfa/$CGF \
        --base-isa $BASEISA \
        --flen $FLEN \
        -d tests_$BASEISA_$FLEN/

Exceptions are:
* fcvtmod.w.d.cgf is for FLEN=32 only
* fmvh.x.d and fmvp.d.x are for BASEISA=rv32i only

The resulting tests have been copied to the target directory.

The generation of the Zfa test cases depends on a PR in the riscv-ctg
repository:
  riscv-software-src/riscv-ctg#60

The Zfa specification is ratified and can be found here:
  https://github.com/riscv/riscv-isa-manual/blob/main/src/zfa.adoc

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
@cmuellner
Copy link
Contributor Author

Thanks for spotting the reintroduction of the rtz issue.
I've updated riscv-software-src/riscv-ctg#60 so that this won't happen again.

I've updated this PR with regenerated tests.

@allenjbaum
Copy link
Collaborator

allenjbaum commented Apr 2, 2024 via email

Signed-off-by: Allen Baum <31423142+allenjbaum@users.noreply.github.com>
@cmuellner
Copy link
Contributor Author

It's failing the C/I because of changelog issues. I don't know if that's because the version number wasn't updated, or because it was updated, but shouldn't have been though.

This PR shows: "Review required", "All checks have passed", "Merging is blocked".
So, the CI is OK with merging this PR.
But I prefer not to merge this unless riscv-software-src/riscv-ctg#60 is merged (this PR depends on the changes there).

@allenjbaum
Copy link
Collaborator

Ah, good, I was wondering about that. I won't pull any triggers until that is done.

@jamesbeyond
Copy link
Collaborator

@UmerShahidengr
Copy link
Collaborator

I have reviewed and merged riscv-software-src/riscv-ctg#60, so there are no dependecies left for this one. We can merge this one as well, since it has already been reviewed by many people.

Signed-off-by: Umer Shahid <umer.shahid@10xengineers.ai>
Added new entry in Changelog and resolved conflicts

Signed-off-by: Umer Shahid <umer.shahid@10xengineers.ai>
@UmerShahidengr
Copy link
Collaborator

I have resolved the conflicts by a forced commit.

@UmerShahidengr
Copy link
Collaborator

As its parallel riscv-ctg PR has been merged, so I am merging this one too.

@UmerShahidengr UmerShahidengr merged commit 67c5e71 into riscv-non-isa:main May 7, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants