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

Subversion Repositories astron_multiplier

[/] [astron_multiplier/] [trunk/] [common_mult.vhd] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 danv
-------------------------------------------------------------------------------
2
--
3
-- Copyright (C) 2011
4
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
5
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
6
--
7
-- This program is free software: you can redistribute it and/or modify
8
-- it under the terms of the GNU General Public License as published by
9
-- the Free Software Foundation, either version 3 of the License, or
10
-- (at your option) any later version.
11
--
12
-- This program is distributed in the hope that it will be useful,
13
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
14
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
-- GNU General Public License for more details.
16
--
17
-- You should have received a copy of the GNU General Public License
18
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
--
20
-------------------------------------------------------------------------------
21
 
22
LIBRARY ieee, common_pkg_lib, common_components_lib;
23
USE ieee.std_logic_1164.ALL;
24
--USE technology_lib.technology_select_pkg.ALL;
25
USE common_pkg_lib.common_pkg.ALL;
26
 
27
-- Function: Default one or more independent products dependent on g_nof_mult
28
--
29
--   If g_nof_mult = 2 then the input vectors are
30
--     a = a(1) & a(0) and b = b(1) & b(0)
31
--   and the independent products in the product vector will be:
32
--     p = a(1)*b(1) & a(0)*b(0)
33
--
34
-- Remarks:
35
-- . When g_out_p_w < g_in_a_w+g_in_b_w then the common_mult truncates the
36
--   MSbit of the product.
37
-- . For c_prod_w = g_in_a_w+g_in_b_w the full product range is preserved. Use
38
--   g_out_p_w = c_prod_w-1 to skip the double sign bit that is only needed
39
--   when the maximum positive product -2**(g_in_a_w-1) * -2**(g_in_b_w-1) has
40
--   to be represented, which is typically not needed in DSP.
41
 
42
ENTITY common_mult IS
43
  GENERIC (
44
    g_technology       : NATURAL  := 0;
45
    g_variant          : STRING   := "IP";
46
    g_in_a_w           : POSITIVE := 18;
47
    g_in_b_w           : POSITIVE := 18;
48
    g_out_p_w          : POSITIVE := 36;      -- c_prod_w = g_in_a_w+g_in_b_w, use smaller g_out_p_w to truncate MSbits, or larger g_out_p_w to extend MSbits
49
    g_nof_mult         : POSITIVE := 1;       -- using 2 for 18x18, 4 for 9x9 may yield better results when inferring * is used
50
    g_pipeline_input   : NATURAL  := 1;        -- 0 or 1
51
    g_pipeline_product : NATURAL  := 1;        -- 0 or 1
52
    g_pipeline_output  : NATURAL  := 1;        -- >= 0
53
    g_representation   : STRING   := "SIGNED"   -- or "UNSIGNED"
54
  );
55
  PORT (
56
    rst        : IN  STD_LOGIC := '0';
57
    clk        : IN  STD_LOGIC;
58
    clken      : IN  STD_LOGIC := '1';
59
    in_a       : IN  STD_LOGIC_VECTOR(g_nof_mult*g_in_a_w-1 DOWNTO 0);
60
    in_b       : IN  STD_LOGIC_VECTOR(g_nof_mult*g_in_b_w-1 DOWNTO 0);
61
    in_val     : IN  STD_LOGIC := '1';        -- only propagate valid, not used internally
62
    out_p      : OUT STD_LOGIC_VECTOR(g_nof_mult*g_out_p_w-1 DOWNTO 0);
63
    out_val    : OUT STD_LOGIC
64
  );
65
END common_mult;
66
 
67
ARCHITECTURE str OF common_mult IS
68
 
69
  CONSTANT c_pipeline        : NATURAL := g_pipeline_input + g_pipeline_product + g_pipeline_output;
70
 
71
  -- Extra output pipelining using common_pipeline is only needed when g_pipeline_output > 1
72
  CONSTANT c_pipeline_output : NATURAL := sel_a_b(g_pipeline_output>0, g_pipeline_output-1, 0);
73
 
74
  SIGNAL result        : STD_LOGIC_VECTOR(out_p'RANGE);                      -- stage dependent on g_pipeline_output  being 0 or 1
75
 
76
BEGIN
77
 
78
  u_mult : ENTITY work.tech_mult
79
  GENERIC MAP(
80
    g_technology       => g_technology,
81
    g_variant          => g_variant,
82
    g_in_a_w           => g_in_a_w,
83
    g_in_b_w           => g_in_b_w,
84
    g_out_p_w          => g_out_p_w,
85
    g_nof_mult         => g_nof_mult,
86
    g_pipeline_input   => g_pipeline_input,
87
    g_pipeline_product => g_pipeline_product,
88
    g_pipeline_output  => g_pipeline_output,
89
    g_representation   => g_representation
90
  )
91
  PORT MAP(
92
    rst        => rst,
93
    clk        => clk,
94
    clken      => clken,
95
    in_a       => in_a,
96
    in_b       => in_b,
97
    out_p      => result
98
  );
99
 
100
  -- Propagate in_val with c_pipeline latency
101
  u_out_val : ENTITY common_components_lib.common_pipeline_sl
102
  GENERIC MAP (
103
    g_pipeline  => c_pipeline
104
  )
105
  PORT MAP (
106
    rst     => rst,
107
    clk     => clk,
108
    clken   => clken,
109
    in_dat  => in_val,
110
    out_dat => out_val
111
  );
112
 
113
  ------------------------------------------------------------------------------
114
  -- Extra output pipelining
115
  ------------------------------------------------------------------------------
116
 
117
  u_output_pipe : ENTITY common_components_lib.common_pipeline  -- pipeline output
118
  GENERIC MAP (
119
    g_representation => g_representation,
120
    g_pipeline       => c_pipeline_output,
121
    g_in_dat_w       => result'LENGTH,
122
    g_out_dat_w      => result'LENGTH
123
  )
124
  PORT MAP (
125
    rst     => rst,
126
    clk     => clk,
127
    clken   => clken,
128
    in_dat  => STD_LOGIC_VECTOR(result),
129
    out_dat => out_p
130
  );
131
 
132
END str;

powered by: WebSVN 2.1.0

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