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

powered by: WebSVN 2.1.0

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