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

Subversion Repositories ft816float

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

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

Line No. Rev Author Line
1 29 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2007-2019  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch@finitron.ca
6
//       ||
7
//
8
//      fpCompare.sv
9
//    - floating point comparison unit
10
//    - parameterized FPWIDth
11
//    - 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
`include "fpConfig.sv"
30
 
31
module fpCompare(a, b, o, nanx);
32
parameter FPWID = 32;
33
`include "fpSize.sv"
34
 
35
input [MSB:0] a, b;
36
output [4:0] o;
37
reg [4:0] o;
38
output nanx;
39
 
40
// Decompose the operands
41
wire sa;
42
wire sb;
43
wire [EMSB:0] xa;
44
wire [EMSB:0] xb;
45
wire [FMSB:0] ma;
46
wire [FMSB:0] mb;
47
wire az, bz;
48
wire nan_a, nan_b;
49
 
50
fpDecomp #(FPWID) u1(.i(a), .sgn(sa), .exp(xa), .man(ma), .vz(az), .qnan(), .snan(), .nan(nan_a) );
51
fpDecomp #(FPWID) u2(.i(b), .sgn(sb), .exp(xb), .man(mb), .vz(bz), .qnan(), .snan(), .nan(nan_b) );
52
 
53
wire unordered = nan_a | nan_b;
54
 
55
wire eq = !unordered & ((az & bz) || (a==b));  // special test for zero
56
wire gt1 = {xa,ma} > {xb,mb};
57
wire lt1 = {xa,ma} < {xb,mb};
58
 
59
wire lt = sa ^ sb ? sa & !(az & bz): sa ? gt1 : lt1;
60
 
61
always @(unordered or eq or lt or lt1)
62
begin
63
        o[0] = eq;
64
        o[1] = lt;
65
        o[2] = lt|eq;
66
        o[3] = lt1;
67
        o[4] = unordered;
68
end
69
 
70
// an unorder comparison will signal a nan exception
71
//assign nanx = op!=`FCOR && op!=`FCUN && unordered;
72
assign nanx = 1'b0;
73
 
74
endmodule

powered by: WebSVN 2.1.0

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