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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [rtl/] [fpUnit/] [fp_cmp_unit.v] - Blame information for rev 51

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 51 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2007-2016  Robert Finch, Waterloo
5
//    \  __ /    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
localparam MSB = WID-1;
33
localparam EMSB = WID==128 ? 14 :
34
                  WID==96 ? 14 :
35
                  WID==80 ? 14 :
36
                  WID==64 ? 10 :
37
                                  WID==52 ? 10 :
38
                                  WID==48 ? 11 :
39
                                  WID==44 ? 10 :
40
                                  WID==42 ? 10 :
41
                                  WID==40 ?  9 :
42
                                  WID==32 ?  7 :
43
                                  WID==24 ?  6 : 4;
44
localparam FMSB = WID==128 ? 111 :
45
                  WID==96 ? 79 :
46
                  WID==80 ? 63 :
47
                  WID==64 ? 51 :
48
                                  WID==52 ? 39 :
49
                                  WID==48 ? 34 :
50
                                  WID==44 ? 31 :
51
                                  WID==42 ? 29 :
52
                                  WID==40 ? 28 :
53
                                  WID==32 ? 22 :
54
                                  WID==24 ? 15 : 9;
55
 
56
input [WID-1:0] a, b;
57
output [4:0] o;
58
reg [4:0] o;
59
output nanx;
60
 
61
// Decompose the operands
62
wire sa;
63
wire sb;
64
wire [EMSB:0] xa;
65
wire [EMSB:0] xb;
66
wire [FMSB:0] ma;
67
wire [FMSB:0] mb;
68
wire az, bz;
69
wire nan_a, nan_b;
70
 
71
fp_decomp #(WID) u1(.i(a), .sgn(sa), .exp(xa), .man(ma), .vz(az), .qnan(), .snan(), .nan(nan_a) );
72
fp_decomp #(WID) u2(.i(b), .sgn(sb), .exp(xb), .man(mb), .vz(bz), .qnan(), .snan(), .nan(nan_b) );
73
 
74
wire unordered = nan_a | nan_b;
75
 
76
wire eq = (az & bz) || (a==b);  // special test for zero
77
wire gt1 = {xa,ma} > {xb,mb};
78
wire lt1 = {xa,ma} < {xb,mb};
79
 
80
wire lt = sa ^ sb ? sa & !(az & bz): sa ? gt1 : lt1;
81
 
82
always @(unordered or eq or lt or lt1)
83
begin
84
        o[0] = eq;
85
        o[1] = lt;
86
        o[2] = lt|eq;
87
        o[3] = lt1;
88
        o[4] = unordered;
89
end
90
 
91
// an unorder comparison will signal a nan exception
92
//assign nanx = op!=`FCOR && op!=`FCUN && unordered;
93
assign nanx = 1'b0;
94
 
95
endmodule

powered by: WebSVN 2.1.0

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