当前位置:网站首页>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
边栏推荐
- Remove interval (greedy)
- Qlogsystem log system configuration use
- Function of getinstance() method
- QT database connection deletion
- 【中國海洋大學】考研初試複試資料分享
- JS capture, target, bubble phase
- Using Sphinx to automatically generate API documents from py source files
- For the first time in China, Chinatelecom 5g underground personnel positioning project is officially commercial: it can track the position in real time to ensure operation safety
- [Ocean University of China] Data Sharing for retest of initial Examination
- [untitled]
猜你喜欢

【中國海洋大學】考研初試複試資料分享

How to view the Chrome browser plug-in location

QQ情话糖果情话内容获取并保存

JS floating point multiplication and division method can not accurately calculate the problem

From 408 to independent proposition, 211 to postgraduate entrance examination of Guizhou University

Iterator failure condition

Gif动图如何裁剪?收下这个图片在线裁剪工具

Thymeleaf Usage Summary

电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备
![[Ocean University of China] Data Sharing for retest of initial Examination](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[Ocean University of China] Data Sharing for retest of initial Examination
随机推荐
Character encoding minutes
Function of getinstance() method
@Font face fonts only work on their own domain - @font-face fonts only work on their own domain
搭建极简GB28181 网守和网关服务器,建立AI推理和3d服务场景,然后开源代码(一)
Basic usage of markdown (plain text and grammar)
Qmake uses toplevel or topbuilddir
JS recursion and while
如何裁剪动图大小?试试这个在线照片裁剪工具
C language escape character and its meaning
C language LNK2019 unresolved external symbols_ Main error
有哪个瞬间让你觉得这个世界出bug了?
Uniapp icon configuration
电源自动测试系统NSAT-8000,精准高速可靠的电源测试设备
Async await to achieve sleep waiting effect
Build a minimalist gb28181 gatekeeper and gateway server, establish AI reasoning and 3D service scenarios, and then open source code (I)
Iterator failure condition
Open a restaurant
[HBZ sharing] use of locksupport
Clinical Chemistry | 张建中/徐健开发幽门螺杆菌单细胞精准诊疗技术
【深度学习】多任务学习 多个数据集 数据集漏标