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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [fpScaleb.sv] - Blame information for rev 70

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

Line No. Rev Author Line
1 29 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2019  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      fpScaleb.sv
9
//              - floating point Scaleb()
10
//
11
// This source file is free software: you can redistribute it and/or modify
12
// it under the terms of the GNU Lesser General Public License as published
13
// by the Free Software Foundation, either version 3 of the License, or
14
// (at your option) any later version.
15
//
16
// This source file is distributed in the hope that it will be useful,
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
// GNU General Public License for more details.
20
//
21
// You should have received a copy of the GNU General Public License
22
// along with this program.  If not, see .
23
//
24
// ============================================================================
25
 
26
module fpScaleb(clk, ce, a, b, o);
27
parameter FPWID=80;
28
`include "fpSize.sv"
29
input clk;
30
input ce;
31
input [FPWID-1+`EXTRA_BITS:0] a;
32
input [FPWID-1+`EXTRA_BITS:0] b;
33
output reg [FPWID-1+`EXTRA_BITS:0] o;
34
 
35
wire [4:0] cmp_o;
36
wire nana, nanb;
37
wire xza, mza;
38
 
39
wire [EMSB:0] infXp = {EMSB+1{1'b1}};
40
wire [EMSB:0] xa;
41
wire xinfa;
42
wire anan;
43
reg anan1;
44
wire sa;
45
reg sa1, sa2;
46
wire [FMSB:0] ma;
47
reg [EMSB+1:0] xa1a, xa1b, xa2;
48
reg [FMSB:0] ma1, ma2;
49
wire bs = b[FPWID-1];
50
reg bs1;
51
 
52
fpDecomp #(FPWID) u1 (.i(a), .sgn(sa), .exp(xa), .man(ma), .fract(), .xz(xza), .mz(), .vz(), .inf(), .xinf(xinfa), .qnan(), .snan(), .nan(anan));
53
 
54
// ----------------------------------------------------------------------------
55
// Clock cycle 1
56
// ----------------------------------------------------------------------------
57
always @(posedge clk)
58
        if (ce) xa1a <= xa;
59
always @(posedge clk)
60
        if (ce) xa1b <= xa + b;
61
always @(posedge clk)
62
        if (ce) bs1 <= bs;
63
always @(posedge clk)
64
        if (ce) anan1 <= anan;
65
always @(posedge clk)
66
        if (ce) sa1 <= sa;
67
always @(posedge clk)
68
        if (ce) ma1 <= ma;
69
 
70
// ----------------------------------------------------------------------------
71
// Clock cycle 2
72
// ----------------------------------------------------------------------------
73
always @(posedge clk)
74
        if (ce) sa2 <= sa1;
75
always @(posedge clk)
76
if (ce) begin
77
        if (anan1) begin
78
                xa2 <= xa1a;
79
                ma2 <= ma1;
80
        end
81
        // Underflow? -> limit exponent to zero
82
        else if (bs1 & xa1b[EMSB+1]) begin
83
                xa2 <= 1'd0;
84
                ma2 <= ma1;
85
        end
86
        // overflow ? -> set value to infinity
87
        else if (~bs1 & xa1b[EMSB+1]) begin
88
                xa2 <= infXp;
89
                ma2 <= 1'd0;
90
        end
91
        else begin
92
                xa2 <= xa1b;
93
                ma2 <= ma1;
94
        end
95
end
96
 
97
assign o = {sa2,xa2,ma2};
98
 
99
endmodule

powered by: WebSVN 2.1.0

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