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

Subversion Repositories raytrac

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

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 52 jguarin200
 
19
--! Libreria de definici&oacute;n de segnales y tipos estandares, comportamiento de operadores aritmeticos y logicos.\n 
20 2 jguarin200
library ieee;
21 52 jguarin200
--! Paquete de definicion estandard de logica. 
22 2 jguarin200
use ieee.std_logic_1164.all;
23 52 jguarin200
--! Se usaran en esta descripcion los componentes del package arithpack.vhd. 
24 2 jguarin200
use work.arithpack.all;
25
entity adder is
26
        generic (
27 27 jguarin200
                width : integer := 4;
28
                carry_logic : string := "CLA";
29
                substractor_selector : string := "YES"
30 2 jguarin200
        );
31
 
32
        port (
33 27 jguarin200
                a,b     : in std_logic_vector(width-1 downto 0);
34
                s,ci    : in std_logic;
35
                result  : out std_logic_vector(width-1 downto 0);
36
                cout    : out std_logic
37 2 jguarin200
        );
38
end adder;
39
 
40 67 jguarin200
--! @brief      Arquitectura del sumador
41 2 jguarin200
architecture adder_arch of adder is
42
 
43 27 jguarin200
        signal sa,p,g:  std_logic_vector(width-1 downto 0);
44
        signal sCarry:  std_logic_vector(width downto 1);
45 2 jguarin200
 
46
 
47 27 jguarin200
begin
48
 
49
 
50
 
51
 
52 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 --
53
 
54
        result(0)<= a(0) xor b(0) xor ci;
55
        wide_adder:
56 52 jguarin200
 
57
 
58 27 jguarin200
        if (width>1) generate
59 2 jguarin200
                wide_adder_generate_loop:
60 27 jguarin200
                for i in 1 to width-1 generate
61 2 jguarin200
                        result(i) <= a(i) xor b(i) xor sCarry(i);
62
                end generate wide_adder_generate_loop;
63
        end generate wide_adder;
64 27 jguarin200
        cout <= sCarry(width);
65 2 jguarin200
        g<= sa and b;
66
        p<= sa or b;
67
 
68
 
69 67 jguarin200
        --! Si se configura una se&ntilde;al para seleccionar entre suma y resta, se generar&aacute; el circuito a continuaci&oacute;n.
70 2 jguarin200
 
71
        adder_sub_logic :       -- adder substractor logic
72
        if substractor_selector = "YES" generate
73
                a_xor_s:
74 27 jguarin200
                for i in 0 to width-1 generate
75 2 jguarin200
                        sa(i) <= a(i) xor s;
76
                end generate a_xor_s;
77
        end generate adder_sub_Logic;
78
 
79 52 jguarin200
        add_logic:      --!Si no se configura una se&ntilde;al de selecci&oacute;n entonces sencillamente se conecta a a sa.
80 2 jguarin200
        if substractor_selector = "NO" generate
81
                sa <= a;
82
        end generate add_logic;
83
 
84
 
85
 
86
        -- Conditional Instantiation / RCA/CLA Logical Blocks Generation --
87 52 jguarin200
 
88
        --! Si se selecciona un ripple carry adder se instancia el siguiente circuito
89 2 jguarin200
        rca_logic_block_instancing:     -- Ripple Carry Adder
90 27 jguarin200
        if carry_logic="RCA" generate
91 2 jguarin200
                rca_x: rca_logic_block
92 27 jguarin200
                generic map (width=>width)
93 2 jguarin200
                port map (
94
                        p=>p,
95
                        g=>g,
96
                        cin=>ci,
97
                        c=>sCarry
98
                );
99
        end generate rca_logic_block_instancing;
100
 
101 52 jguarin200
        --! Si se selecciona un Carry Lookahead adder se instancia el siguiente circuito
102 2 jguarin200
        cla_logic_block_instancing:     -- Carry Lookahead Adder
103
        if carry_logic="CLA" generate
104
                cla_x: cla_logic_block
105 27 jguarin200
                generic map (width=>width)
106 2 jguarin200
                port map (
107
                        p=>p,
108
                        g=>g,
109
                        cin=>ci,
110
                        c=>sCarry
111
                );
112
        end generate cla_logic_block_instancing;
113 27 jguarin200
 
114 2 jguarin200
 
115
end adder_arch;
116
 
117
 

powered by: WebSVN 2.1.0

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