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

Better verilog standard compliance #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hansfbaier
Copy link

These items show up as compile errors when compiling in Vivado:

  • blocks with locally declared signals need to be named blocks
  • signals which are written to from always-blocks need to be reg type
  • array size with single digit is only allowed in system verilog

@hansfbaier
Copy link
Author

Compiles successfully in Quartus 17.0
log.gz

@birdybro
Copy link
Member

birdybro commented Apr 4, 2024

There does seem to be some kind of change here. There are new SDC warnings that weren't present before. Just a heads up.

Left is the current template core, right is compiled with your changes.

Extra warnings change:
image

blockram utilization changes (take it with a grain of salt, the "seeding" changed here too obviously):
image

@hansfbaier
Copy link
Author

Hi, thanks for looking into that. I think my changes to conf_str were causing the changes in block ram/logic utilization.
I just pushed a new version (without that change).
Do you want to rebuild and compare?

@hansfbaier
Copy link
Author

Block ram utilization is the same now:

20240404_12h33m22s_grim

@hansfbaier
Copy link
Author

hansfbaier commented Apr 4, 2024

Hmm the ignored filter warnings are still there. Wait a minute, I will commit a fix.
The hierarchy changed because of the named blocks. Those elements now have the block name prefixed.

@hansfbaier
Copy link
Author

OK I adjusted the sdc accordingly. The sdc warnings are now gone.

@birdybro
Copy link
Member

birdybro commented Apr 4, 2024

Yup, the SDC issues seem to be fixed.

@jotego
Copy link
Member

jotego commented Apr 4, 2024

Now that you're looking at that... are these changes working with simulators? The current code is rather incompatible with simulation tools from several vendors. I think your changes will make it more compatible. Did you give it a go?

@hansfbaier
Copy link
Author

hansfbaier commented Apr 4, 2024

@jotego The changes here are mainly to fix vivado syntax errors during elaboration.
If I run verilator with --lint-only, I am getting a ton of warnings, and some errors.
The most common type of error is this:

%Error-BLKANDNBLK: osd.v:104:13: Unsupported: Blocked and non-blocking assignments to same variable: 'osd.pix_block.cnt'
  104 |  reg [21:0] cnt = 0;
      |             ^~~
                   osd.v:104:19: ... Location of blocking assignment
  104 |  reg [21:0] cnt = 0;
      |                   ^
                   osd.v:108:6: ... Location of nonblocking assignment
  108 |  cnt <= cnt + 1'd1;
      |      ^~

But there is also:

%Error: scanlines.v:5:20: Unsupported in C: Variable has same name as instance: 'scanlines'
    5 |  input       [1:0] scanlines,
      |                    ^~~~~~~~~

Which means it won't work when it is compiled down to C.

But all of those are not related with the changes in this PR.

@birdybro
Copy link
Member

birdybro commented Apr 4, 2024

In practice, the MiSTer cores that use verilator often don't include the framework present in the template. Jimmystones' verilator template completely leaves out the sys folder.

https://github.com/JimmyStones/Verilator_Template

@jotego
Copy link
Member

jotego commented Apr 5, 2024

I also leave the framework out in simulations, which is a shame because we should be able to simulate the whole system. Anyway, this PR is a step in the right direction.

@sorgelig
Copy link
Member

sorgelig commented Apr 6, 2024

MiSTer is currently uses Intel/Altera FPGA and corresponding compiler. Different manufacturers have different requirements, but i see no point to make it complaint with other compilers and make code more complicated.

@sorgelig sorgelig closed this Apr 6, 2024
@sorgelig
Copy link
Member

sorgelig commented Apr 6, 2024

ok. i'll leave it open for some reasons.
Some changes break original concept. For example adding default values for parameters gives a potential hidden bug where parameters may be incompatible with specific core. Leaving parameters undefined requires it to be set in upper level module.

@sorgelig sorgelig reopened this Apr 6, 2024
@hansfbaier
Copy link
Author

hansfbaier commented Apr 6, 2024

Означает ли это, что если я откатываю это изменение, его можно будет объединить?

@jotego
Copy link
Member

jotego commented Apr 7, 2024

ok. i'll leave it open for some reasons. Some changes break original concept. For example adding default values for parameters gives a potential hidden bug where parameters may be incompatible with specific core. Leaving parameters undefined requires it to be set in upper level module.

I think default values for parameters are required by the standard and should be in place. Many tools produce errors if default values are missing.

Just set a default value that would be compatible with the current situation, i.e a default value that would cause the same effect as not having a definition in the current code.

@hansfbaier
Copy link
Author

Just set a default value that would be compatible with the current situation, i.e a default value that would cause the same effect as not having a definition in the current code.

I set the default values the same as in the instance site .

@hansfbaier
Copy link
Author

@jotego I am seeing with this version quartus seems to infer more register. This is a bit weird, because the output reg signals were all part of synchronous always blocks, so they should have inferred registers anyway.

20240408_04h45m16s_grim

@hansfbaier
Copy link
Author

@jotego
20240408_04h50m16s_grim
This here would explain 24 of those, but I can't see in any case how that could be done without inferring registers.

@birdybro
Copy link
Member

birdybro commented Apr 8, 2024

Minor adjustments in the amount of registers happens because of seeding changing sometimes. The fitter is like an aluminum annealing algorithm, there is no absolute solution, it's a best fit given a pseudorandom starting point and a time limit for how much effort to apply. If you add whitespaces to the code you will see registers fluctuate by these small amounts because the physical starting points lead to buffer logic being added sometimes, or not being needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants