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

Arithmetic shift-right generated SV can be ineffective depending on nearby logic #295

Closed
mkorbel1 opened this issue Mar 2, 2023 · 2 comments · Fixed by #296
Closed

Arithmetic shift-right generated SV can be ineffective depending on nearby logic #295

mkorbel1 opened this issue Mar 2, 2023 · 2 comments · Fixed by #296
Labels
bug Something isn't working

Comments

@mkorbel1
Copy link
Contributor

mkorbel1 commented Mar 2, 2023

Describe the bug

If an unsigned operation is applied to the result of an arithmetic shift-right in the generated SystemVerilog, it may perform as a logical (unsigned) right-shift instead.

For example, if generated SystemVerilog looks like this:

  assign x = {32{c}} & ($signed(a) >>> b) ;

This actually performs an unsigned shift right.

To Reproduce

Perform an unsigned bitwise operation on the result of an arithmetic shift-right.

Expected behavior

Generated verilog for arithmetic shift right is consistent always.

Actual behavior

Depending on surrounding logic, a logical shift-right may occur instead.

Additional: Dart SDK info

No response

Additional: pubspec.yaml

No response

Additional: Context

Present in v0.4.2

@mkorbel1 mkorbel1 added the bug Something isn't working label Mar 2, 2023
mkorbel1 added a commit to mkorbel1/rohd that referenced this issue Mar 2, 2023
@saw235
Copy link

saw235 commented Mar 4, 2023

Can you try this one? Note the curly braces instead of the parenthesis.

 assign x = {32{c}} & {$signed(a) >>> b} ;

The reason for this is because the curly braces makes it self-determined. I suspect that the & operator causes it to think that the result type should be unsigned and thus the arithmetic shift makes a zero extend.

@mkorbel1
Copy link
Contributor Author

mkorbel1 commented Mar 6, 2023

Can you try this one? Note the curly braces instead of the parenthesis.

 assign x = {32{c}} & {$signed(a) >>> b} ;

The reason for this is because the curly braces makes it self-determined. I suspect that the & operator causes it to think that the result type should be unsigned and thus the arithmetic shift makes a zero extend.

Good call @saw235, I like this better. Tests pass, updated PR with that adjusted. Look good to you?
#296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants