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

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [rtl/] [lxp32_mul_seq.vhd] - Blame information for rev 9

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 9 ring0_mipt
---------------------------------------------------------------------
2
-- Sequential multiplier
3
--
4
-- Part of the LXP32 CPU
5
--
6
-- Copyright (c) 2016 by Alex I. Kuznetsov
7
--
8
-- The smallest possible multiplier. Implemented using
9
-- an accumulator. One multiplication takes 34 cycles.
10
---------------------------------------------------------------------
11
 
12
library ieee;
13
use ieee.std_logic_1164.all;
14
use ieee.numeric_std.all;
15
 
16
entity lxp32_mul_seq is
17
        port(
18
                clk_i: in std_logic;
19
                rst_i: in std_logic;
20
                ce_i: in std_logic;
21
                op1_i: in std_logic_vector(31 downto 0);
22
                op2_i: in std_logic_vector(31 downto 0);
23
                ce_o: out std_logic;
24
                result_o: out std_logic_vector(31 downto 0)
25
        );
26
end entity;
27
 
28
architecture rtl of lxp32_mul_seq is
29
 
30
signal reg1: unsigned(op1_i'range);
31
signal reg2: unsigned(op2_i'range);
32
signal pp: unsigned(31 downto 0);
33
signal acc_sum: unsigned(31 downto 0);
34
signal cnt: integer range 0 to 32:=0;
35
signal ceo: std_logic:='0';
36
 
37
begin
38
 
39
pp<=reg1 when reg2(0)='1' else (others=>'0');
40
 
41
process (clk_i) is
42
begin
43
        if rising_edge(clk_i) then
44
                if rst_i='1' then
45
                        ceo<='0';
46
                        cnt<=0;
47
                        reg1<=(others=>'-');
48
                        reg2<=(others=>'-');
49
                        acc_sum<=(others=>'-');
50
                else
51
                        if cnt=1 then
52
                                ceo<='1';
53
                        else
54
                                ceo<='0';
55
                        end if;
56
 
57
                        if ce_i='1' then
58
                                cnt<=32;
59
                                reg1<=unsigned(op1_i);
60
                                reg2<=unsigned(op2_i);
61
                                acc_sum<=(others=>'0');
62
                        else
63
                                acc_sum<=acc_sum+pp;
64
                                reg1<=reg1(reg1'high-1 downto 0)&"0";
65
                                reg2<="0"&reg2(reg2'high downto 1);
66
                                if cnt>0 then
67
                                        cnt<=cnt-1;
68
                                end if;
69
                        end if;
70
                end if;
71
        end if;
72
end process;
73
 
74
result_o<=std_logic_vector(acc_sum);
75
ce_o<=ceo;
76
 
77
end architecture;

powered by: WebSVN 2.1.0

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