OpenCores
URL https://opencores.org/ocsvn/System09/System09/trunk

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [VHDL/] [mul32.vhd] - Blame information for rev 103

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 99 davidgb
--===========================================================================--
2
--                                                                           --
3
--  mul32.vhd - Synthesizable 32 bit Multiplier Register for Spartan 3/3E    --
4
--                                                                           --
5
--===========================================================================--
6 65 davidgb
--
7 99 davidgb
--  File name      : mul32.vhd
8
--
9
--  Entity name    : mul32
10 65 davidgb
--
11 99 davidgb
--  Purpose        : Implements a 32 bit x 32 bit hardware multiplier register
12
--                   with 64 bit result. Consists of 16 x 8 bit registers.
13
--                   Designed for Spartan 3/3E with 18 x 18 bit multiplier blocks. 
14 65 davidgb
--                  
15 99 davidgb
--  Dependencies   : ieee.std_logic_1164
16
--                   ieee.std_logic_unsigned
17
--                   unisim.vcomponents
18
--
19
--  Author         : John E. Kent
20
--
21
--  Email          : dilbert57@opencores.org      
22
--
23
--  Web            : http://opencores.org/project,system09
24
--
25
--  Registers      :
26
-- 
27
--   0 R/W left   input  Most Significant Byte
28
--   1 R/W left   input
29
--   2 R/W left   input
30
--   3 R/W left   input  Least Significant Byte
31
--   4 R/W right  input  Most Significant Byte
32
--   5 R/W right  input
33
--   6 R/W right  input
34
--   7 R/W right  input  Least Significant Byte
35
--   8 R/O result output Most Significant Byte
36
--   9 R/O result output 
37
--  10 R/O result output 
38
--  11 R/O result output 
39
--  12 R/O result output 
40
--  13 R/O result output 
41
--  14 R/O result output 
42
--  15 R/O result output Least Significant Byte
43
--
44
--  Copyright (C) 2008 - 2010 John Kent
45
--
46
--  This program is free software: you can redistribute it and/or modify
47
--  it under the terms of the GNU General Public License as published by
48
--  the Free Software Foundation, either version 3 of the License, or
49
--  (at your option) any later version.
50
--
51
--  This program is distributed in the hope that it will be useful,
52
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
53
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
54
--  GNU General Public License for more details.
55
--
56
--  You should have received a copy of the GNU General Public License
57
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
58
--
59
--===========================================================================--
60
--                                                                           --
61
--                              Revision  History                            --
62
--                                                                           --
63
--===========================================================================--
64
--
65
-- Version  Author        Date         Description
66
--
67
-- 0.1      John Kent     2008-09-07   Initial version
68
--
69
-- 0.2      John Kent     2010-06-17   Header & GPL added
70 65 davidgb
--
71
 
72
library ieee;
73
  use ieee.std_logic_1164.all;
74
  use ieee.std_logic_unsigned.all;
75
library unisim;
76
  use unisim.vcomponents.all;
77
 
78
entity mul32 is
79
        port (
80
         clk       : in  std_logic;
81
    rst       : in  std_logic;
82
    cs        : in  std_logic;
83
    rw        : in  std_logic;
84
    addr      : in  std_logic_vector(3 downto 0);
85
    dati      : in  std_logic_vector(7 downto 0);
86
         dato      : out std_logic_vector(7 downto 0));
87
end entity;
88
 
89 99 davidgb
architecture rtl of mul32 is
90
--
91
-- registers
92 65 davidgb
--
93
signal mul_reg0 : std_logic_vector(7 downto 0);
94
signal mul_reg1 : std_logic_vector(7 downto 0);
95
signal mul_reg2 : std_logic_vector(7 downto 0);
96
signal mul_reg3 : std_logic_vector(7 downto 0);
97
signal mul_reg4 : std_logic_vector(7 downto 0);
98
signal mul_reg5 : std_logic_vector(7 downto 0);
99
signal mul_reg6 : std_logic_vector(7 downto 0);
100
signal mul_reg7 : std_logic_vector(7 downto 0);
101
signal mul_reg8 : std_logic_vector(7 downto 0);
102
signal mul_reg9 : std_logic_vector(7 downto 0);
103
signal mul_reg10 : std_logic_vector(7 downto 0);
104
signal mul_reg11 : std_logic_vector(7 downto 0);
105
signal mul_reg12 : std_logic_vector(7 downto 0);
106
signal mul_reg13 : std_logic_vector(7 downto 0);
107
signal mul_reg14 : std_logic_vector(7 downto 0);
108
signal mul_reg15 : std_logic_vector(7 downto 0);
109
 
110
begin
111
 
112
---------------------------------
113
--
114
-- Write Multiplier Registers
115
--
116
---------------------------------
117
 
118
mul_write : process( clk )
119
begin
120
  if clk'event and clk = '0' then
121
    if rst = '1' then
122
      mul_reg0  <= "00000000";
123
      mul_reg1  <= "00000000";
124
      mul_reg2  <= "00000000";
125
      mul_reg3  <= "00000000";
126
      mul_reg4  <= "00000000";
127
      mul_reg5  <= "00000000";
128
      mul_reg6  <= "00000000";
