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

Support for attributes on parameters in Verilog #25

Merged
merged 17 commits into from
May 27, 2019

Conversation

mkurc-ant
Copy link

@mkurc-ant mkurc-ant commented May 16, 2019

This PR adds support for attributes on parameters for Verilog.

The Verilog frontend was augmented with parsing and storing attributes of parameters in their AST nodes. Parameter attributes are only stored for those that actually have them. The default value of a parameter is also preserved.

…their default values.

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
…ctionality.

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
kernel/rtlil.h Outdated Show resolved Hide resolved
Copy link
Member

@mithro mithro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to update the chparam and setparam + equivalent commands to use the new iterators for parameter lists?

kernel/rtlil.h Outdated Show resolved Hide resolved
@mkurc-ant
Copy link
Author

@mithro I didn't do anything to chparam and setparam because the actual parameter values are stored somehow differently. I'think there is no need to change that.

…rmer functionality."

This reverts commit fece472.

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
…the Verilog backend

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
@mkurc-ant
Copy link
Author

Now the RTLIL::Module class holds:

pool<RTLIL::IdString> avail_parameters;
dict<RTLIL::IdString, RTLIL::ParameterInfo> parameter_information;
dict<RTLIL::IdString, dict<RTLIL::IdString,RTLIL::Const>> parameter_attributes;

The functionality regarding avail_parameters is unchanged. The structure parameter_information is meant to hold "metadata" of a parameter (default value, width etc.) Currently only the default value is stored.

The dict parameter_attributes contains attributes of parameters but only for those which actually have them.

I also updated the JSON, ilang and Verilog backends. Attributes of parameters are now visible when using the dump command.

@mkurc-ant mkurc-ant changed the title [WIP] Support for attributes on parameters in Verilog Support for attributes on parameters in Verilog May 17, 2019
…alues though.

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
…heir names violate Verilog syntax.

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
Copy link

@litghost litghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Two general thoughts:

  • Are there tests we should be adding?
  • Can we flag out the "cost" of these changes?

backends/ilang/ilang_backend.cc Show resolved Hide resolved
{
for (auto& param : module->avail_parameters) {

// Skip the parameter if its name begins with '$'. Such names are illegal

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this is correct? You can use escape identifiers to write them out?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

kernel/rtlil.h Show resolved Hide resolved
kernel/rtlil.cc Show resolved Hide resolved
@mkurc-ant
Copy link
Author

@litghost I already added some tests regarding parsing of parameter attributes and they are merged upstream. I suppose I should add additional tests which will include eg. reading Verilog, writing JSON/ILANG and comparing output with a reference. I haven't found any similar tests in the Yosys tests folder. What do you think ?

Regarding the "cost": I believe that the cost can only be observable when processing verilogs with huge number of attributes on parameters. I would need to think of some kind of memory usage and performance tests. I haven't found such tests either.

…backend

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
Copy link

@litghost litghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mkurc-ant
Copy link
Author

@litghost Do not merge. I recently discovered that floating point constants are handled differently than strings and integers. Also a floating point constant is a different object in the AST tree. I added a quick workaround which treats floating point constants as integer 0 but it is not an acceptable solution.

In order to fix that I would need either to refactor the RTLIL::Const class so it can store a float or the newly added RTLIL::ParameterInfo class which holds default value of a parameter. I think the latter will be less memory consuming.

Anyway, there is still some work to do with this PR.

@litghost
Copy link

@litghost In order to fix that I would need either to refactor the RTLIL::Const clas

Maybe we should not modify Yosys and simply extract the FASM_PARAM annotation using a coarse parser. I'm not a fan of keeping a Yosys fork forever, and the more that has to change, the less likely they will accept it. @mithro, thoughts?

…erilog frontend/backend

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
…e JSON backend

Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
Signed-off-by: Maciej Kurc <mkurc@antmicro.com>
@mkurc-ant
Copy link
Author

Anyway I managed to do the fix. So the default value of a parameter can now be floating point. It is correctly loaded by the Verilog frontend and correctly outputted by the Verilog and the JSON backend.

The ilang frontend never parsed default values of parameters so I left its functionality intact.

Copy link
Member

@mithro mithro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@mithro
Copy link
Member

mithro commented May 27, 2019

@litghost Let's land this and then we can figure out an alternative approach.

@mithro mithro merged commit a69222f into SymbiFlow:master+wip May 27, 2019
@mithro
Copy link
Member

mithro commented May 28, 2019

The attribute is specified as a prefix to a declaration, a module item, a statement or a port connection. Three examples are:

  • (* optimize *) module control ( ... );
  • (* state_variable *) reg [7:0] S;
  • dff il (q, d, (* clock_line *) ckl, rst);

The attribute is specified as a suffix to an operator or the function name in a function call.

  • sum = a + (* ripple_adder *) b;
  • assign next_state = fsm_func(* meally_fsm *) (state, a, b, c);

@mithro
Copy link
Member

mithro commented May 28, 2019

ordered_port_connection ::= (From A.4.1)
{ attribute_instance } [ expression ]
named_port_connection ::=
{ attribute_instance } . port_identifier ( [ expression ] )

@mithro
Copy link
Member

mithro commented May 28, 2019

@mkurc-ant So, it appears you missed being able to add an attribute to a port connection. See the third item above. Could you fix that?

@eddiehung
Copy link

I've discussed this issue with Yosys upstream and we agree this is a good idea, however, the way we'd suggest implementing it would be to transform the parameter into a new wire (permanently) driven by the parameter value. That way, it appears post-elaboration, and in the backend too, so that it can be inspected during simulation or used during formal verification too.

Would you consider trying this approach instead?

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

Successfully merging this pull request may close these issues.

None yet

4 participants