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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [mult64x64.sv] - Blame information for rev 61

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

Line No. Rev Author Line
1 49 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2020  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      mult64x64.sv
9
//  - Karatsuba multiply
10
//  - 11 cycle latency
11
//
12
// BSD 3-Clause License
13
// Redistribution and use in source and binary forms, with or without
14
// modification, are permitted provided that the following conditions are met:
15
//
16
// 1. Redistributions of source code must retain the above copyright notice, this
17
//    list of conditions and the following disclaimer.
18
//
19
// 2. Redistributions in binary form must reproduce the above copyright notice,
20
//    this list of conditions and the following disclaimer in the documentation
21
//    and/or other materials provided with the distribution.
22
//
23
// 3. Neither the name of the copyright holder nor the names of its
24
//    contributors may be used to endorse or promote products derived from
25
//    this software without specific prior written permission.
26
//
27
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
//
38
// ============================================================================
39
 
40
module mult64x64(clk, ce, a, b, o);
41
input clk;
42
input ce;
43
input [63:0] a;
44
input [63:0] b;
45
output reg [127:0] o;
46
 
47
reg [31:0] a2, b2;
48
reg [32:0] a1, b1;
49
reg [63:0] z0, z2, z0a, z2a, z0b, z2b, z0c, z2c, z0d, z2d, p3, p4;
50
reg [64:0] z1;  // extra bit for carry
51
reg sgn2, sgn10;
52
wire sgn9;
53
 
54
always @(posedge clk)
55
        if (ce) a1 <= a[31: 0] - a[63:32];  // x0-x1
56
always @(posedge clk)
57
        if (ce) b1 <= b[63:32] - b[31: 0];  // y1-y0
58
always @(posedge clk)
59
        if (ce) a2 <= a1[32] ? -a1 : a1;
60
always @(posedge clk)
61
        if (ce) b2 <= b1[32] ? -b1 : b1;
62
always @(posedge clk)
63
  if (ce) sgn2 <= a1[32]^b1[32];
64
 
65
delay #(.WID(1), .DEP(7)) udl1 (.clk(clk), .ce(ce), .i(sgn2), .o(sgn9));
66
always @(posedge clk)
67
  if (ce) sgn10 <= sgn9;
68
 
69
// 6 cycle latency
70
mult32x32 u1 (
71
  .clk(clk),
72
  .ce(ce),
73
  .a(a[63:32]),
74
  .b(b[63:32]),
75
  .o(z2)          // z2 = x1 * y1
76
);
77
 
78
mult32x32 u2 (
79
  .clk(clk),
80
  .ce(ce),
81
  .a(a[31:0]),
82
  .b(b[31:0]),
83
  .o(z0)          // z0 = x0 * y0
84
);
85
 
86
mult32x32 u3 (
87
  .clk(clk),
88
  .ce(ce),
89
  .a(a2[31:0]),
90
  .b(b2[31:0]),
91
  .o(p3)        // p3 = abs(x0-x1) * abs(y1-y0)
92
);
93
 
94
always @(posedge clk)
95
        if (ce) p4 <= sgn9 ? -p3 : p3;
96
 
97
always @(posedge clk)
98
  if (ce) z2a <= z2;
99
always @(posedge clk)
100
  if (ce) z0a <= z0;
101
always @(posedge clk)
102
  if (ce) z2b <= z2a;
103
always @(posedge clk)
104
  if (ce) z0b <= z0a;
105
always @(posedge clk)
106
  if (ce) z2c <= z2b;
107
always @(posedge clk)
108
  if (ce) z0c <= z0b;
109
always @(posedge clk)
110
        if (ce) z1 <= {{64{sgn10}},p4} + z2c + z0c;
111
 
112
always @(posedge clk)
113
  if (ce) z2d <= z2c;
114
always @(posedge clk)
115
  if (ce) z0d <= z0c;
116
always @(posedge clk)
117
        if (ce) o <= {z2d,z0d} + {z1,32'd0};
118
 
119
endmodule

powered by: WebSVN 2.1.0

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