Line 4... |
Line 4... |
---- This file is part of the ----
|
---- This file is part of the ----
|
---- Modular Simultaneous Exponentiation Core project ----
|
---- Modular Simultaneous Exponentiation Core project ----
|
---- http://www.opencores.org/cores/mod_sim_exp/ ----
|
---- http://www.opencores.org/cores/mod_sim_exp/ ----
|
---- ----
|
---- ----
|
---- Description ----
|
---- Description ----
|
---- stepping logic for the pipelined montgomery multiplier ----
|
---- stepping logic to control the pipeline for one ----
|
|
---- montgommery multiplication ----
|
---- ----
|
---- ----
|
---- Dependencies: ----
|
---- Dependencies: ----
|
---- - d_flip_flop ----
|
---- - d_flip_flop ----
|
---- - counter_sync ----
|
---- - counter_sync ----
|
---- ----
|
---- ----
|
Line 50... |
Line 51... |
|
|
library mod_sim_exp;
|
library mod_sim_exp;
|
use mod_sim_exp.mod_sim_exp_pkg.all;
|
use mod_sim_exp.mod_sim_exp_pkg.all;
|
|
|
|
|
|
-- stepping logic for the pipeline, generates the start pulses for the
|
|
-- first stage and keeps track of when the last stages are done
|
entity stepping_logic is
|
entity stepping_logic is
|
generic(
|
generic(
|
n : integer := 1536; -- max nr of steps required to complete a multiplication
|
n : integer := 1536; -- max nr of steps required to complete a multiplication
|
t : integer := 192 -- total nr of steps in the pipeline
|
t : integer := 192 -- total nr of steps in the pipeline
|
);
|
);
|
port(
|
port(
|
core_clk : in std_logic;
|
core_clk : in std_logic; -- clock input
|
start : in std_logic;
|
start : in std_logic; -- start signal for pipeline (one multiplication)
|
reset : in std_logic;
|
reset : in std_logic; -- reset signal
|
t_sel : in integer range 0 to t; -- nr of stages in the pipeline piece
|
t_sel : in integer range 0 to t; -- nr of stages in the pipeline piece
|
n_sel : in integer range 0 to n; -- nr of steps required for a complete multiplication
|
n_sel : in integer range 0 to n; -- nr of steps(bits in operands) required for a complete multiplication
|
start_first_stage : out std_logic;
|
start_first_stage : out std_logic; -- start pulse output for first stage
|
stepping_done : out std_logic
|
stepping_done : out std_logic -- done signal
|
);
|
);
|
end stepping_logic;
|
end stepping_logic;
|
|
|
|
|
architecture Behavioral of stepping_logic is
|
architecture Behavioral of stepping_logic is
|
signal laststeps_in_i : std_logic := '0';
|
|
signal laststeps_out_i : std_logic := '0';
|
-- signals for the first stage control, pulses and counters
|
signal start_stop_in_i : std_logic := '0';
|
signal first_stage_done : std_logic; -- indicates the first stage is done running for this multiplication
|
signal start_stop_out_i : std_logic := '0';
|
signal first_stage_active : std_logic; -- indicates the first stage is active
|
signal steps_in_i : std_logic := '0';
|
signal first_stage_active_d : std_logic; -- delayed version of first_stage_active
|
signal steps_out_i : std_logic := '0';
|
signal start_first_stage_i : std_logic; -- internal version of start_first_stage output
|
signal substeps_in_i : std_logic := '0';
|
|
signal substeps_out_i : std_logic := '0';
|
-- signals for the last stages control and counter
|
signal done_reg_in_i : std_logic := '0';
|
signal last_stages_done : std_logic; -- indicates the last stages are done running for this multiplication
|
signal done_reg_out_i : std_logic := '0';
|
signal last_stages_active : std_logic; -- indicates the last stages are active
|
signal start_first_stage_i : std_logic := '0';
|
signal last_stages_active_d : std_logic; -- delayed version of last_stages_active
|
signal start_i : std_logic := '0';
|
|
|
|
begin
|
begin
|
start_i <= start;
|
|
|
|
-- map outputs
|
-- map outputs
|
start_first_stage <= start_first_stage_i;
|
stepping_done <= last_stages_done;
|
stepping_done <= laststeps_out_i;
|
|
|
|
-- internal signals
|
-- internal signals
|
start_stop_in_i <= start_i or (start_stop_out_i and not steps_out_i);
|
--------------------
|
substeps_in_i <= start_stop_in_i;
|
-- first_stage_active signal gets active from a start pulse
|
steps_in_i <= substeps_out_i;
|
-- inactive from first_stage_done pulse
|
done_reg_in_i <= steps_out_i or (done_reg_out_i and not laststeps_out_i);
|
first_stage_active <= start or (first_stage_active_d and not first_stage_done);
|
laststeps_in_i <= done_reg_in_i;
|
|
start_first_stage_i <= start_i or steps_in_i;
|
-- done signal gets active from a first_stage_done pulse
|
--start_first_stage_i <= steps_in_i;
|
-- inactive from last_stages_done pulse
|
|
last_stages_active <= first_stage_done or (last_stages_active_d and not last_stages_done);
|
|
|
|
-- map start_first_stage_i to output, but also use the initial start pulse
|
|
start_first_stage <= start or start_first_stage_i;
|
|
|
done_reg : d_flip_flop
|
last_stages_active_delay : d_flip_flop
|
port map(
|
port map(
|
core_clk => core_clk,
|
core_clk => core_clk,
|
reset => reset,
|
reset => reset,
|
din => done_reg_in_i,
|
din => last_stages_active,
|
dout => done_reg_out_i
|
dout => last_stages_active_d
|
);
|
);
|
|
|
start_stop_reg : d_flip_flop
|
first_stage_active_delay : d_flip_flop
|
port map(
|
port map(
|
core_clk => core_clk,
|
core_clk => core_clk,
|
reset => reset,
|
reset => reset,
|
din => start_stop_in_i,
|
din => first_stage_active,
|
dout => start_stop_out_i
|
dout => first_stage_active_d
|
);
|
);
|
|
|
-- for counting the last steps
|
-- the counters
|
|
----------------
|
|
|
|
-- for counting the last steps (waiting for the other stages to stop)
|
|
-- counter for keeping track of how many stages are done
|
laststeps_counter : counter_sync
|
laststeps_counter : counter_sync
|
generic map(
|
generic map(
|
max_value => t
|
max_value => t
|
)
|
)
|
port map(
|
port map(
|
reset_value => t_sel,
|
reset_value => t_sel,
|
core_clk => core_clk,
|
core_clk => core_clk,
|
ce => laststeps_in_i,
|
ce => last_stages_active,
|
reset => reset,
|
reset => reset,
|
overflow => laststeps_out_i
|
overflow => last_stages_done
|
);
|
);
|
|
|
-- counter for keeping track of the steps
|
-- counter for keeping track of how many times the first stage is started
|
|
-- counts bits in operand x till operand width then generates pulse on first_stage_done
|
steps_counter : counter_sync
|
steps_counter : counter_sync
|
generic map(
|
generic map(
|
max_value => n
|
max_value => n
|
)
|
)
|
port map(
|
port map(
|
reset_value => (n_sel),
|
reset_value => (n_sel),
|
core_clk => core_clk,
|
core_clk => core_clk,
|
ce => steps_in_i,
|
ce => start_first_stage_i,
|
reset => reset,
|
reset => reset,
|
overflow => steps_out_i
|
overflow => first_stage_done
|
);
|
);
|
|
|
-- makes sure we don't start too early with a new step
|
-- the output (overflow) of this counter starts the first stage every 2 clock cycles
|
substeps_counter : counter_sync
|
substeps_counter : counter_sync
|
generic map(
|
generic map(
|
max_value => 2
|
max_value => 2
|
)
|
)
|
port map(
|
port map(
|
reset_value => 2,
|
reset_value => 2,
|
core_clk => core_clk,
|
core_clk => core_clk,
|
ce => substeps_in_i,
|
ce => first_stage_active,
|
reset => reset,
|
reset => reset,
|
overflow => substeps_out_i
|
overflow => start_first_stage_i
|
);
|
);
|
|
|
end Behavioral;
|
end Behavioral;
|
No newline at end of file
|
No newline at end of file
|