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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [fpUnit/] [fs2d.v] - Blame information for rev 51

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
//      fs2d.v
10
//    - convert floating point single to double
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 fs2d(a, o);
29
input [31:0] a;
30
output [63:0] o;
31
 
32
reg signo;
33
reg [10:0] expo;
34
reg [51:0] mano;
35
 
36
assign o = {signo,expo,mano};
37
 
38
wire signi;
39
wire [7:0] expi;
40
wire [22:0] mani;
41
wire xinf;      // exponent infinite
42
wire vz;        // value zero
43
wire xz;        // exponent zero
44
 
45
fpDecomp #(32) u1 (.i(a), .sgn(signi), .exp(expi), .man(mani), .xinf(xinf), .xz(xz), .vz(vz) );
46
wire [4:0] lz;
47
cntlz24 u2 ({mani,1'b1}, lz);   // '1' bit already unhidden due to denormalized number
48
 
49
always @(a)
50
begin
51
    // sign out always just = sign in
52
    signo = signi;
53
 
54
    // special check for zero
55
    if (vz) begin
56
        expo <= 0;
57
        mano <= 0;
58
    end
59
    // convert infinity / nan
60
    // infinity in = infinity out
61
    else if (xinf) begin
62
        expo <= 11'h7ff;
63
        mano <= {mani,29'b0};
64
    end
65
    // convert denormal
66
    // a denormal was really a number with an exponent of -126
67
    // this value is easily represented in the double format
68
    // it may be possible to normalize the value if it isn't
69
    // zero
70
    else if (xz) begin
71
        expo <= 11'd897 - lz;   // 1023 "zero" -126 - lz
72
        mano <= {mani << (lz + 1), 29'd0};      // shift one more to hide leading '1'
73
    end
74
    // convert typical number
75
    // adjust exponent, copy mantissa
76
    else begin
77
        expo <= expi + 11'd896;         // 1023-127
78
        mano <= {mani,29'd0};
79
    end
80
end
81
 
82
endmodule

powered by: WebSVN 2.1.0

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