zoukankan      html  css  js  c++  java
  • UVM 之SV数组

    数组的定义:

      An array is a collection of variables, all of the sametype, and accessed using the same name plus one or more  indices.

    合并数组和非合并数组:packed array,unpacked array.

    bit[ 7:0] c1; // packed array    数组大小放变量前面,类似向量 reg [7:0]  a;    wire  [3:0] bus;

    bit [3:0] [7:0] j; // j is a packed array 注意,这里表示4个8位元素组成的数组,而不是8个4bit组成的数组
    real ul [7:0]; // unpacked array  数组大小放变量后面,类似 单bit数组   

    real si [3:0] ;含义4个1bit的元素的数组

    int busB [1:0]; // unpacked array of 2 integers

    bit busA [7:0] [31:0] ; // unpacked array of 8 32-bit vectors    8个32bit元素的数组 等价于 reg [31:0] busA [7:0];

    这里的区别是:

    bit [3:0] [7:0] A;

    bit  [7:0] B [3:0];     可以把A作为一个整体来进行@A 判断,而对于B则不能整体来使用,必须用@B[0] @B[1]等。

    这个packed只用于单bit的合并,Packed arrays can only be made of the single bit types (bit, logic, reg, wire, and the other net types),所以int 这种类型就只能是非合并类型数组。

    动态数组:
    A dynamic array is one dimension of an unpacked array whose size can be set or changed at runtime. The
    space for a dynamic array doesn’t exist until the array is explicitly created at runtime.它是一维的,非合并的。只有在运行时创建时才存在。

    bit [3:0] nibble[]; // Dynamic array of 4-bit vectors  4bit宽的,个数未知
    integer  mem[];  // Dynamic array of integers    个数位置的整数动态数组
    The new[]operator is used to set or change the size of the array.   用new[n]来分配空间

    integeraddr[]; // Declare the dynamic array.
    addr = new[100]; // Create a 100-element array.
    The size()built-in method returns the current size of the array.

    intj = addr.size;   用变量加点再加size来获取动态数组的大小1...n
    The delete()built-in method clears all the elementsyielding an empty array (zero size).

    ab.delete;    用变量名加点加delete来删除动态数组。

    队列

    A queue is a variable-size, ordered collection of homogeneous elements. A queue supports constant time
    access to all its elements as well as constant time insertion and removal at the beginning or the end of the
    queue.

    队列和链表相似,可以在队列的任何地方增加或删除元素,也像数组,可以用索引来访问元素。队列的声明是使用带有美元符号的下标[$]。队列元素的编号是从0到$。

    在队列的前面或后面存取数据非常方便,无论队列有多大,这种操作所好味的时间都是一样的。在队列的中间增加或删除元素需要对已经存在的数据进行搬移一遍腾出空间,相应的操作所耗费的时间会随着队列的大小线性增加。

    队列的基本操作如下:

    int  q[$] = { 2, 4, 8 };
    int  p[$];
    inte, pos;
    e = q[0]; // read the first (left-most) item
    e = q[$]; // read the last (right-most) item
    q[0] = e; // write the first item
    p = q; // read and write entire queue (copy)
    q = { q, 6 }; // insert ’6’ at the end (append 6)
    q = { e, q }; // insert ’e’ at the beginning (prepend e)
    q = q[1:$]; // delete the first (left-most) item
    队列还自带其他操作,如:

    q.size;

    Q.insert(i, e)is equivalent to: Q = {Q[0:i-1], e, Q[i,$]}  在第i个元素前插入一个元素

    Q.delete(i)is equivalent to: Q = {Q[0:i-1], Q[i+1,$]}  删除第i个元素

    e= Q.pop_front()is equivalent to: e = Q[0]; Q = Q[1,$]    提取出第一个元素,并删除

    e = Q.pop_back()is equivalent to: e = Q[$]; Q = Q[0,$-1] 提取出最后一个元素,并删除

    Q.push_front(e)is equivalent to: Q = {e, Q}    在队列头上插入元素e

    Q.push_back(e)is equivalent to: Q = {Q, e}  在队列尾部插入元素e

    关联数组:Associative arrays

    它是一种通过标号来分配空间和访问的数组,其好处就是值分配使用到的特定地址空间,当访问一个较大地址的数据时,SV值针对该地址分配空间。

  • 相关阅读:
    smarty display和fetch的区别 简单
    ERRORLEVEL is not %ERRORLEVEL%
    孟岩 快速掌握一个语言最常用的50%
    Delphi 的用户们,早点开始享受 MSBuild 吧!
    DLL的Export和Import
    WinFX Architecture for developers
    孟岩 技术路线的选择重要但不具有决定性
    科技部基础软件产品重大专项2009年课题(基础软件产品部分 转载)
    nmake vs MSBuild
    关于nmake, build , sources 文件 WDM驱动程序设计之编译安装篇
  • 原文地址:https://www.cnblogs.com/liheng369/p/8610991.html
Copyright © 2011-2022 走看看