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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [rtl/] [bigsub.v] - Blame information for rev 59

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

Line No. Rev Author Line
1 3 dgisselq
////////////////////////////////////////////////////////////////////////////////
2
//
3
// Filename:    bigsub.v
4
//
5
// Project:     OpenArty, an entirely open SoC based upon the Arty platform
6
//
7 34 dgisselq
// Purpose:     To subtract two 64-bit numbers, while maintaining
8
//              synchronization to whatever purpose these numbers had
9
//      originally.  For this reason, there is an i_sync input and an o_sync
10
//      output.  If i_sync is true with a particular set of data, o_sync will
11
//      then be true when that data is placed on the output.
12 3 dgisselq
//
13 34 dgisselq
//      If we needed to slow this down even more, I suppose we could register
14
//      the inputs before we used them ...
15
//
16 3 dgisselq
// Creator:     Dan Gisselquist, Ph.D.
17
//              Gisselquist Technology, LLC
18
//
19
////////////////////////////////////////////////////////////////////////////////
20
//
21
// Copyright (C) 2016, Gisselquist Technology, LLC
22
//
23
// This program is free software (firmware): you can redistribute it and/or
24
// modify it under the terms of  the GNU General Public License as published
25
// by the Free Software Foundation, either version 3 of the License, or (at
26
// your option) any later version.
27
//
28
// This program is distributed in the hope that it will be useful, but WITHOUT
29
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
30
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
31
// for more details.
32
//
33
// You should have received a copy of the GNU General Public License along
34
// with this program.  (It's in the $(ROOT)/doc directory, run make with no
35
// target there if the PDF file isn't present.)  If not, see
36
// <http://www.gnu.org/licenses/> for a copy.
37
//
38
// License:     GPL, v3, as defined and found on www.gnu.org,
39
//              http://www.gnu.org/licenses/gpl.html
40
//
41
//
42
////////////////////////////////////////////////////////////////////////////////
43
//
44
//
45
module  bigsub(i_clk, i_sync, i_a, i_b, o_r, o_sync);
46 34 dgisselq
        parameter       NCLOCKS = 1;
47 3 dgisselq
        input                   i_clk, i_sync;
48
        input           [63:0]   i_a, i_b;
49 34 dgisselq
        output  wire    [63:0]   o_r;
50
        output  wire    o_sync;
51 3 dgisselq
 
52 34 dgisselq
        generate
53
        if (NCLOCKS == 0)
54
        begin
55
                assign  o_sync= i_sync;
56
                assign  o_r = i_a - i_b;
57
        end else if (NCLOCKS == 1)
58
        begin
59
                reg             r_sync;
60
                reg     [63:0]   r_out;
61
                always @(posedge i_clk)
62
                        r_sync <= i_sync;
63
                always @(posedge i_clk)
64
                        r_out <= i_a - i_b;
65 3 dgisselq
 
66 34 dgisselq
                assign  o_sync = r_sync;
67
                assign  o_r = r_out;
68
        end else // if (NCLOCKS == 2)
69
        begin
70
                reg             r_sync, r_pps;
71
                reg     [31:0]   r_hi, r_low;
72 3 dgisselq
 
73 34 dgisselq
                reg     [63:0]   f_r;
74
                reg             f_sync;
75 3 dgisselq
 
76 34 dgisselq
                wire    [63:0]   i_b_n;
77
                assign          i_b_n = ~i_b;
78 3 dgisselq
 
79 34 dgisselq
                initial r_sync = 1'b0;
80
                always @(posedge i_clk)
81
                        r_sync <= i_sync;
82
 
83
                always @(posedge i_clk)
84
                        { r_pps, r_low } <= i_a[31:0] + i_b_n[31:0] + 1'b1;
85
                always @(posedge i_clk)
86
                        r_hi <= i_a[63:32] + i_b_n[63:32];
87
 
88
                initial f_sync = 1'b0;
89
                always @(posedge i_clk)
90
                        f_sync <= r_sync;
91
                always @(posedge i_clk)
92
                        f_r[31:0] <= r_low;
93
                always @(posedge i_clk)
94
                        f_r[63:32] <= r_hi + { 31'h00, r_pps };
95
 
96
                assign  o_sync = f_sync;
97
                assign  o_r    = f_r;
98
 
99
        end endgenerate
100
 
101 3 dgisselq
endmodule
102 34 dgisselq
 

powered by: WebSVN 2.1.0

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