当前位置:网站首页>System Verilog - data type
System Verilog - data type
2022-06-25 14:56:00 【Long water and sky】
Catalog
One 、 Built in data type
| Four valued logic type | Binary logic type |
|---|---|
| logic integer reg net-type | byte int longint shortint bit |
| There are sign types | Unsigned type |
|---|---|
| byte integer int longint shortint | logic bit reg net-type |
Tips:
(1) The default value returned by the four value status is x, The default value returned by binary status is 0.
(2)logic Type can only have one driver .
(3) The output of the network is when there is no driver z.
Two 、 Array
1. Fixed width array
Declaration of fixed width array
int array_lo_hi[0:15];//16 It's an integer [0]...[15]
int array_c_style[16];//16 It's an integer [0]...[15]
Declaration of multidimensional array
int array1 [0:7][0:3];// Complete statement
int array2 [8][4];// A compact statement
array1[7][3] = 1;// Set the last element
Initialization of constant array
int ascend[4] = '{
0, 1, 2, 3};// Initialize the four elements
int descend[5];
descend = '{
4, 3, 2, 1, 0};// Assign values to five elements
descend[0:2] = '{
5, 6, 7};// Assign values to the first three elements
ascend = '{
4{
8}};// Assign all four values to 8
ascend = '{
9, 8, default:1};// The assignment is {9,8,1,1,1}
Basic array operations
<1> foreach
Syntax format of multidimensional array traversal
int md[2][3] = '{
'{
0, 1, 2}, '{
3, 4, 5}};
foreach(md[i, j])
$display("md[%0d][%0d]=%0d", i, j, md[i, j]);
For arrays f[0:4] Come on ,foreach(f[i]) Equate to
for(int i=0;i<=4;i++)
For arrays rev[6:2] Come on ,foreach(rev[i]) Equate to
for(int i=6;i>=2; i--)
<2> Copy and compare
dst == src;// hold src All elements of the are copied to dst
Use “?:” Operators for comparison ,
Such as A?B:C, Judge A,A Carry out for real B, Otherwise execution C.
<3> Use of merged and non merged arrays
Merge / Declaration of unconsolidated mixed arrays
bit[3:0][7:0]barray[3];// A non merged array with three merged elements ,3x32 The bit
bit[31:0]lw = 32'h0123_4567;// One word
bit[7:0][3:0]nibbles;// Merge array
barray[0] = lw;// Use a subscript , You can get one word of data
barray[0][3] = 8'h01;// Use two subscripts , You can get a byte of data
barray[0][1][6] = 1'b1;// Use three subscripts , A single bit can be accessed
nibbles = barray[0];// Copy the element values of the merged array
Tips:
(1) When declaring a merged array , The combined bit and array size must be specified before the variable name as part of the data type . The format of the array size definition must be [msb:lsb], instead of [size].
(2) The array declaration specifies the size of the array after the variable name barray[3], This dimension is not merged , So when using this array, there must be at least one subscript .
2. The dynamic array
(1) The width of a dynamic array is not given at compile time like a fixed width array , Instead, specify when the program is running .
(2) The array is empty at the beginning , Need to call new[ ] To allocate space , At the same time, pass the array width in square brackets .
(3) As long as the basic data types are the same , For example, it's all int, Fixed width array and dynamic array can be assigned to each other , With the same number of elements , You can copy the values of a dynamic array to a fixed width array .
int d1[],d2[];// Declare dynamic arrays
initial begin
d1 = new[5];// Assigned to d1 The five elements
foreach(d1[i]) d1[i] = i;// Initialize the element
d2 = d1;// Copy a dynamic array
d2[0] = 5;// Modify the copy value
$display(d1[0], d2[0]);// Display value (0 and 5)
d1 = new[20](d1);// Distribute 20 An integer value and the original d1 The array is copied to the first five elements
d1 = new[100];// Distribute 100 A new integer value , The old value no longer exists
d1.delete();// Delete all elements
end
3. Associative array
Associative arrays can be used to hold elements of sparse matrices , When you address a very large address space , The array only allocates space for the elements actually written , So that the occupied space is very small .
initial begin
bit[63:0]assoc[bit[63:0]], idx = 1;
// Initialize sparsely distributed elements
repeat(64) begin
assoc[idx] = idx;
idx = idx<<1;
end
// Use foreach Traversal array
foreach(assoc[i])
$display("assoc[%h] = %h", i, assoc[i]);
end
4. Array method
- Array reduction method ( Reduce an array to one value )
sum, Sum all the elements in the array .
Besides , also product( product ),and( And ),or( or ),xor( Exclusive or ). - Array positioning method
// Array positioning method min, max, unique
int f[6] = '{
1, 6, 2, 6, 8, 6};
int d[ ] = '{
2, 4, 6, 8, 10};
int q[$] = '{
1, 3, 5, 7}, tq[$];
tq = q.min();//{1}
tq = d.max();//{10}
tq = f.unique();//{1, 6, 2, 8}
// Array positioning method find
int d[ ] = '{
9, 1, 8, 3, 4, 4}, tq[$];
// Find all that are greater than 3 The elements of
tq = d.find with(item >3);//{9, 8, 4, 4}
// Equivalent code
foreach (d[i])
if (d[i])
tq.push_back(d[i]);
tq = d.find_index with(item >3);//{0, 2, 4, 5},( namely 9, 8, 4, 4 Of index)
tq = d.find_first with(item >99);//{ } Can't find
tq = d.find_first_index with(item == 8);//{2} d[2] = 8
// Array positioning method count and total
int count, total, d[ ] = '{
9, 1, 8, 3, 4, 4};
count = d.sum with(item > 7);//2 {9, 8}
total = d.sum with((item > 7) * item);//17 1*9+1*8
count = d.sum with(item < 8);//4 {1, 3, 4, 4}
total = d.sum with(item < 8 ? item :0);//12 1+3+4+4
count = d.sum with(item == 4);//2 {4, 4}
- Sort of array
int d[ ] = '{
9, 1, 8, 3, 4, 4};
d.reverse();// reverse {4, 4, 3, 8, 1, 9}
d.sort();// positive sequence {1, 3, 4, 4, 8, 9}
d.rsort();// The reverse {9, 8, 4, 4, 3, 1}
d.shuffle();// Shuffle {9, 4, 3, 8, 1, 4}
3、 ... and 、 queue
- It combines the advantages of linked list and array , You can add or remove elements anywhere else , And access to any element through the index .
- The queue is declared using subscripts [ $ ], The label of the queue element is from 0 To $.( You can use word subscripts to concatenate ,[ $:2 ] representative [0:2], [1 : $] representative [1:2].)
- Queue not required new[ ] To create space , Just use its method to add or remove elements , At first, the space was 0.
- The queue can pass through push_back() and pop_front() To achieve FIFO.
int j = 1;
q2[$] = {
3, 4};// Queue constants do not need to use "'"
q[$] = {
0, 2, 5};//{0, 2, 5}
initial begin
q.insert(1, j);//{0, 1, 2, 5} stay 2 Insert before 1
q.insert(3, q2);//{0, 1, 2, 3, 4, 5} stay q Insert a queue in
q.delete(1);//{0, 2, 3, 4, 5 } Delete first element
q.push_front(6);//{6, 0, 2, 3, 4, 5} Insert... In front of the queue
j = q.pop_back();//{6, 0, 2, 3, 4} j = 5
q.push_back(8);//{6, 0, 2, 3, 4, 8} Insert... At the end of the queue
j = q.pop_front();//{0, 2, 3 ,4, 8} j = 6
foreach(q[i])
$display(q[i]);// Print the entire queue
q.delete();// Delete the entire queue
end
Four 、 character string
String method
getc(N): return N Bytes at position .
toupper: Returns a string with all uppercase characters .
tolower: Returns a string with all characters in lowercase .
{ }: Used to concatenate strings .
putc(M, C): Put bytes C Write to string M position .
substr(start, end): Extract from position start To end All characters between .
string s;
initial begin
s = "IEEE ";
$display(s.getc(0));//73('I')
$display(s.tolower());//ieee
s.putc(s.len()-1, "-");// Change the space to '-'
s = {
s, "P1800"};//“IEEE-P1800”
$display(s.substr(2, 5));//EE-P
end
边栏推荐
- [untitled]
- Power automatic test system nsat-8000, accurate, high-speed and reliable power test equipment
- 买卖股票的最佳时机
- Character encoding minutes
- Function of getinstance() method
- Iterator failure condition
- Design and implementation of timer
- 全国首例,中国电信 5G 井下人员定位项目正式商用:可实时跟踪位置,保障作业安全
- 移除区间(贪心)
- Kubernetes understands kubectl/ debugging
猜你喜欢

