• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. Dynamic arrays

Stats

  • Locked Locked
  • Replies 8
  • Subscribers 64
  • Views 14878
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Dynamic arrays

archive
archive over 17 years ago

Hi @all,

I wish you a happy new year.

I have a question concerning dynamic array.
I have to write a class method, which gets an integer (the CRC type, e.g. 8, 16, 32 ...) and a dynamic array, which contains the polynomial (binary).
It should be possible to change the CRC type in each single testcase, for example:

[code]
testclass tc;
tc = new;
tc.set_crc(8, 'b11110000);
[/code]

The first problem was, that it was not possible to give the function a dynamic array, but I think I have solved the problem with the ref keyword in order to call it by reference.
My whole function is listed below:

[code]
  function void Layer4::set_crc_properties(int crc_type, ref bit crc_polynomial[]);
    if ( crc_type + 1 != crc_polynomial.size() )
    begin
      $display("crc_type and dimension of polynomial does not match!");
      $display("Not assigning any value");
      return;
    end  
    this.crc_type = crc_type;
    this.crc_polynomial = new[this.crc_type+1](crc_polynomial);
  endfunction : set_crc_properties
[/code]

Within this function it seems to work (but I'm not quite sure).
The problem ist the code in the constructor-function, where I simple do the following:

[code]
this.crc_polynomial = new[17]('b0);   
[/code]

Here I get the following error message:
[code]
   this.crc_polynomial = new[17]('b0);                                                      
                            |
ncvlog: *E,TYPEERR (cc1100.sv,108|28): assignment operator type check failed.
    this.crc_polynomial = new[17]('b0); 
                                    |
ncvlog: *E,DYNINI (cc1100.sv,108|36):  is not a dynamic array.
        program worklib.cc1100
                errors: 2, warnings: 0
[/code]

Without the ('b0) it works.
Can you help me and tell me, whats going wrong here?
Thank you very much for your help!
Sebastian


Originally posted in cdnusers.org by sebastian
  • Cancel
  • archive
    archive over 17 years ago

    Me again.
    Sorry for the bad legibility!


    Originally posted in cdnusers.org by sebastian
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 17 years ago

    First of all, I believe the formatting only works when you use the "Reply" button and not in the "Quick Reply".

    As for your problem, what are you trying to do by passing the ('b0) to the DA constructor? According to LRM 5.6.1, The argument in the ( ) must be "a dynamic array of a data type equivalent to the array on the left-hand side, but it need not have the same size".

    I assume you're trying to initialize the array to be 'b0. If that is the case, you don't have to do anything, since the type bit will initialize to 0 by default.

    Tim


    Originally posted in cdnusers.org by tpylant
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 17 years ago

    Thanks for your reply. I think this is the problem, but I'm not sure yet how to solve the problem. I want to set the array with a function called:

    set_crc (16, 'b1111000011110000);

    But the compiler tolds me, that only dynamic arrays are allowed as parameter in this context. So, I have to look for another solution. If somebody has a good idea, I would be very thankful.

    Sebastian


    Originally posted in cdnusers.org by sebastian
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 17 years ago

    Here is a testcase I used:

    module test;

    class testclass;

      int crc_type;
      bit crc_polynomial[];

      function void set_crc(int crc_type, ref bit crc_polynomial[]);
        if ( crc_type != crc_polynomial.size() )
        begin
          $display("crc_type (%0d) and dimension of polynomial (%0d) does not match!", crc_type, crc_polynomial.size());
          $display("Not assigning any value");
          return;
        end
        this.crc_type = crc_type;
        this.crc_polynomial = new[this.crc_type+1](crc_polynomial);
    & nbsp; endfunction

      function void print();
        $write("type = %0d  value = ", crc_type);
        for (int i=crc_polynomial.size()-1; i>=0; i--)
          $write(crc_polynomial[i]);
        $display();
      endfunction
    endclass

    testclass tc;
    bit poly[];

    initial begin
      tc = new;
      set_poly(8, 'b11110000);
      tc.set_crc(8, poly);
      tc.print();
    end

    function void set_poly(int size, longint vect);
      poly = new[size];
      for (int i=0; i     poly[i] = vect[i];
      $display("%0b ", vect);
      for (int i=poly.size()-1; i>=0; i--)
        $write(poly[i]);
      $display();
    endfunction

    endmodule


    Tim


    Originally posted in cdnusers.org by tpylant
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 17 years ago

    Hi Tim,

    thank you very much for your source file, I will try it immediately.

    Sebastian


    Originally posted in cdnusers.org by sebastian
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 17 years ago

    Hey, me again,

    I have know developed a new idea, which should work, but before implementing this, I would ask you, if it can work.

    I save the crc_checksum (in this example CRC16) in an array looking like this: bit [7:0] crc_checksum [2]. During calculation, this sum has to be left shifted. If it would be an integer (like in C) it would be: crc_checksum = crc_checksum << 1;

    Does this work with an array of this type too? The reason, why I cannot use an integer is, because I do not know, which type of CRC, it could be 8, 16, 32 or 64.

    Thanks for your help!
    Sebastian


    Originally posted in cdnusers.org by sebastian
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 17 years ago

    You can do it if you are using packed arrays. Packed arrays can be read and loaded in parallel as if all their bits are concatenated into a single large vector. This code works for me in IUS 6.11 (I had to try it since I don't write code using this capability every day and I wanted to see if it actually worked).

    module testit;

      reg [1:0] [7:0] a;

      initial
      begin
        $display("Packed array testcase");
        a[1] = 8'b10;
        a[0] = 8'b01;
        #10 $displayb ( a[1], , a[0] );
        #10 a = a << 3;
        #10 $displayb ( a[1], , a[0] );
        #100 $finish;
      end
     
    endmodule


    Originally posted in cdnusers.org by TAM
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 17 years ago

    In my previous post, the omega symbol should be "[ 1" , the epsilon symbol should be "[ 7", and the Y (ypsilon?) symbol should be "[ 0".


    Originally posted in cdnusers.org by TAM
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information