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

opt_rmdff with init attribute #60

Closed
gaomy3832 opened this issue Apr 18, 2015 · 1 comment
Closed

opt_rmdff with init attribute #60

gaomy3832 opened this issue Apr 18, 2015 · 1 comment

Comments

@gaomy3832
Copy link
Contributor

I am using yosys to handle some verilog code generated from Vivado HLS. The code has some weird style for FSM, and there is a reg with an initial value. After processing the code, I find there is a $dff cell with constant input, and this constant input is equal to the initial value. So I think the cell should be removed by opt_rmdff, but that is not the case. I dive in the code and see that opt_rmdff will skip the dff with init attribute, regardless of whether or not the initial value is equal to the constant. Is there any reason not to do so? If not, I suggest a simple fix to it as

diff --git a/passes/opt/opt_rmdff.cc b/passes/opt/opt_rmdff.cc
index 5f52bb8..20966fd 100644
--- a/passes/opt/opt_rmdff.cc
+++ b/passes/opt/opt_rmdff.cc
@@ -122,7 +122,7 @@ bool handle_dff(RTLIL::Module *mod, RTLIL::Cell *dff)
                goto delete_dff;
        }

-       if (sig_d.is_fully_const() && !sig_r.size() && !has_init) {
+       if (sig_d.is_fully_const() && !sig_r.size() && (!has_init || (has_init && val_init == sig_d.as_const()))) {
                RTLIL::SigSig conn(sig_q, sig_d);
                mod->connect(conn);
                goto delete_dff;
@cliffordwolf
Copy link
Collaborator

Thanks for the patch! Fixed this and a few similar cases in commit 9041f34.

mkurc-ant referenced this issue in antmicro/yosys Feb 1, 2021
Enabling addf2dff in non-adder mode
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

No branches or pull requests

2 participants