URL
https://opencores.org/ocsvn/thor/thor/trunk
Details |
Compare with Previous |
View Log
Line No. |
Rev |
Author |
Line |
1 |
51 |
robfinch |
`timescale 1ns / 1ps
|
2 |
|
|
// ============================================================================
|
3 |
|
|
// __
|
4 |
|
|
// \\__/ o\ (C) 2006-2017 Robert Finch, Waterloo
|
5 |
|
|
// \ __ / All rights reserved.
|
6 |
|
|
// \/_// robfinch<remove>@finitron.ca
|
7 |
|
|
// ||
|
8 |
|
|
//
|
9 |
|
|
// fd2s.v
|
10 |
|
|
// - convert floating point double to single
|
11 |
|
|
//
|
12 |
|
|
//
|
13 |
|
|
// This source file is free software: you can redistribute it and/or modify
|
14 |
|
|
// it under the terms of the GNU Lesser General Public License as published
|
15 |
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
16 |
|
|
// (at your option) any later version.
|
17 |
|
|
//
|
18 |
|
|
// This source file is distributed in the hope that it will be useful,
|
19 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
|
|
// GNU General Public License for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
25 |
|
|
//
|
26 |
|
|
// ============================================================================
|
27 |
|
|
|
28 |
|
|
module fd2s(a, o);
|
29 |
|
|
input [63:0] a;
|
30 |
|
|
output reg [31:0] o;
|
31 |
|
|
|
32 |
|
|
wire signi;
|
33 |
|
|
wire [10:0] expi;
|
34 |
|
|
wire [51:0] mani;
|
35 |
|
|
wire xinf;
|
36 |
|
|
wire xz;
|
37 |
|
|
wire vz;
|
38 |
|
|
fpDecomp #(64) u1 (.i(a), .sgn(signi), .exp(expi), .man(mani), .xinf(xinf), .xz(xz), .vz(vz) );
|
39 |
|
|
wire [11:0] exp = expi - 11'h896; // 1023-127 (difference of the bias)
|
40 |
|
|
|
41 |
|
|
always @*
|
42 |
|
|
begin
|
43 |
|
|
o[31] <= signi; // sign out = sign in, easy
|
44 |
|
|
o[22:0] <= a[51:29];
|
45 |
|
|
if (xinf)
|
46 |
|
|
o[30:23] <= 8'hFF;
|
47 |
|
|
else if (vz)
|
48 |
|
|
o[30:23] <= 8'h00;
|
49 |
|
|
else if (xz)
|
50 |
|
|
o[30:23] <= 8'h00;
|
51 |
|
|
else begin
|
52 |
|
|
if (exp[11]) begin // exponent is too low - set number to zero
|
53 |
|
|
o[30:23] <= 8'h00;
|
54 |
|
|
o[22:0] <= 23'h000000;
|
55 |
|
|
end
|
56 |
|
|
else if (|exp[10:8]) begin // exponent is too high - set number to infinity
|
57 |
|
|
o[30:23] <= 8'hFF;
|
58 |
|
|
o[22:0] <= 23'h000000;
|
59 |
|
|
end
|
60 |
|
|
else // exponent in range
|
61 |
|
|
o[30:23] <= exp[7:0];
|
62 |
|
|
end
|
63 |
|
|
end
|
64 |
|
|
|
65 |
|
|
endmodule
|
© copyright 1999-2025
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.