|
|
|
|
|
|
|
|
|
|
|
|
Array Methods
|
|
|
SystemVerilog provides following build in methods to help with usage of arrays. This methods can be used with fixed, dynamic, queues, and associative arrays. |
|
|
|
|
|
|
|
|
Method
|
Description
|
sum
|
Returns sum of all array elements.
|
product
|
Returns product of all array elements.
|
and
|
Returns bitwise AND (&) of all array elements.
|
or
|
Returns bitwise OR (|) of all array elements.
|
xor
|
Returns bitwise XOR (^) of all array elements.
|
min
|
Returns array element which is minimum of all elements.
|
max
|
Returns array element which is maximum of all elements.
|
unique
|
Returns all elements with unique values.
|
|
|
|
|
|
|
|
|
|
|
|
|
Example : Array Methods
|
|
|
|
|
|
1 module array_methods();
2
3 int data [0:9] = '{1,2,3,6,5,7,8,9,9,2};
4 int queue [$];
5
6 initial begin
7 queue = data.min;
8 $display("Min size element is %0d",queue.pop_front());
9 queue = data.max;
10 $display("Max size element is %0d",queue.pop_front());
11 $display("Sum of array %0d",data.sum);
12 $display("Product of array %0d",data.product);
13 $display("XOR of array %0d",data.xor);
14 $display("AND of array %0d",data.and);
15 $display("OR of array %0d",data.or);
16 end
17
18 endmodule
You could download file array_methods.sv here
|
|
|
|
|
|
Simulation : Array Methods
|
|
|
|
|
|
Min size element is 1
Max size element is 9
Sum of array 52
Product of array 1632960
XOR of array 14
AND of array 0
OR of array 15
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|