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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [bigsmpy.v] - Blame information for rev 3

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

Line No. Rev Author Line
1 3 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    bigsmpy.v
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7
// Purpose:     
8
//
9
// Creator:     Dan Gisselquist, Ph.D.
10
//              Gisselquist Technology, LLC
11
//
12
////////////////////////////////////////////////////////////////////////////////
13
//
14
// Copyright (C) 2015-2016, Gisselquist Technology, LLC
15
//
16
// This program is free software (firmware): you can redistribute it and/or
17
// modify it under the terms of  the GNU General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or (at
19
// your option) any later version.
20
//
21
// This program is distributed in the hope that it will be useful, but WITHOUT
22
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
23
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
24
// for more details.
25
//
26
// You should have received a copy of the GNU General Public License along
27
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
28
// target there if the PDF file isn't present.)  If not, see
29
// <http://www.gnu.org/licenses/> for a copy.
30
//
31
// License:     GPL, v3, as defined and found on www.gnu.org,
32
//              http://www.gnu.org/licenses/gpl.html
33
//
34
//
35
////////////////////////////////////////////////////////////////////////////////
36
//
37
//
38
module  bigsmpy(i_clk, i_sync, i_sgn, i_a, i_b, o_r, o_sync);
39
        input                   i_clk, i_sync, i_sgn;
40
        input           [31:0]   i_a, i_b;
41
        output  reg     [63:0]   o_r;
42
        output  reg             o_sync;
43
 
44
        //
45
        // A pipeline, shift register, to track our synchronization pulse
46
        reg     [3:0]    r_s;
47
 
48
        //
49
        reg             r_mpy_signed;
50
        reg     [31:0]   r_mpy_a_input, r_mpy_b_input;
51
        always @(posedge i_clk)
52
        begin
53
                if (i_sgn)
54
                begin
55
                        r_mpy_a_input <= {(~i_a[31]), i_a[30:0] };
56
                        r_mpy_b_input <= {(~i_b[31]), i_b[30:0] };
57
                end else begin
58
                        r_mpy_a_input <= i_a[31:0];
59
                        r_mpy_b_input <= i_b[31:0];
60
                end
61
 
62
                r_mpy_signed <= i_sgn;
63
                r_s[0] <= i_sync;
64
        end
65
 
66
        reg     [31:0]   pp_f, pp_o, pp_i, pp_l;
67
        reg     [32:0]   pp_s;
68
        always @(posedge i_clk)
69
        begin
70
                pp_f <= r_mpy_a_input[31:16] * r_mpy_b_input[31:16];
71
                pp_o <= r_mpy_a_input[31:16] * r_mpy_b_input[15: 0];
72
                pp_i <= r_mpy_a_input[15: 0] * r_mpy_b_input[31:16];
73
                pp_l <= r_mpy_a_input[15: 0] * r_mpy_b_input[15: 0];
74
 
75
                if (r_mpy_signed)
76
                        pp_s <= 32'h8000_0000 - (r_mpy_a_input[31:0]
77
                                + r_mpy_b_input[31:0]);
78
                else
79
                        pp_s <= 33'h0;
80
                r_s[1] <= r_s[0];
81
        end
82
 
83
        reg     [32:0]   partial_mpy_oi, partial_mpy_lo;
84
        reg     [31:0]   partial_mpy_hi;
85
        always @(posedge i_clk)
86
        begin
87
                partial_mpy_lo[30: 0] <= pp_l[30:0];
88
                partial_mpy_lo[32:31] <= pp_s[0] + pp_l[31];
89
                partial_mpy_oi[32: 0] <= pp_o + pp_i;
90
                partial_mpy_hi[31: 0] <= pp_s[32:1] + pp_f;
91
                r_s[2] <= r_s[1];
92
        end
93
 
94
        reg             partial_mpy_2cl, partial_mpy_2ch;
95
        reg     [31:0]   partial_mpy_2lo, partial_mpy_2hi;
96
        always @(posedge i_clk)
97
        begin
98
                partial_mpy_2lo[15:0] <= partial_mpy_lo[15:0];
99
                { partial_mpy_2cl, partial_mpy_2lo[31:16] }
100
                        <= { 1'b0, partial_mpy_oi[15:0]}+ partial_mpy_lo[32:16];
101
                { partial_mpy_2ch, partial_mpy_2hi[16:0] }
102
                        <= partial_mpy_oi[32:16] + partial_mpy_hi[16:0];
103
                partial_mpy_2hi[31:16] <= { partial_mpy_2hi[31:17], 1'b0 };
104
                r_s[3] <= r_s[2];
105
        end
106
 
107
        always @(posedge i_clk)
108
        begin
109
                o_r[31: 0] <= partial_mpy_2lo[31:0];
110
                o_r[63:32] <= partial_mpy_2hi
111
                        + { 13'h0, partial_mpy_2ch, 1'b0,
112
                                        15'h0, partial_mpy_2cl };
113
                o_sync <= r_s[3];
114
        end
115
 
116
 
117
endmodule

powered by: WebSVN 2.1.0

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