-
Notifications
You must be signed in to change notification settings - Fork 104
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: Introduce floating point api NAN #493
Conversation
* Introduce new float api nan/snan/qnan. * Introduce common for types and helper functions. * Introduce interface for all-in-one float api. * Add test framework for float api. * Add test cases for float nan api. Signed-off-by: Pan Li <[email protected]>
This reverts commit 44cb2d8.
* Introduce new float api nan/snan/qnan. * Introduce common for types and helper functions. * Introduce interface for all-in-one float api. * Add test framework for float api. * Add test cases for float nan api. Signed-off-by: Pan Li <[email protected]>
test/float/run_tests.py
Outdated
basename = os.path.splitext(os.path.basename(filename))[0] | ||
tests[filename] = os.fork() | ||
if tests[filename] == 0: | ||
step('{} {}/{} 2> {}.error'.format(sail, test_cases_dir, filename, basename)) |
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.
Hi @Alasdair
Could you please help to enlighten me the best practice to run the nan_test.sail
here when you are free?
Just work out a POC of the standalone float lib but would like to consult from expert like you for the right direction.
Thanks and CC @billmcspadden-riscv for awareness.
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.
Hi, I'll take a look next week. Please ping me again if I forget and don't get around to it.
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.
Sure thing and thanks a lot. It is not urgent, take your time.
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.
Kindly ping for this, take your time if you are in the middle of sth.
One thing I noticed - it seems like you have some cmi and cmo files accidentally checked in. |
Yeah, for the first commit, and I eliminated that from the newest commit. |
Signed-off-by: Pan Li <[email protected]>
lib/float/nan.sail
Outdated
val float_is_snan : fp_bits -> bool | ||
function float_is_snan (op) = { | ||
let struct {_, exp, mantissa} = float_decompose(op); | ||
let highest_bit = sizeof(mantissa) - 1; |
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 suggestion for get the size(bits) of mantissa here?
For now we will have the below error.
Type error:
/home/pli/repos/sail/sail-fork/lib/float/nan.sail:46.20-40:
46 | let highest_bit = sizeof(mantissa) - 1;
| ^------------------^
| No overloading for (operator -), tried:
| * sub_atom
| Cannot re-write sizeof(mantissa)
| * sub_int
| Cannot re-write sizeof(mantissa)
Meanwhile, 'mantissa
like let (_, exp, 'mantissa) = float_decompose(op);
won't work here too.
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.
Do you need sizeof at all 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.
Sorry not very familiar as green hand for sail, is there any alternatives?
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 think just let highest_bit = mantissa - 1;
?
sizeof
is used for converting a type back into a runtime value, which I'm not sure is needed 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.
If mantissa
indicates bits[22 .. 0] (take single as example) of floating-point, the let highest_bit = mantissa - 1
may not be the value 22
which is the highest bit index of mantissa?
For snan, we only need to check the highest bits 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.
Or one silly way is that we can have a helper function to return the highest bit of float, may similar to
function float_mantissa_bits (op) = {
match 'n {
16 => 10,
32 => 23,
64 => 52
}
}
It may works but not that perfect.
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.
Or one silly way is that we can have a helper function to return the highest bit of float, may similar to
function float_mantissa_bits (op) = { match 'n { 16 => 10, 32 => 23, 64 => 52 } }
It may works but not that perfect.
Tried this approach but meet another issue for vector bits access. Updated code for aligning the below error, not sure if I missed something.
47 | let tmp_1 = mantissa[highest_bit - 1];
| ^-----------------------^
| No overloading for vector_access, tried:
| * bitvector_access
| Could not resolve quantifiers for bitvector_access
| * (0 <= ('_#highest_bit - 1) & ('_#highest_bit - 1) < (if 'ex284# == 16 then 10 else (if 'ex284# == 32 then 23 else 52)))
| * plain_vector_access
| Could not unify vector('n, 'a) and bitvector((if 'ex284# == 16 then 10 else (if 'ex284# == 32 then 23 else 52)))
|
| Caused by /home/pli/repos/sail/sail-fork/lib/float/nan.sail:47.14-39:
| 47 | let tmp_1 = mantissa[highest_bit - 1];
| | ^-----------------------^
| | Vector access could not be interpreted as a bitfield access
Signed-off-by: Pan Li <[email protected]>
cc9ccee
to
a226c96
Compare
I had a look at your code, I think the following may be what you want:
I didn't end up using the mantissa_length function, so maybe we just don't need it as float_decompose is enough. The Sail library is a bit more bare-bones than what the RISC-V model has, so we use the |
Thanks a lot, let me have a try and update it. |
Signed-off-by: Pan Li <[email protected]>
Updated, I think |
Signed-off-by: Pan Li <[email protected]>
891c164
to
3632022
Compare
For the test script you could look at the one in |
Got it. Let me have a try for this. |
Signed-off-by: Pan Li <[email protected]>
Just have a try to convert the sail code to c for build and run. And there is one type check error similar to below, but it works well if I only let the n = 16 with the struct has fixed bitsize. Seems comes from the struct with if-then-else for its' fields length, will have another try for this...
|
The type level if-then-else is something I recently added, I think there's some awkward interaction between it and the code that produces a function to generate undefined values of some type. You should be able to do:
to make sure that doesn't happen for the time being. |
Cool, |
Signed-off-by: Pan Li <[email protected]>
Merged, thanks! I think the issue you ran into should be fixed by ededb75 |
Great, thanks a lot. Let me have a try and file another PR to remove the TODO and workaround. |
Signed-off-by: Pan Li [email protected]