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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [positVerilog/] [positToFp.sv] - Blame information for rev 76

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

Line No. Rev Author Line
1 36 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2020  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8 48 robfinch
//      positToFp.sv
9 36 robfinch
//    - 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 48 robfinch
import posit::*;
32
import fp::*;
33
`include "../fpu/fpTypes.sv"
34 36 robfinch
 
35
module positToFp(i, o);
36
input [FPWID-1:0] i;
37
output reg [FPWID-1:0] o;
38
 
39
parameter BIAS = {1'b0,{EMSB{1'b1}}};
40
localparam N = FPWID;
41
localparam E = EMSB+1;
42
localparam M = FMSB+1;
43
localparam Bs = $clog2(FPWID-1);
44
localparam EO = E > es+Bs ? E : es+Bs;
45
 
46
wire sgn;
47
wire rgs;
48
wire [Bs-1:0] rgm;
49
wire [es-1:0] exp;
50
wire [N-es-1:0] sig;
51
wire zer;
52
wire inf;
53
 
54 48 robfinch
positDecompose #(.PSTWID(PSTWID)) u1 (.i(i), .sgn(sgn), .rgs(rgs), .rgm(rgm), .exp(exp), .sig(sig), .zer(zer), .inf(inf));
55 36 robfinch
 
56
wire [N-1:0] m = {sig,{es{1'b0}}};
57
wire [EO+1:0] e;
58
assign e = {(rgs ? {{EO-es-Bs+1{1'b0}},rgm} : -{{EO-es-Bs+1{1'b0}},rgm}),exp} + BIAS;
59
wire exv = |e[EO:E];
60
wire exinf = &e[E-1:0];
61
 
62
always @*
63
casez({zer,inf|exv|exinf})    // exponent all ones or exponent overflow?
64
// convert to +0.0 zero-in zero-out (the sign will always be plus)
65
2'b1?:  o = {sgn,{FPWID-1{1'b0}}};
66
// Infinity in or exponent overflow in conversion = infinity out
67
2'b01:  o = {sgn,{E-1{1'b1}},{M{1'b0}}};
68
// Other numbers
69
default:  o = {sgn,e[E-1:0],m[N-2:E]};
70
endcase
71
 
72
endmodule

powered by: WebSVN 2.1.0

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