-
Notifications
You must be signed in to change notification settings - Fork 167
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
Float: Add floating-point equals API in sail model #403
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to avoid the global variables for the new functions and just return the result directly (might need something like #340 to be merged first)?
Thanks for the comments. I think at least we can return the float result directly in For #340 , I am afraid we may not need this anymore if the softfloat migrates to sail. The sofefloat in c_emulator will be depreciated soon as I understand. Feel free to correct me if any misleading. |
This patch would like to introduce the soft floating-point equals API into the sail model. Then the softfloat_interface is able to leverage the new softfloat in sail, instead of the c_emulator. * Add softfloat common for softfloat enter and leave. * Add enum like immutable exception flags. * Add softfloat equals API for half, single and double floating-point. * Replace the extern call of softfloat interface to sail model. * Add helper functions to utils. * Adjust build system for new files. Signed-off-by: Pan Li <pan2.li@intel.com>
3f2f277
to
2923e21
Compare
I think that was an aspirational hope rather than someone actually saying "I will do this". It would be great though! I need to take another look at #340. IIRC it failed because of the OCaml emulator (which we don't use) and I don't know OCaml... Probably shouldn't block this anyway. |
Thanks for the comments. Lots of useful items, especially for the green hands to sail like me. I will address it soon. |
Signed-off-by: Pan Li <pan2.li@intel.com>
Please avoid creating 16/32/64 copies of every function. You should in general be able to write one polymorphic function that handles all sizes. |
Signed-off-by: Pan Li <pan2.li@intel.com>
Thanks all, addressed comments with all fp tests passed. |
This is much better, though I think you could go even further. There's not really much point to the You could just delete them, and then change the code that uses them to call your new functions instead. Note that there's already this function in the vector extension:
I would:
And then change all the code that used Hope that makes sense! Thanks for the contribution btw! |
Thanks for comments. I see, looks you would like to suggest get rid of softfloat_interface.sail up to a point. I plan to do that later and make this change simple enough for review. But as you mentioned already, I will add that part to this PR. |
Signed-off-by: Pan Li <pan2.li@intel.com>
Updated with |
Signed-off-by: Pan Li <pan2.li@intel.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM just some minor nits left
Signed-off-by: Pan Li <pan2.li@intel.com>
Thanks a lot for comments. Addressed all except the |
Ah yeah sometimes the type inference doesn't work entirely intuitively... All LGTM anyway! |
Thanks. Looks like I have no authority to merge, will continue the rest part of softfloat following the pattern of this PR. |
Yeah currently @billmcspadden-riscv is chief merger, but he is ill at the moment. Also I finally figured out why I can't resolve my conversations:
That seems bonkers - surely the person who started a conversation should be able to resolve it? I guess it explains it at least! Anyway since you opened the PR you should be able to resolve all my conversations. |
Yes, I’m in hospital right now and have limited ability to do much work.
Martin Burger can also do a merge as well.
The question for the team is: do we want to do small, incremental merges
for this project, or do we want to put this on a feature branch (with a
full merge once all the work is done) like what we did for Vector last
year? I think we should just go ahead and do the small incremental merges
on main. Thots?
Bill McSpadden
Formal Verification Engineer
RISC-V International
mobile: 503-807-9309
…On Tue, Feb 13, 2024 at 6:04 AM Tim Hutt ***@***.***> wrote:
Yeah currently @billmcspadden-riscv
<https://github.com/billmcspadden-riscv> is chief merger, but he is ill
at the moment.
Also I finally figured out why I can't resolve my conversations:
You can resolve a conversation in a pull request if you opened the pull
request or if you have write access to the repository where the pull
request was opened.
That seems bonkers - surely the person who started a conversation should
be able to resolve it? I guess it explains it at least! Anyway since you
opened the PR you should be able to resolve all my conversations.
—
Reply to this email directly, view it on GitHub
<#403 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXROLOCJPW74P7MSTYEVNCTYTNJGPAVCNFSM6AAAAABC5HFXZCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBRGM3DQMBQG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
@Timmmm @billmcspadden-riscv |
Yeah I agree - this is a change that can easily be done piecemeal so we should do so. @Incarnation-p-lee probably a good idea to squash your commits. |
Cannot agree anymore, take squash merger here and we will see only one commit from the main branch. That would be much clear. |
model/riscv_softfloat_interface.sail
Outdated
/* Internal registers to pass results across the softfloat interface */ | ||
/* to avoid return types involving structures. */ | ||
/* */ | ||
/* Todo: Return the float_result directly in Sail. */ | ||
/* ***************************************************************** */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you should be touching this? Your new code doesn't have this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just hint here to remind that, the float in saill will return directly, as well as the softfloat_interface will be retired soon.
I can revert this change if you have any concern here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted this change.
@@ -26,7 +26,6 @@ | |||
/* All arguments and results have one of these types */ | |||
|
|||
type bits_rm = bits(3) /* Rounding mode */ | |||
type bits_fflags = bits(5) /* Accrued exceptions: NV,DZ,OF,UF,NX */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't see how this builds if you delete the type used by the unconverted functions...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see, you moved that but nothing else to a new file. That seems like a strange design choice; I would expect fflags and frm to be defined next to each other given they both constitute fcsr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type moved to the riscv_float_common.sail
, which will be leveraged by the floating-point implementation (like float_eq) in sail.
Given the softfloat_interface will be retired soon, it is better to let the softfloat_interface
depends on riscv_float_common.sail
. Of course, you are right, the related types like frm/fflags will be removed to the riscv_float_common.sail
soon. I didn't perform this change because they are not referenced by the float_eq.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, please help to review when you free.
Also: projects like GCC are very different to something like sail-riscv. Many of the people reviewing patches on the GCC mailing list are full-time employees paid by their organisation to do that, or at least a large part of their job. That is not the case here; it is nobody's full-time job, for many it's just a small part of their job, and many are also volunteers. So please consider that before having high expectations of how quickly people will reply to you. And of course the more time spent discussing things like this, the less time spent doing actually useful work... |
Take it easy, I think our goal is the same for the the best reasonable outcome.
I agree with you on this point as I said in comments, I am totally Ok for making changes.
I think the point is not about the 48 hours or not. I think it is important to make things clear and an efficient way to communicate. You can just reply first comment similar to "Yes, please revert this change", and the second one similar to "Yes, please move all related types to the new file.", instead of saying outstanding, and shrugged off. I think that should be more clear here. Agree there is no place to get someone to win, just to make it clear to both of us. |
Understood the timing you mentioned, sorry I didn't get any information from this repo about it. I think we are on the same page now. I will make the changes as your comments soon. |
Signed-off-by: Pan Li <pan2.li@intel.com>
I think @jrtc27's response was very measured. This repo is quite slow moving - partly because we don't have very good testing yet - so you have to be quite patient! Can be a little frustrating at times but there you go. I think the situation will improve eventually. Anyway back to the engineering... I had another idea about testing this. Since Sail can generate SMT2, and the CVC5 SMT solver understands IEEE float, we can in theory formally prove the Sail implementation (modulo bugs in CVC5 but I guess their implementation must be pretty well tested right?). I had a go at this. Here's the 64-bit float equals extracted into a standalone file:
If you now do this:
It will compile it to SMT2 and run it through CVC4. Of course in this case it is able to generate a counterexample because
I.e. it found We can run
The generated SMT2 looks like this:
With a lot of squinting you can find the
It doesn't quite work because it doesn't know about
And tada!
I double checked by introducing a bug:
Then
This seems like it will be a really easy method, except that it's very tedious to edit the SMT2. We probably want some support from the Sail compiler. Maybe a way to export functions as SMT2 functions? Like this:
Another downside is that it can't verify raising flags as far as I can see. @Alasdair fyi. @Incarnation-p-lee if you implement a more complex function (maybe division?) I can try to prove it like this. |
Thanks @Timmmm for the explain. Got you point here and I believe we can have a test framework for the sail code eventually.
Not sure my understanding is correct but can we perform both the float point migration work and a test framework for sail code? I think they should be independent in most cases, as well as we need this for the complex (strictly for simple API like equal too) cases. From the materials you shared, it looks like we need some time to work out a test framework but I would like to have a try for your proposal(Sorry I have no idea about SMT2, and CVC2, so no suggestion from myside, :)). I notice you have shared more extensive tests (I bet it is well designed for float). I wonder if we can port these test cases to sail and find a place to run/execute them. Because the test files can be considered as(or easily convert to) another sort of API(s). They should be visible for any other sail code. However I am not familiar with the sail compiler, just brainstorm here. |
I mean we can test the Sail implementations of floating point by formally verifying them against the SMTLIB2 implementation.
Yeah... though I'm not sure you need a whole framework. I think if Sail supported
Yeah definitely. Shouldn't be too hard; you just need to make them write to the HTIF interface that Sail uses (it's very simple) for UART and exit status and then cross-compile to RISC-V. |
Actually I had a sudden thought... turns out Sail already supports declaring extern
Then you only need to modify the top of the output file to
So actually all we need is to change the |
Ok I hacked up a patch to the Sail compiler to switch to CVC5, update the Sail property:
Then
I'll send @Alasdair the patch at some point. Better do some real work now... |
That would be great! I think it is good enough to port the test to sail and add a new target to run (includes CI/CD). I will have a try once the sail compiler is ready. Thanks a lot for this. |
Hi @Timmmm I have a try to make COVERAGE=1 for the c code line coverage (I suppose it cannot cover the sail code) but meet below issue when
Could you please help to insight me is there anything/step(s) missing here? |
It's coverage of the Sail code that it's measuring, there's a small library here that it links into the generated binary and measures the coverage. It's available here: https://github.com/rems-project/sail/tree/sail2/lib/coverage |
Thanks, let me have a try. |
Just have a try for the sail model coverage by Given that, shall we move forward for simple API porting like compare, or wait for the softfloat testsuite with the upgraded sail compiler? Both approaches are LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw a couple of minor simplifications I noticed. The old code wasn't wrong - just could be simplified a bit.
model/float/riscv_float_eq.sail
Outdated
function float_eq (op1, op2) = { | ||
let is_nan = f_is_NaN(op1) | f_is_NaN(op2); | ||
let is_snan = f_is_SNaN(op1) | f_is_SNaN(op2); | ||
let fflags = if is_nan & is_snan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is_nan &
can be removed here because is_snan
is a subset of is_nan
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
model/float/riscv_float_eq.sail
Outdated
let fflags = if is_nan & is_snan | ||
then float_flag_invalid | ||
else zeros(); | ||
let is_equal : bool = if not(is_nan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to the following:
let is_equal = not(is_nan) & (op1 == op2 | ((op1 | op2) << 1) == zeros());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated and removed the bool declaration.
Thanks Tim, that make sense to me. Let me update it. BTW, the float will be promoted to a standalone lib (as well as its test suite) in sail, thus I suppose we don't need this anymore. |
Signed-off-by: Pan Li <pan2.li@intel.com>
Thanks! This LGTM and I think we could land it, but if you intend to make it into a separate library I guess that's fine too. A library sounds like a good idea to me. |
Thanks @Timmmm for the review and help, learned a lot from the expert like you! Shall we keep this open until we integrate this repo with the new float standalone lib? Or just close it. Both are Ok to me. |
Yeah lets leave it open in case the standalone lib doesn't happen for some reason. |
Seems like the float lib in the Sail compiler is going extremely well so I'll close this. Hope that's ok @Incarnation-p-lee! |
That is all right, thanks @Timmmm for following up. |
This patch would like to introduce the floating-point equals API into the sail model. Then floating-point equals will be invoked in sail instead of the c_emulator.
./test/run_tests.sh
.