1 |
2 |
petebleack |
-- ***** BEGIN LICENSE BLOCK *****
|
2 |
|
|
--
|
3 |
10 |
petebleack |
-- $Id: ARITHMETIC_UNIT.vhd,v 1.4 2006-10-05 16:17:11 petebleackley Exp $ $Name: not supported by cvs2svn $
|
4 |
2 |
petebleack |
-- *
|
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 |
10 |
petebleack |
-- * Contributor(s): Peter Bleackley (Original author)
|
24 |
2 |
petebleack |
-- *
|
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 |
|
|
library IEEE;
|
39 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
40 |
|
|
use IEEE.STD_LOGIC_ARITH.ALL;
|
41 |
|
|
use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
42 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
43 |
|
|
|
44 |
|
|
-- Uncomment the following lines to use the declarations that are
|
45 |
|
|
-- provided for instantiating Xilinx primitive components.
|
46 |
|
|
--library UNISIM;
|
47 |
|
|
--use UNISIM.VComponents.all;
|
48 |
|
|
|
49 |
10 |
petebleack |
entity ARITHMETIC_UNIT is
|
50 |
2 |
petebleack |
Port ( DIFFERENCE : in std_logic_vector(15 downto 0);
|
51 |
10 |
petebleack |
PROB : in std_logic_vector(7 downto 0);
|
52 |
2 |
petebleack |
LOW : in std_logic_vector(15 downto 0);
|
53 |
|
|
ENABLE : in std_logic;
|
54 |
|
|
RESET : in std_logic;
|
55 |
|
|
CLOCK : in std_logic;
|
56 |
|
|
DIFFERENCE_OUT0 : out std_logic_vector(15 downto 0);
|
57 |
|
|
DIFFERENCE_OUT1 : out std_logic_vector(15 downto 0);
|
58 |
|
|
RESULT_OUT0 : out std_logic_vector(15 downto 0);
|
59 |
|
|
RESULT_OUT1 : out std_logic_vector(15 downto 0);
|
60 |
|
|
DATA_LOAD : out std_logic :='1');
|
61 |
|
|
end ARITHMETIC_UNIT;
|
62 |
|
|
|
63 |
|
|
architecture RTL of ARITHMETIC_UNIT is
|
64 |
5 |
petebleack |
|
65 |
2 |
petebleack |
signal LOW2 : std_logic_vector(16 downto 0);
|
66 |
10 |
petebleack |
signal PRODUCT : std_logic_vector (24 downto 0);
|
67 |
2 |
petebleack |
signal PRODUCT2 : std_logic_vector (16 downto 0);
|
68 |
|
|
signal RESULT : std_logic_vector (16 downto 0);
|
69 |
4 |
petebleack |
signal RESULT0 : std_logic_vector (16 downto 0);
|
70 |
2 |
petebleack |
signal DIFFERENCE1 : std_logic_vector (16 downto 0);
|
71 |
|
|
signal DIFFERENCE2 : std_logic_vector(16 downto 0);
|
72 |
|
|
signal DIFFERENCE3 : std_logic_vector(16 downto 0);
|
73 |
|
|
signal DIFFERENCE4 : std_logic_vector(16 downto 0);
|
74 |
|
|
signal DELAY1 : std_logic;
|
75 |
10 |
petebleack |
-- signal DELAY2 : std_logic;
|
76 |
2 |
petebleack |
signal CALCULATE : std_logic;
|
77 |
|
|
begin
|
78 |
|
|
|
79 |
|
|
-- The arithmetic
|
80 |
|
|
DIFFERENCE2 <= ('0' & DIFFERENCE) + "00000000000000001";
|
81 |
10 |
petebleack |
MULTIPLY : process (CLOCK)
|
82 |
2 |
petebleack |
begin
|
83 |
|
|
if CLOCK'event and CLOCK = '1' then
|
84 |
10 |
petebleack |
if ENABLE = '1' then
|
85 |
|
|
PRODUCT <= DIFFERENCE2 * PROB;
|
86 |
|
|
end if;
|
87 |
2 |
petebleack |
end if;
|
88 |
10 |
petebleack |
end process MULTIPLY;
|
89 |
|
|
|
90 |
|
|
PRODUCT2 <= PRODUCT(24 downto 8);
|
91 |
2 |
petebleack |
RESULT <= LOW2 + PRODUCT2;
|
92 |
|
|
RESULT_OUT1 <= RESULT(15 downto 0);
|
93 |
|
|
RESULT0 <= (RESULT - "00000000000000001");
|
94 |
|
|
RESULT_OUT0 <= RESULT0(15 downto 0);
|
95 |
|
|
DIFFERENCE3 <= (PRODUCT2 - "00000000000000001");
|
96 |
|
|
DIFFERENCE4 <= (DIFFERENCE1 - PRODUCT2);
|
97 |
|
|
DIFFERENCE_OUT1 <= DIFFERENCE4(15 downto 0);
|
98 |
10 |
petebleack |
DIFFERENCE_OUT0 <= DIFFERENCE3(15 downto 0);
|
99 |
2 |
petebleack |
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
-- Control logic
|
103 |
|
|
CALCULATE <= ENABLE and not RESET;
|
104 |
10 |
petebleack |
DATA_LOAD <= DELAY1;-- and DELAY2;
|
105 |
2 |
petebleack |
|
106 |
|
|
-- Sequential control logic
|
107 |
|
|
|
108 |
5 |
petebleack |
DELAYS: process (CLOCK)
|
109 |
|
|
begin
|
110 |
|
|
if CLOCK'event and CLOCK = '1' then
|
111 |
|
|
DELAY1 <= CALCULATE;
|
112 |
10 |
petebleack |
-- DELAY2 <= DELAY1;
|
113 |
|
|
if ENABLE = '1' then
|
114 |
|
|
DIFFERENCE1 <= '0' & DIFFERENCE;
|
115 |
|
|
LOW2 <= '0' & LOW;
|
116 |
|
|
end if;
|
117 |
|
|
|
118 |
5 |
petebleack |
end if;
|
119 |
|
|
end process DELAYS;
|
120 |
2 |
petebleack |
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
end RTL;
|