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

Subversion Repositories ft816float

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

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

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

powered by: WebSVN 2.1.0

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