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

Subversion Repositories rv01_riscv_core

[/] [rv01_riscv_core/] [trunk/] [VHDL/] [RV01_adder_f.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 madsilicon
-----------------------------------------------------------------
2
--                                                             --
3
-----------------------------------------------------------------
4
--                                                             --
5
-- Copyright (C) 2015 Stefano Tonello                          --
6
--                                                             --
7
-- This source file may be used and distributed without        --
8
-- restriction provided that this copyright statement is not   --
9
-- removed from the file and that any derivative work contains --
10
-- the original copyright notice and the associated disclaimer.--
11
--                                                             --
12
-- THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY         --
13
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED   --
14
-- TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS   --
15
-- FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR      --
16
-- OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,         --
17
-- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES    --
18
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE   --
19
-- GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR        --
20
-- BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  --
21
-- LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT  --
22
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT  --
23
-- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE         --
24
-- POSSIBILITY OF SUCH DAMAGE.                                 --
25
--                                                             --
26
-----------------------------------------------------------------
27
 
28
---------------------------------------------------------------
29
-- 'Fast' adder (carry-select style)
30
---------------------------------------------------------------
31
 
32
library IEEE;
33
use IEEE.std_logic_1164.all;
34
use IEEE.numeric_std.all;
35
 
36
entity RV01_ADDER_F is
37
  generic(
38
    LEN1 : integer := 16;
39
    LEN2 : integer := 16
40
  );
41
  port(
42
    OPA_i : in signed(LEN1+LEN2-1 downto 0);
43
    OPB_i : in signed(LEN1+LEN2-1 downto 0);
44
    CI_i : in std_logic;
45
 
46
    SUM_o : out signed(LEN1+LEN2-1 downto 0)
47
  );
48
end RV01_ADDER_F;
49
 
50
architecture ARC of RV01_ADDER_F is
51
 
52
begin
53
 
54
  process(OPA_i,OPB_i,CI_i)
55
    variable A_LO,B_LO : signed(LEN1-1 downto 0);
56
    variable A_HI,B_HI : signed(LEN2-1 downto 0);
57
    variable SUM_LO : signed(LEN1+1 downto 0);
58
    variable SUM_HI0,SUM_HI1 : signed(LEN2 downto 0);
59
  begin
60
 
61
    A_LO := OPA_i(LEN1-1 downto 0);
62
    A_HI := OPA_i(LEN2+LEN1-1 downto LEN1);
63
 
64
    B_LO := OPB_i(LEN1-1 downto 0);
65
    B_HI := OPB_i(LEN2+LEN1-1 downto LEN1);
66
 
67
    -- low parts sum
68
    SUM_LO := ('0' & A_LO & '1') + ('0' & B_LO & CI_i);
69
 
70
    -- high parts sum (assuming carry-out is zero)
71
    SUM_HI0 := (A_HI & '0') + (B_HI & '0');
72
 
73
    -- high parts sum (assuming carry-out is one)
74
    SUM_HI1 := (A_HI & '1') + (B_HI & '1');
75
 
76
    -- SUM_o low part is low parts sum
77
    SUM_o(LEN1-1 downto 0) <= SUM_LO(LEN1 downto 1);
78
 
79
    -- select SUM_o high part according to low parts sum carry-out
80
    if(SUM_LO(LEN1+1) = '1') then
81
      SUM_o(LEN2+LEN1-1 downto LEN1) <= SUM_HI1(LEN2 downto 1);
82
    else
83
      SUM_o(LEN2+LEN1-1 downto LEN1) <= SUM_HI0(LEN2 downto 1);
84
    end if;
85
 
86
  end process;
87
 
88
end ARC;

powered by: WebSVN 2.1.0

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