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 Zfh extension #129

Merged
merged 1 commit into from
Jan 19, 2022
Merged

Conversation

bilalsakhawat
Copy link
Contributor

“Zfh” Standard Extensions for Half-Precision Floating-Point, Version 0.1

Chapter 15 in the draft spec.

FCVT.Q.H and FCVT.H.Q are not implemented. (Quad-Precision is not supported by sail yet)

Copy link
Collaborator

@martinberger martinberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you commit prover snapshots? They are auto-generated.

@PeterSewell
Copy link
Collaborator

PeterSewell commented Nov 20, 2021 via email

@scottj97
Copy link
Contributor

Why do you commit prover snapshots? They are auto-generated.

They already existed in the repo, so he's just keeping them up to date, which is better than letting them fall behind.

Are you recommending these be deleted from the repo?

@martinberger
Copy link
Collaborator

martinberger commented Nov 20, 2021

it's often handy, e.g. so people can see the prover definitions directly

@PeterSewell Yes, but then we need to make sure the generated prover definitions stay up-to-date with the sail model. For example generating prover snapshots in not in the GH Actions CI. So I'm wondering if they are even up-to-date.

@scottj97 If they get auto-generated by the CI, we can delete them.

@martinberger
Copy link
Collaborator

@PeterSewell How much work do you think it would be to script the building of all the prover snapshot with GitHub Actions, so we can remove the word "not" from https://github.com/riscv/sail-riscv/blob/master/prover_snapshots/README.md ? I imagine there was a reason why the current build process does not automate this.

Copy link
Collaborator

@jrtc27 jrtc27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately with the recent landing of Zfinx you picked a bad time to submit this pull request, and will need to rebase on top of that and apply the same changes to the new Zfh code. I think it should be relatively straightforward, if tedious. The only thing noteworthy that comes to mind is nan_(un)box should probably be made overloaded calling _S and _H versions (with the _S version being what is currently there) rather than having nan_(un)box and nan_(un)box_H as is done here.

Glancing at the implementation I'm reminded of how non-conforming the F/D code is (blame Bluespec's internal code style for that, which I suspect is derived from treating everything like it's Haskell), but I agree with your choice here to copy the F/D code style (I assume you just copied F and swept through converting all the F-specificity to Zfh-specificity) rather than reformat it for Zfh and increase the divergence between them.

@@ -112,6 +113,35 @@ function update_softfloat_fflags(flags) = {
/* **************************************************************** */
/* ADD/SUB/MUL/DIV */


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray extra line

@@ -389,6 +418,13 @@ function process_fload32(rd, addr, value) =
MemException(e) => { handle_mem_exception(addr, e); RETIRE_FAIL }
}

val process_fload16 : (regidx, xlenbits, MemoryOpResult(bits(16)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really the functions should be the other way round, but that's not your problem, so this is the right thing to do in the situation

@@ -0,0 +1,916 @@

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably have the copyright header from fext given this is heavily derived from it, as well as an equivalent to:

/* **************************************************************** */
/* This file specifies the instructions in the F extension          */
/* (single precision floating point).                               */

/* RISC-V follows IEEE 754-2008 floating point arithmetic standard. */

/* Original version written by Rishiyur S. Nikhil, Sept-Oct 2019    */

/* **************************************************************** */
/* IMPORTANT!                                                       */
/* The files 'riscv_insts_fext.sail' and 'riscv_insts_dext.sail'    */
/* define the F and D extensions, respectively.                     */
/* The texts follow each other very closely; please try to maintain */
/* this correspondence as the files are maintained for bug-fixes,   */
/* improvements, and version updates.                               */

/* **************************************************************** */

That should probably also be updated across all three to reference Zfh

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Normally wouldn't mandate that block of documentation but F and D, and now Zfh, are a bit special in how they're implemented and we want to ensure they stay as similar as possible)

@bilalsakhawat
Copy link
Contributor Author

@jrtc27 I refactor the code for Zfh Extension. I think, modifications from Zfh to ZFinx_Zfh should be in a separate Pull Request. If you agree, I just need to add copyright header in the model/riscv_insts_zfh.sail and this PR is good to go.

@jrtc27
Copy link
Collaborator

jrtc27 commented Dec 5, 2021

Deferring Zhinx seems ok to me, it's true that requesting it is moving the goalposts for this PR. Had you been slightly later and copied the F or D file with Z[fd]inx support then you would've been 95% of the way there already for free, but alas that's not what happened and so instead it's a bunch of work to repeat all the changes to the Zfh code.

I quickly skimmed the PR and noticed that the stray line comment from 8 days ago also still applies. I also found the "RV64 only" comment for the L[U] conversions mentions F not Zfh.

I'll try and take a more thorough look tomorrow.

@martinberger
Copy link
Collaborator

I'll try and take a more thorough look tomorrow.

@jrtc27 Did you manage to take a look?

-> Retired effect {escape, rreg, wreg}
function process_fload16(rd, addr, value) =
match value {
MemValue(result) => { F(rd) = nan_box_H(result); RETIRE_SUCCESS },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be nan_box, same as process_fload32

FDIV_H => riscv_f16Div (rm_3b, rs1_val_16b, rs2_val_16b)
};
write_fflags(fflags);
F(rd) = nan_box_H (rd_val_16b);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can all be nan_box, for consistency with F (that or those should be changed to nan_box_S, but I don't see the benefit from that, might as well make use of the language's overloading to make the code a bit cleaner to read), though given they'll all need changing in future to F_or_X_H(rd) = ... with the NaN boxing implicit I guess this is fine, unlike the one for FP_LOAD which will stay and thus should be fixed (though arguably pushing that into a new F_H/S/D might make things slightly cleaner and more consistent, as a future minor refactor).

/* Execution semantics ================================ */

function clause execute (F_BIN_RM_TYPE_H(rs2, rs1, rm, rd, op)) = {
let rs1_val_16b = nan_unbox_H (F(rs1));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will all need to use (a new) F_or_X_H but I guess it's fine to express it this way for now

@jrtc27
Copy link
Collaborator

jrtc27 commented Jan 18, 2022

I'll try and take a more thorough look tomorrow.

@jrtc27 Did you manage to take a look?

I did not but have now. One minor comment, the rest observations. The commits should also be squashed down into a single commit rather than the 3 there are now (or 4 that it may become).

@bilalsakhawat
Copy link
Contributor Author

bilalsakhawat commented Jan 19, 2022

@jrtc27 I have incorporated the changes suggested by you.

Copy link
Collaborator

@jrtc27 jrtc27 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is now ready

Copy link
Collaborator

@martinberger martinberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me.

@martinberger martinberger merged commit 612958b into riscv:master Jan 19, 2022
@martinberger
Copy link
Collaborator

Merged.

Thanks @bilalsakhawat-10xe @jrtc27

bilalsakhawat added a commit to bilalsakhawat/sail-riscv that referenced this pull request Jan 20, 2022
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.

5 participants