| 1 |
3 |
JonasDC |
----------------------------------------------------------------------
|
| 2 |
|
|
---- operand_ram ----
|
| 3 |
|
|
---- ----
|
| 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 |
|
|
---- BRAM memory and logic to the store 4 (1536-bit) operands ----
|
| 10 |
|
|
---- for the montgomery multiplier ----
|
| 11 |
|
|
---- ----
|
| 12 |
|
|
---- Dependencies: ----
|
| 13 |
|
|
---- - operand_dp (coregen) ----
|
| 14 |
|
|
---- ----
|
| 15 |
|
|
---- Authors: ----
|
| 16 |
|
|
---- - Geoffrey Ottoy, DraMCo research group ----
|
| 17 |
|
|
---- - Jonas De Craene, JonasDC@opencores.org ----
|
| 18 |
|
|
---- ----
|
| 19 |
|
|
----------------------------------------------------------------------
|
| 20 |
|
|
---- ----
|
| 21 |
|
|
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG ----
|
| 22 |
|
|
---- ----
|
| 23 |
|
|
---- This source file may be used and distributed without ----
|
| 24 |
|
|
---- restriction provided that this copyright statement is not ----
|
| 25 |
|
|
---- removed from the file and that any derivative work contains ----
|
| 26 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
| 27 |
|
|
---- ----
|
| 28 |
|
|
---- This source file is free software; you can redistribute it ----
|
| 29 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
| 30 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
| 31 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
| 32 |
|
|
---- later version. ----
|
| 33 |
|
|
---- ----
|
| 34 |
|
|
---- This source is distributed in the hope that it will be ----
|
| 35 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
| 36 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
| 37 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
| 38 |
|
|
---- details. ----
|
| 39 |
|
|
---- ----
|
| 40 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
| 41 |
|
|
---- Public License along with this source; if not, download it ----
|
| 42 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
| 43 |
|
|
---- ----
|
| 44 |
|
|
----------------------------------------------------------------------
|
| 45 |
2 |
JonasDC |
|
| 46 |
3 |
JonasDC |
library ieee;
|
| 47 |
|
|
use ieee.std_logic_1164.all;
|
| 48 |
|
|
use ieee.std_logic_arith.all;
|
| 49 |
|
|
use ieee.std_logic_unsigned.all;
|
| 50 |
2 |
JonasDC |
|
| 51 |
3 |
JonasDC |
library mod_sim_exp;
|
| 52 |
|
|
use mod_sim_exp.mod_sim_exp_pkg.all;
|
| 53 |
|
|
|
| 54 |
|
|
|
| 55 |
2 |
JonasDC |
entity operand_ram is
|
| 56 |
3 |
JonasDC |
port( -- write_operand_ack voorzien?
|
| 57 |
|
|
-- global ports
|
| 58 |
|
|
collision : out std_logic;
|
| 59 |
|
|
-- bus side connections (32-bit serial)
|
| 60 |
94 |
JonasDC |
bus_clk : in std_logic;
|
| 61 |
3 |
JonasDC |
operand_addr : in std_logic_vector(5 downto 0);
|
| 62 |
|
|
operand_in : in std_logic_vector(31 downto 0);
|
| 63 |
|
|
operand_in_sel : in std_logic_vector(1 downto 0);
|
| 64 |
|
|
result_out : out std_logic_vector(31 downto 0);
|
| 65 |
|
|
write_operand : in std_logic;
|
| 66 |
|
|
-- multiplier side connections (1536 bit parallel)
|
| 67 |
94 |
JonasDC |
core_clk : in std_logic;
|
| 68 |
3 |
JonasDC |
result_dest_op : in std_logic_vector(1 downto 0);
|
| 69 |
|
|
operand_out : out std_logic_vector(1535 downto 0);
|
| 70 |
|
|
operand_out_sel : in std_logic_vector(1 downto 0); -- controlled by bus side
|
| 71 |
|
|
write_result : in std_logic;
|
| 72 |
|
|
result_in : in std_logic_vector(1535 downto 0)
|
| 73 |
|
|
);
|
| 74 |
2 |
JonasDC |
end operand_ram;
|
| 75 |
|
|
|
| 76 |
3 |
JonasDC |
|
| 77 |
2 |
JonasDC |
architecture Behavioral of operand_ram is
|
| 78 |
3 |
JonasDC |
-- port a signals
|
| 79 |
|
|
signal addra : std_logic_vector(5 downto 0);
|
| 80 |
|
|
signal part_enable : std_logic_vector(3 downto 0);
|
| 81 |
|
|
signal wea : std_logic_vector(3 downto 0);
|
| 82 |
|
|
signal write_operand_i : std_logic;
|
| 83 |
|
|
|
| 84 |
|
|
-- port b signals
|
| 85 |
94 |
JonasDC |
signal addrb : std_logic_vector(1 downto 0);
|
| 86 |
3 |
JonasDC |
signal web : std_logic_vector(0 downto 0);
|
| 87 |
94 |
JonasDC |
signal douta0 : std_logic_vector(31 downto 0);
|
| 88 |
|
|
signal douta1 : std_logic_vector(31 downto 0);
|
| 89 |
|
|
signal douta2 : std_logic_vector(31 downto 0);
|
| 90 |
3 |
JonasDC |
|
| 91 |
2 |
JonasDC |
begin
|
| 92 |
3 |
JonasDC |
|
| 93 |
2 |
JonasDC |
-- WARNING: Very Important!
|
| 94 |
|
|
-- wea & web signals must never be high at the same time !!
|
| 95 |
|
|
-- web has priority
|
| 96 |
|
|
write_operand_i <= write_operand and not write_result;
|
| 97 |
|
|
web(0) <= write_result;
|
| 98 |
|
|
collision <= write_operand and write_result;
|
| 99 |
|
|
|
| 100 |
|
|
-- the dual port ram has a depth of 4 (each layer contains an operand)
|
| 101 |
|
|
-- result is always stored in position 3
|
| 102 |
|
|
-- doutb is always result
|
| 103 |
94 |
JonasDC |
with write_result select
|
| 104 |
|
|
addrb <= result_dest_op when '1',
|
| 105 |
|
|
operand_out_sel when others;
|
| 106 |
2 |
JonasDC |
|
| 107 |
94 |
JonasDC |
|
| 108 |
|
|
|
| 109 |
2 |
JonasDC |
with operand_addr(5 downto 4) select
|
| 110 |
3 |
JonasDC |
part_enable <= "0001" when "00",
|
| 111 |
|
|
"0010" when "01",
|
| 112 |
|
|
"0100" when "10",
|
| 113 |
|
|
"1000" when others;
|
| 114 |
94 |
JonasDC |
|
| 115 |
|
|
with write_operand select
|
| 116 |
|
|
wea <= part_enable when '1',
|
| 117 |
|
|
"0000" when others;
|
| 118 |
|
|
|
| 119 |
|
|
addra <= operand_in_sel & operand_addr(3 downto 0);
|
| 120 |
90 |
JonasDC |
|
| 121 |
2 |
JonasDC |
with operand_addr(5 downto 4) select
|
| 122 |
94 |
JonasDC |
result_out <= douta0 when "00",
|
| 123 |
|
|
douta1 when "01",
|
| 124 |
|
|
douta2 when others;
|
| 125 |
2 |
JonasDC |
|
| 126 |
3 |
JonasDC |
-- 3 instances of a dual port ram to store the parts of the operand
|
| 127 |
|
|
op_0 : operand_dp
|
| 128 |
|
|
port map (
|
| 129 |
94 |
JonasDC |
clka => bus_clk,
|
| 130 |
3 |
JonasDC |
wea => wea(0 downto 0),
|
| 131 |
|
|
addra => addra,
|
| 132 |
|
|
dina => operand_in,
|
| 133 |
94 |
JonasDC |
douta => douta0,
|
| 134 |
|
|
clkb => core_clk,
|
| 135 |
3 |
JonasDC |
web => web,
|
| 136 |
|
|
addrb => addrb,
|
| 137 |
|
|
dinb => result_in(511 downto 0),
|
| 138 |
94 |
JonasDC |
doutb => operand_out(511 downto 0)
|
| 139 |
3 |
JonasDC |
);
|
| 140 |
2 |
JonasDC |
|
| 141 |
3 |
JonasDC |
op_1 : operand_dp
|
| 142 |
|
|
port map (
|
| 143 |
94 |
JonasDC |
clka => bus_clk,
|
| 144 |
3 |
JonasDC |
wea => wea(1 downto 1),
|
| 145 |
|
|
addra => addra,
|
| 146 |
|
|
dina => operand_in,
|
| 147 |
94 |
JonasDC |
douta => douta1,
|
| 148 |
|
|
clkb => core_clk,
|
| 149 |
3 |
JonasDC |
web => web,
|
| 150 |
|
|
addrb => addrb,
|
| 151 |
|
|
dinb => result_in(1023 downto 512),
|
| 152 |
94 |
JonasDC |
doutb => operand_out(1023 downto 512)
|
| 153 |
3 |
JonasDC |
);
|
| 154 |
|
|
|
| 155 |
|
|
op_2 : operand_dp
|
| 156 |
|
|
port map (
|
| 157 |
94 |
JonasDC |
clka => bus_clk,
|
| 158 |
3 |
JonasDC |
wea => wea(2 downto 2),
|
| 159 |
|
|
addra => addra,
|
| 160 |
|
|
dina => operand_in,
|
| 161 |
94 |
JonasDC |
douta => douta2,
|
| 162 |
|
|
clkb => core_clk,
|
| 163 |
3 |
JonasDC |
web => web,
|
| 164 |
|
|
addrb => addrb,
|
| 165 |
|
|
dinb => result_in(1535 downto 1024),
|
| 166 |
94 |
JonasDC |
doutb => operand_out(1535 downto 1024)
|
| 167 |
3 |
JonasDC |
);
|
| 168 |
|
|
|
| 169 |
2 |
JonasDC |
end Behavioral;
|