library ieee;
use ieee.std_logic_1164.all;
entity sum_of_squares is
port (
clk : in std_logic;
rst : in std_logic
);
end entity sum_of_squares;
architecture RTL of sum_of_squares is
type onedarrint is array(integer range<>) of real;
procedure sum_squares(inputarr: in onedarrint; result: out real) is
variable acc: real := 0.0;
begin
for i in inputarr'range loop
acc:= acc + (inputarr(i)*inputarr(i));
end loop;
result := acc;
end procedure sum_squares;
begin
testprocedure : process is
variable variations: onedarrint(0 to 100);
variable sum: real;
begin
-- Initialize array
for i in variations'range loop
variations(i):= real(i);
end loop;
sum_squares(variations,sum);
wait;
end process testprocedure;
use ieee.std_logic_1164.all;
entity sum_of_squares is
port (
clk : in std_logic;
rst : in std_logic
);
end entity sum_of_squares;
architecture RTL of sum_of_squares is
type onedarrint is array(integer range<>) of real;
procedure sum_squares(inputarr: in onedarrint; result: out real) is
variable acc: real := 0.0;
begin
for i in inputarr'range loop
acc:= acc + (inputarr(i)*inputarr(i));
end loop;
result := acc;
end procedure sum_squares;
begin
testprocedure : process is
variable variations: onedarrint(0 to 100);
variable sum: real;
begin
-- Initialize array
for i in variations'range loop
variations(i):= real(i);
end loop;
sum_squares(variations,sum);
wait;
end process testprocedure;
No comments:
Post a Comment