OpenCores
URL https://opencores.org/ocsvn/distributed_intelligence/distributed_intelligence/trunk

Subversion Repositories distributed_intelligence

[/] [distributed_intelligence/] [trunk/] [SRC/] [sum_x16.vhd] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 leoel
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: Léo Germond 
4
-- 
5
-- Create Date:    21:11:24 11/05/2009 
6
-- Design Name: 
7
-- Module Name:    add_sub_x16 - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
use IEEE.NUMERIC_STD.ALL;
23
 
24
---- Uncomment the following library declaration if instantiating
25
---- any Xilinx primitives in this code.
26
--library UNISIM;
27
--use UNISIM.VComponents.all;
28
 
29
entity add_sub_x16 is
30
    Port ( dataA : in  STD_LOGIC_VECTOR (15 downto 0);
31
           dataB : in  STD_LOGIC_VECTOR (15 downto 0);
32
           sum : out  STD_LOGIC_VECTOR (15 downto 0);
33
           is_signed : in  STD_LOGIC;
34
                          is_sub : IN std_logic;
35
           overflow : out  STD_LOGIC);
36
end add_sub_x16;
37
 
38
architecture Behavioral of add_sub_x16 is
39
                signal sresult  : SIGNED (16 downto 0);
40
                signal uresult  : UNSIGNED (16 downto 0);
41
                signal tRes: std_logic_vector (16 downto 0); -- somme sur 17 bits 
42
begin
43
 
44
        doAddSub: process (is_sub, is_signed, dataA, dataB)
45
        begin
46
                uresult <=(others => '-');
47
                sresult <=(others => '-');
48
 
49
                if is_signed = '0' then
50
                        if is_sub = '0' then
51
                                uresult <= unsigned('0' & dataA) + unsigned('0' & dataB);
52
                        else
53
                                uresult <= unsigned('0' & dataA) - unsigned('0' & dataB);
54
                        end if;
55
                else
56
                        if is_sub = '0' then
57
                                sresult <= signed(dataA(15) & dataA) + signed(dataB(15) & dataB);
58
                        else
59
                                sresult <= signed(dataA(15) & dataA) - signed(dataB(15) & dataB);
60
                        end if;
61
                end if;
62
        end process;
63
 
64
 
65
        setTRes: process (is_signed, uresult, sresult)
66
        begin
67
                if is_signed = '1' then
68
                        tRes <= std_logic_vector(sresult);
69
                else
70
                        tRes <= std_logic_vector(uresult);
71
                end if;
72
        end process;
73
        sum <= tRes(15 downto 0);
74
 
75
        set_overflow_bit: process(is_signed, is_sub, tRes)
76
        begin
77
                if is_signed = '1' then
78
                        overflow <= tRes(16) xor tRes(15);
79
                else
80
                        overflow <= tRes(16);
81
                end if;
82
        end process;
83
 
84
end Behavioral;

powered by: WebSVN 2.1.0

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