Electronic – VHDL “compile time” math

vhdl

I have a generic VHDL entity and I have this code:

--- in testbench
const bits : integer := 13;          -- number of bits
const pow: integer := 8192;          -- 2^bits
const squared : integer := 67108864; -- pow^2

In where I pass those 3 constants to the entity. What I would really like is something like:

--- in testbench
const bits: integer := 13;

--- in architecture (generic bits:integer)
const pow : integer := 2^bits;
const squared : integer := pow^2;

Since bits is known at synthesis time is there any way to do it without using hardware?

Best Answer

The VHDL power operator is **.

So your code should look like this:

-- in testbench
constant bits    : integer := 13;

-- in architecture
constant pow     : integer := 2**bits;
constant squared : integer := pow**2;