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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [positVerilog/] [positDecompose.sv] - Blame information for rev 61

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
//      positDecompose.sv
9
//
10
// This source file is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published
12
// by the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
14
//
15
// This source file is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
// GNU General Public License for more details.
19
//
20
// You should have received a copy of the GNU General Public License
21
// along with this program.  If not, see .
22
//
23
// ============================================================================
24
//
25 48 robfinch
import posit::*;
26 36 robfinch
 
27
// Decompose a posit number.
28
module positDecompose(i, sgn, rgs, rgm, exp, sig, zer, inf);
29 48 robfinch
parameter PSTWID = `PSTWID;
30 36 robfinch
input [PSTWID-1:0] i;
31
output sgn;                       // sign of number
32
output rgs;                       // sign of regime
33 41 robfinch
output [rs:0] rgm;   // regime (absolute value)
34 36 robfinch
output [es-1:0] exp;              // exponent
35 41 robfinch
output [PSTWID-1-es:0] sig;       // significand
36 36 robfinch
output zer;                       // number is zero
37
output inf;                       // number is infinite
38
 
39 42 robfinch
wire [rs-1:0] lzcnt;
40
wire [rs-1:0] locnt;
41 36 robfinch
 
42
 
43
assign sgn = i[PSTWID-1];
44
assign inf = ~|i[PSTWID-2:0] & i[PSTWID-1];
45
assign zer = ~|i;
46
wire [PSTWID-1:0] ii = sgn ? -i : i;
47
assign rgs = ii[PSTWID-2];
48
 
49 48 robfinch
positCntlz #(.PSTWID(PSTWID)) u1 (.i(ii[PSTWID-2:0]), .o(lzcnt));
50
positCntlo #(.PSTWID(PSTWID)) u2 (.i(ii[PSTWID-2:0]), .o(locnt));
51 36 robfinch
 
52
assign rgm = rgs ? locnt - 1 : lzcnt;
53 41 robfinch
wire [rs:0] shamt = rgs ? locnt + 2'd1 : lzcnt + 2'd1;
54 36 robfinch
wire [PSTWID-1:0] tmp = ii << shamt;
55
assign exp = |es ? tmp[PSTWID-2:PSTWID-1-es] : 0;
56
assign sig = {~zer,tmp[PSTWID-2-es:0]};
57
 
58
endmodule
59
 
60
// Decompose posit number and register outputs.
61
module positDecomposeReg(clk, ce, i, sgn, rgs, rgm, exp, sig, zer, inf);
62 48 robfinch
parameter PSTWID = `PSTWID;
63 36 robfinch
input clk;
64
input ce;
65
input [PSTWID-1:0] i;
66
output reg sgn;
67
output reg rgs;
68
output reg [$clog2(PSTWID)-1:0] rgm;
69
output reg [es-1:0] exp;
70
output reg [PSTWID-es-1:0] sig;
71
output reg zer;
72
output reg inf;
73
 
74
wire isgn;
75
wire irgs;
76
wire [$clog2(PSTWID)-1:0] irgm;
77
wire [es-1:0] iexp;
78
wire [PSTWID-es-1:0] isig;
79
wire izer;
80
wire iinf;
81
 
82 48 robfinch
positDecompose #(PSTWID) u1 (i, isgn, irgs, irgm, iexp, isig, izer, iinf);
83 36 robfinch
 
84
always @(posedge clk)
85
if (ce) begin
86 48 robfinch
  sgn <= isgn;
87
  rgs <= irgs;
88
  rgm <= irgm;
89
  exp <= iexp;
90
  sig <= isig;
91
  inf <= iinf;
92
  zer <= izer;
93 36 robfinch
end
94
 
95
endmodule
96
 

powered by: WebSVN 2.1.0

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