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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [adder.vhd] - Blame information for rev 51

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 jguarin200
-- RAYTRAC
2
-- Author Julian Andres Guarin
3
-- adder.vhd
4
-- This file is part of raytrac.
5
-- 
6
--     raytrac is free software: you can redistribute it and/or modify
7
--     it under the terms of the GNU General Public License as published by
8
--     the Free Software Foundation, either version 3 of the License, or
9
--     (at your option) any later version.
10
-- 
11
--     raytrac is distributed in the hope that it will be useful,
12
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
13
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
--     GNU General Public License for more details.
15
-- 
16
--     You should have received a copy of the GNU General Public License
17
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.
18 2 jguarin200
library ieee;
19
use ieee.std_logic_1164.all;
20 27 jguarin200
 
21 2 jguarin200
use work.arithpack.all;
22
entity adder is
23
        generic (
24 27 jguarin200
                width : integer := 4;
25
                carry_logic : string := "CLA";
26
                substractor_selector : string := "YES"
27 2 jguarin200
        );
28
 
29
        port (
30 27 jguarin200
                a,b     : in std_logic_vector(width-1 downto 0);
31
                s,ci    : in std_logic;
32
                result  : out std_logic_vector(width-1 downto 0);
33
                cout    : out std_logic
34 2 jguarin200
        );
35
end adder;
36
 
37
 
38
architecture adder_arch of adder is
39
 
40 27 jguarin200
        signal sa,p,g:  std_logic_vector(width-1 downto 0);
41
        signal sCarry:  std_logic_vector(width downto 1);
42 2 jguarin200
 
43
 
44 27 jguarin200
begin
45
 
46
 
47
 
48
 
49 2 jguarin200
        -- Usual Structural Model / wether or not CLA/RCA is used and wether or not add/sub selector is used, this port is always instanced --
50
 
51
        result(0)<= a(0) xor b(0) xor ci;
52
        wide_adder:
53 27 jguarin200
        if (width>1) generate
54 2 jguarin200
                wide_adder_generate_loop:
55 27 jguarin200
                for i in 1 to width-1 generate
56 2 jguarin200
                        result(i) <= a(i) xor b(i) xor sCarry(i);
57
                end generate wide_adder_generate_loop;
58
        end generate wide_adder;
59 27 jguarin200
        cout <= sCarry(width);
60 2 jguarin200
        g<= sa and b;
61
        p<= sa or b;
62
 
63
 
64
        -- Conditional Instantiation / Adder Substraction Logic --
65
 
66
        adder_sub_logic :       -- adder substractor logic
67
        if substractor_selector = "YES" generate
68
                a_xor_s:
69 27 jguarin200
                for i in 0 to width-1 generate
70 2 jguarin200
                        sa(i) <= a(i) xor s;
71
                end generate a_xor_s;
72
        end generate adder_sub_Logic;
73
 
74
        add_logic:      -- just adder.
75
        if substractor_selector = "NO" generate
76
                sa <= a;
77
        end generate add_logic;
78
 
79
 
80
 
81
        -- Conditional Instantiation / RCA/CLA Logical Blocks Generation --
82
        rca_logic_block_instancing:     -- Ripple Carry Adder
83 27 jguarin200
        if carry_logic="RCA" generate
84 2 jguarin200
                rca_x: rca_logic_block
85 27 jguarin200
                generic map (width=>width)
86 2 jguarin200
                port map (
87
                        p=>p,
88
                        g=>g,
89
                        cin=>ci,
90
                        c=>sCarry
91
                );
92
        end generate rca_logic_block_instancing;
93
 
94
        cla_logic_block_instancing:     -- Carry Lookahead Adder
95
        if carry_logic="CLA" generate
96
                cla_x: cla_logic_block
97 27 jguarin200
                generic map (width=>width)
98 2 jguarin200
                port map (
99
                        p=>p,
100
                        g=>g,
101
                        cin=>ci,
102
                        c=>sCarry
103
                );
104
        end generate cla_logic_block_instancing;
105 27 jguarin200
 
106
 
107 2 jguarin200
 
108 27 jguarin200
 
109
 
110
 
111
 
112
 
113
 
114
 
115
 
116
 
117 2 jguarin200
end adder_arch;
118
 
119
 

powered by: WebSVN 2.1.0

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