1 |
2 |
petebleack |
-- ***** BEGIN LICENSE BLOCK *****
|
2 |
|
|
--
|
3 |
|
|
-- $Id: ARITHMETIC_UNIT.vhd,v 1.1.1.1 2005-03-30 10:09:49 petebleackley Exp $ $Name: not supported by cvs2svn $
|
4 |
|
|
-- *
|
5 |
|
|
-- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
6 |
|
|
-- *
|
7 |
|
|
-- * The contents of this file are subject to the Mozilla Public License
|
8 |
|
|
-- * Version 1.1 (the "License"); you may not use this file except in compliance
|
9 |
|
|
-- * with the License. You may obtain a copy of the License at
|
10 |
|
|
-- * http://www.mozilla.org/MPL/
|
11 |
|
|
-- *
|
12 |
|
|
-- * Software distributed under the License is distributed on an "AS IS" basis,
|
13 |
|
|
-- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
14 |
|
|
-- * the specific language governing rights and limitations under the License.
|
15 |
|
|
-- *
|
16 |
|
|
-- * The Original Code is BBC Research and Development code.
|
17 |
|
|
-- *
|
18 |
|
|
-- * The Initial Developer of the Original Code is the British Broadcasting
|
19 |
|
|
-- * Corporation.
|
20 |
|
|
-- * Portions created by the Initial Developer are Copyright (C) 2004.
|
21 |
|
|
-- * All Rights Reserved.
|
22 |
|
|
-- *
|
23 |
|
|
-- * Contributor(s): Peter Bleackley (Original author)
|
24 |
|
|
-- *
|
25 |
|
|
-- * Alternatively, the contents of this file may be used under the terms of
|
26 |
|
|
-- * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
|
27 |
|
|
-- * Public License Version 2.1 (the "LGPL"), in which case the provisions of
|
28 |
|
|
-- * the GPL or the LGPL are applicable instead of those above. If you wish to
|
29 |
|
|
-- * allow use of your version of this file only under the terms of the either
|
30 |
|
|
-- * the GPL or LGPL and not to allow others to use your version of this file
|
31 |
|
|
-- * under the MPL, indicate your decision by deleting the provisions above
|
32 |
|
|
-- * and replace them with the notice and other provisions required by the GPL
|
33 |
|
|
-- * or LGPL. If you do not delete the provisions above, a recipient may use
|
34 |
|
|
-- * your version of this file under the terms of any one of the MPL, the GPL
|
35 |
|
|
-- * or the LGPL.
|
36 |
|
|
-- * ***** END LICENSE BLOCK ***** */
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
library IEEE;
|
40 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
41 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
42 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
43 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
44 |
|
|
|
45 |
|
|
-- Uncomment the following lines to use the declarations that are
|
46 |
|
|
-- provided for instantiating Xilinx primitive components.
|
47 |
|
|
--library UNISIM;
|
48 |
|
|
--use UNISIM.VComponents.all;
|
49 |
|
|
|
50 |
|
|
entity ARITHMETIC_UNIT is
|
51 |
|
|
Port ( DIFFERENCE : in std_logic_vector(15 downto 0);
|
52 |
|
|
PROB : in std_logic_vector(9 downto 0);
|
53 |
|
|
LOW : in std_logic_vector(15 downto 0);
|
54 |
|
|
ENABLE : in std_logic;
|
55 |
|
|
RESET : in std_logic;
|
56 |
|
|
CLOCK : in std_logic;
|
57 |
|
|
DIFFERENCE_OUT0 : out std_logic_vector(15 downto 0);
|
58 |
|
|
DIFFERENCE_OUT1 : out std_logic_vector(15 downto 0);
|
59 |
|
|
RESULT_OUT0 : out std_logic_vector(15 downto 0);
|
60 |
|
|
RESULT_OUT1 : out std_logic_vector(15 downto 0);
|
61 |
|
|
DATA_LOAD : out std_logic :='1');
|
62 |
|
|
end ARITHMETIC_UNIT;
|
63 |
|
|
|
64 |
|
|
architecture RTL of ARITHMETIC_UNIT is
|
65 |
|
|
component D_TYPE
|
66 |
|
|
port(D,CLOCK: in std_logic;
|
67 |
|
|
Q: out std_logic);
|
68 |
|
|
end component D_TYPE;
|
69 |
|
|
signal LOW2 : std_logic_vector(16 downto 0);
|
70 |
|
|
signal PRODUCT : std_logic_vector (26 downto 0);
|
71 |
|
|
signal PRODUCT2 : std_logic_vector (16 downto 0);
|
72 |
|
|
signal RESULT : std_logic_vector (16 downto 0);
|
73 |
|
|
signal RESULT0 : std_logic_vector (15 downto 0);
|
74 |
|
|
signal DIFFERENCE1 : std_logic_vector (16 downto 0);
|
75 |
|
|
signal DIFFERENCE2 : std_logic_vector(16 downto 0);
|
76 |
|
|
signal DIFFERENCE3 : std_logic_vector(16 downto 0);
|
77 |
|
|
signal DIFFERENCE4 : std_logic_vector(16 downto 0);
|
78 |
|
|
signal DELAY1 : std_logic;
|
79 |
|
|
signal DELAY2 : std_logic;
|
80 |
|
|
signal CALCULATE : std_logic;
|
81 |
|
|
begin
|
82 |
|
|
|
83 |
|
|
-- The arithmetic
|
84 |
|
|
DIFFERENCE2 <= ('0' & DIFFERENCE) + "00000000000000001";
|
85 |
|
|
MULTIPLY : process (CLOCK, DIFFERENCE2, PROB)
|
86 |
|
|
begin
|
87 |
|
|
if CLOCK'event and CLOCK = '1' then
|
88 |
|
|
PRODUCT <= DIFFERENCE2 * PROB;
|
89 |
|
|
end if;
|
90 |
|
|
end process MULTIPLY;
|
91 |
|
|
PRODUCT2 <= PRODUCT(26 downto 10);
|
92 |
|
|
RESULT <= LOW2 + PRODUCT2;
|
93 |
|
|
RESULT_OUT1 <= RESULT(15 downto 0);
|
94 |
|
|
RESULT0 <= (RESULT - "00000000000000001");
|
95 |
|
|
RESULT_OUT0 <= RESULT0(15 downto 0);
|
96 |
|
|
DIFFERENCE3 <= (PRODUCT2 - "00000000000000001");
|
97 |
|
|
DIFFERENCE4 <= (DIFFERENCE1 - PRODUCT2);
|
98 |
|
|
DIFFERENCE_OUT1 <= DIFFERENCE4(15 downto 0);
|
99 |
|
|
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
|
103 |
|
|
-- Control logic
|
104 |
|
|
CALCULATE <= ENABLE and not RESET;
|
105 |
|
|
DATA_LOAD <= DELAY1 and DELAY2;
|
106 |
|
|
|
107 |
|
|
-- Sequential control logic
|
108 |
|
|
|
109 |
|
|
READ_DELAY: D_TYPE
|
110 |
|
|
port map(D => CALCULATE,
|
111 |
|
|
CLOCK => CLOCK,
|
112 |
|
|
Q => DELAY1);
|
113 |
|
|
|
114 |
|
|
CHECK_DELAY: D_TYPE
|
115 |
|
|
port map(D => DELAY1,
|
116 |
|
|
CLOCK => CLOCK,
|
117 |
|
|
Q => DELAY2);
|
118 |
|
|
|
119 |
|
|
DELAYS: for I in 0 to 15 generate
|
120 |
|
|
|
121 |
|
|
DIFF_DELAY: D_TYPE
|
122 |
|
|
port map(D => DIFFERENCE(I),
|
123 |
|
|
CLOCK => CLOCK,
|
124 |
|
|
Q => DIFFERENCE1(I));
|
125 |
|
|
|
126 |
|
|
LOW_DELAY: D_TYPE
|
127 |
|
|
port map(D => LOW(I),
|
128 |
|
|
CLOCK => CLOCK,
|
129 |
|
|
Q => LOW2(I));
|
130 |
|
|
|
131 |
|
|
OUT_DELAY0: D_TYPE
|
132 |
|
|
port map(D => DIFFERENCE3(I),
|
133 |
|
|
CLOCK => CLOCK,
|
134 |
|
|
Q => DIFFERENCE_OUT0(I));
|
135 |
|
|
|
136 |
|
|
|
137 |
|
|
end generate;
|
138 |
|
|
|
139 |
|
|
LOW2(16) <= '0';
|
140 |
|
|
DIFFERENCE1(16) <= '0';
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
end RTL;
|