bit [msb:lsb] var_name [=initial_value];
default : 0
x or z 값은 0으로
byte
: 8 bit signedshortint
: 16 bit signedint
: 32 bit signedlogint
: 64 bit signedreale
: double
in Cshortreal
: float
in Crealtime
: 64 bit 실수, $realtime
으로 사용reg | logic [msb:lsb] variable_name [=initial_value];
default : x
integer variable_name [=initial_value];
: 32 bit signedtime variable_name [=initial_value];
: 64 bit unsignedstring variable_name [=initial_value]
$sformat()
시스템 함수로 생성 가능==
, !=
, compare()
, incompare()
itoa()
, atoi()
, atohex()
, toupper()
, tolower()
len()
, getc()
, putc()
, substr()
등 사용 가능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);
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 출력
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();
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}
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;
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());
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
Array Type | Application | Performance |
---|---|---|
Fixed-Size | Use in RTL for FIFO, Memory, Buffer. | Best |
Dynamic | Random read/write access 필요할 때 | Good |
Queue | Stack, CAM applications, Scoreboard | Good |
Associated | sparse memory applications 에 유용함. hash tables 만들 때 사용 | Moderate |
int addr[$:4] = {0,1,2,3,4};
addr.push_back(10);
addr[0] = addr[5];
error 발생 안하지만
push_back
해도 안되고
addr[5]
는 0을 반환
$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
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];
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
몰라
task
and function
)task
는 block 가능, function
은 불가능
direction | effect |
---|---|
input | copy value in at beginning - default |
output | copy value out at end |
inout | copy in at beginning and copy out at return |
ref | pass by reference |
const ref | pass by reference but read only |
default direction :
input
default type :logic
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