In VHDL gibt es den Begriff der "static expression".
Das klingt zwar so ähnlich wie das C-Schlüsselwort, ist aber etwas
anderes (eher vergleichbar zu constexpr in C++).
Letzendlich heisst es nichts anderes, als daß ein VHDL-Konstrukt
(eigentlich) nicht synthesitierbare Elemente enthalten darf, solange es
so geschrieben wird, daß diese zur Synthesezeit vollständig (in
synthesitierbare Elemente) evaluiert werden können:
1 | architecture rtl of sintab is
|
2 | type sinus_table_type is array(natural range <>) of signed(31 downto 0);
|
3 | function sinus_table(start_value, end_value, step : real) return sinus_table_type is
|
4 | constant table_size : natural :=
|
5 | integer(ieee.math_real.ceil(
|
6 | end_value - start_value) / step);
|
7 | variable sintab : sinus_table_type(0 to table_size - 1);
|
8 | begin
|
9 | for i in sintab'low to sintab'high loop
|
10 | sintab(i) := to_signed(integer(
|
11 | ieee.math_real.sin(start_value + real(i) * step) *
|
12 | 32767.0), sintab(i)'length);
|
13 | end loop;
|
14 | return sintab;
|
15 | end function sinus_table;
|
16 |
|
17 | function isin(sintab : sinus_table_type; us : signed) return signed is
|
18 | variable ret : signed(us'range);
|
19 | begin
|
20 | ret := sintab(to_integer(us mod sintab'length));
|
21 | return ret;
|
22 | end function isin;
|
23 |
|
24 | constant PI : real := 3.1415926;
|
25 | constant stab : sinus_table_type := sinus_table(0.0, 2.0 * PI, 0.01);
|
26 | begin
|
27 | calc : process
|
28 | begin
|
29 | wait until rising_edge(clk);
|
30 | res <= isin(stab, arg);
|
31 | end process calc;
|
32 | end architecture rtl;
|