1 |
29 |
robfinch |
// ============================================================================
|
2 |
|
|
// __
|
3 |
|
|
// \\__/ o\ (C) 2006-2019 Robert Finch, Waterloo
|
4 |
|
|
// \ __ / All rights reserved.
|
5 |
|
|
// \/_// robfinch<remove>@finitron.ca
|
6 |
|
|
// ||
|
7 |
|
|
//
|
8 |
|
|
// fpDecompReg.v
|
9 |
|
|
// - decompose floating point value with registered outputs
|
10 |
|
|
// - parameterized FPWIDth
|
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 |
|
|
`include "fpConfig.sv"
|
29 |
|
|
|
30 |
|
|
module fpDecomp(i, sgn, exp, man, fract, xz, mz, vz, inf, xinf, qnan, snan, nan);
|
31 |
|
|
parameter FPWID=32;
|
32 |
|
|
`include "fpSize.sv"
|
33 |
|
|
|
34 |
|
|
input [MSB:0] i;
|
35 |
|
|
|
36 |
|
|
output sgn;
|
37 |
|
|
output [EMSB:0] exp;
|
38 |
|
|
output [FMSB:0] man;
|
39 |
|
|
output [FMSB+1:0] fract; // mantissa with hidden bit recovered
|
40 |
|
|
output xz; // denormalized - exponent is zero
|
41 |
|
|
output mz; // mantissa is zero
|
42 |
|
|
output vz; // value is zero (both exponent and mantissa are zero)
|
43 |
|
|
output inf; // all ones exponent, zero mantissa
|
44 |
|
|
output xinf; // all ones exponent
|
45 |
|
|
output qnan; // nan
|
46 |
|
|
output snan; // signalling nan
|
47 |
|
|
output nan;
|
48 |
|
|
|
49 |
|
|
// Decompose input
|
50 |
|
|
assign sgn = i[MSB];
|
51 |
|
|
assign exp = i[MSB-1:FMSB+1];
|
52 |
|
|
assign man = i[FMSB:0];
|
53 |
|
|
assign xz = !(|exp); // denormalized - exponent is zero
|
54 |
|
|
assign mz = !(|man); // mantissa is zero
|
55 |
|
|
assign vz = xz & mz; // value is zero (both exponent and mantissa are zero)
|
56 |
|
|
assign inf = &exp & mz; // all ones exponent, zero mantissa
|
57 |
|
|
assign xinf = &exp;
|
58 |
|
|
assign qnan = &exp & man[FMSB];
|
59 |
|
|
assign snan = &exp & !man[FMSB] & !mz;
|
60 |
|
|
assign nan = &exp & !mz;
|
61 |
|
|
assign fract = {!xz,i[FMSB:0]};
|
62 |
|
|
|
63 |
|
|
endmodule
|
64 |
|
|
|
65 |
|
|
|
66 |
|
|
module fpDecompReg(clk, ce, i, o, sgn, exp, man, fract, xz, mz, vz, inf, xinf, qnan, snan, nan);
|
67 |
|
|
parameter FPWID=32;
|
68 |
|
|
`include "fpSize.sv"
|
69 |
|
|
|
70 |
|
|
input clk;
|
71 |
|
|
input ce;
|
72 |
|
|
input [MSB:0] i;
|
73 |
|
|
|
74 |
|
|
output reg [MSB:0] o;
|
75 |
|
|
output reg sgn;
|
76 |
|
|
output reg [EMSB:0] exp;
|
77 |
|
|
output reg [FMSB:0] man;
|
78 |
|
|
output reg [FMSB+1:0] fract; // mantissa with hidden bit recovered
|
79 |
|
|
output reg xz; // denormalized - exponent is zero
|
80 |
|
|
output reg mz; // mantissa is zero
|
81 |
|
|
output reg vz; // value is zero (both exponent and mantissa are zero)
|
82 |
|
|
output reg inf; // all ones exponent, zero mantissa
|
83 |
|
|
output reg xinf; // all ones exponent
|
84 |
|
|
output reg qnan; // nan
|
85 |
|
|
output reg snan; // signalling nan
|
86 |
|
|
output reg nan;
|
87 |
|
|
|
88 |
|
|
// Decompose input
|
89 |
|
|
always @(posedge clk)
|
90 |
|
|
if (ce) begin
|
91 |
|
|
o <= i;
|
92 |
|
|
sgn = i[MSB];
|
93 |
|
|
exp = i[MSB-1:FMSB+1];
|
94 |
|
|
man = i[FMSB:0];
|
95 |
|
|
xz = !(|exp); // denormalized - exponent is zero
|
96 |
|
|
mz = !(|man); // mantissa is zero
|
97 |
|
|
vz = xz & mz; // value is zero (both exponent and mantissa are zero)
|
98 |
|
|
inf = &exp & mz; // all ones exponent, zero mantissa
|
99 |
|
|
xinf = &exp;
|
100 |
|
|
qnan = &exp & man[FMSB];
|
101 |
|
|
snan = &exp & !man[FMSB] & !mz;
|
102 |
|
|
nan = &exp & !mz;
|
103 |
|
|
fract = {|exp,i[FMSB:0]};
|
104 |
|
|
end
|
105 |
|
|
|
106 |
|
|
endmodule
|