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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [DFPTrunc96.sv] - Blame information for rev 89

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 88 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2019-2021  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      DFPTrunc96.sv
9
//              - convert floating point to integer (chop off fractional bits)
10
//              - single cycle latency floating point unit
11
//              - IEEE 754 representation
12
//
13
//
14
// BSD 3-Clause License
15
// Redistribution and use in source and binary forms, with or without
16
// modification, are permitted provided that the following conditions are met:
17
//
18
// 1. Redistributions of source code must retain the above copyright notice, this
19
//    list of conditions and the following disclaimer.
20
//
21
// 2. Redistributions in binary form must reproduce the above copyright notice,
22
//    this list of conditions and the following disclaimer in the documentation
23
//    and/or other materials provided with the distribution.
24
//
25
// 3. Neither the name of the copyright holder nor the names of its
26
//    contributors may be used to endorse or promote products derived from
27
//    this software without specific prior written permission.
28
//
29
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
33
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39
//
40
// ============================================================================
41
 
42
import DFPPkg::*;
43
 
44
module DFPTrunc96(clk, ce, i, o, overflow);
45
parameter N=25; // number of sig. digits
46
input clk;
47
input ce;
48
input DFP96 i;
49
output DFP96 o;
50
output reg overflow;
51
 
52
 
53
integer n;
54
DFP96U maxInt;
55
DFP96U iu, ou;
56
 
57
DFPUnpack96 u01 (i, iu);
58
DFPPack96 u02 (ou, o);
59
 
60
assign maxInt.sign = 1'b0;
61
assign maxInt.exp = 12'hBFE;
62
assign maxInt.sig = 100'h9999999999999999999999999;// maximum unsigned integer value
63
wire [11:0] zeroXp = 12'h5FF;           // simple constant - value of exp for zero
64
 
65
// Decompose fp value
66
reg sgn;                                                                        // sign
67
reg [11:0] exp;
68
reg [N*4-1:0] man;
69
reg [N*4-1:0] mask;
70
 
71
wire [12:0] shamt = (N - 1) - (exp - zeroXp);
72
 
73
genvar g;
74
generate begin : gMask
75
for (g = 0; g < N; g = g +1)
76
        always_comb
77 89 robfinch
                mask[g*4+3:g*4] = (g >= shamt) ? 4'hF : 4'h0;
78 88 robfinch
end
79
endgenerate
80
 
81
always_comb
82
        sgn = iu.sign;
83
always_comb
84
        exp = iu.exp;
85
always_comb
86
        if (exp > zeroXp + (N-1))
87
                man = iu.sig;
88
        else
89
                man = iu.sig & mask;
90
 
91
always_ff @(posedge clk)
92
        if (ce) begin
93
                if (exp < zeroXp) begin
94
                        ou <= 'd0;
95
                        ou.sign <= sgn; // retain sign
96
                end
97
                else begin
98
                        ou.sign <= sgn;
99
                        ou.exp <= exp;
100
                        ou.sig <= man;
101
                end
102
        end
103
 
104
always_comb
105
        overflow <= 1'b0;
106
 
107
endmodule

powered by: WebSVN 2.1.0

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