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

[PARTSELECT PLUS MINUS FIX] Fixed the MSB or LSB computation for the … #98

Open
wants to merge 3 commits into
base: fix_partselect
Choose a base branch
from

Conversation

loopyK1ng
Copy link

Fixed the MSB or LSB computation for the indexed vector partselect for Verilog. The second value is not a direct offset but the width of the selected part. So the value needs to be decreased by 1 before adding or subtracting it from the base.

Example Code:
module.v

module top
  (
   input wire clk, 
   input wire rstn,
   input wire [31:0] in,
   input wire [31:0] key_in,
   output reg [31:0] out
  );

  reg taint [31:0] key;

  assign key = key_in;

  always
  begin
    out[15-:16] = in[15-:16] & key[0+:16];
    out[31:16] = in[15:0] | key[15:0];
  end
endmodule

The first indices for OUT result in 15 (MSB) and -1 (LSB). Same for the first in. Additionally, 0+:16 results in 0 (LSB) and 16 (MSB).

Also contributed and a big thanks to:
@GorgeousWalrus

…indexed vector partselect for Verilog. The second value is not a direct offset but the width of the selected part. So the value needs to be decreased by 1 before adding or subtracting it from the base.
@shtaxxx shtaxxx changed the base branch from develop to fix_partselect December 24, 2022 06:14
@shtaxxx
Copy link
Member

shtaxxx commented Dec 24, 2022

I think inc_value should not be the first class object of Python.
In the following case, Minus object of Pyverilog is better.

         # original
         inc_value = p[5]
         inc_value.value = str(int(inc_value.value)-1)
         p[0] = Partselect(p[1], p[3], Plus(p[3], inc_value), lineno=p.lineno(1))
         # proposal
         inc_value = Minus(p[5], IntConst('1'))
         p[0] = Partselect(p[1], p[3], Plus(p[3], inc_value), lineno=p.lineno(1))

@loopyK1ng
Copy link
Author

You are right. Included your suggestions.

@loopyK1ng
Copy link
Author

Is there still something missing?

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.

2 participants