1 // SPDX-License-Identifier: GPL-2.0-only
3 * IEEE754 floating point arithmetic
4 * single precision: MAX{,A}.f
5 * MAX : Scalar Floating-Point Maximum
6 * MAXA: Scalar Floating-Point argument with Maximum Absolute Value
8 * MAX.S : FPR[fd] = maxNum(FPR[fs],FPR[ft])
9 * MAXA.S: FPR[fd] = maxNumMag(FPR[fs],FPR[ft])
11 * MIPS floating point support
12 * Copyright (C) 2015 Imagination Technologies, Ltd.
13 * Author: Markos Chandras <markos.chandras@imgtec.com>
16 #include "ieee754sp.h"
18 union ieee754sp
ieee754sp_fmax(union ieee754sp x
, union ieee754sp y
)
31 switch (CLPAIR(xc
, yc
)) {
32 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_SNAN
):
33 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_SNAN
):
34 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_SNAN
):
35 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_SNAN
):
36 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_SNAN
):
37 return ieee754sp_nanxcpt(y
);
39 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_SNAN
):
40 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_QNAN
):
41 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_ZERO
):
42 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_NORM
):
43 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_DNORM
):
44 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_INF
):
45 return ieee754sp_nanxcpt(x
);
52 * The case of both inputs quiet NaNs
54 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_QNAN
):
58 * The cases of exactly one input quiet NaN (numbers
59 * are here preferred as returned values to NaNs)
61 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_QNAN
):
62 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_QNAN
):
63 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_QNAN
):
64 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_QNAN
):
67 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_ZERO
):
68 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_NORM
):
69 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_DNORM
):
70 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_INF
):
74 * Infinity and zero handling
76 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_ZERO
):
77 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_NORM
):
78 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_DNORM
):
79 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_ZERO
):
80 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_ZERO
):
83 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_INF
):
84 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_INF
):
85 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_INF
):
86 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_INF
):
87 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_NORM
):
88 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_DNORM
):
91 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_ZERO
):
92 return ieee754sp_zero(xs
& ys
);
94 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_DNORM
):
98 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_DNORM
):
102 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_NORM
):
106 /* Finally get to do some computation */
108 assert(xm
& SP_HIDDEN_BIT
);
109 assert(ym
& SP_HIDDEN_BIT
);
117 /* Signs of inputs are equal, let's compare exponents */
119 /* Inputs are both positive */
125 /* Inputs are both negative */
132 /* Signs and exponents of inputs are equal, let's compare mantissas */
134 /* Inputs are both positive, with equal signs and exponents */
139 /* Inputs are both negative, with equal signs and exponents */
145 union ieee754sp
ieee754sp_fmaxa(union ieee754sp x
, union ieee754sp y
)
158 switch (CLPAIR(xc
, yc
)) {
159 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_SNAN
):
160 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_SNAN
):
161 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_SNAN
):
162 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_SNAN
):
163 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_SNAN
):
164 return ieee754sp_nanxcpt(y
);
166 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_SNAN
):
167 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_QNAN
):
168 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_ZERO
):
169 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_NORM
):
170 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_DNORM
):
171 case CLPAIR(IEEE754_CLASS_SNAN
, IEEE754_CLASS_INF
):
172 return ieee754sp_nanxcpt(x
);
179 * The case of both inputs quiet NaNs
181 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_QNAN
):
185 * The cases of exactly one input quiet NaN (numbers
186 * are here preferred as returned values to NaNs)
188 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_QNAN
):
189 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_QNAN
):
190 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_QNAN
):
191 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_QNAN
):
194 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_ZERO
):
195 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_NORM
):
196 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_DNORM
):
197 case CLPAIR(IEEE754_CLASS_QNAN
, IEEE754_CLASS_INF
):
201 * Infinity and zero handling
203 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_INF
):
204 return ieee754sp_inf(xs
& ys
);
206 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_ZERO
):
207 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_NORM
):
208 case CLPAIR(IEEE754_CLASS_INF
, IEEE754_CLASS_DNORM
):
209 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_ZERO
):
210 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_ZERO
):
213 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_INF
):
214 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_INF
):
215 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_INF
):
216 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_NORM
):
217 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_DNORM
):
220 case CLPAIR(IEEE754_CLASS_ZERO
, IEEE754_CLASS_ZERO
):
221 return ieee754sp_zero(xs
& ys
);
223 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_DNORM
):
227 case CLPAIR(IEEE754_CLASS_NORM
, IEEE754_CLASS_DNORM
):
231 case CLPAIR(IEEE754_CLASS_DNORM
, IEEE754_CLASS_NORM
):
235 /* Finally get to do some computation */
237 assert(xm
& SP_HIDDEN_BIT
);
238 assert(ym
& SP_HIDDEN_BIT
);
240 /* Compare exponent */
246 /* Compare mantissa */