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

Subversion Repositories raytrac

[/] [raytrac/] [trunk/] [adder.vhd] - Diff between revs 22 and 27

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 22 Rev 27
Line 1... Line 1...
--! @file adder.vhd
-- RAYTRAC
--! @brief Sumador parametrizable.  
-- Author Julian Andres Guarin
 
-- adder.vhd
 
-- This file is part of raytrac.
--! Libreria de definicion de senales y tipos estandares, comportamiento de operadores aritmeticos y logicos.\n Signal and types definition library. This library also defines 
-- 
 
--     raytrac is free software: you can redistribute it and/or modify
 
--     it under the terms of the GNU General Public License as published by
 
--     the Free Software Foundation, either version 3 of the License, or
 
--     (at your option) any later version.
 
-- 
 
--     raytrac is distributed in the hope that it will be useful,
 
--     but WITHOUT ANY WARRANTY; without even the implied warranty of
 
--     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
--     GNU General Public License for more details.
 
-- 
 
--     You should have received a copy of the GNU General Public License
 
--     along with raytrac.  If not, see <http://www.gnu.org/licenses/>.
library ieee;
library ieee;
--! Paquete de definicion estandard de logica. Standard logic definition pack.
 
use ieee.std_logic_1164.all;
use ieee.std_logic_1164.all;
--! Se usaran en esta descripcion los componentes del package arithpack.vhd.\n It will be used in this description the components on the arithpack.vhd package. 
 
use work.arithpack.all;
 
 
 
--! Sumador parametrizable.
use work.arithpack.all;
 
 
--! La entidad es un sumador parametrizable. Las características parametrizables son el ancho de los sumandos, si se usa un circuito ripple carry adder y si se sintetiza una compuerta xor en la entrada que permita la selección de la operación a realizar (suma o resta).
 
--! Las entradas y las salidas son las usuales de un sumador: a y b los sumandos, ci el carry de entrada, cout el carry de salida y el valor de la suma en result. Adicionalmente si se selecciona el parametro substractor_selector como "YES" entonces la entrada s, servirá para seleccionar si el sumador realizará la operacion A+B (s=0) ó A-B (s=0). Finalmente la siguiente tabla sintetiza el comportamiento de la entidad.
 
--! \n\n
 
--! <table>
 
--! <tr><th>substractor_selector</th><th>S</th><th>Operación ejecutada</th></tr> <tr><td>"YES"</td><td>0</td><td>A+B</td></tr> --! <tr><td>"YES"</td><td>1</td><td>A-B</td></tr> <tr><td>Otro valor.</td><td>n/a</td><td>A+B</td></tr></table>
 
 
 
--! El circuito es combinatorio puro y la propagación de las señales hasta el resultado del ultimo carry tiene un tiempo, el cual debe ser considerado para implementar posteriores etapas de pipe en caso de ser necesario.   
 
entity adder is
entity adder is
        generic (
        generic (
                w : integer := 9;       --! Ancho de los sumandos
                width : integer := 4;
                carry_logic : string := "CLA";                  --! Carry logic, seleccione "CLA" para Carry Look Ahead ó "RCA" para Ripple Carry Adder. 
                carry_logic : string := "CLA";
                substractor_selector : string := "YES"  --! Al seleccionar este parametro en "YES" se puede usar el sumador para restar a través de la señal s.
                substractor_selector : string := "YES"
        );
        );
 
 
        port (
        port (
                a,b     : in std_logic_vector(w-1 downto 0);     --! Sumandos
                a,b     : in std_logic_vector(width-1 downto 0);
                s       : in std_logic;                                                 --! Selector Suma / Resta
                s,ci    : in std_logic;
                ci      : in std_logic;                                                 --! Datos Carry In.                                                              
                result  : out std_logic_vector(width-1 downto 0);
                result  : out std_logic_vector(w-1 downto 0);--! Resultado de la suma.
                cout    : out std_logic
                cout    : out std_logic                                         --! Carry out (Overflow).
 
        );
        );
end adder;
end adder;
--! Arquitectura del sumador parametrizable.
 
 
 
