SystemVerilog Language

SungchulCHA·2024년 8월 28일
0

System Verilog

목록 보기
2/6

2-State Data Types

bit [msb:lsb] var_name [=initial_value];
default : 0
x or z 값은 0으로

  • byte : 8 bit signed
  • shortint : 16 bit signed
  • int : 32 bit signed
  • logint : 64 bit signed
  • reale : double in C
  • shortreal : float in C
  • realtime : 64 bit 실수, $realtime 으로 사용

4-State Data Types

reg | logic [msb:lsb] variable_name [=initial_value];
default : x

  • integer variable_name [=initial_value]; : 32 bit signed
  • time variable_name [=initial_value]; : 64 bit unsigned
    "ns" 같은 time unit 사용 가능

String Data Type

string variable_name [=initial_value]

  • default : ""
  • $sformat() 시스템 함수로 생성 가능
  • ==, !=, compare(), incompare()
  • itoa(), atoi(), atohex(), toupper(), tolower()
  • len(), getc(), putc(), substr() 등 사용 가능

Enumerated Data Types

  • Define
    typedef enum [data_type] {named constants} enumtype

  • Declare
    enumtype var_name [=initial_value]

default : int 형, '0
name() 함수나 %p 로 ASCII 코드 출력 가능

typedef enum bit[2:0] {IDLE=1, TEST, START} state_e;
state_e current, next = IDLE
$display("current = %0d, next = %s", current, next.name());
$display("next = %p", next);

Data Arrays

Fixed-size Arrays

type array_name[size] [=initial_value]

int b[2] = '{3, 7};

bit[31:0] c[2][3] = '{{3,7,1},{1,2,3}};
byte d[7][2] = '{default:-1};

bit [31:0] a[2][3] = c;  // types and sizes must be same
for(int i=0; i<$dimensions(a), i++;)
  $display($size(a, i+1));  // 2 3 32 출력

Dynamic Arrays

type array_name[] [=initial_value];

logic[7:0] ID[], array[] = new[16];
logic[7:0] data_array[];

ID = new[100];
data_array = new[ID.size()] (ID);  // copy - types muast match

ID = new[ID.size() *2] (ID);
data_array.delete();

Queues

type array_name[$[:bound]] [=initial_value];

  • push_back(), push_front(), insert()
  • pop_back(), pop_front(), delete()
  • new[16]; 사용 안됨
int j = 2;
int q[$] = {0,1,3,6};
int b[$] = {4,5};
q.insert(2, j);  // {0, 2, 3, 6}
q.insert(4, b);  // {0, 1, 2, 3, 4, 5, 6}
q.delete(1);     // {0, 2, 3, 4, 5, 6}
$display("%p", q); // '{0,2,3,4,5,6}

Associative Arrays

type array_name[index_type];

  • first(), next(), prev(), last()
  • num()
  • exists()
byte opcode[string], t[int], ID_aray[bit[15:0]];
int index;

opcode["ADD"] = -8;
for (int i = 0; i < 10; i++)
  t[1<<i] = i;

Loop Support and Reduction Oprators

int data[] = '{1,2,3,4,5,6,7}, qd[$][];
qd.push_back(data);
foreach(data[i])
  $display("data[%0d] = %0d", i, data[i]);
  
$display("sum of array content = %0d", data.sum());
$display("product value is = %0d",     data.product());
$display("and'ed value is = %0d",      data.and());
$display("or'ed value is = %0d",       data.or());
$display("xor'ed value is = %0d",      data.xor());

Array Methods

  • find(), find_index()
program automatic test;
  bit[7:0] SQ_array[$] = {2, 1, 8, 3, 5};
  bit[7:0] SQ[$];
  int idx[$];
  
  initial begin
    SQ = SQ_array.find() with ( item > 3 );  // item is default iterator variable
  
    idx = SQ_aray.find_index(addr) with ( addr > 3 );
  end
endprogram: test
  • find_first(), find_first_index()
program automatic test;
  int array[] = new[5];
  int idx[#], val[$], dyn_2d[][], mixed_2d[$][];
  
  initial begin
    foreach(array[i])
      array[i] = 4 - i;
    
    val = array.find_first() with ( item > 3 );  // val[0] == 4
    idx = array.find_first_index() with ( item < 0 ); // idx == {}
  end
endprogram: test

Unpacked Array Performance

Array TypeApplicationPerformance
Fixed-SizeUse in RTL for FIFO, Memory, Buffer.Best
DynamicRandom read/write access 필요할 때Good
QueueStack, CAM applications, ScoreboardGood
Associatedsparse memory applications 에 유용함. hash tables 만들 때 사용Moderate

Packed Array


Out-of-Bounds Access

int addr[$:4] = {0,1,2,3,4};
addr.push_back(10);
addr[0] = addr[5];

error 발생 안하지만 push_back해도 안되고
addr[5]는 0을 반환


Randomization

$urandom : Return 32 bit unsigned random number
$urandom_range(max, [min]) : Return 32 bit unsigned random number in specified range. min 의 default는 0
randcase : Select a weighted executable statement

randcase
  10 : f1();
  20 : f2();
  50 : x = 100;
  30 : randcase ... endcase;
endcase

User Defined Types

typedef bit [31:0] uint; // define
uint my_var;             // create variable

bit[7:0] payload[];

int temp = $urandom;
payload = new[(temp % 3) + 2];
payload = new[(uint'(temp) % 3) + 2];

Operator

inside

bit [31:0] r1, r2, smpl;
int golden[$] = {3,4,5};

if (smpl inside {[r1:r2]}) ...
if (result inside {1, 2, golden}) ...

x, z는 무시됨
integral expressions 에서는 wildcards(==?) 사용됨

iff

몰라


Subroutine(task and function)

task는 block 가능, function은 불가능

directioneffect
inputcopy value in at beginning - default
outputcopy value out at end
inoutcopy in at beginning and copy out at return
refpass by reference
const refpass by reference but read only

default direction : input
default type : logic

Helpful Debugging Features

function void check();
  static int cnt = 0;
  string message;
  if (!compare(message)) begin
    $display(%m\n[ERROR]%t: %s", $realtime, message);
    $finish;
  end
  $display("[NOTE]%t: %0d Packets passed\n", $realtime, ++cnt);
endfunction: check
profile
Myongji UNIV. B.S. in Electronic Engineering

0개의 댓글