mac.vhd 1017 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.std_logic_arith.ALL;
  4. use IEEE.std_logic_textio.ALL;
  5. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  6. use work.myPackage.ALL;
  7. -- Uncomment the following library declaration if using
  8. -- arithmetic functions with Signed or Unsigned values
  9. --use IEEE.NUMERIC_STD.ALL;
  10. -- Uncomment the following library declaration if instantiating
  11. -- any Xilinx leaf cells in this code.
  12. --library UNISIM;
  13. --use UNISIM.VComponents.all;
  14. entity mac is
  15. Port ( inputs : in dataVector;
  16. weights : in dataVector;
  17. bias : in dataType;
  18. outp : out dataType;
  19. clk: in STD_LOGIC);
  20. end mac;
  21. architecture Behavioral of mac is
  22. begin
  23. MAIN: process(clk)
  24. variable sum : dataType;
  25. begin
  26. if rising_edge(clk) then
  27. sum := bias;
  28. for i in 0 to nNodes-1 loop
  29. sum := signed(sum) + conv_integer(signed(inputs(i))) * conv_integer(signed(weights(i)));
  30. end loop;
  31. outp <= sum;
  32. end if;
  33. end process;
  34. end Behavioral;