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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog2/] [fpCompare.sv] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 robfinch
// ============================================================================
2
//        __
3 48 robfinch
//   \\__/ o\    (C) 2007-2020  Robert Finch, Waterloo
4 29 robfinch
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      fpCompare.sv
9
//    - floating point comparison unit
10 48 robfinch
//    - parameterized width
11 29 robfinch
//    - IEEE 754 representation
12
//
13
//
14
// This source file is free software: you can redistribute it and/or modify
15
// it under the terms of the GNU Lesser General Public License as published
16
// by the Free Software Foundation, either version 3 of the License, or
17
// (at your option) any later version.
18
//
19
// This source file is distributed in the hope that it will be useful,
20
// but WITHOUT ANY WARRANTY; without even the implied warranty of
21
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
// GNU General Public License for more details.
23
//
24
// You should have received a copy of the GNU General Public License
25
// along with this program.  If not, see .
26
//
27
// ============================================================================
28
 
29 48 robfinch
import fp::*;
30 29 robfinch
 
31 48 robfinch
module fpCompare(a, b, o, nan, snan);
32
input [FPWID-1:0] a, b;
33 29 robfinch
output [4:0] o;
34
reg [4:0] o;
35 48 robfinch
output nan;
36
output snan;
37 29 robfinch
 
38
// Decompose the operands
39
wire sa;
40
wire sb;
41
wire [EMSB:0] xa;
42
wire [EMSB:0] xb;
43
wire [FMSB:0] ma;
44
wire [FMSB:0] mb;
45
wire az, bz;
46
wire nan_a, nan_b;
47
 
48 48 robfinch
fpDecomp u1(.i(a), .sgn(sa), .exp(xa), .man(ma), .vz(az), .qnan(), .snan(), .nan(nan_a) );
49
fpDecomp u2(.i(b), .sgn(sb), .exp(xb), .man(mb), .vz(bz), .qnan(), .snan(), .nan(nan_b) );
50 29 robfinch
 
51
wire unordered = nan_a | nan_b;
52
 
53
wire eq = !unordered & ((az & bz) || (a==b));  // special test for zero
54
wire gt1 = {xa,ma} > {xb,mb};
55
wire lt1 = {xa,ma} < {xb,mb};
56
 
57
wire lt = sa ^ sb ? sa & !(az & bz): sa ? gt1 : lt1;
58
 
59
always @(unordered or eq or lt or lt1)
60
begin
61
        o[0] = eq;
62
        o[1] = lt;
63
        o[2] = lt|eq;
64
        o[3] = lt1;
65
        o[4] = unordered;
66
end
67
 
68
// an unorder comparison will signal a nan exception
69
//assign nanx = op!=`FCOR && op!=`FCUN && unordered;
70 48 robfinch
assign nan = nan_a|nan_b;
71
assign snan = (nan_a & ~ma[FMSB]) | (nan_b & ~mb[FMSB]);
72 29 robfinch
 
73
endmodule

powered by: WebSVN 2.1.0

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