129
      mul_reg7  <= "00000000";
130
    else
131
           if cs = '1' and rw = '0' then
132
        case addr is
133
             when "0000" =>
134
                    mul_reg0 <= dati;
135
             when "0001" =>
136
                    mul_reg1 <= dati;
137
             when "0010" =>
138
                    mul_reg2 <= dati;
139
             when "0011" =>
140
                    mul_reg3 <= dati;
141
             when "0100" =>
142
                    mul_reg4 <= dati;
143
             when "0101" =>
144
                    mul_reg5 <= dati;
145
             when "0110" =>
146
                    mul_reg6 <= dati;
147
             when "0111" =>
148
                    mul_reg7 <= dati;
149
        when others =>
150
                    null;
151
                  end case;
152
           end if;
153
         end if;
154
  end if;
155
end process;
156 99 davidgb
 
157 65 davidgb
---------------------------------
158
--
159
-- Read Multiplier Registers
160
--
161
---------------------------------
162
 
163
mul_read : process(  addr,
164
                     mul_reg0, mul_reg1, mul_reg2, mul_reg3,
165
                     mul_reg4, mul_reg5, mul_reg6, mul_reg7,
166
                     mul_reg8, mul_reg9, mul_reg10, mul_reg11,
167
                     mul_reg12, mul_reg13, mul_reg14, mul_reg15 )
168
begin
169
      case addr is
170
             when "0000" =>
171
                    dato <= mul_reg0;
172
             when "0001" =>
173
                    dato <= mul_reg1;
174
             when "0010" =>
175
                    dato <= mul_reg2;
176
             when "0011" =>
177
                    dato <= mul_reg3;
178
             when "0100" =>
179
                    dato <= mul_reg4;
180
             when "0101" =>
181
                    dato <= mul_reg5;
182
             when "0110" =>
183
                    dato <= mul_reg6;
184
             when "0111" =>
185
                    dato <= mul_reg7;
186
             when "1000" =>
187
                    dato <= mul_reg8;
188
             when "1001" =>
189
                    dato <= mul_reg9;
190
             when "1010" =>
191
                    dato <= mul_reg10;
192
             when "1011" =>
193
                    dato <= mul_reg11;
194
             when "1100" =>
195
                    dato <= mul_reg12;
196
             when "1101" =>
197
                    dato <= mul_reg13;
198
             when "1110" =>
199
                    dato <= mul_reg14;
200
             when "1111" =>
201
                    dato <= mul_reg15;
202
        when others =>
203
                    null;
204
                end case;
205
 
206
end process;
207 99 davidgb
 
208 65 davidgb
---------------------------------
209
--
210
-- Perform 32 x 32 multiply
211
--
212
---------------------------------
213 99 davidgb
 
214 65 davidgb
my_mul32 : process(
215
                     mul_reg0, mul_reg1, mul_reg2, mul_reg3,
216
                     mul_reg4, mul_reg5, mul_reg6, mul_reg7
217 99 davidgb
                                                         )
218
variable mul_left_hi  : std_logic_vector(17 downto 0);
219
variable mul_left_lo  : std_logic_vector(17 downto 0);
220
variable mul_right_hi : std_logic_vector(17 downto 0);
221
variable mul_right_lo : std_logic_vector(17 downto 0);
222
variable mul_out_0    : std_logic_vector(35 downto 0);
223
variable mul_out_1    : std_logic_vector(35 downto 0);
224
variable mul_out_2    : std_logic_vector(35 downto 0);
225
variable mul_out_3    : std_logic_vector(35 downto 0);
226
variable mul_out      : std_logic_vector(63 downto 0);
227
begin
228
  mul_left_hi  := "00" & mul_reg0 & mul_reg1;
229
  mul_left_lo  := "00" & mul_reg2 & mul_reg3;
230
  mul_right_hi := "00" & mul_reg4 & mul_reg5;
231
  mul_right_lo := "00" &mul_reg6 & mul_reg7;
232
  mul_out_0    := mul_left_hi * mul_right_hi;
233
  mul_out_1    := mul_left_hi * mul_right_lo;
234
  mul_out_2    := mul_left_lo * mul_right_hi;
235
  mul_out_3    := mul_left_lo * mul_right_lo;
236
  mul_out      := (mul_out_0( 31 downto 0) & "0000000000000000" & "0000000000000000") +
237
                  ("0000000000000000" & mul_out_1( 31 downto 0) & "0000000000000000") +
238
                  ("0000000000000000" & mul_out_2( 31 downto 0) & "0000000000000000") +
239
                  ("0000000000000000" & "0000000000000000" & mul_out_3( 31 downto 0));
240
  mul_reg8  <= mul_out(63 downto 56);
241
  mul_reg9  <= mul_out(55 downto 48);
242
  mul_reg10 <= mul_out(47 downto 40);
243
  mul_reg11 <= mul_out(39 downto 32);
244
  mul_reg12 <= mul_out(31 downto 24);
245
  mul_reg13 <= mul_out(23 downto 16);
246
  mul_reg14 <= mul_out(15 downto  8);
247
  mul_reg15 <= mul_out( 7 downto  0);
248
end process;
249 65 davidgb
 
250
end rtl;
251
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.