Pyverilog icon indicating copy to clipboard operation
Pyverilog copied to clipboard

Part-select addressing

Open cclienti opened this issue 10 years ago • 0 comments

Hello,

I looked in the verilog standard ieee 1364-2005 regarding the partselect adressing. I've created a module base on their example.

module partselect_test
   (input wire [15:0] big_vect,
    input wire [0:15] little_vect,

    output wire [7:0] big_part1,
    output wire [7:0] big_part2,

    output wire [0:7] little_part1,
    output wire [0:7] little_part2);

    assign big_part1 = big_vect[ 0 +: 8]; // == big_vect[ 7 : 0]
    assign big_part2 = big_vect[15 -: 8]; // == big_vect[15 : 8]

    assign little_part1 = little_vect[ 0 +: 8]; // == little_vect[0 :  7]
    assign little_part2 = little_vect[15 -: 8]; // == little_vect[8 : 15]

endmodule

When I parsed the code, I obtained the following AST (I've put only the assign nodes) :

      Assign:  (at 11)
        Lvalue:  (at 11)
          Identifier: big_part1 (at 11)
        Rvalue:  (at 11)
          Partselect:  (at 11)                   // The partselect parsed is [0:8]
            Identifier: big_vect (at 11)         // The standard says [7:0]
            IntConst: 0 (at 11)
            Plus:  (at 11)
              IntConst: 0 (at 11)
              IntConst: 8 (at 11)
      Assign:  (at 12)
        Lvalue:  (at 12)
          Identifier: big_part2 (at 12)
        Rvalue:  (at 12)
          Partselect:  (at 12)                     // The partselect parsed is [15:7]
            Identifier: big_vect (at 12)           // The standard says [15:8]
            IntConst: 15 (at 12)
            Minus:  (at 12)
              IntConst: 15 (at 12)
              IntConst: 8 (at 12)
      Assign:  (at 14)
        Lvalue:  (at 14)
          Identifier: little_part1 (at 14)
        Rvalue:  (at 14)
          Partselect:  (at 14)                     // The partselect parsed is [0:8]
            Identifier: little_vect (at 14)        // The standard says [0:7]
            IntConst: 0 (at 14)
            Plus:  (at 14)
              IntConst: 0 (at 14)
              IntConst: 8 (at 14)
      Assign:  (at 15)
        Lvalue:  (at 15)
          Identifier: little_part2 (at 15)
        Rvalue:  (at 15)
          Partselect:  (at 15)                     // The partselect parsed is [15:7]
            Identifier: little_vect (at 15)        // The standard says [8:15]
            IntConst: 15 (at 15)
            Minus:  (at 15)
              IntConst: 15 (at 15)        
              IntConst: 8 (at 15)

I think that you cannot resolve the "+:" or "-:" without analyzing the declaration of the variable to know if the bit range is ascending or descending (see parser.py lines 726, 731, 741, 746).

In my opinion the best way to manage this issue would be to create a new node type (PartselectDynamic for instance). This node would be instantiated by the parser when the tokens PLUSCOLON or MINUSCOLON are found. The codegen would be easy to modify, but I don't know the impact on the other parts of PyVerilog.

I can try this solution if you want.

Christophe

cclienti avatar Apr 15 '16 08:04 cclienti