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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [BCDSub8NClk.sv] - Blame information for rev 67

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

Line No. Rev Author Line
1 66 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2012-2022  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch@finitron.ca
7
//       ||
8
//
9
//      BCDSub8NClk.sv
10
//
11
// BSD 3-Clause License
12
// Redistribution and use in source and binary forms, with or without
13
// modification, are permitted provided that the following conditions are met:
14
//
15
// 1. Redistributions of source code must retain the above copyright notice, this
16
//    list of conditions and the following disclaimer.
17
//
18
// 2. Redistributions in binary form must reproduce the above copyright notice,
19
//    this list of conditions and the following disclaimer in the documentation
20
//    and/or other materials provided with the distribution.
21
//
22
// 3. Neither the name of the copyright holder nor the names of its
23
//    contributors may be used to endorse or promote products derived from
24
//    this software without specific prior written permission.
25
//
26
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
30
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
//
37
// ============================================================================
38
//
39
// The following added breaks up the carry chain.
40
//
41
// The adder is organized into three rows and N*2 columns of digits. The first
42
// row is set to the input a, b operands. The carry for the first row and column
43
// is set to the carry input. The operands in a row are added without taking
44
// carry into consideration. But the carry out is recorded and added as the 'B'
45
// operand in the next row. The sum from one row is fed as the 'A' operand into
46
// the next row. Values (sum and carry) are moved between rows in a clocked
47
// fashion. The first row contains full BCD adders. After that only a single
48
// bit is added.
49
//
50
// There cannot be more than three rows required. The worst case scenario occurs
51
// when all the inputs are at a max and there is a carry input. This generates a
52
// carry output from each digit in the second row.
53
//
54
// In that case
55
//   99999999
56
// + 99999999
57
// +        1 (carry in)
58
//---------------
59
//  188888889           <- first row result
60
// + 11111110           <- carries out of first row
61
//---------------
62
//  199999999   <- second row result
63
 
64
module BCDSub8NClk(clk, ld, a, b, o, ci, co, done);
65
parameter N=33;
66
input clk;
67
input ld;
68
input [N*8-1:0] a;
69
input [N*8-1:0] b;
70
output reg [N*8-1:0] o;
71
input ci;
72
output reg co;
73
output reg done;
74
 
75
reg [N-1:0] c [0:2];
76
wire [N*8-1:0] o1 [0:2];
77
reg [N*8-1:0] o2 [0:2];
78
wire [N:0] d [0:2];
79
 
80
genvar g,k;
81
generate begin : gBCDadd
82
for (g = 0; g < N; g = g + 1) begin
83
        for (k = 0; k < 3; k = k + 1) begin
84
                BCDSub u1 (
85
                        .ci(k==0 && g==0 ? ci : 1'b0),
86
                        .a(k==0 ? a[g*8+7:g*8] : o2[k-1][g*8+7:g*8]),
87
                        .b(k==0 ? b[g*8+7:g*8] : {7'h00,c[k-1][g]}),
88
                        .o(o1[k][g*8+7:g*8]),
89
                        .c(d[k][g])
90
                );
91
                always_ff @(posedge clk)
92
                        o2[k] <= o1[k];
93
                always_ff @(posedge clk)
94
                        c[k][g] <= d[k][g];
95
        end
96
end
97
always_ff @(posedge clk)
98
begin
99
        o <= o1[2];
100
        co <= c[2][N-1];
101
end
102
end
103
endgenerate
104
endmodule
105
 

powered by: WebSVN 2.1.0

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