-
Notifications
You must be signed in to change notification settings - Fork 50
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
Parse Floating Point Constants #2195
Conversation
1c8e8c8
to
ce90f1d
Compare
}, | ||
"mem_write": { | ||
"data": [ | ||
4.2 |
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 the second thought is that it only proves that it reads/writes the same value, but doesn't prove that it's not necessarily intepretting 4.2
as the decimal representation..
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.
Can you explain what you mean by that? The comment is lacking enough context to make sense to me.
calyx-frontend/src/syntax.pest
Outdated
@@ -26,7 +27,8 @@ num_lit = ${ | |||
~ ( "d" ~ decimal | |||
| "b" ~ binary | |||
| "x" ~ hex | |||
| "o" ~ octal ) | |||
| "o" ~ octal | |||
| "f" ~ float) |
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.
One challenging thing about this is that we are hardcoding IEEE-754 encoding for floating point and might eventually want to support things like posits (something that @Mark1626 was working on) so we might want a different way to specify floating point numbers?
@sampsyo thoughts? One thing I was thinking is that the syntax is only available in a magical primitive:
cf1 = ieee754_const(5.11231); // Error if exact representation is not possible
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.
@jiahanxie353 What do you think about this approach? Instead of allowing floating point constants, we define a primitive ieee754_const
and only allow the parser to parse floating point values within as its parameters. In all other cases, we throw an error saying that floating point constants must be generated using this special cell.
This will require some trickery in the parser/well-formedness checker but hopefully not too complicated?
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.
@jiahanxie353 ping about this!
ce90f1d
to
269ec2c
Compare
Currently, it keeps saying: Error: tests/correctness/float/float-const.futil
13 | reg0.in = ieee754_const(32'f1.0);
| ^ Parse error
expected guard_eq, guard_neq, guard_leq, guard_geq, guard_lt, guard_gt, guard_or, or guard_and Any advice on how to fix the parsing? |
I'm not sure what is happening with the PR: the diff is too big for me to read the changes you've added. |
… decimal representation of real numbers
4dcea02
to
36cf6ba
Compare
Now it should cleaner! |
wires { | ||
group read { | ||
mem_read.addr0 = 1'b0; | ||
reg0.in = ieee754_const(1.00); |
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.
@sampsyo thoughts on this representation as opposed to the idea of only having a primitive called ieee754
and using its output port?
@jiahanxie353 your pattern for float is:
So how would the following thing match it:
|
@@ -16,17 +16,22 @@ binary = @{ ASCII_HEX_DIGIT+ } | |||
decimal = @{ ASCII_HEX_DIGIT+ } | |||
octal = @{ ASCII_HEX_DIGIT+ } | |||
hex = @{ ASCII_HEX_DIGIT+ } | |||
float = @{ ASCII_DIGIT+ ~ "." ~ ASCII_DIGIT+ } | |||
|
|||
ieee754_const = { "ieee754_const(" ~ float ~ ")" } |
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.
separate out iee754_const(
into "ieee754" ~ "("
Another note from a synchronous chat: IEEE754 requires information on the number of bits being used. |
This pull request has not seen activity in 14 days and is being marked as stale. If you're continuing work on this, please reply and state how to get this PR in a mergeable state or what issues it is blocked on. If the PR is not ready for review, please mark it as a draft. The PR will be closed in 7 days if there is no further activity. |
This is blocking #1928 |
This may become important for AMC soon too. What's the limiting factor here? It would also be nice to be able to support at least f16, f32, and f64. |
iirc @rachitnigam took it over after a synchronous meeting; but i can work on this if @rachitnigam is busy |
Right, I ended up being pretty busy so didn't have time to check up on this. |
@jiahanxie353 remind me what problem you were running into? |
I remember the main thing was about the format and the parsing:
|
Closing in favor of #2316. @jiahanxie353 once that is merged, can you make similar changes on the CIRCT side and make the rest of the flow work? |
Thanks @rachitnigam !
Sure, will do! |
This PR tries to address #2061
Support: