1 |
350 |
julius |
/////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// or1200_fpu_fcmp ////
|
4 |
|
|
//// Single precision Floating Point Compare Unit ////
|
5 |
|
|
//// ////
|
6 |
|
|
//// Author: Rudolf Usselmann ////
|
7 |
|
|
//// rudi@asics.ws ////
|
8 |
|
|
//// ////
|
9 |
|
|
/////////////////////////////////////////////////////////////////////
|
10 |
|
|
//// ////
|
11 |
|
|
//// Copyright (C) 2000 Rudolf Usselmann ////
|
12 |
|
|
//// rudi@asics.ws ////
|
13 |
|
|
//// ////
|
14 |
|
|
//// This source file may be used and distributed without ////
|
15 |
|
|
//// restriction provided that this copyright statement is not ////
|
16 |
|
|
//// removed from the file and that any derivative work contains ////
|
17 |
|
|
//// the original copyright notice and the associated disclaimer.////
|
18 |
|
|
//// ////
|
19 |
|
|
//// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY ////
|
20 |
|
|
//// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED ////
|
21 |
|
|
//// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS ////
|
22 |
|
|
//// FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR ////
|
23 |
|
|
//// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, ////
|
24 |
|
|
//// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ////
|
25 |
|
|
//// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE ////
|
26 |
|
|
//// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ////
|
27 |
|
|
//// BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ////
|
28 |
|
|
//// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ////
|
29 |
|
|
//// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ////
|
30 |
|
|
//// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ////
|
31 |
|
|
//// POSSIBILITY OF SUCH DAMAGE. ////
|
32 |
|
|
//// ////
|
33 |
|
|
/////////////////////////////////////////////////////////////////////
|
34 |
|
|
|
35 |
|
|
`timescale 1ns / 100ps
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
module or1200_fpu_fcmp(opa, opb, unordered, altb, blta, aeqb, inf, zero);
|
39 |
|
|
|
40 |
|
|
input [31:0] opa, opb;
|
41 |
|
|
output unordered;
|
42 |
|
|
output altb, blta, aeqb;
|
43 |
|
|
output inf, zero;
|
44 |
|
|
|
45 |
|
|
////////////////////////////////////////////////////////////////////////
|
46 |
|
|
//
|
47 |
|
|
// Local Wire
|
48 |
|
|
//
|
49 |
|
|
|
50 |
|
|
reg altb, blta, aeqb;
|
51 |
|
|
|
52 |
|
|
wire signa, signb;
|
53 |
|
|
wire [7:0] expa, expb;
|
54 |
|
|
wire [22:0] fracta, fractb;
|
55 |
|
|
|
56 |
|
|
wire expa_ff, expb_ff, fracta_00, fractb_00;
|
57 |
|
|
wire qnan_a, snan_a, qnan_b, snan_b, opa_inf, opb_inf, inf;
|
58 |
|
|
wire qnan, snan, opa_zero, opb_zero;
|
59 |
|
|
|
60 |
|
|
wire exp_eq, exp_gt, exp_lt;
|
61 |
|
|
wire fract_eq, fract_gt, fract_lt;
|
62 |
|
|
wire all_zero;
|
63 |
|
|
|
64 |
|
|
////////////////////////////////////////////////////////////////////////
|
65 |
|
|
//
|
66 |
|
|
// Aliases
|
67 |
|
|
//
|
68 |
|
|
|
69 |
|
|
assign signa = opa[31];
|
70 |
|
|
assign signb = opb[31];
|
71 |
|
|
assign expa = opa[30:23];
|
72 |
|
|
assign expb = opb[30:23];
|
73 |
|
|
assign fracta = opa[22:0];
|
74 |
|
|
assign fractb = opb[22:0];
|
75 |
|
|
|
76 |
|
|
////////////////////////////////////////////////////////////////////////
|
77 |
|
|
//
|
78 |
|
|
// Exception Logic
|
79 |
|
|
//
|
80 |
|
|
|
81 |
|
|
assign expa_ff = &expa;
|
82 |
|
|
assign expb_ff = &expb;
|
83 |
|
|
|
84 |
|
|
assign fracta_00 = !(|fracta);
|
85 |
|
|
assign fractb_00 = !(|fractb);
|
86 |
|
|
|
87 |
|
|
assign qnan_a = fracta[22];
|
88 |
|
|
assign snan_a = !fracta[22] & |fracta[21:0];
|
89 |
|
|
assign qnan_b = fractb[22];
|
90 |
|
|
assign snan_b = !fractb[22] & |fractb[21:0];
|
91 |
|
|
|
92 |
|
|
assign opa_inf = (expa_ff & fracta_00);
|
93 |
|
|
assign opb_inf = (expb_ff & fractb_00);
|
94 |
|
|
assign inf = opa_inf | opb_inf;
|
95 |
|
|
|
96 |
|
|
assign qnan = (expa_ff & qnan_a) | (expb_ff & qnan_b);
|
97 |
|
|
assign snan = (expa_ff & snan_a) | (expb_ff & snan_b);
|
98 |
|
|
assign unordered = qnan | snan;
|
99 |
|
|
|
100 |
|
|
assign opa_zero = !(|expa) & fracta_00;
|
101 |
|
|
assign opb_zero = !(|expb) & fractb_00;
|
102 |
|
|
assign zero = opa_zero;
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
////////////////////////////////////////////////////////////////////////
|
106 |
|
|
//
|
107 |
|
|
// Comparison Logic
|
108 |
|
|
//
|
109 |
|
|
|
110 |
|
|
assign exp_eq = expa == expb;
|
111 |
|
|
assign exp_gt = expa > expb;
|
112 |
|
|
assign exp_lt = expa < expb;
|
113 |
|
|
|
114 |
|
|
assign fract_eq = fracta == fractb;
|
115 |
|
|
assign fract_gt = fracta > fractb;
|
116 |
|
|
assign fract_lt = fracta < fractb;
|
117 |
|
|
|
118 |
|
|
assign all_zero = opa_zero & opb_zero;
|
119 |
|
|
|
120 |
|
|
always @( qnan or snan or opa_inf or opb_inf or signa or signb or exp_eq or exp_gt or
|
121 |
|
|
exp_lt or fract_eq or fract_gt or fract_lt or all_zero)
|
122 |
|
|
|
123 |
|
|
casex( {qnan, snan, opa_inf, opb_inf, signa, signb, exp_eq, exp_gt, exp_lt, fract_eq, fract_gt, fract_lt, all_zero})
|
124 |
|
|
//13'b??_??_??_???_???_?: {altb, blta, aeqb} = 3'b000;
|
125 |
|
|
|
126 |
|
|
13'b1?_??_??_???_???_?: {altb, blta, aeqb} = 3'b000; // qnan
|
127 |
|
|
13'b?1_??_??_???_???_?: {altb, blta, aeqb} = 3'b000; // snan
|
128 |
|
|
|
129 |
|
|
13'b00_11_00_???_???_?: {altb, blta, aeqb} = 3'b001; // both op INF comparisson
|
130 |
|
|
13'b00_11_01_???_???_?: {altb, blta, aeqb} = 3'b100;
|
131 |
|
|
13'b00_11_10_???_???_?: {altb, blta, aeqb} = 3'b010;
|
132 |
|
|
13'b00_11_11_???_???_?: {altb, blta, aeqb} = 3'b001;
|
133 |
|
|
|
134 |
|
|
13'b00_10_00_???_???_?: {altb, blta, aeqb} = 3'b100; // opa INF comparisson
|
135 |
|
|
13'b00_10_01_???_???_?: {altb, blta, aeqb} = 3'b100;
|
136 |
|
|
13'b00_10_10_???_???_?: {altb, blta, aeqb} = 3'b010;
|
137 |
|
|
13'b00_10_11_???_???_?: {altb, blta, aeqb} = 3'b010;
|
138 |
|
|
|
139 |
|
|
13'b00_01_00_???_???_?: {altb, blta, aeqb} = 3'b010; // opb INF comparisson
|
140 |
|
|
13'b00_01_01_???_???_?: {altb, blta, aeqb} = 3'b100;
|
141 |
|
|
13'b00_01_10_???_???_?: {altb, blta, aeqb} = 3'b010;
|
142 |
|
|
13'b00_01_11_???_???_?: {altb, blta, aeqb} = 3'b100;
|
143 |
|
|
|
144 |
|
|
13'b00_00_10_???_???_0: {altb, blta, aeqb} = 3'b010; //compare base on sign
|
145 |
|
|
13'b00_00_01_???_???_0: {altb, blta, aeqb} = 3'b100; //compare base on sign
|
146 |
|
|
|
147 |
|
|
13'b00_00_??_???_???_1: {altb, blta, aeqb} = 3'b001; //compare base on sign both are zero
|
148 |
|
|
|
149 |
|
|
13'b00_00_00_010_???_?: {altb, blta, aeqb} = 3'b100; // cmp exp, equal sign
|
150 |
|
|
13'b00_00_00_001_???_?: {altb, blta, aeqb} = 3'b010;
|
151 |
|
|
13'b00_00_11_010_???_?: {altb, blta, aeqb} = 3'b010;
|
152 |
|
|
13'b00_00_11_001_???_?: {altb, blta, aeqb} = 3'b100;
|
153 |
|
|
|
154 |
|
|
13'b00_00_00_100_010_?: {altb, blta, aeqb} = 3'b100; // compare fractions, equal sign, equal exp
|
155 |
|
|
13'b00_00_00_100_001_?: {altb, blta, aeqb} = 3'b010;
|
156 |
|
|
13'b00_00_11_100_010_?: {altb, blta, aeqb} = 3'b010;
|
157 |
|
|
13'b00_00_11_100_001_?: {altb, blta, aeqb} = 3'b100;
|
158 |
|
|
|
159 |
|
|
13'b00_00_00_100_100_?: {altb, blta, aeqb} = 3'b001;
|
160 |
|
|
13'b00_00_11_100_100_?: {altb, blta, aeqb} = 3'b001;
|
161 |
|
|
|
162 |
|
|
default: {altb, blta, aeqb} = 3'bxxx;
|
163 |
|
|
endcase
|
164 |
|
|
|
165 |
|
|
endmodule // or1200_fpu_fcmp
|
166 |
|
|
|