thermal: fix Mediatek thermal controller build
[linux/fpc-iii.git] / arch / mips / math-emu / dp_fmin.c
blobc1072b0dfb9519dad2b5e0d8b79d2199012d1213
1 /*
2 * IEEE754 floating point arithmetic
3 * double precision: MIN{,A}.f
4 * MIN : Scalar Floating-Point Minimum
5 * MINA: Scalar Floating-Point argument with Minimum Absolute Value
7 * MIN.D : FPR[fd] = minNum(FPR[fs],FPR[ft])
8 * MINA.D: FPR[fd] = maxNumMag(FPR[fs],FPR[ft])
10 * MIPS floating point support
11 * Copyright (C) 2015 Imagination Technologies, Ltd.
12 * Author: Markos Chandras <markos.chandras@imgtec.com>
14 * This program is free software; you can distribute it and/or modify it
15 * under the terms of the GNU General Public License as published by the
16 * Free Software Foundation; version 2 of the License.
19 #include "ieee754dp.h"
21 union ieee754dp ieee754dp_fmin(union ieee754dp x, union ieee754dp y)
23 COMPXDP;
24 COMPYDP;
26 EXPLODEXDP;
27 EXPLODEYDP;
29 FLUSHXDP;
30 FLUSHYDP;
32 ieee754_clearcx();
34 switch (CLPAIR(xc, yc)) {
35 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
36 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
37 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
38 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
39 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
40 return ieee754dp_nanxcpt(y);
42 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
43 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
44 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
45 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
46 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
47 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
48 return ieee754dp_nanxcpt(x);
50 /* numbers are preferred to NaNs */
51 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
52 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
53 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
54 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
55 return x;
57 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
58 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
59 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
60 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
61 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
62 return y;
65 * Infinity and zero handling
67 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
68 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
69 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
70 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
71 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
72 return xs ? x : y;
74 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
75 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
76 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
77 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
78 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
79 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
80 return ys ? y : x;
82 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
83 if (xs == ys)
84 return x;
85 return ieee754dp_zero(1);
87 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
88 DPDNORMX;
90 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
91 DPDNORMY;
92 break;
94 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
95 DPDNORMX;
98 /* Finally get to do some computation */
100 assert(xm & DP_HIDDEN_BIT);
101 assert(ym & DP_HIDDEN_BIT);
103 /* Compare signs */
104 if (xs > ys)
105 return x;
106 else if (xs < ys)
107 return y;
109 /* Compare exponent */
110 if (xe > ye)
111 return y;
112 else if (xe < ye)
113 return x;
115 /* Compare mantissa */
116 if (xm <= ym)
117 return x;
118 return y;
121 union ieee754dp ieee754dp_fmina(union ieee754dp x, union ieee754dp y)
123 COMPXDP;
124 COMPYDP;
126 EXPLODEXDP;
127 EXPLODEYDP;
129 FLUSHXDP;
130 FLUSHYDP;
132 ieee754_clearcx();
134 switch (CLPAIR(xc, yc)) {
135 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_SNAN):
136 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_SNAN):
137 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_SNAN):
138 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_SNAN):
139 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_SNAN):
140 return ieee754dp_nanxcpt(y);
142 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_SNAN):
143 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_QNAN):
144 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_ZERO):
145 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_NORM):
146 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_DNORM):
147 case CLPAIR(IEEE754_CLASS_SNAN, IEEE754_CLASS_INF):
148 return ieee754dp_nanxcpt(x);
150 /* numbers are preferred to NaNs */
151 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_QNAN):
152 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_QNAN):
153 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_QNAN):
154 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_QNAN):
155 return x;
157 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_QNAN):
158 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_ZERO):
159 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_NORM):
160 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_DNORM):
161 case CLPAIR(IEEE754_CLASS_QNAN, IEEE754_CLASS_INF):
162 return y;
165 * Infinity and zero handling
167 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_ZERO):
168 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_NORM):
169 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_DNORM):
170 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_ZERO):
171 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_ZERO):
172 return x;
174 case CLPAIR(IEEE754_CLASS_INF, IEEE754_CLASS_INF):
175 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_INF):
176 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_INF):
177 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_INF):
178 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_NORM):
179 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_DNORM):
180 return y;
182 case CLPAIR(IEEE754_CLASS_ZERO, IEEE754_CLASS_ZERO):
183 if (xs == ys)
184 return x;
185 return ieee754dp_zero(1);
187 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_DNORM):
188 DPDNORMX;
190 case CLPAIR(IEEE754_CLASS_NORM, IEEE754_CLASS_DNORM):
191 DPDNORMY;
192 break;
194 case CLPAIR(IEEE754_CLASS_DNORM, IEEE754_CLASS_NORM):
195 DPDNORMX;
198 /* Finally get to do some computation */
200 assert(xm & DP_HIDDEN_BIT);
201 assert(ym & DP_HIDDEN_BIT);
203 /* Compare exponent */
204 if (xe > ye)
205 return y;
206 else if (xe < ye)
207 return x;
209 /* Compare mantissa */
210 if (xm <= ym)
211 return x;
212 return y;