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

Wrong Parameter calculation in the elaborated model #3960

Closed
Pietro4F opened this issue Feb 6, 2024 · 3 comments
Closed

Wrong Parameter calculation in the elaborated model #3960

Pietro4F opened this issue Feb 6, 2024 · 3 comments

Comments

@Pietro4F
Copy link

Pietro4F commented Feb 6, 2024

Hello,
I've notice an error in the calculation of a parameter in the elaborated model.

I have different files with different modules, one of them is similar to this...

module abc #(
    // --
    // Parameters
    // --
    parameter A = 8_000_000,
    parameter B = 100,
    ...
    )
    (
    // --
    // Clock and ...
    // --
    input wire                       clk,
    input wire                      .......
 );

 localparam C= B * (A / 1_000_000);
 

In the not elaborated tree i have this

|vpiParamAssign:
\_param_assign: , line:x, endln:x
  |vpiParent:
  \_module_inst: work@abc (work@abc), file:abc.v, line:x, endln:x
  |vpiRhs:
  \_constant: , line:x, endln:x
    |vpiParent:
    \_param_assign: , line:x, endln:x
    |vpiDecompile:8_000_000
    |vpiSize:64
    |UINT:8
    |vpiTypespec:
    \_ref_typespec: (work@abc)
      |vpiParent:
      \_constant: , line:x, endln:x
      |vpiFullName:work@abc
      |vpiActual:
      \_int_typespec: , line:x, endln:x
    |vpiConstType:9
  |vpiLhs:
  \_parameter: ([email protected]), line:x, endln:x
.
.
.
|vpiParamAssign:
\_param_assign: , line:x, endln:x
  |vpiParent:
  \_module_inst: work@abc (work@abc), file:abc.v, line:x, endln:x
  |vpiRhs:
  \_constant: , line:x, endln:x
    |vpiParent:
    \_param_assign: , line:x, endln:x
    |vpiDecompile:100
    |vpiSize:64
    |UINT:100
    |vpiTypespec:
    \_ref_typespec: (work@abc)
      |vpiParent:
      \_constant: , line:x, endln:x
      |vpiFullName:work@abc
      |vpiActual:
      \_int_typespec: , line:x, endln:x
    |vpiConstType:9
  |vpiLhs:
  \_parameter: ([email protected]), line:x, endln:x
.
.
.
|vpiParamAssign:
  \_param_assign: , line:x, endln:x
    |vpiParent:
    \_module_inst: work@abc (work@abc), file:abc.v, line:x, endln:x
    |vpiRhs:
    \_operation: , line:x, endln:x
      |vpiParent:
      \_param_assign: , line:x, endln:x
      |vpiOpType:25
      |vpiOperand:
      \_ref_obj: ([email protected]), line:x, endln:x
        |vpiParent:
        \_operation: , line:x, endln:x
        |vpiName:B
        |vpiFullName:[email protected]
      |vpiOperand:
      \_operation: , line:x, endln:x
        |vpiParent:
        \_operation: , line:x, endln:x
        |vpiOpType:12
        |vpiOperand:
        \_ref_obj: ([email protected]), line:x, endln:x
          |vpiParent:
          \_operation: , line:x, endln:x
          |vpiName:A
          |vpiFullName:[email protected]
        |vpiOperand:
        \_constant: , line:x, endln:x
          |vpiParent:
          \_operation: , line:x, endln:x
          |vpiDecompile:1_000_000
          |vpiSize:64
          |UINT:1
          |vpiConstType:9
    |vpiLhs:
    \_parameter: ([email protected]), line:x, endln:x

But the in the elaborated tree i obtain 800000000 instead 800.


    |vpiParamAssign:
    \_param_assign: , line:x, endln:x
        |vpiParent:
        \_module_inst: work@abc ([email protected]), file:abc.v, line:x, endln:x
        |vpiRhs:
        \_constant: , line:x, endln:x
        |vpiParent:
        \_param_assign: , line:x, endln:x
        |vpiDecompile:800000000
        |vpiSize:64
        |INT:800000000
        |vpiConstType:7
        |vpiLhs:
        \_parameter: ([email protected]), line:x, endln:x

During the inclusion a give to the parameters the same values ad the default ones.

I have tried the same thing but with one simple module in one file.
So my module in that case is not included anywhere and I can obtain the correct result 800.

