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

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [rtl/] [verilog/] [fp/] [fp_cmp_unit.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 robfinch
/* ============================================================================
2
        (C) 2007  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
`define FCLT            3'd0
25
`define FCGE            3'd1
26
`define FCLE            3'd2
27
`define FCGT            3'd3
28
`define FCEQ            3'd4
29
`define FCNE            3'd5
30
`define FCUN            3'd6
31
`define FCOR            3'd7
32
 
33
module fp_cmp_unit(op, a, b, o, nanx);
34
parameter WID = 32;
35
localparam MSB = WID-1;
36
localparam EMSB = WID==80 ? 14 :
37
                  WID==64 ? 10 :
38
                                  WID==52 ? 10 :
39
                                  WID==48 ? 10 :
40
                                  WID==44 ? 10 :
41
                                  WID==42 ? 10 :
42
                                  WID==40 ?  9 :
43
                                  WID==32 ?  7 :
44
                                  WID==24 ?  6 : 4;
45
localparam FMSB = WID==80 ? 63 :
46
                  WID==64 ? 51 :
47
                                  WID==52 ? 39 :
48
                                  WID==48 ? 35 :
49
                                  WID==44 ? 31 :
50
                                  WID==42 ? 29 :
51
                                  WID==40 ? 28 :
52
                                  WID==32 ? 22 :
53
                                  WID==24 ? 15 : 9;
54
 
55
input [2:0] op;
56
input [WID-1:0] a, b;
57
output o;
58
reg 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, ugh!
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 @(op or unordered or eq or lt)
83
        case (op)       // synopsys full_case parallel_case
84
        `FCOR:  o = !unordered;
85
        `FCUN:  o =  unordered;
86
        `FCEQ:  o =  eq;
87
        `FCNE:  o = !eq;
88
        `FCLT:  o =  lt;
89
        `FCGE:  o = !lt;
90
        `FCLE:  o =  lt | eq;
91
        `FCGT:  o = !(lt | eq);
92
        endcase
93
 
94
// an unorder comparison will signal a nan exception
95
assign nanx = op!=`FCOR && op!=`FCUN && unordered;
96
 
97
endmodule

powered by: WebSVN 2.1.0

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