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

Subversion Repositories thor

[/] [thor/] [trunk/] [rtl/] [verilog/] [fpUnit/] [fpDecompReg.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 robfinch
/* ============================================================================
2
        (C) 2006, 2007  Robert T Finch
3
        All rights reserved.
4
        rob@birdcomputer.ca
5
 
6
        fpDecompReg.v
7
                - decompose floating point value with registered outputs
8
                - parameterized width
9
 
10
        Verilog 1995
11
 
12
        This source code is free for use and modification for non-commercial or
13
        evaluation purposes, provided this copyright statement and disclaimer
14
        remains present in the file.
15
 
16
        If the code is modified, please state the origin and note that the code
17
        has been modified.
18
 
19
        NO WARRANTY.
20
        THIS Work, IS PROVIDEDED "AS IS" WITH NO WARRANTIES OF ANY KIND, WHETHER
21
        EXPRESS OR IMPLIED. The user must assume the entire risk of using the
22
        Work.
23
 
24
        IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
25
        INCIDENTAL, CONSEQUENTIAL, OR PUNITIVE DAMAGES WHATSOEVER RELATING TO
26
        THE USE OF THIS WORK, OR YOUR RELATIONSHIP WITH THE AUTHOR.
27
 
28
        IN ADDITION, IN NO EVENT DOES THE AUTHOR AUTHORIZE YOU TO USE THE WORK
29
        IN APPLICATIONS OR SYSTEMS WHERE THE WORK'S FAILURE TO PERFORM CAN
30
        REASONABLY BE EXPECTED TO RESULT IN A SIGNIFICANT PHYSICAL INJURY, OR IN
31
        LOSS OF LIFE. ANY SUCH USE BY YOU IS ENTIRELY AT YOUR OWN RISK, AND YOU
32
        AGREE TO HOLD THE AUTHOR AND CONTRIBUTORS HARMLESS FROM ANY CLAIMS OR
33
        LOSSES RELATING TO SUCH UNAUTHORIZED USE.
34
 
35
 
36
        Ref: Webpack 8.1i Spartan3-4 xc3s1000 4ft256
37
        10 slices / 20 LUTs / 12 ns  (32 bits)
38
 
39
============================================================================ */
40
 
41
module fpDecomp(i, sgn, exp, man, fract, xz, mz, vz, inf, xinf, qnan, snan, nan);
42
 
43
parameter WID=32;
44
 
45
localparam MSB = WID-1;
46
localparam EMSB = WID==80 ? 14 :
47
                  WID==64 ? 10 :
48
                                  WID==52 ? 10 :
49
                                  WID==48 ? 10 :
50
                                  WID==44 ? 10 :
51
                                  WID==42 ? 10 :
52
                                  WID==40 ?  9 :
53
                                  WID==32 ?  7 :
54
                                  WID==24 ?  6 : 4;
55
localparam FMSB = WID==80 ? 63 :
56
                  WID==64 ? 51 :
57
                                  WID==52 ? 39 :
58
                                  WID==48 ? 35 :
59
                                  WID==44 ? 31 :
60
                                  WID==42 ? 29 :
61
                                  WID==40 ? 28 :
62
                                  WID==32 ? 22 :
63
                                  WID==24 ? 15 : 9;
64
 
65
input [MSB:0] i;
66
 
67
output sgn;
68
output [EMSB:0] exp;
69
output [FMSB:0] man;
70
output [FMSB+1:0] fract; // mantissa with hidden bit recovered
71
output xz;              // denormalized - exponent is zero
72
output mz;              // mantissa is zero
73
output vz;              // value is zero (both exponent and mantissa are zero)
74
output inf;             // all ones exponent, zero mantissa
75
output xinf;    // all ones exponent
76
output qnan;    // nan
77
output snan;    // signalling nan
78
output nan;
79
 
80
// Decompose input
81
assign sgn = i[MSB];
82
assign exp = i[MSB-1:FMSB+1];
83
assign man = i[FMSB:0];
84
assign xz = !(|exp);    // denormalized - exponent is zero
85
assign mz = !(|man);    // mantissa is zero
86
assign vz = xz & mz;    // value is zero (both exponent and mantissa are zero)
87
assign inf = &exp & mz; // all ones exponent, zero mantissa
88
assign xinf = &exp;
89
assign qnan = &exp &  man[FMSB];
90
assign snan = &exp & !man[FMSB] & !mz;
91
assign nan = &exp & !mz;
92
assign fract = {!xz,i[FMSB:0]};
93
 
94
endmodule
95
 
96
 
97
module fpDecompReg(clk, ce, i, o, sgn, exp, man, fract, xz, mz, vz, inf, xinf, qnan, snan, nan);
98
 
99
parameter WID=32;
100
 
101
localparam MSB = WID-1;
102
localparam EMSB = WID==80 ? 14 :
103
                  WID==64 ? 10 :
104
                                  WID==52 ? 10 :
105
                                  WID==48 ? 10 :
106
                                  WID==44 ? 10 :
107
                                  WID==42 ? 10 :
108
                                  WID==40 ?  9 :
109
                                  WID==32 ?  7 :
110
                                  WID==24 ?  6 : 4;
111
localparam FMSB = WID==80 ? 63 :
112
                  WID==64 ? 51 :
113
                                  WID==52 ? 39 :
114
                                  WID==48 ? 35 :
115
                                  WID==44 ? 31 :
116
                                  WID==42 ? 29 :
117
                                  WID==40 ? 28 :
118
                                  WID==32 ? 22 :
119
                                  WID==24 ? 15 : 9;
120
 
121
input clk;
122
input ce;
123
input [MSB:0] i;
124
 
125
output reg [MSB:0] o;
126
output reg sgn;
127
output reg [EMSB:0] exp;
128
output reg [FMSB:0] man;
129
output reg [FMSB+1:0] fract;     // mantissa with hidden bit recovered
130
output reg xz;          // denormalized - exponent is zero
131
output reg mz;          // mantissa is zero
132
output reg vz;          // value is zero (both exponent and mantissa are zero)
133
output reg inf;         // all ones exponent, zero mantissa
134
output reg xinf;        // all ones exponent
135
output reg qnan;        // nan
136
output reg snan;        // signalling nan
137
output reg nan;
138
 
139
// Decompose input
140
always @(posedge clk)
141
        if (ce) begin
142
                o <= i;
143
                sgn = i[MSB];
144
                exp = i[MSB-1:FMSB+1];
145
                man = i[FMSB:0];
146
                xz = !(|exp);   // denormalized - exponent is zero
147
                mz = !(|man);   // mantissa is zero
148
                vz = xz & mz;   // value is zero (both exponent and mantissa are zero)
149
                inf = &exp & mz;        // all ones exponent, zero mantissa
150
                xinf = &exp;
151
                qnan = &exp &  man[FMSB];
152
                snan = &exp & !man[FMSB] & !mz;
153
                nan = &exp & !mz;
154
                fract = {|exp,i[FMSB:0]};
155
        end
156
 
157
endmodule

powered by: WebSVN 2.1.0

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