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

Subversion Repositories thor

[/] [thor/] [trunk/] [rtl/] [verilog/] [fpUnit/] [fp_cmp_unit.v] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 robfinch
/* ============================================================================
2
        (C) 2007,2015  Robert T Finch
3
        All rights reserved.
4
        rob@birdcomputer.ca
5
 
6
        fp_cmp_unit.v
7
                - floating point comparison unit
8
                - parameterized width
9
                - IEEE 754 representation
10
 
11
        Verilog 2001
12
 
13
        Notice of Confidentiality
14
 
15
        http://en.wikipedia.org/wiki/IEEE_754
16
 
17
        Ref: Webpack 8.1i Spartan3-4 xc3s1000-4ft256
18
        111 LUTS / 58 slices / 16 ns
19
        Ref: Webpack 8.1i Spartan3-4 xc3s1000-4ft256
20
        109 LUTS / 58 slices / 16.4 ns
21
 
22
============================================================================ */
23
 
24
module fp_cmp_unit(a, b, o, nanx);
25
parameter WID = 32;
26
localparam MSB = WID-1;
27
localparam EMSB = WID==80 ? 14 :
28
                  WID==64 ? 10 :
29
                                  WID==52 ? 10 :
30
                                  WID==48 ? 10 :
31
                                  WID==44 ? 10 :
32
                                  WID==42 ? 10 :
33
                                  WID==40 ?  9 :
34
                                  WID==32 ?  7 :
35
                                  WID==24 ?  6 : 4;
36
localparam FMSB = WID==80 ? 63 :
37
                  WID==64 ? 51 :
38
                                  WID==52 ? 39 :
39
                                  WID==48 ? 35 :
40
                                  WID==44 ? 31 :
41
                                  WID==42 ? 29 :
42
                                  WID==40 ? 28 :
43
                                  WID==32 ? 22 :
44
                                  WID==24 ? 15 : 9;
45
 
46
input [WID-1:0] a, b;
47
output [3:0] o;
48
reg [3:0] o;
49
output nanx;
50
 
51
// Decompose the operands
52
wire sa;
53
wire sb;
54
wire [EMSB:0] xa;
55
wire [EMSB:0] xb;
56
wire [FMSB:0] ma;
57
wire [FMSB:0] mb;
58
wire az, bz;
59
wire nan_a, nan_b;
60
 
61
fp_decomp #(WID) u1(.i(a), .sgn(sa), .exp(xa), .man(ma), .vz(az), .qnan(), .snan(), .nan(nan_a) );
62
fp_decomp #(WID) u2(.i(b), .sgn(sb), .exp(xb), .man(mb), .vz(bz), .qnan(), .snan(), .nan(nan_b) );
63
 
64
wire unordered = nan_a | nan_b;
65
 
66
wire eq = (az & bz) || (a==b);  // special test for zero
67
wire gt1 = {xa,ma} > {xb,mb};
68
wire lt1 = {xa,ma} < {xb,mb};
69
 
70
wire lt = sa ^ sb ? sa & !(az & bz): sa ? gt1 : lt1;
71
 
72
always @(unordered or eq or lt)
73
begin
74
        o[0] = eq;
75
        o[1] = lt;
76
        o[2] = lt1;
77
        o[3] = unordered;
78
end
79
 
80
// an unorder comparison will signal a nan exception
81
//assign nanx = op!=`FCOR && op!=`FCUN && unordered;
82
assign nanx = 1'b0;
83
 
84
endmodule

powered by: WebSVN 2.1.0

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