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

Subversion Repositories ft816float

[/] [ft816float/] [trunk/] [rtl/] [verilog/] [fp_cmp_unit.v] - Blame information for rev 89

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

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

powered by: WebSVN 2.1.0

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