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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [positDecompose.sv] - Blame information for rev 82

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

Line No. Rev Author Line
1 48 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
input [PSTWID-1:0] i;
32
output sgn;                       // sign of number
33
output rgs;                       // sign of regime
34
output [$clog2(PSTWID)-1:0] rgm;   // regime (absolute value)
35
output [es-1:0] exp;              // exponent
36
output [PSTWID-es-1:0] sig;        // significand
37
output zer;                       // number is zero
38
output inf;                       // number is infinite
39
 
40
wire [$clog2(PSTWID-2):0] lzcnt;
41
wire [$clog2(PSTWID-2):0] locnt;
42
 
43
 
44
assign sgn = i[PSTWID-1];
45
assign inf = ~|i[PSTWID-2:0] & i[PSTWID-1];
46
assign zer = ~|i;
47
wire [PSTWID-1:0] ii = sgn ? -i : i;
48
assign rgs = ii[PSTWID-2];
49
 
50
positCntlz #(PSTWID,es) u1 (.i(ii[PSTWID-2:0]), .o(lzcnt));
51
positCntlo #(PSTWID,es) u2 (.i(ii[PSTWID-2:0]), .o(locnt));
52
 
53
assign rgm = rgs ? locnt - 1 : lzcnt;
54
wire [$clog2(PSTWID)-1:0] shamt = rgs ? locnt + 2'd1 : lzcnt + 2'd1;
55
wire [PSTWID-1:0] tmp = ii << shamt;
56
assign exp = |es ? tmp[PSTWID-2:PSTWID-1-es] : 0;
57
assign sig = {1'b1,tmp[PSTWID-2-es:0]};
58
 
59
endmodule
60
 
61
// Decompose posit number and register outputs.
62
module positDecomposeReg(clk, ce, i, sgn, rgs, rgm, exp, sig, zer, inf);
63
`include "positSize.sv"
64
input clk;
65
input ce;
66
input [PSTWID-1:0] i;
67
output reg sgn;
68
output reg rgs;
69
output reg [$clog2(PSTWID)-1:0] rgm;
70
output reg [es-1:0] exp;
71
output reg [PSTWID-es-1:0] sig;
72
output reg zer;
73
output reg inf;
74
 
75
wire isgn;
76
wire irgs;
77
wire [$clog2(PSTWID)-1:0] irgm;
78
wire [es-1:0] iexp;
79
wire [PSTWID-es-1:0] isig;
80
wire izer;
81
wire iinf;
82
 
83
positDecompose #(PSTWID) u1 (i, isgn, irgs, irgm, iexp, isig, iinf);
84
 
85
always @(posedge clk)
86
if (ce) begin
87
  sgn = isgn;
88
  rgs = irgs;
89
  rgm = irgm;
90
  exp = iexp;
91
  sig = isig;
92
  inf = iinf;
93
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.