Time stamp calculation and audio-visual synchronization of TS stream combined video by ffmpeg protocol concat

Uniapp icon configuration

‘make_ unique’ is not a member of ‘std’

How to crop GIF dynamic graph? Take this picture online clipping tool

Sequential programming 1

电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备

JS component

JS get the height and width corresponding to the box model (window.getcomputedstyle, dom.getboundingclientrect)

搭建极简GB28181 网守和网关服务器,建立AI推理和3d服务场景,然后开源代码(一)

【中國海洋大學】考研初試複試資料分享
随机推荐
搭建极简GB28181 网守和网关服务器,建立AI推理和3d服务场景,然后开源代码(一)
Kubernetes understands kubectl/ debugging
Modal and modeless dialogs for QT
【Try to Hack】vulnhub DC1
New good friend Pinia, leading the new era of state management
[untitled]
JS to add elements to the header, or tail of an array
QT inline dialog
Why should the coroutine be set to non blocking IO
【中国海洋大学】考研初试复试资料分享
What is the difference between escape, encodeuri and encodeuricomponent?
成员变量与局部变量的区别
15 -- k points closest to the origin
JS recursion and while
Ideal L9 in the eyes of the post-90s: the simplest product philosophy, creating the most popular products
HMS Core机器学习服务实现同声传译,支持中英文互译和多种音色语音播报
QQ情话糖果情话内容获取并保存
弹性布局(display:flex;)属性详解
Yolov3 spp Darknet version to caffemodel and then to OM model
Function of getinstance() method