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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [fd2s.v] - Blame information for rev 32

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

Line No. Rev Author Line
1 29 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2006-2017  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      fd2s.v
9
//    - convert floating point double to single
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
`include "fpConfig.sv"
28
 
29
module fd2s(a, o);
30
input [63:0] a;
31
output reg [31:0] o;
32
 
33
wire signi;
34
wire [10:0] expi;
35
wire [51:0] mani;
36
wire xinf;
37
wire xz;
38
wire vz;
39
fpDecomp #(64) u1 (.i(a), .sgn(signi), .exp(expi), .man(mani), .xinf(xinf), .xz(xz), .vz(vz) );
40
wire [11:0] exp = expi - 11'h896;   // 1023-127 (difference of the bias)
41
 
42
always @*
43
begin
44
o[31] <= signi;         // sign out = sign in, easy
45
o[22:0] <= a[51:29];
46
if (xinf)
47
    o[30:23] <= 8'hFF;
48
else if (vz)
49
    o[30:23] <= 8'h00;
50
else if (xz)
51
    o[30:23] <= 8'h00;
52
else begin
53
    if (exp[11]) begin  // exponent is too low - set number to zero
54
        o[30:23] <= 8'h00;
55
        o[22:0] <= 23'h000000;
56
    end
57
    else if (|exp[10:8]) begin  // exponent is too high - set number to infinity
58
        o[30:23] <= 8'hFF;
59
        o[22:0] <= 23'h000000;
60
    end
61
    else    // exponent in range
62
        o[30:23] <= exp[7:0];
63
end
64
end
65
 
66
endmodule

powered by: WebSVN 2.1.0

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