-
Notifications
You must be signed in to change notification settings - Fork 276
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
[FIRRTL] (div) A/A mismatch #363
Comments
I think we're generating the correct code here. The only case I can imagine a mismatch is when the divisor is zero, which is UB. Do you see a problem with the generated verilog? |
I think this is a good question for the broader discussion https://twitter.com/wavedrom/status/1342932252531945472 |
Related FIRRTL discussion chipsalliance/firrtl#2029 |
@drom: One thing I should have mentioned to you is to also check without optimizations enabled. If you run with We should strive for formal equivalence with the unoptimized code and be very careful about deviating there. If we deviate due to optimizations, I think that's fine as long as we understand why. However, I'd expect that we'd implement this same optimization at some point in the RTL dialect. About the optimization... This optimization looks legal. I.e.,
It's legal to let |
Is it a bit unfair to disable ALL optimizations just because of this one case? |
I'm not sure what you mean here. I don't think we need an option-to-option drop in compatible replacement yet, but that may be useful down the road. However, are you actually talking about behaviorally compatible? We aren't going to be exactly equivalent in terms of the performed optimizations in all cases. In this case, I think we should just implement the fold for X/X in CIRCT though! -Chris |
Yosys is very good at finding the equivalency of circuits with different levels of optimizations when optimizations can be proven by themselves. I have only 2 questionable cases with FIRRTL fuzzer. |
Clarifying: I'm suggesting we check formal equivalence against the SFC with optimizations off and with optimizations on. If the former differs, then that's highly indicative of a problem. If the latter differs then that's likely indicative of one of the following:
If we implement the optimization/fold, then things should agree again. I think the questions are then do we fold Edit: I'm in the camp of adding this as a |
Just implementing |
I'm not interested in that level of bug compatibility with SFC. We should just add the firrtl::DivOp fold in the natural way like @seldridge suggests. Anyone want to take a crack at it? It should be a simple addition of a fold() hook. |
This definitely should be done in the RTL dialect, doing it in the firrtl dialect is also a good thing. |
IMHO |
Why? |
Got it makes sense! It would be good to add that as a comment to rtl::div's fold so future versions of us remember that :) |
It could be replaced with a compare with zero and a mux, however, which is almost certainly simpler than any divider. |
Trying to generalize this... I think there're two questions:
The following examples try to provide some answers and direct the discussion. Example 1
Is there an expectation that Example 2
Are DiscussionThe FIRRTL spec allows for division by zero to be undefined which implies the compiler can optimize around it however it wants. Therefore, breaking formal equivalence in Example 2 seems fine. (This is an example of Verilog semantics not blocking optimization in an earlier dialect.) It would seem odd to curtail a legal FIRRTL optimization because of the backend target. Is implementing the fold for FIRRTL's div op then non-controversial? Whether or not formal equivalence is preserved in Example 1 should then depend on the semantics of |
Oddly enough, so far, I was able to keep Example 2 equivalency intact on the large volume of randomly generated FIRRTL programs. Except for 5 categories:
Are we ready to sacrifice all (Example 2) equivalency stories for this one case? Or we should just disable it in FIRRTL? |
I think we're getting hung up on trusting LEC... The FIRRTL specification states that I'm not proposing we sacrifice all equivalency checks. I'm saying that we have one optimization, I'd be curious what LEC says if we instead optimize |
I agree, we should just do this for the firrtl dialect. @seldridge, can you take care of this, and also capture the undefined on zero behavior in the description for firrtl.div in the .td file? I agree with the upthread comments that we have design space to decide what rtl.div does. Can we bring this to the wednesday open discussion? |
Sure, I can add the fold and the description. A (bounded) discussion could be good, too! |
thx! |
This should be addressed by @seldridge 's patch. |
The following FIRRTL program
Compiled with
firtool --lower-to-rtl
produces this Verilog:Compiled with
firrtl-1.4.0
produces this Verilog:Yosys (Yosys 0.9+3755 (git sha1 442d19f6, clang 11.0.0 -fPIC -Os)) reports formal mismatch:
The text was updated successfully, but these errors were encountered: