OpenCores
URL https://opencores.org/ocsvn/multiply-accumulate/multiply-accumulate/trunk

Subversion Repositories multiply-accumulate

[/] [multiply-accumulate/] [trunk/] [mac.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 gubertoli
LIBRARY ieee;
2
USE ieee.std_logic_1164.ALL;
3
USE ieee.numeric_std.ALL;
4
 
5
ENTITY mac IS
6
        GENERIC (n   :   INTEGER := 4); --define X and Y size 
7
        PORT (
8
                ck  : IN  STD_LOGIC;
9
                rst : IN  STD_LOGIC;
10
                X   : IN  SIGNED (n-1 DOWNTO 0); --n
11
                Y   : IN  SIGNED (n-1 DOWNTO 0); --n
12
                A   : OUT SIGNED ((2+2*n)-1 DOWNTO 0)  --2+2n (include two leading bits for overflow)
13
        );
14
END mac;
15
 
16
ARCHITECTURE hdl OF mac IS
17
        SIGNAL acc : SIGNED ((2+2*n)-1 DOWNTO 0) := (OTHERS => '0'); --2+2n
18
 
19
BEGIN
20
 
21
        PROCESS (ck)
22
        BEGIN
23
                IF rising_edge(ck) THEN
24
                        IF rst ='0' THEN --reset accumulator at low
25
                                acc <= (OTHERS => '0');
26
                        ELSE
27
                                acc <= acc + shift_left(X * Y, 1);
28
                        END IF;
29
                END IF;
30
        END PROCESS;
31
 
32
        A <= acc;
33
END hdl;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.