1 |
2 |
jeunes2 |
-- This file is part of the marca processor.
|
2 |
|
|
-- Copyright (C) 2007 Wolfgang Puffitsch
|
3 |
|
|
|
4 |
|
|
-- This program is free software; you can redistribute it and/or modify it
|
5 |
|
|
-- under the terms of the GNU Library General Public License as published
|
6 |
|
|
-- by the Free Software Foundation; either version 2, or (at your option)
|
7 |
|
|
-- any later version.
|
8 |
|
|
|
9 |
|
|
-- This program is distributed in the hope that it will be useful,
|
10 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12 |
|
|
-- Library General Public License for more details.
|
13 |
|
|
|
14 |
|
|
-- You should have received a copy of the GNU Library General Public
|
15 |
|
|
-- License along with this program; if not, write to the Free Software
|
16 |
|
|
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
17 |
|
|
|
18 |
|
|
-------------------------------------------------------------------------------
|
19 |
|
|
-- MARCA divider
|
20 |
|
|
-------------------------------------------------------------------------------
|
21 |
|
|
-- architecture for a bit-serial divider
|
22 |
|
|
-------------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
-------------------------------------------------------------------------------
|
25 |
|
|
-- Wolfgang Puffitsch
|
26 |
|
|
-- Computer Architecture Lab, Group 3
|
27 |
|
|
-------------------------------------------------------------------------------
|
28 |
|
|
|
29 |
|
|
library IEEE;
|
30 |
|
|
use IEEE.std_logic_1164.all;
|
31 |
|
|
use IEEE.numeric_std.all;
|
32 |
|
|
|
33 |
|
|
use work.marca_pkg.all;
|
34 |
|
|
|
35 |
|
|
architecture behaviour of divider is
|
36 |
|
|
|
37 |
|
|
signal reg_busy : std_logic;
|
38 |
|
|
signal reg_denom : std_logic_vector(2*width-2 downto 0);
|
39 |
|
|
signal reg_remain : std_logic_vector(width-1 downto 0);
|
40 |
|
|
signal reg_quotient : std_logic_vector(width-1 downto 0);
|
41 |
|
|
signal reg_hotbit : std_logic_vector(width-1 downto 0);
|
42 |
|
|
|
43 |
|
|
signal next_busy : std_logic;
|
44 |
|
|
signal next_denom : std_logic_vector(2*width-2 downto 0);
|
45 |
|
|
signal next_remain : std_logic_vector(width-1 downto 0);
|
46 |
|
|
signal next_quotient : std_logic_vector(width-1 downto 0);
|
47 |
|
|
signal next_hotbit : std_logic_vector(width-1 downto 0);
|
48 |
|
|
|
49 |
|
|
begin -- behaviour
|
50 |
|
|
|
51 |
|
|
busy <= reg_busy;
|
52 |
|
|
quotient <= reg_quotient;
|
53 |
|
|
remain <= reg_remain;
|
54 |
|
|
|
55 |
|
|
syn_proc: process (clock, reset)
|
56 |
|
|
begin -- process sync
|
57 |
|
|
|
58 |
|
|
if reset = RESET_ACTIVE then -- asynchronous reset (active low)
|
59 |
|
|
|
60 |
|
|
reg_busy <= '0';
|
61 |
|
|
reg_denom <= (others => '0');
|
62 |
|
|
reg_remain <= (others => '0');
|
63 |
|
|
reg_quotient <= (others => '0');
|
64 |
|
|
reg_hotbit <= (others => '0');
|
65 |
|
|
reg_hotbit(0) <= '1';
|
66 |
|
|
|
67 |
|
|
elsif clock'event and clock = '1' then -- rising clock edge
|
68 |
|
|
|
69 |
|
|
if trigger = '1' then
|
70 |
|
|
reg_denom(2*width-2 downto width-1) <= denom;
|
71 |
|
|
reg_denom(width-2 downto 0) <= (others => '0');
|
72 |
|
|
reg_remain <= numer;
|
73 |
|
|
reg_quotient <= (others => '0');
|
74 |
|
|
reg_hotbit(width-1) <= '1';
|
75 |
|
|
reg_hotbit(width-2 downto 0) <= (others => '0');
|
76 |
|
|
if zero(denom) = '1' then
|
77 |
|
|
exc <= '1';
|
78 |
|
|
reg_busy <= '0';
|
79 |
|
|
else
|
80 |
|
|
exc <= '0';
|
81 |
|
|
reg_busy <= '1';
|
82 |
|
|
end if;
|
83 |
|
|
else
|
84 |
|
|
reg_denom <= next_denom;
|
85 |
|
|
reg_remain <= next_remain;
|
86 |
|
|
reg_quotient <= next_quotient;
|
87 |
|
|
reg_hotbit <= next_hotbit;
|
88 |
|
|
reg_busy <= next_busy;
|
89 |
|
|
exc <= '0';
|
90 |
|
|
end if;
|
91 |
|
|
|
92 |
|
|
end if;
|
93 |
|
|
end process syn_proc;
|
94 |
|
|
|
95 |
|
|
compute: process (reg_denom, reg_remain, reg_quotient, reg_hotbit)
|
96 |
|
|
variable tmp_remain : std_logic_vector(2*width-2 downto 0);
|
97 |
|
|
begin -- process compute
|
98 |
|
|
|
99 |
|
|
next_denom <= '0' & reg_denom(2*width-2 downto 1);
|
100 |
|
|
next_remain <= reg_remain;
|
101 |
|
|
next_quotient <= reg_quotient;
|
102 |
|
|
next_hotbit <= '0' & reg_hotbit(width-1 downto 1);
|
103 |
|
|
|
104 |
|
|
if reg_hotbit(0) = '1' then
|
105 |
|
|
next_hotbit <= reg_hotbit;
|
106 |
|
|
next_busy <= '0';
|
107 |
|
|
else
|
108 |
|
|
next_busy <= '1';
|
109 |
|
|
end if;
|
110 |
|
|
|
111 |
|
|
tmp_remain := std_logic_vector(resize(unsigned(reg_remain), 2*width-1) - unsigned(reg_denom));
|
112 |
|
|
if tmp_remain(2*width-2) = '0' then
|
113 |
|
|
next_remain <= tmp_remain(width-1 downto 0);
|
114 |
|
|
next_quotient <= reg_quotient or reg_hotbit;
|
115 |
|
|
end if;
|
116 |
|
|
|
117 |
|
|
end process compute;
|
118 |
|
|
|
119 |
|
|
end behaviour;
|