@alaindargelas
Copy link
Collaborator

@Pietro4F , please add a test that is a complete Verilog file (That at least parses and compile, even if it is minimal). Not just snippet of code.

@Pietro4F
Copy link
Author

Pietro4F commented Feb 9, 2024

I think the problem is just the it can't recognize the number with _ , for example It probably counts the 1_000_000 in the division as just 1, the same for 8_000_000.
I try to recreate the same error.

module abc #(
  parameter A = 8_000_000,
  parameter B = 100
)(
  input wire clk,
  input wire rst
);

  localparam C = B * (A / 1_000_000);

endmodule

module top (
  input wire clk,
  input wire rst
);

  abc #( .A(8_000_000), .B(100) ) u_abc (
    .clk(clk),
    .rst(rst)
  );

endmodule

In this first case C has the correct value only because A has the value of 8.


|uhdmtopModules:
\_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
  |vpiName:work@top
  |vpiDefName:work@top
  |vpiTop:1
  |vpiNet:
  \_logic_net: ([email protected]), line:14:14, endln:14:17
    |vpiParent:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
    |vpiTypespec:
    \_ref_typespec: ([email protected])
      |vpiParent:
      \_logic_net: ([email protected]), line:14:14, endln:14:17
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_typespec: , line:14:9, endln:14:13
    |vpiName:clk
    |vpiFullName:[email protected]
    |vpiNetType:1
  |vpiNet:
  \_logic_net: ([email protected]), line:15:14, endln:15:17
    |vpiParent:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
    |vpiTypespec:
    \_ref_typespec: ([email protected])
      |vpiParent:
      \_logic_net: ([email protected]), line:15:14, endln:15:17
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_typespec: , line:15:9, endln:15:13
    |vpiName:rst
    |vpiFullName:[email protected]
    |vpiNetType:1
  |vpiTopModule:1
  |vpiPort:
  \_port: (clk), line:14:14, endln:14:17
    |vpiParent:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
    |vpiName:clk
    |vpiDirection:1
    |vpiLowConn:
    \_ref_obj: ([email protected]), line:14:14, endln:14:17
      |vpiParent:
      \_port: (clk), line:14:14, endln:14:17
      |vpiName:clk
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_net: ([email protected]), line:14:14, endln:14:17
    |vpiTypedef:
    \_ref_typespec: ([email protected])
      |vpiParent:
      \_port: (clk), line:14:14, endln:14:17
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_typespec: , line:14:9, endln:14:13
    |vpiInstance:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
  |vpiPort:
  \_port: (rst), line:15:14, endln:15:17
    |vpiParent:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
    |vpiName:rst
    |vpiDirection:1
    |vpiLowConn:
    \_ref_obj: ([email protected]), line:15:14, endln:15:17
      |vpiParent:
      \_port: (rst), line:15:14, endln:15:17
      |vpiName:rst
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_net: ([email protected]), line:15:14, endln:15:17
    |vpiTypedef:
    \_ref_typespec: ([email protected])
      |vpiParent:
      \_port: (rst), line:15:14, endln:15:17
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_typespec: , line:15:9, endln:15:13
    |vpiInstance:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
  |vpiModule:
  \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
    |vpiParent:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
    |vpiName:u_abc
    |vpiFullName:[email protected]_abc
    |vpiParameter:
    \_parameter: ([email protected]_abc.A), line:2:13, endln:2:14
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |UINT:8
      |vpiTypespec:
      \_ref_typespec: ([email protected]_abc.A)
        |vpiParent:
        \_parameter: ([email protected]_abc.A), line:2:13, endln:2:14
        |vpiFullName:[email protected]_abc.A
        |vpiActual:
        \_int_typespec: , line:2:3, endln:2:26
      |vpiName:A
      |vpiFullName:[email protected]_abc.A
    |vpiParameter:
    \_parameter: ([email protected]_abc.B), line:3:13, endln:3:14
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |UINT:100
      |vpiTypespec:
      \_ref_typespec: ([email protected]_abc.B)
        |vpiParent:
        \_parameter: ([email protected]_abc.B), line:3:13, endln:3:14
        |vpiFullName:[email protected]_abc.B
        |vpiActual:
        \_int_typespec: , line:3:3, endln:3:20
      |vpiName:B
      |vpiFullName:[email protected]_abc.B
    |vpiParameter:
    \_parameter: ([email protected]_abc.C), line:9:14, endln:9:15
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |vpiLocalParam:1
      |vpiName:C
      |vpiFullName:[email protected]_abc.C
    |vpiParamAssign:
    \_param_assign: , line:2:13, endln:2:26
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |vpiOverriden:1
      |vpiRhs:
      \_constant: , line:2:17, endln:2:26
        |vpiParent:
        \_param_assign: , line:2:13, endln:2:26
        |vpiDecompile:8
        |vpiSize:32
        |UINT:8
        |vpiTypespec:
        \_ref_typespec: ([email protected]_abc)
          |vpiParent:
          \_constant: , line:2:17, endln:2:26
          |vpiFullName:[email protected]_abc
          |vpiActual:
          \_int_typespec: , line:2:3, endln:2:26
        |vpiConstType:9
      |vpiLhs:
      \_parameter: ([email protected]_abc.A), line:2:13, endln:2:14
    |vpiParamAssign:
    \_param_assign: , line:3:13, endln:3:20
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |vpiOverriden:1
      |vpiRhs:
      \_constant: , line:3:17, endln:3:20
        |vpiParent:
        \_param_assign: , line:3:13, endln:3:20
        |vpiDecompile:100
        |vpiSize:32
        |UINT:100
        |vpiTypespec:
        \_ref_typespec: ([email protected]_abc)
          |vpiParent:
          \_constant: , line:3:17, endln:3:20
          |vpiFullName:[email protected]_abc
          |vpiActual:
          \_int_typespec: , line:3:3, endln:3:20
        |vpiConstType:9
      |vpiLhs:
      \_parameter: ([email protected]_abc.B), line:3:13, endln:3:14
    |vpiParamAssign:
    \_param_assign: , line:9:14, endln:9:37
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |vpiRhs:
      \_constant: , line:9:18, endln:9:37
        |vpiParent:
        \_param_assign: , line:9:14, endln:9:37
        |vpiDecompile:800
        |vpiSize:64
        |INT:800
        |vpiConstType:7
      |vpiLhs:
      \_parameter: ([email protected]_abc.C), line:9:14, endln:9:15

