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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [positVerilog/] [positFDPMul.sv] - Blame information for rev 53

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

Line No. Rev Author Line
1 42 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2020  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8 48 robfinch
//      positFDPMul.sv
9 42 robfinch
//    - fused dot product posit number multiplier
10
//    - parameterized width
11
//    - perform a multiplication but retain all the product bits
12
//      in the result in preparation for addition.
13
//
14
//
15
// This source file is free software: you can redistribute it and/or modify
16
// it under the terms of the GNU Lesser General Public License as published
17
// by the Free Software Foundation, either version 3 of the License, or
18
// (at your option) any later version.
19
//
20
// This source file is distributed in the hope that it will be useful,
21
// but WITHOUT ANY WARRANTY; without even the implied warranty of
22
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
// GNU General Public License for more details.
24
//
25
// You should have received a copy of the GNU General Public License
26
// along with this program.  If not, see .
27
//
28
// ============================================================================
29
 
30 48 robfinch
import posit::*;
31 42 robfinch
 
32
module positFDPMul(a, b, o, zero, inf);
33
input [PSTWID-1:0] a;
34
input [PSTWID-1:0] b;
35
output reg [PSTWID+es+(PSTWID-es)*2-1:0] o;
36
output zero;
37
output inf;
38
 
39
wire sa, sb, so;
40
wire [rs:0] rgma, rgmb;
41
wire [rs+1:0] rgm1, rgm2;
42
wire rgsa, rgsb;
43
wire [es-1:0] expa, expb;
44
wire [PSTWID-es-1:0] siga, sigb;
45
wire [(PSTWID-es)*2-1:0] prod;
46
wire zera, zerb;
47
wire infa, infb;
48
wire inf = infa|infb;
49
wire zero = zera|zerb;
50
 
51 48 robfinch
positDecompose #(PSTWID) u1 (
52 42 robfinch
  .i(a),
53
  .sgn(sa),
54
  .rgs(rgsa),
55
  .rgm(rgma),
56
  .exp(expa),
57
  .sig(siga),
58
  .zer(zera),
59
  .inf(infa)
60
);
61
 
62 48 robfinch
positDecompose #(PSTWID) u2 (
63 42 robfinch
  .i(b),
64
  .sgn(sb),
65
  .rgs(rgsb),
66
  .rgm(rgmb),
67
  .exp(expb),
68
  .sig(sigb),
69
  .zer(zerb),
70
  .inf(infb)
71
);
72
 
73
assign so = sa ^ sb;  // compute sign
74
assign prod = siga * sigb;
75
// The product could have one or two whole digits before the point. Detect which it is
76
// and realign the product.
77
wire mo = prod[(PSTWID-es)*2-1];
78
wire [(PSTWID-es)*2-1:0] prod1 = mo ? prod : prod << 1'b1;  // left align product
79
// Convert to the real +/- regime value
80
assign rgm1 = rgsa ? rgma : -rgma;
81
assign rgm2 = rgsb ? rgmb : -rgmb;
82
// Compute regime and exponent, include product alignment shift.
83
wire [rs+es+1:0] rxtmp = {rgm1,expa} + {rgm2,expb} + mo;
84
// Make a negative rx positive
85
wire [rs+es+1:0] rxtmp2c = rxtmp[rs+es+1] ? ~rxtmp + 2'd1 : rxtmp;
86
// Break out the exponent and regime portions
87
wire [es-1:0] exp = |es ? rxtmp[es-1:0] : 0;
88
// Take absolute value of regime portion
89
wire srxtmp = rxtmp[rs+es+1];
90
wire [rs:0] rgm = srxtmp ? -rxtmp[rs+es+1:es] : rxtmp[rs+es+1:es];
91
// Compute the length of the regime bit string, +1 for positive regime
92
wire [rs+es+1:0] rxn = rxtmp[rs+es+1] ? rxtmp2c : rxtmp;
93
wire [rs:0] rgml;
94
// Build expanded posit number:
95
// trim one leading bit off the product bits
96
// and keep guard, round bits, and create sticky bit
97
wire [PSTWID+es+(PSTWID-es)*2-2:0] tmp;
98
generate begin : gTmp
99
if (es > 0) begin
100
assign rgml = (~srxtmp | |(rxn[es-1:0])) ? rxtmp2c[rs+es:es] + 2'd1 : rxtmp2c[rs+es:es];
101
assign tmp = {{PSTWID-1{~srxtmp}},srxtmp,exp,prod1[(PSTWID-es)*2-2:0]};
102
end
103
else begin
104
assign rgml = (~srxtmp) ? rxtmp2c[rs+es:es] + 2'd1 : rxtmp2c[rs+es:es];
105
assign tmp = {{PSTWID-1{~srxtmp}},srxtmp,prod1[(PSTWID-es)*2-2:0]};
106
end
107
end
108
endgenerate
109
wire [PSTWID+es+(PSTWID-es)*2-2:0] tmp1 = tmp << (PSTWID-rgml-1);
110
wire [PSTWID+es+(PSTWID-es)*2-1:0] abstmp = so ? {1'b1,-tmp1} : {1'b0,tmp1};
111
 
112
always @*
113
  casez({zero,inf})
114
  2'b1?: o = {PSTWID+es+(PSTWID-es)*2-2{1'b0}};
115
  2'b01: o = {1'b1,{PSTWID+es+(PSTWID-es)*2-2-1{1'b0}}};
116
  default:  o = abstmp;
117
  endcase
118
 
119
endmodule

powered by: WebSVN 2.1.0

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