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

Subversion Repositories mod_sim_exp

[/] [mod_sim_exp/] [tags/] [Release_1.0/] [rtl/] [vhdl/] [core/] [adder_n.vhd] - Blame information for rev 100

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 JonasDC
----------------------------------------------------------------------  
2
----  adder_n                                                     ---- 
3 2 JonasDC
----                                                              ---- 
4
----  This file is part of the                                    ----
5
----    Modular Simultaneous Exponentiation Core project          ---- 
6
----    http://www.opencores.org/cores/mod_sim_exp/               ---- 
7
----                                                              ---- 
8
----  Description                                                 ---- 
9
----    This file contains the implementation of a n-bit adder    ----
10 9 JonasDC
----    using adder_blocks, divides the adder in stages           ----
11 3 JonasDC
----    used for the montgommery multiplier pre- and post-        ----
12 2 JonasDC
----    computation adder                                         ---- 
13
----                                                              ---- 
14
----  Dependencies:                                               ---- 
15
----   - adder_block                                              ---- 
16
----                                                              ---- 
17
----  Author(s):                                                  ----
18
----      - Geoffrey Ottoy, DraMCo research group                 ----
19
----      - Jonas De Craene, JonasDC@opencores.org                ---- 
20
----                                                              ---- 
21
---------------------------------------------------------------------- 
22
----                                                              ---- 
23
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG   ---- 
24
----                                                              ---- 
25
---- This source file may be used and distributed without         ---- 
26
---- restriction provided that this copyright statement is not    ---- 
27
---- removed from the file and that any derivative work contains  ---- 
28
---- the original copyright notice and the associated disclaimer. ---- 
29
----                                                              ---- 
30
---- This source file is free software; you can redistribute it   ---- 
31
---- and/or modify it under the terms of the GNU Lesser General   ---- 
32
---- Public License as published by the Free Software Foundation; ---- 
33
---- either version 2.1 of the License, or (at your option) any   ---- 
34
---- later version.                                               ---- 
35
----                                                              ---- 
36
---- This source is distributed in the hope that it will be       ---- 
37
---- useful, but WITHOUT ANY WARRANTY; without even the implied   ---- 
38
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ---- 
39
---- PURPOSE.  See the GNU Lesser General Public License for more ---- 
40
---- details.                                                     ---- 
41
----                                                              ---- 
42
---- You should have received a copy of the GNU Lesser General    ---- 
43
---- Public License along with this source; if not, download it   ---- 
44
---- from http://www.opencores.org/lgpl.shtml                     ---- 
45
----                                                              ---- 
46
----------------------------------------------------------------------
47
 
48 3 JonasDC
library ieee;
49
use ieee.std_logic_1164.all;
50
use ieee.std_logic_arith.all;
51
use ieee.std_logic_unsigned.all;
52 2 JonasDC
 
53 3 JonasDC
library mod_sim_exp;
54
use mod_sim_exp.mod_sim_exp_pkg.all;
55 2 JonasDC
 
56 9 JonasDC
-- n-bit adder using adder blocks. works in stages, to prevent large 
57
-- carry propagation
58 13 JonasDC
-- Result avaiable after (width/block_width) clock cycles
59 2 JonasDC
entity adder_n is
60 3 JonasDC
  generic (
61 9 JonasDC
    width       : integer := 1536; -- adder operands width
62
    block_width : integer := 8     -- adder blocks size
63 3 JonasDC
  );
64
  port (
65 9 JonasDC
    -- clock input
66
    core_clk : in std_logic;
67
    -- adder input operands (width)-bit
68
    a : in std_logic_vector((width-1) downto 0);
69
    b : in std_logic_vector((width-1) downto 0);
70
    -- carry in, out
71
    cin   : in std_logic;
72
    cout  : out std_logic;
73
    -- adder output result (width)-bit
74
    r : out std_logic_vector((width-1) downto 0)
75 3 JonasDC
  );
76 2 JonasDC
end adder_n;
77
 
78 3 JonasDC
 
79 2 JonasDC
architecture Structural of adder_n is
80 9 JonasDC
  constant nr_of_blocks : integer := width/block_width;   -- number of blocks/stages in the adder
81 13 JonasDC
  signal carry : std_logic_vector(nr_of_blocks downto 0); -- vector for the carry bits
82 2 JonasDC
begin
83 9 JonasDC
 
84 13 JonasDC
  -- report failure if width is not dividable by block_width
85
  assert (width mod block_width)=0
86
  report "adder_n: width is not divisible by block_width!!" severity failure;
87
 
88 9 JonasDC
  -- carry in
89 3 JonasDC
  carry(0) <= cin;
90
 
91 9 JonasDC
  -- structure of (nr_of_blocks) adder_blocks
92 3 JonasDC
  adder_block_chain : for i in 0 to (nr_of_blocks-1) generate
93
    adder_blocks : adder_block
94
    generic map(
95
      width => block_width
96
    )
97
    port map(
98
      core_clk => core_clk,
99
      a        => a((((i+1)*block_width)-1) downto (i*block_width)),
100
      b        => b((((i+1)*block_width)-1) downto (i*block_width)),
101
      cin      => carry(i),
102
      cout     => carry(i+1),
103 9 JonasDC
      r        => r((((i+1)*block_width)-1) downto (i*block_width))
104 3 JonasDC
    );
105
  end generate;
106
 
107 9 JonasDC
  -- carry out
108 3 JonasDC
  cout <= carry(nr_of_blocks);
109
 
110 2 JonasDC
end Structural;

powered by: WebSVN 2.1.0

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