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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [fs2d.v] - Blame information for rev 78

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

Line No. Rev Author Line
1 29 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2006-2019  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      fs2d.v
9
//    - convert floating point single to double
10
//
11
//
12
// This source file is free software: you can redistribute it and/or modify 
13
// it under the terms of the GNU Lesser General Public License as published 
14
// by the Free Software Foundation, either version 3 of the License, or     
15
// (at your option) any later version.                                      
16
//                                                                          
17
// This source file is distributed in the hope that it will be useful,      
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
20
// GNU General Public License for more details.                             
21
//                                                                          
22
// You should have received a copy of the GNU General Public License        
23
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
24
//                                                                          
25
// ============================================================================
26
 
27
module fs2d(a, o);
28
input [39:0] a;
29
output [79:0] o;
30
 
31
reg signo;
32
reg [14:0] expo;
33
reg [63:0] mano;
34
 
35
assign o = {signo,expo,mano};
36
 
37
wire signi;
38
wire [9:0] expi;
39
wire [28:0] mani;
40
wire xinf;      // exponent infinite
41
wire vz;        // value zero
42
wire xz;        // exponent zero
43
 
44
fpDecomp #(40) u1 (.i(a), .sgn(signi), .exp(expi), .man(mani), .xinf(xinf), .xz(xz), .vz(vz) );
45
wire [5:0] lz;
46
cntlz32 u2 ({mani,3'b111}, lz); // '1' bit already unhidden due to denormalized number
47
 
48
always @*
49
begin
50
  // sign out always just = sign in
51
  signo = signi;
52
 
53
  // special check for zero
54
  if (vz) begin
55
    expo <= 0;
56
    mano <= 0;
57
  end
58
  // convert infinity / nan
59
  // infinity in = infinity out
60
  else if (xinf) begin
61
    expo <= 15'h7fff;
62
    mano <= {mani,35'b0};
63
  end
64
  // convert denormal
65
  // a denormal was really a number with an exponent of -126
66
  // this value is easily represented in the double format
67
  // it may be possible to normalize the value if it isn't
68
  // zero
69
  else if (xz) begin
70
    expo <= 15'd31745 - lz;     // 32767 "zero" -1022 - lz
71
    mano <= {mani << (lz + 1), 35'd0};  // shift one more to hide leading '1'
72
  end
73
  // convert typical number
74
  // adjust exponent, copy mantissa
75
  else begin
76
    expo <= expi + 15'd31744;           // 32767-1023  1023-127
77
    mano <= {mani,35'd0};
78
  end
79
end
80
 
81
endmodule

powered by: WebSVN 2.1.0

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