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