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

Subversion Repositories funbase_ip_library

[/] [funbase_ip_library/] [trunk/] [TUT/] [ip.hwp.accelerator/] [dctqidct/] [1.0/] [hdl/] [common_da/] [Serial_multiplier.vhd] - Blame information for rev 145

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 145 lanttu
------------------------------------------------------------------------------
2
-- Author               : Timo Alho
3
-- e-mail               : timo.a.alho@tut.fi
4
-- Date                 : 14.06.2004 15:03:07
5
-- File                 : Serial_multiplier.vhd
6
-- Design               : 
7
------------------------------------------------------------------------------
8
-- Description  : Serial multiplier (with signed numbers) using shift-and-add
9
-- topology.
10
--
11
-- Two's complement multiplication:
12
-- A sequence of two's complement additions of shifted multiplicands expect for
13
-- last step where the shifted multiplicand corresponfing to MSB must be
14
-- negated.
15
-- Before adding a shifted multiplicand to the partial product, an additional
16
-- bit is added to the left of the partial product using sign extension.
17
--
18
-- Usage: Multiplicand is fed into input accoring to the bits of the
19
-- multiplier (starting with multipliers LSB).
20
--
21
-- Example:
22
--      01011 = 11
23
--  *   01101 = 13
24
--  _________
25
--      01011
26
--     00000
27
--    01011
28
--   01011
29
--  00000
30
--  _________
31
--  010001111 = 143
32
--
33
-- The input sequence in this case should be 11, 0, 11, 11, 0.
34
-- Before the first input value, signal start should be held high during one
35
-- clock cycle. During the last input value, signal last_value should be held
36
-- high. 
37
--
38
------------------------------------------------------------------------------
39
LIBRARY ieee;
40
USE ieee.std_logic_1164.ALL;
41
USE ieee.std_logic_arith.ALL;
42
 
43
ENTITY Serial_multiplier IS
44
   GENERIC(
45
      coeffw_g    : integer := 14;
46
      i_dataw_g   : integer := 18;
47
      round_val_g : integer := 64
48
   );
49
   PORT(
50
      clk        : IN     std_logic;
51
      --last_value must be '1', when last bit (MSB) of multiplier is
52
      --processed
53
      last_value : IN     std_logic;
54
      --multiplicand input
55
      mul_in     : IN     std_logic_vector (coeffw_g-1 DOWNTO 0);
56
      rst_n      : IN     std_logic;
57
      --start = '1' clears the partial result register
58
      start      : IN     std_logic;
59
      --result output
60
      mul_out    : OUT    std_logic_vector (i_dataw_g-1 DOWNTO 0)
61
   );
62
 
63
-- Declarations
64
 
65
END Serial_multiplier ;
66
 
67
--
68
ARCHITECTURE rtl OF Serial_multiplier IS
69
  SIGNAL partial_res_r : std_logic_vector(i_dataw_g DOWNTO 0);
70
                                        -- paritial result is stored here
71
 
72
  SIGNAL extended_input  : signed(coeffw_g DOWNTO 0);
73
  SIGNAL shifted_partres : signed(coeffw_g DOWNTO 0);
74
  SIGNAL sum_out         : signed(coeffw_g DOWNTO 0);
75
 
76
BEGIN
77
 
78
  -- purpose: adds one bit to the left of input using sign extension
79
  -- type   : combinational
80
  -- inputs : mul_in
81
  -- outputs: extended_input
82
  ext_in          : PROCESS (mul_in)
83
  BEGIN  -- PROCESS ext_in
84
    extended_input(coeffw_g)            <= mul_in(coeffw_g-1);  --MSB
85
    extended_input(coeffw_g-1 DOWNTO 0) <= signed(mul_in);
86
  END PROCESS ext_in;
87
 
88
  -- purpose: shifts partial result (arithmeticly) by one
89
  -- type   : combinational
90
  -- inputs : partial_res_r
91
  -- outputs: shifted_partres
92
  sh_partres      : PROCESS (partial_res_r)
93
    VARIABLE temp : signed(coeffw_g DOWNTO 0);
94
  BEGIN
95
    temp := shr(signed(partial_res_r(i_dataw_g DOWNTO i_dataw_g-coeffw_g)),
96
                conv_unsigned(1, 1));
97
    shifted_partres <= temp;
98
  END PROCESS sh_partres;
99
 
100
  -- purpose: adds or subtracts partial result and input
101
  -- type   : combinational
102
  -- inputs : shifted_input, shifted_sum, last_value
103
  -- outputs: sum_out
104
  sum : PROCESS (extended_input, shifted_partres, last_value)
105
  BEGIN  -- PROCESS sum
106
    IF (last_value = '1') THEN
107
      sum_out <= shifted_partres - extended_input;
108
    ELSE
109
      sum_out <= shifted_partres + extended_input;
110
    END IF;
111
  END PROCESS sum;
112
 
113
 
114
  clocked      : PROCESS (clk, rst_n)
115
    VARIABLE i : integer;
116
  BEGIN  -- PROCESS clocked
117
    IF rst_n = '0' THEN                 -- asynchronous reset (active low)
118
      partial_res_r <= (OTHERS => '0');  -- clear partial result register
119
 
120
    ELSIF clk'event AND clk = '1' THEN  -- rising clock edge
121
      IF (start = '1') THEN
122
        --put rounding value into partial result register
123
        partial_res_r <= conv_std_logic_vector(round_val_g, i_dataw_g+1);
124
 
125
      ELSE
126
        --save sum into partial result register
127
        partial_res_r(i_dataw_g DOWNTO i_dataw_g-coeffw_g) <=
128
          conv_std_logic_vector(sum_out, coeffw_g+1);
129
 
130
        FOR i IN i_dataw_g-coeffw_g DOWNTO 1 LOOP
131
          partial_res_r(i-1) <= partial_res_r(i);  --shift last bits
132
        END LOOP;  -- i
133
 
134
      END IF;
135
    END IF;
136
  END PROCESS clocked;
137
 
138
  --MSB of partial result register contains no information!
139
  mul_out <= partial_res_r(i_dataw_g-1 DOWNTO 0);
140
 
141
END rtl;
142
 
143
 
144
 
145
 
146
 
147
 
148
 
149
 
150
 
151
 
152
 
153
 
154
 
155
 
156
 
157
 
158
 
159
 
160
 
161
 
162
 
163
 
164
 
165
 
166
 
167
 

powered by: WebSVN 2.1.0

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