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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [positVerilog/] [positDecompose.sv] - Diff between revs 41 and 42

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

Rev 41 Rev 42
`include "positConfig.sv"
`include "positConfig.sv"
// ============================================================================
// ============================================================================
//        __
//        __
//   \\__/ o\    (C) 2020  Robert Finch, Waterloo
//   \\__/ o\    (C) 2020  Robert Finch, Waterloo
//    \  __ /    All rights reserved.
//    \  __ /    All rights reserved.
//     \/_//     robfinch@finitron.ca
//     \/_//     robfinch@finitron.ca
//       ||
//       ||
//
//
//      positDecompose.sv
//      positDecompose.sv
//
//
// 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"
`include "positConfig.sv"
// Decompose a posit number.
// Decompose a posit number.
module positDecompose(i, sgn, rgs, rgm, exp, sig, zer, inf);
module positDecompose(i, sgn, rgs, rgm, exp, sig, zer, inf);
`include "positSize.sv"
`include "positSize.sv"
localparam rs = $clog2(PSTWID-1);
localparam rs = $clog2(PSTWID-1);
input [PSTWID-1:0] i;
input [PSTWID-1:0] i;
output sgn;                       // sign of number
output sgn;                       // sign of number
output rgs;                       // sign of regime
output rgs;                       // sign of regime
output [rs:0] rgm;   // regime (absolute value)
output [rs:0] rgm;   // regime (absolute value)
output [es-1:0] exp;              // exponent
output [es-1:0] exp;              // exponent
output [PSTWID-1-es:0] sig;       // significand
output [PSTWID-1-es:0] sig;       // significand
output zer;                       // number is zero
output zer;                       // number is zero
output inf;                       // number is infinite
output inf;                       // number is infinite
 
 
wire [rs:0] lzcnt;
wire [rs-1:0] lzcnt;
wire [rs:0] locnt;
wire [rs-1:0] locnt;
 
 
assign sgn = i[PSTWID-1];
assign sgn = i[PSTWID-1];
assign inf = ~|i[PSTWID-2:0] & i[PSTWID-1];
assign inf = ~|i[PSTWID-2:0] & i[PSTWID-1];
assign zer = ~|i;
assign zer = ~|i;
wire [PSTWID-1:0] ii = sgn ? -i : i;
wire [PSTWID-1:0] ii = sgn ? -i : i;
assign rgs = ii[PSTWID-2];
assign rgs = ii[PSTWID-2];
positCntlz #(PSTWID) u1 (.i(ii[PSTWID-2:0]), .o(lzcnt));
positCntlz #(PSTWID) u1 (.i(ii[PSTWID-2:0]), .o(lzcnt));
positCntlo #(PSTWID) u2 (.i(ii[PSTWID-2:0]), .o(locnt));
positCntlo #(PSTWID) u2 (.i(ii[PSTWID-2:0]), .o(locnt));
assign rgm = rgs ? locnt - 1 : lzcnt;
assign rgm = rgs ? locnt - 1 : lzcnt;
wire [rs:0] shamt = rgs ? locnt + 2'd1 : lzcnt + 2'd1;
wire [rs:0] shamt = rgs ? locnt + 2'd1 : lzcnt + 2'd1;
wire [PSTWID-1:0] tmp = ii << shamt;
wire [PSTWID-1:0] tmp = ii << shamt;
assign exp = |es ? tmp[PSTWID-2:PSTWID-1-es] : 0;
assign exp = |es ? tmp[PSTWID-2:PSTWID-1-es] : 0;
assign sig = {~zer,tmp[PSTWID-2-es:0]};
assign sig = {~zer,tmp[PSTWID-2-es:0]};
endmodule
endmodule
// Decompose posit number and register outputs.
// Decompose posit number and register outputs.
module positDecomposeReg(clk, ce, i, sgn, rgs, rgm, exp, sig, zer, inf);
module positDecomposeReg(clk, ce, i, sgn, rgs, rgm, exp, sig, zer, inf);
`include "positSize.sv"
`include "positSize.sv"
input clk;
input clk;
input ce;
input ce;
input [PSTWID-1:0] i;
input [PSTWID-1:0] i;
output reg sgn;
output reg sgn;
output reg rgs;
output reg rgs;
output reg [$clog2(PSTWID)-1:0] rgm;
output reg [$clog2(PSTWID)-1:0] rgm;
output reg [es-1:0] exp;
output reg [es-1:0] exp;
output reg [PSTWID-es-1:0] sig;
output reg [PSTWID-es-1:0] sig;
output reg zer;
output reg zer;
output reg inf;
output reg inf;
wire isgn;
wire isgn;
wire irgs;
wire irgs;
wire [$clog2(PSTWID)-1:0] irgm;
wire [$clog2(PSTWID)-1:0] irgm;
wire [es-1:0] iexp;
wire [es-1:0] iexp;
wire [PSTWID-es-1:0] isig;
wire [PSTWID-es-1:0] isig;
wire izer;
wire izer;
wire iinf;
wire iinf;
positDecompose #(PSTWID) u1 (i, isgn, irgs, irgm, iexp, isig, iinf);
positDecompose #(PSTWID) u1 (i, isgn, irgs, irgm, iexp, isig, iinf);
always @(posedge clk)
always @(posedge clk)
if (ce) begin
if (ce) begin
  sgn = isgn;
  sgn = isgn;
  rgs = irgs;
  rgs = irgs;
  rgm = irgm;
  rgm = irgm;
  exp = iexp;
  exp = iexp;
  sig = isig;
  sig = isig;
  inf = iinf;
  inf = iinf;
end
end
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

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