--! Si se configura el sumador para que s seleccione si se va a realizar una suma ó una resta, entonces se instanciara para cada bit de la entrada a, una compuerta xor. Por cada bit del operando a se realizará la operación lógica ai xor s. El resultado se almacena en la señal sa. Si por el contrario el sumador está configurado para ignorar el selector s, entonces la señal sa se conecta directamente a la entrada a. 
 
 
 
architecture adder_arch of adder is
architecture adder_arch of adder is
 
 
        signal sa,p,g:  std_logic_vector(w-1 downto 0);
        signal sa,p,g:  std_logic_vector(width-1 downto 0);
        signal sCarry:  std_logic_vector(w downto 1);
        signal sCarry:  std_logic_vector(width downto 1);
 
 
 
 
begin
begin
 
 
 
 
 
 
 
 
        -- Usual Structural Model / wether or not CLA/RCA is used and wether or not add/sub selector is used, this port is always instanced --
        -- Usual Structural Model / wether or not CLA/RCA is used and wether or not add/sub selector is used, this port is always instanced --
 
 
        result(0)<= a(0) xor b(0) xor ci;
        result(0)<= a(0) xor b(0) xor ci;
        wide_adder:
        wide_adder:
        if (w>1) generate
        if (width>1) generate
                wide_adder_generate_loop:
                wide_adder_generate_loop:
                for i in 1 to w-1 generate
                for i in 1 to width-1 generate
                        result(i) <= a(i) xor b(i) xor sCarry(i);
                        result(i) <= a(i) xor b(i) xor sCarry(i);
                end generate wide_adder_generate_loop;
                end generate wide_adder_generate_loop;
        end generate wide_adder;
        end generate wide_adder;
        cout <= sCarry(w);
        cout <= sCarry(width);
        g<= sa and b;
        g<= sa and b;
        p<= sa or b;
        p<= sa or b;
 
 
 
 
        -- Conditional Instantiation / Adder Substraction Logic --
        -- Conditional Instantiation / Adder Substraction Logic --
 
 
        adder_sub_logic :       -- adder substractor logic
        adder_sub_logic :       -- adder substractor logic
        if substractor_selector = "YES" generate
        if substractor_selector = "YES" generate
                a_xor_s:
                a_xor_s:
                for i in 0 to w-1 generate
                for i in 0 to width-1 generate
                        sa(i) <= a(i) xor s;
                        sa(i) <= a(i) xor s;
                end generate a_xor_s;
                end generate a_xor_s;
        end generate adder_sub_Logic;
        end generate adder_sub_Logic;
 
 
        add_logic:      -- just adder.
        add_logic:      -- just adder.
Line 77... Line 79...
 
 
 
 
        -- Conditional Instantiation / RCA/CLA Logical Blocks Generation --
        -- Conditional Instantiation / RCA/CLA Logical Blocks Generation --
        rca_logic_block_instancing:     -- Ripple Carry Adder
        rca_logic_block_instancing:     -- Ripple Carry Adder
        if carry_logic="RCA" generate
        if carry_logic="RCA" generate
                --! Generar un bloque de cálculo de Carry, Ripple Carry Adder. carry_logic = "RCA". 
 
                rca_x: rca_logic_block
                rca_x: rca_logic_block
                generic map (w=>w)
                generic map (width=>width)
                port map (
                port map (
                        p=>p,
                        p=>p,
                        g=>g,
                        g=>g,
                        cin=>ci,
                        cin=>ci,
                        c=>sCarry
                        c=>sCarry
                );
                );
        end generate rca_logic_block_instancing;
        end generate rca_logic_block_instancing;
 
 
        cla_logic_block_instancing:     -- Carry Lookahead Adder
        cla_logic_block_instancing:     -- Carry Lookahead Adder
        if carry_logic="CLA" generate
        if carry_logic="CLA" generate
                --! Generar un bloque de cálculo de Carry, Carry Look Ahead. carry_logic = "CLA".
 
                cla_x: cla_logic_block
                cla_x: cla_logic_block
                generic map (w=>w)
                generic map (width=>width)
                port map (
                port map (
                        p=>p,
                        p=>p,
                        g=>g,
                        g=>g,
                        cin=>ci,
                        cin=>ci,
                        c=>sCarry
                        c=>sCarry
                );
                );
        end generate cla_logic_block_instancing;
        end generate cla_logic_block_instancing;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
end adder_arch;
end adder_arch;
 
 
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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