-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNon_restoring_divider.vhd
131 lines (119 loc) · 4.38 KB
/
Non_restoring_divider.vhd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 19.07.2020 16:46:18
-- Design Name:
-- Module Name: Non_restoring_divider - Behavioral
-- Project Name:
-- Target Devices:
-- Tool Versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
use IEEE.NUMERIC_STD.ALL;
-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;
entity Non_restoring_divider is
generic (N: integer := 32);
port (dividend: in std_logic_vector(N-1 downto 0);
divider: in std_logic_vector(N-1 downto 0);
clk, rst: in std_logic;
soa: in std_logic; --StartOfAlgorithm.
quotient: out std_logic_vector(N-1 downto 0);
reminder: out std_logic_vector(N-1 downto 0);
eoa: out std_logic); --EndOfAlgorithm.
end Non_restoring_divider;
architecture Behavioral of Non_restoring_divider is
type statetype is (reset, idle, check_sign, check_after_shift, add, sub, last_check, output);
signal c_j, n_j: integer;
signal c_state, n_state: statetype;
signal c_a_q, n_a_q: std_logic_vector(2*N-1 downto 0);
begin
clk_process:
process(clk)
begin
if (clk='1'and clk'event) then
if (rst = '1') then
c_state <= reset;
c_a_q <= (others =>'0');
c_j <= 0;
else
c_a_q <= n_a_q;
c_state <= n_state;
c_j <= n_j;
end if;
end if;
end process;
state_process:
process(soa, dividend, divider, c_state, c_j, c_a_q)
begin
case c_state is
when reset =>
n_state <= idle;
eoa <= '0';
n_a_q <= c_a_q;
when idle =>
eoa <= '0';
n_j <= 0;
if (soa = '1') then
n_state <= check_sign;--start algorithm.
n_a_q(N-1 downto 0) <= dividend;
n_a_q (2*N-1 downto N) <= (others => '0');
else
n_a_q <= (others=>'0');
n_state <= idle;
end if;
when check_sign =>
n_a_q <= std_logic_vector(shift_left(signed(c_a_q),1));
if (c_a_q(2*N-1) = '0') then
n_state <= sub;
else
n_state <= add;
end if;
when add =>
n_a_q(2*N-1 downto N) <= std_logic_vector(signed(c_a_q(2*N-1 downto N)) + signed(divider));
n_state <= check_after_shift;
when sub =>
n_a_q(2*N-1 downto N) <= std_logic_vector(signed(c_a_q(2*N-1 downto N)) - signed(divider));
n_state <= check_after_shift;
when check_after_shift=>
eoa <= '0';
n_j <= c_j + 1;
if (c_a_q(2*N-1) = '0') then
n_a_q(0) <= '1';
else
n_a_q(0) <= '0';
end if;
if (c_j = N-1) then
n_state <= last_check;
else
n_state <= check_sign;
end if;
when last_check =>
if (c_a_q(2*N-1) = '1') then
n_a_q(2*N-1 downto N) <= std_logic_vector(signed(c_a_q(2*N-1 downto N)) + signed(divider));
else
n_a_q <= c_a_q;
end if;
n_state <= output;
when output=>
eoa <= '1';
n_state <= idle;
end case;
end process;
quotient <= c_a_q (N-1 downto 0);
reminder <= c_a_q (2*N-1 downto N);
end Behavioral;