Instead if I change from 8_000_000 to 8000000 I obtain C = 8000000

module abc #(
  parameter A = 8_000_000,
  parameter B = 100
)(
  input wire clk,
  input wire rst
);

  localparam C = B * (A / 1_000_000);

endmodule

module top (
  input wire clk,
  input wire rst
);

  abc #( .A(8000000), .B(100) ) u_abc (
    .clk(clk),
    .rst(rst)
  );

endmodule
|uhdmtopModules:
\_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
  |vpiName:work@top
  |vpiDefName:work@top
  |vpiTop:1
  |vpiNet:
  \_logic_net: ([email protected]), line:14:14, endln:14:17
    |vpiParent:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
    |vpiTypespec:
    \_ref_typespec: ([email protected])
      |vpiParent:
      \_logic_net: ([email protected]), line:14:14, endln:14:17
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_typespec: , line:14:9, endln:14:13
    |vpiName:clk
    |vpiFullName:[email protected]
    |vpiNetType:1
  |vpiNet:
  \_logic_net: ([email protected]), line:15:14, endln:15:17
    |vpiParent:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
    |vpiTypespec:
    \_ref_typespec: ([email protected])
      |vpiParent:
      \_logic_net: ([email protected]), line:15:14, endln:15:17
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_typespec: , line:15:9, endln:15:13
    |vpiName:rst
    |vpiFullName:[email protected]
    |vpiNetType:1
  |vpiTopModule:1
  |vpiPort:
  \_port: (clk), line:14:14, endln:14:17
    |vpiParent:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
    |vpiName:clk
    |vpiDirection:1
    |vpiLowConn:
    \_ref_obj: ([email protected]), line:14:14, endln:14:17
      |vpiParent:
      \_port: (clk), line:14:14, endln:14:17
      |vpiName:clk
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_net: ([email protected]), line:14:14, endln:14:17
    |vpiTypedef:
    \_ref_typespec: ([email protected])
      |vpiParent:
      \_port: (clk), line:14:14, endln:14:17
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_typespec: , line:14:9, endln:14:13
    |vpiInstance:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
  |vpiPort:
  \_port: (rst), line:15:14, endln:15:17
    |vpiParent:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
    |vpiName:rst
    |vpiDirection:1
    |vpiLowConn:
    \_ref_obj: ([email protected]), line:15:14, endln:15:17
      |vpiParent:
      \_port: (rst), line:15:14, endln:15:17
      |vpiName:rst
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_net: ([email protected]), line:15:14, endln:15:17
    |vpiTypedef:
    \_ref_typespec: ([email protected])
      |vpiParent:
      \_port: (rst), line:15:14, endln:15:17
      |vpiFullName:[email protected]
      |vpiActual:
      \_logic_typespec: , line:15:9, endln:15:13
    |vpiInstance:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
  |vpiModule:
  \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
    |vpiParent:
    \_module_inst: work@top (work@top), file:/home/top.v, line:13:1, endln:23:10
    |vpiName:u_abc
    |vpiFullName:[email protected]_abc
    |vpiParameter:
    \_parameter: ([email protected]_abc.A), line:2:13, endln:2:14
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |UINT:8
      |vpiTypespec:
      \_ref_typespec: ([email protected]_abc.A)
        |vpiParent:
        \_parameter: ([email protected]_abc.A), line:2:13, endln:2:14
        |vpiFullName:[email protected]_abc.A
        |vpiActual:
        \_int_typespec: , line:2:3, endln:2:26
      |vpiName:A
      |vpiFullName:[email protected]_abc.A
    |vpiParameter:
    \_parameter: ([email protected]_abc.B), line:3:13, endln:3:14
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |UINT:100
      |vpiTypespec:
      \_ref_typespec: ([email protected]_abc.B)
        |vpiParent:
        \_parameter: ([email protected]_abc.B), line:3:13, endln:3:14
        |vpiFullName:[email protected]_abc.B
        |vpiActual:
        \_int_typespec: , line:3:3, endln:3:20
      |vpiName:B
      |vpiFullName:[email protected]_abc.B
    |vpiParameter:
    \_parameter: ([email protected]_abc.C), line:9:14, endln:9:15
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |vpiLocalParam:1
      |vpiName:C
      |vpiFullName:[email protected]_abc.C
    |vpiParamAssign:
    \_param_assign: , line:2:13, endln:2:26
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |vpiOverriden:1
      |vpiRhs:
      \_constant: , line:2:17, endln:2:26
        |vpiParent:
        \_param_assign: , line:2:13, endln:2:26
        |vpiDecompile:8000000
        |vpiSize:32
        |UINT:8000000
        |vpiTypespec:
        \_ref_typespec: ([email protected]_abc)
          |vpiParent:
          \_constant: , line:2:17, endln:2:26
          |vpiFullName:[email protected]_abc
          |vpiActual:
          \_int_typespec: , line:2:3, endln:2:26
        |vpiConstType:9
      |vpiLhs:
      \_parameter: ([email protected]_abc.A), line:2:13, endln:2:14
    |vpiParamAssign:
    \_param_assign: , line:3:13, endln:3:20
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |vpiOverriden:1
      |vpiRhs:
      \_constant: , line:3:17, endln:3:20
        |vpiParent:
        \_param_assign: , line:3:13, endln:3:20
        |vpiDecompile:100
        |vpiSize:32
        |UINT:100
        |vpiTypespec:
        \_ref_typespec: ([email protected]_abc)
          |vpiParent:
          \_constant: , line:3:17, endln:3:20
          |vpiFullName:[email protected]_abc
          |vpiActual:
          \_int_typespec: , line:3:3, endln:3:20
        |vpiConstType:9
      |vpiLhs:
      \_parameter: ([email protected]_abc.B), line:3:13, endln:3:14
    |vpiParamAssign:
    \_param_assign: , line:9:14, endln:9:37
      |vpiParent:
      \_module_inst: work@abc ([email protected]_abc), file:/home/top.v, line:18:3, endln:21:5
      |vpiRhs:
      \_constant: , line:9:18, endln:9:37
        |vpiParent:
        \_param_assign: , line:9:14, endln:9:37
        |vpiDecompile:800000000
        |vpiSize:64
        |INT:800000000
        |vpiConstType:7
      |vpiLhs:
      \_parameter: ([email protected]_abc.C), line:9:14, endln:9:15

@alaindargelas
Copy link
Collaborator

Fixed in #3962

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