System Verilog

# System Verilog : Array Reduction & Array Ordering Methods

Array reduction methods can be applied to any unpacked array. The “with” clause can be used to specify the item to be used in the reduction.

sum() :
returns the sum of all the array elements.

product() :
returns the product of all the array elements

and() :
returns the bit-wise AND(&) of all the array elements.

or() :
returns the bit-wise OR(|) of all the array elements.

xor() :
returns the logical XOR (^) of all the array elements.

In the above code, sum is the sum of all elements in the array. The execution of xor method has been done on myarr and larr. With larr with clause is used which will add 1 to each element and then do xor.

Array Ordering Methods:
Array ordering methods reorder the elements of any unpacked array (fixed or dynamically sized) except for associative arrays.

reverse() :
It reverses the order of the elements in the array. The `with` clause cannot be specified with this.

sort() :
It sorts the array in ascending order.

rsort() :
It sorts the array in descending order.For both `sort` and `rsort`, the `with` clause (and its expression) is optional when the relational operators (<, >, ==) are defined for the array element type. If a `with` clause is specified, the relational operators(<, >, ==) shall be defined for the type of the expression.

shuffle() :
It randomizes the order of the elements in the array. The `with` clause cannot be specified with this.

3 Comments
1. sharan

September 10, 2014 at 4:37 pm

A very good site for beginners. Could I suggest some more topics ?

• Sini Mukundan

September 11, 2014 at 7:42 pm

Of course!

• sharan

September 15, 2014 at 5:26 pm

Could add differences between like task and function, program and module block?
What can we use inside module and program block and same way, what not to use ?(for example, can we use always block inside program block ,similar to that ).
Please email me if you want further any.
I am fresher so I will encounter these questions. Just sharing

2. Vijaykanth Ch

April 19, 2017 at 11:27 pm

Hi sir/mam,
please upload the testbest bench file for above (module array_order)
program.

3. PARTH GANDHI

April 22, 2017 at 9:05 am

Doubt in example for Array_reduction:
Actual : rxor = larr.xor with ( item + 1); // 11 ^ 01 ^ 11 ^ 01 ^ 11 ^ 11 ^ 11 ^ 01;
Shouldn’t be like : rxor = larr.xor with ( item + 1); // 10 ^ 01 ^ 10 ^ 01 ^ 10 ^ 10 ^ 10 ^ 01;
Please lemme know if there is any mistake in my understanding ?

### Most Popular

VLSI Pro is a professional network of VLSI engineers. Here you can find latest news, helpful articles and more on VLSI technology.

Copyright © 2016 VLSI Pro

To Top