1 |
3 |
JonasDC |
----------------------------------------------------------------------
|
2 |
|
|
---- x_shift_reg ----
|
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 |
20 |
JonasDC |
---- n bit shift register for the x operand of the multiplier ----
|
10 |
|
|
---- with bit output ----
|
11 |
3 |
JonasDC |
---- ----
|
12 |
|
|
---- Dependencies: none ----
|
13 |
|
|
---- ----
|
14 |
|
|
---- Authors: ----
|
15 |
|
|
---- - Geoffrey Ottoy, DraMCo research group ----
|
16 |
|
|
---- - Jonas De Craene, JonasDC@opencores.org ----
|
17 |
|
|
---- ----
|
18 |
|
|
----------------------------------------------------------------------
|
19 |
|
|
---- ----
|
20 |
|
|
---- Copyright (C) 2011 DraMCo research group and OPENCORES.ORG ----
|
21 |
|
|
---- ----
|
22 |
|
|
---- This source file may be used and distributed without ----
|
23 |
|
|
---- restriction provided that this copyright statement is not ----
|
24 |
|
|
---- removed from the file and that any derivative work contains ----
|
25 |
|
|
---- the original copyright notice and the associated disclaimer. ----
|
26 |
|
|
---- ----
|
27 |
|
|
---- This source file is free software; you can redistribute it ----
|
28 |
|
|
---- and/or modify it under the terms of the GNU Lesser General ----
|
29 |
|
|
---- Public License as published by the Free Software Foundation; ----
|
30 |
|
|
---- either version 2.1 of the License, or (at your option) any ----
|
31 |
|
|
---- later version. ----
|
32 |
|
|
---- ----
|
33 |
|
|
---- This source is distributed in the hope that it will be ----
|
34 |
|
|
---- useful, but WITHOUT ANY WARRANTY; without even the implied ----
|
35 |
|
|
---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----
|
36 |
|
|
---- PURPOSE. See the GNU Lesser General Public License for more ----
|
37 |
|
|
---- details. ----
|
38 |
|
|
---- ----
|
39 |
|
|
---- You should have received a copy of the GNU Lesser General ----
|
40 |
|
|
---- Public License along with this source; if not, download it ----
|
41 |
|
|
---- from http://www.opencores.org/lgpl.shtml ----
|
42 |
|
|
---- ----
|
43 |
|
|
----------------------------------------------------------------------
|
44 |
2 |
JonasDC |
|
45 |
3 |
JonasDC |
library ieee;
|
46 |
|
|
use ieee.std_logic_1164.all;
|
47 |
|
|
use ieee.std_logic_arith.all;
|
48 |
|
|
use ieee.std_logic_unsigned.all;
|
49 |
2 |
JonasDC |
|
50 |
20 |
JonasDC |
-- shift register for the x operand of the multiplier
|
51 |
|
|
-- outputs the lsb of the register or bit at offset according to the
|
52 |
|
|
-- selected pipeline part
|
53 |
2 |
JonasDC |
entity x_shift_reg is
|
54 |
3 |
JonasDC |
generic(
|
55 |
20 |
JonasDC |
n : integer := 1536; -- width of the operands (# bits)
|
56 |
|
|
t : integer := 48; -- total number of stages
|
57 |
|
|
tl : integer := 16 -- lower number of stages
|
58 |
3 |
JonasDC |
);
|
59 |
|
|
port(
|
60 |
20 |
JonasDC |
-- clock input
|
61 |
3 |
JonasDC |
clk : in std_logic;
|
62 |
20 |
JonasDC |
-- x operand in (n-bit)
|
63 |
3 |
JonasDC |
x_in : in std_logic_vector((n-1) downto 0);
|
64 |
20 |
JonasDC |
-- control signals
|
65 |
|
|
reset : in std_logic; -- reset, clears register
|
66 |
|
|
load_x : in std_logic; -- load operand into shift register
|
67 |
|
|
next_x : in std_logic; -- next bit of x
|
68 |
|
|
p_sel : in std_logic_vector(1 downto 0); -- pipeline selection
|
69 |
|
|
-- x operand bit out (serial)
|
70 |
|
|
x_i : out std_logic
|
71 |
3 |
JonasDC |
);
|
72 |
2 |
JonasDC |
end x_shift_reg;
|
73 |
|
|
|
74 |
3 |
JonasDC |
|
75 |
2 |
JonasDC |
architecture Behavioral of x_shift_reg is
|
76 |
20 |
JonasDC |
signal x_reg : std_logic_vector((n-1) downto 0); -- register
|
77 |
|
|
constant s : integer := n/t; -- stage width
|
78 |
3 |
JonasDC |
constant offset : integer := s*tl; -- calculate startbit pos of higher part of pipeline
|
79 |
2 |
JonasDC |
begin
|
80 |
3 |
JonasDC |
|
81 |
2 |
JonasDC |
REG_PROC: process(reset, clk)
|
82 |
|
|
begin
|
83 |
|
|
if reset = '1' then -- Reset, clear the register
|
84 |
20 |
JonasDC |
x_reg <= (others => '0');
|
85 |
2 |
JonasDC |
elsif rising_edge(clk) then
|
86 |
|
|
if load_x = '1' then -- Load_x, load the register with x_in
|
87 |
20 |
JonasDC |
x_reg <= x_in;
|
88 |
2 |
JonasDC |
elsif next_x = '1' then -- next_x, shift to right. LSbit gets lost and zero's are shifted in
|
89 |
20 |
JonasDC |
x_reg((n-2) downto 0) <= x_reg((n-1) downto 1);
|
90 |
2 |
JonasDC |
else -- else remember state
|
91 |
20 |
JonasDC |
x_reg <= x_reg;
|
92 |
2 |
JonasDC |
end if;
|
93 |
|
|
end if;
|
94 |
|
|
end process;
|
95 |
|
|
|
96 |
|
|
with p_sel select -- pipeline select
|
97 |
20 |
JonasDC |
x_i <= x_reg(offset) when "10", -- use bit at offset for high part of pipeline
|
98 |
|
|
x_reg(0) when others; -- use LS bit for lower part of pipeline
|
99 |
2 |
JonasDC |
|
100 |
|
|
end Behavioral;
|