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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [positVerilog/] [positToFp.sv] - Diff between revs 36 and 48

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 36 Rev 48
// ============================================================================
// ============================================================================
//        __
//        __
//   \\__/ o\    (C) 2020  Robert Finch, Waterloo
//   \\__/ o\    (C) 2020  Robert Finch, Waterloo
//    \  __ /    All rights reserved.
//    \  __ /    All rights reserved.
//     \/_//     robfinch@finitron.ca
//     \/_//     robfinch@finitron.ca
//       ||
//       ||
//
//
//      positToFp.v
//      positToFp.sv
//    - posit number to floating point convertor
//    - posit number to floating point convertor
//    - can issue every clock cycle
//    - can issue every clock cycle
//    - parameterized width
//    - parameterized width
//    - IEEE 754 representation
//    - IEEE 754 representation
//
//
// Parts of this code originated from Posit_to_FP.v by Manish Kumar Jaiswal
// Parts of this code originated from Posit_to_FP.v by Manish Kumar Jaiswal
//
//
// This source file is free software: you can redistribute it and/or modify
// This source file is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// (at your option) any later version.
//
//
// This source file is distributed in the hope that it will be useful,
// This source file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see .
// along with this program.  If not, see .
//
//
// ============================================================================
// ============================================================================
 
 
`include "positConfig.sv"
import posit::*;
`include "fpConfig.sv"
import fp::*;
`include "fpTypes.sv"
`include "../fpu/fpTypes.sv"
 
 
module positToFp(i, o);
module positToFp(i, o);
parameter FPWID = 32;
 
`include "fpSize.sv"
 
`include "positSize.sv"
 
input [FPWID-1:0] i;
input [FPWID-1:0] i;
output reg [FPWID-1:0] o;
output reg [FPWID-1:0] o;
parameter BIAS = {1'b0,{EMSB{1'b1}}};
parameter BIAS = {1'b0,{EMSB{1'b1}}};
localparam N = FPWID;
localparam N = FPWID;
localparam E = EMSB+1;
localparam E = EMSB+1;
localparam M = FMSB+1;
localparam M = FMSB+1;
localparam Bs = $clog2(FPWID-1);
localparam Bs = $clog2(FPWID-1);
localparam EO = E > es+Bs ? E : es+Bs;
localparam EO = E > es+Bs ? E : es+Bs;
wire sgn;
wire sgn;
wire rgs;
wire rgs;
wire [Bs-1:0] rgm;
wire [Bs-1:0] rgm;
wire [es-1:0] exp;
wire [es-1:0] exp;
wire [N-es-1:0] sig;
wire [N-es-1:0] sig;
wire zer;
wire zer;
wire inf;
wire inf;
 
 
positDecompose #(.PSTWID(PSTWID), .es(es)) u1 (.i(i), .sgn(sgn), .rgs(rgs), .rgm(rgm), .exp(exp), .sig(sig), .zer(zer), .inf(inf));
positDecompose #(.PSTWID(PSTWID)) u1 (.i(i), .sgn(sgn), .rgs(rgs), .rgm(rgm), .exp(exp), .sig(sig), .zer(zer), .inf(inf));
 
 
wire [N-1:0] m = {sig,{es{1'b0}}};
wire [N-1:0] m = {sig,{es{1'b0}}};
wire [EO+1:0] e;
wire [EO+1:0] e;
assign e = {(rgs ? {{EO-es-Bs+1{1'b0}},rgm} : -{{EO-es-Bs+1{1'b0}},rgm}),exp} + BIAS;
assign e = {(rgs ? {{EO-es-Bs+1{1'b0}},rgm} : -{{EO-es-Bs+1{1'b0}},rgm}),exp} + BIAS;
wire exv = |e[EO:E];
wire exv = |e[EO:E];
wire exinf = &e[E-1:0];
wire exinf = &e[E-1:0];
always @*
always @*
casez({zer,inf|exv|exinf})    // exponent all ones or exponent overflow?
casez({zer,inf|exv|exinf})    // exponent all ones or exponent overflow?
// convert to +0.0 zero-in zero-out (the sign will always be plus)
// convert to +0.0 zero-in zero-out (the sign will always be plus)
2'b1?:  o = {sgn,{FPWID-1{1'b0}}};
2'b1?:  o = {sgn,{FPWID-1{1'b0}}};
// Infinity in or exponent overflow in conversion = infinity out
// Infinity in or exponent overflow in conversion = infinity out
2'b01:  o = {sgn,{E-1{1'b1}},{M{1'b0}}};
2'b01:  o = {sgn,{E-1{1'b1}},{M{1'b0}}};
// Other numbers
// Other numbers
default:  o = {sgn,e[E-1:0],m[N-2:E]};
default:  o = {sgn,e[E-1:0],m[N-2:E]};
endcase
endcase
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

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