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
)
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
):
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
):
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
):
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
):
82 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_ZERO
):
85 return ieee754dp_zero(1);
87 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_DNORM
):
90 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_DNORM
):
94 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_NORM
):
98 /* Finally get to do some computation */
100 assert(xm
& DP_HIDDEN_BIT
);
101 assert(ym
& DP_HIDDEN_BIT
);
109 /* Compare exponent */
115 /* Compare mantissa */
121 union ieee754dp
ieee754dp_fmina(union ieee754dp x
, union ieee754dp y
)
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
):
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
):
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
):
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
):
182 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_ZERO
):
185 return ieee754dp_zero(1);
187 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_DNORM
):
190 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_DNORM
):
194 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_NORM
):
198 /* Finally get to do some computation */
200 assert(xm
& DP_HIDDEN_BIT
);
201 assert(ym
& DP_HIDDEN_BIT
);
203 /* Compare exponent */
209 /* Compare mantissa */