← Back to list

Operator Overloading in VHDL

In this post, we are going to see how you can overload 2 multidimensional arrays in VHDL.

Muhammed Kocaoğlu · 2022-01-02 18:12 · 10 claps · 3.2 min read
#vhdl #fpga #operator-overloading #multidimensional-arrays
Open on Medium ↗

Operator Overloading in VHDL

In this post, we are going to see how you can overload 2 multidimensional arrays in VHDL.

When I work with C++, I often use operator overloading. There are many built-in implementations, for example, commonly used I when I work with STL libraries. With the STL library, you can add 2 vectors with a simple plus sign.

During my implementation of a filter in VHDL, I needed to overload 2 arrays which I did with for loop. However, I thought there must be a way of overloading 2 arrays with a simple plus sign in VHDL. Then I came to realize that, there are also many operator overloading functions in VHDL that are commonly used. For example, we add 2 std_logic_vector, this is also operator overloading.

What I did at this point was to go to the libraries of Synopsis, and IEEE that are found in your Vivado installation directory. I analyzed them and learned how they are implemented.

First, I created a package with the name OperatorOverloading_pkg and defined function prototypes. In the figure below, you can see the functions I have implemented.

In the first function, I overload 2 2D arrays, and in the second 2 3D arrays. array2d and array3D are user-defined data types and can be seen in the figure below.

Now, let’s see the function implementation of some of the prototypes that are defined in the package.

In the figure below, there are 2 inputs with type array2D, and the addition is realized in for loop in a single clock cycle. Here we need to determine the depths of array elements and can be determined as shown in the figure.

Now, let’s see how 3D arrays can be overloaded. Instead of 1 for-loop, we need 2 nested for loops to perform addition.

Let’s see multiplication. In multiplication, the length return values are different from the input length. If we are multiplying 2 1 bytes, the result becomes 2 bytes. In the figure below, we can see how I determined the length of the array.

Finally, I will show you concatenate operator where I concatenate 2 arrays in a single clock.

After we have seen the function implementation, let me show you the simulation results. The inputs are shown in the figure below, I will perform my function implementation on them.

If we concatenate 2 arrays, the result becomes as shown in the figure below.

Now, let’s add 2 arrays.

The important point is here whether this property is synthesizable or not. Let me synthesize and see the result.

Yes, it is synthesizable. The figure above is the resource utilization for the addition of 2 3D arrays.

The complete package, an example application, and a test bench can be found at this link. You can add many more functions if you need them.

If you have any questions, you can ask me on Linkedin.

Github

Linkedin


메타데이터
post_id
670e3d0c2b20
slug
operator-overloading-in-vhdl-670e3d0c2b20
url
https://medium.com/@kocamuha/operator-overloading-in-vhdl-670e3d0c2b20
canonical_url
https://medium.com/@kocamuha/operator-overloading-in-vhdl-670e3d0c2b20
author_url
https://medium.com/@kocamuha
status
ok
fetched_at
2026-07-27 16:19:55