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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64/] [rtl/] [fpUnit/] [fpDecompReg.v] - Blame information for rev 46

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

Line No. Rev Author Line
1 43 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2006-2016  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch<remove>@finitron.ca
7
//       ||
8
//
9
//      fpDecompReg.v
10
//    - decompose floating point value with registered outputs
11
//    - parameterized width
12
//
13
//
14
// This source file is free software: you can redistribute it and/or modify 
15
// it under the terms of the GNU Lesser General Public License as published 
16
// by the Free Software Foundation, either version 3 of the License, or     
17
// (at your option) any later version.                                      
18
//                                                                          
19
// This source file is distributed in the hope that it will be useful,      
20
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
21
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
22
// GNU General Public License for more details.                             
23
//                                                                          
24
// You should have received a copy of the GNU General Public License        
25
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
26
//                                                                          
27
// ============================================================================
28
 
29
module fpDecomp(i, sgn, exp, man, fract, xz, mz, vz, inf, xinf, qnan, snan, nan);
30
 
31
parameter WID=32;
32
 
33
localparam MSB = WID-1;
34
localparam EMSB = WID==128 ? 14 :
35
                  WID==96 ? 14 :
36
                  WID==80 ? 14 :
37
                  WID==64 ? 10 :
38
                                  WID==52 ? 10 :
39
                                  WID==48 ? 11 :
40
                                  WID==44 ? 10 :
41
                                  WID==42 ? 10 :
42
                                  WID==40 ?  9 :
43
                                  WID==32 ?  7 :
44
                                  WID==24 ?  6 : 4;
45
localparam FMSB = WID==128 ? 111 :
46
                  WID==96 ? 79 :
47
                  WID==80 ? 63 :
48
                  WID==64 ? 51 :
49
                                  WID==52 ? 39 :
50
                                  WID==48 ? 34 :
51
                                  WID==44 ? 31 :
52
                                  WID==42 ? 29 :
53
                                  WID==40 ? 28 :
54
                                  WID==32 ? 22 :
55
                                  WID==24 ? 15 : 9;
56
 
57
input [MSB:0] i;
58
 
59
output sgn;
60
output [EMSB:0] exp;
61
output [FMSB:0] man;
62
output [FMSB+1:0] fract; // mantissa with hidden bit recovered
63
output xz;              // denormalized - exponent is zero
64
output mz;              // mantissa is zero
65
output vz;              // value is zero (both exponent and mantissa are zero)
66
output inf;             // all ones exponent, zero mantissa
67
output xinf;    // all ones exponent
68
output qnan;    // nan
69
output snan;    // signalling nan
70
output nan;
71
 
72
// Decompose input
73
assign sgn = i[MSB];
74
assign exp = i[MSB-1:FMSB+1];
75
assign man = i[FMSB:0];
76
assign xz = !(|exp);    // denormalized - exponent is zero
77
assign mz = !(|man);    // mantissa is zero
78
assign vz = xz & mz;    // value is zero (both exponent and mantissa are zero)
79
assign inf = &exp & mz; // all ones exponent, zero mantissa
80
assign xinf = &exp;
81
assign qnan = &exp &  man[FMSB];
82
assign snan = &exp & !man[FMSB] & !mz;
83
assign nan = &exp & !mz;
84
assign fract = {!xz,i[FMSB:0]};
85
 
86
endmodule
87
 
88
 
89
module fpDecompReg(clk, ce, i, o, sgn, exp, man, fract, xz, mz, vz, inf, xinf, qnan, snan, nan);
90
 
91
parameter WID=32;
92
 
93
localparam MSB = WID-1;
94
localparam EMSB = WID==128 ? 14 :
95
                  WID==96 ? 14 :
96
                  WID==80 ? 14 :
97
                  WID==64 ? 10 :
98
                                  WID==52 ? 10 :
99
                                  WID==48 ? 10 :
100
                                  WID==44 ? 10 :
101
                                  WID==42 ? 10 :
102
                                  WID==40 ?  9 :
103
                                  WID==32 ?  7 :
104
                                  WID==24 ?  6 : 4;
105
localparam FMSB = WID==128 ? 111 :
106
                  WID==96 ? 79 :
107
                  WID==80 ? 63 :
108
                  WID==64 ? 51 :
109
                                  WID==52 ? 39 :
110
                                  WID==48 ? 35 :
111
                                  WID==44 ? 31 :
112
                                  WID==42 ? 29 :
113
                                  WID==40 ? 28 :
114
                                  WID==32 ? 22 :
115
                                  WID==24 ? 15 : 9;
116
 
117
input clk;
118
input ce;
119
input [MSB:0] i;
120
 
121
output reg [MSB:0] o;
122
output reg sgn;
123
output reg [EMSB:0] exp;
124
output reg [FMSB:0] man;
125
output reg [FMSB+1:0] fract;     // mantissa with hidden bit recovered
126
output reg xz;          // denormalized - exponent is zero
127
output reg mz;          // mantissa is zero
128
output reg vz;          // value is zero (both exponent and mantissa are zero)
129
output reg inf;         // all ones exponent, zero mantissa
130
output reg xinf;        // all ones exponent
131
output reg qnan;        // nan
132
output reg snan;        // signalling nan
133
output reg nan;
134
 
135
// Decompose input
136
always @(posedge clk)
137
        if (ce) begin
138
                o <= i;
139
                sgn = i[MSB];
140
                exp = i[MSB-1:FMSB+1];
141
                man = i[FMSB:0];
142
                xz = !(|exp);   // denormalized - exponent is zero
143
                mz = !(|man);   // mantissa is zero
144
                vz = xz & mz;   // value is zero (both exponent and mantissa are zero)
145
                inf = &exp & mz;        // all ones exponent, zero mantissa
146
                xinf = &exp;
147
                qnan = &exp &  man[FMSB];
148
                snan = &exp & !man[FMSB] & !mz;
149
                nan = &exp & !mz;
150
                fract = {|exp,i[FMSB:0]};
151
        end
152
 
153
endmodule

powered by: WebSVN 2.1.0

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