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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [positToFp.sv] - Blame information for rev 79

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

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2020  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      positToFp.v
9
//    - posit number to floating point convertor
10
//    - can issue every clock cycle
11
//    - parameterized width
12
//    - IEEE 754 representation
13
//
14
// Parts of this code originated from Posit_to_FP.v by Manish Kumar Jaiswal
15
//
16
// This source file is free software: you can redistribute it and/or modify
17
// it under the terms of the GNU Lesser General Public License as published
18
// by the Free Software Foundation, either version 3 of the License, or
19
// (at your option) any later version.
20
//
21
// This source file is distributed in the hope that it will be useful,
22
// but WITHOUT ANY WARRANTY; without even the implied warranty of
23
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
// GNU General Public License for more details.
25
//
26
// You should have received a copy of the GNU General Public License
27
// along with this program.  If not, see .
28
//
29
// ============================================================================
30
 
31
`include "positConfig.sv"
32
`include "fpConfig.sv"
33
`include "fpTypes.sv"
34
 
35
module positToFp(i, o);
36
parameter FPWID = 32;
37
`include "fpSize.sv"
38
`include "positSize.sv"
39
input [FPWID-1:0] i;
40
output reg [FPWID-1:0] o;
41
 
42
parameter BIAS = {1'b0,{EMSB{1'b1}}};
43
localparam N = FPWID;
44
localparam E = EMSB+1;
45
localparam M = FMSB+1;
46
localparam Bs = $clog2(FPWID-1);
47
localparam EO = E > es+Bs ? E : es+Bs;
48
 
49
wire sgn;
50
wire rgs;
51
wire [Bs-1:0] rgm;
52
wire [es-1:0] exp;
53
wire [N-es-1:0] sig;
54
wire zer;
55
wire inf;
56
 
57
positDecompose #(.PSTWID(PSTWID), .es(es)) u1 (.i(i), .sgn(sgn), .rgs(rgs), .rgm(rgm), .exp(exp), .sig(sig), .zer(zer), .inf(inf));
58
 
59
wire [N-1:0] m = {sig,{es{1'b0}}};
60
wire [EO+1:0] e;
61
assign e = {(rgs ? {{EO-es-Bs+1{1'b0}},rgm} : -{{EO-es-Bs+1{1'b0}},rgm}),exp} + BIAS;
62
wire exv = |e[EO:E];
63
wire exinf = &e[E-1:0];
64
 
65
always @*
66
casez({zer,inf|exv|exinf})    // exponent all ones or exponent overflow?
67
// convert to +0.0 zero-in zero-out (the sign will always be plus)
68
2'b1?:  o = {sgn,{FPWID-1{1'b0}}};
69
// Infinity in or exponent overflow in conversion = infinity out
70
2'b01:  o = {sgn,{E-1{1'b1}},{M{1'b0}}};
71
// Other numbers
72
default:  o = {sgn,e[E-1:0],m[N-2:E]};
73
endcase
74
 
75
endmodule

powered by: WebSVN 2.1.0

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