1 /* Software floating-point emulation. Common operations.
2 Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Richard Henderson (rth@cygnus.com),
5 Jakub Jelinek (jj@ultra.linux.cz),
6 David S. Miller (davem@redhat.com) and
7 Peter Maydell (pmaydell@chiark.greenend.org.uk).
9 The GNU C Library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
14 The GNU C Library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
19 You should have received a copy of the GNU Library General Public
20 License along with the GNU C Library; see the file COPYING.LIB. If
21 not, write to the Free Software Foundation, Inc.,
22 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 #ifndef __MATH_EMU_OP_COMMON_H__
25 #define __MATH_EMU_OP_COMMON_H__
27 #define _FP_DECL(wc, X) \
28 _FP_I_TYPE X##_c=0, X##_s=0, X##_e=0; \
32 * Finish truly unpacking a native fp value by classifying the kind
33 * of fp value and normalizing both the exponent and the fraction.
36 #define _FP_UNPACK_CANONICAL(fs, wc, X) \
41 _FP_FRAC_HIGH_RAW_##fs(X) |= _FP_IMPLBIT_##fs; \
42 _FP_FRAC_SLL_##wc(X, _FP_WORKBITS); \
43 X##_e -= _FP_EXPBIAS_##fs; \
44 X##_c = FP_CLS_NORMAL; \
48 if (_FP_FRAC_ZEROP_##wc(X)) \
49 X##_c = FP_CLS_ZERO; \
52 /* a denormalized number */ \
54 _FP_FRAC_CLZ_##wc(_shift, X); \
55 _shift -= _FP_FRACXBITS_##fs; \
56 _FP_FRAC_SLL_##wc(X, (_shift+_FP_WORKBITS)); \
57 X##_e -= _FP_EXPBIAS_##fs - 1 + _shift; \
58 X##_c = FP_CLS_NORMAL; \
59 FP_SET_EXCEPTION(FP_EX_DENORM); \
62 FP_SET_EXCEPTION(FP_EX_INEXACT); \
63 X##_c = FP_CLS_ZERO; \
68 case _FP_EXPMAX_##fs: \
69 if (_FP_FRAC_ZEROP_##wc(X)) \
74 /* Check for signaling NaN */ \
75 if (!(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
76 FP_SET_EXCEPTION(FP_EX_INVALID | FP_EX_INVALID_SNAN); \
83 * Before packing the bits back into the native fp result, take care
84 * of such mundane things as rounding and overflow. Also, for some
85 * kinds of fp values, the original parts may not have been fully
86 * extracted -- but that is ok, we can regenerate them now.
89 #define _FP_PACK_CANONICAL(fs, wc, X) \
94 X##_e += _FP_EXPBIAS_##fs; \
98 if (_FP_FRAC_OVERP_##wc(fs, X)) \
100 _FP_FRAC_CLEAR_OVERP_##wc(fs, X); \
103 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
104 if (X##_e >= _FP_EXPMAX_##fs) \
107 switch (FP_ROUNDMODE) \
109 case FP_RND_NEAREST: \
110 X##_c = FP_CLS_INF; \
113 if (!X##_s) X##_c = FP_CLS_INF; \
116 if (X##_s) X##_c = FP_CLS_INF; \
119 if (X##_c == FP_CLS_INF) \
121 /* Overflow to infinity */ \
122 X##_e = _FP_EXPMAX_##fs; \
123 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
127 /* Overflow to maximum normal */ \
128 X##_e = _FP_EXPMAX_##fs - 1; \
129 _FP_FRAC_SET_##wc(X, _FP_MAXFRAC_##wc); \
131 FP_SET_EXCEPTION(FP_EX_OVERFLOW); \
132 FP_SET_EXCEPTION(FP_EX_INEXACT); \
137 /* we've got a denormalized number */ \
138 X##_e = -X##_e + 1; \
139 if (X##_e <= _FP_WFRACBITS_##fs) \
141 _FP_FRAC_SRS_##wc(X, X##_e, _FP_WFRACBITS_##fs); \
142 if (_FP_FRAC_HIGH_##fs(X) \
143 & (_FP_OVERFLOW_##fs >> 1)) \
146 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
151 if (_FP_FRAC_HIGH_##fs(X) \
152 & (_FP_OVERFLOW_##fs >> 1)) \
155 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
156 FP_SET_EXCEPTION(FP_EX_INEXACT); \
161 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
164 if ((FP_CUR_EXCEPTIONS & FP_EX_INEXACT) || \
165 (FP_TRAPPING_EXCEPTIONS & FP_EX_UNDERFLOW)) \
166 FP_SET_EXCEPTION(FP_EX_UNDERFLOW); \
170 /* underflow to zero */ \
172 if (!_FP_FRAC_ZEROP_##wc(X)) \
174 _FP_FRAC_SET_##wc(X, _FP_MINFRAC_##wc); \
176 _FP_FRAC_LOW_##wc(X) >>= (_FP_WORKBITS); \
178 FP_SET_EXCEPTION(FP_EX_UNDERFLOW); \
185 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
189 X##_e = _FP_EXPMAX_##fs; \
190 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
194 X##_e = _FP_EXPMAX_##fs; \
195 if (!_FP_KEEPNANFRACP) \
197 _FP_FRAC_SET_##wc(X, _FP_NANFRAC_##fs); \
198 X##_s = _FP_NANSIGN_##fs; \
201 _FP_FRAC_HIGH_RAW_##fs(X) |= _FP_QNANBIT_##fs; \
206 /* This one accepts raw argument and not cooked, returns
207 * 1 if X is a signaling NaN.
209 #define _FP_ISSIGNAN(fs, wc, X) \
212 if (X##_e == _FP_EXPMAX_##fs) \
214 if (!_FP_FRAC_ZEROP_##wc(X) \
215 && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
226 * Main addition routine. The input values should be cooked.
229 #define _FP_ADD_INTERNAL(fs, wc, R, X, Y, OP) \
231 switch (_FP_CLS_COMBINE(X##_c, Y##_c)) \
233 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NORMAL): \
235 /* shift the smaller number so that its exponent matches the larger */ \
236 _FP_I_TYPE diff = X##_e - Y##_e; \
241 if (diff <= _FP_WFRACBITS_##fs) \
242 _FP_FRAC_SRS_##wc(X, diff, _FP_WFRACBITS_##fs); \
243 else if (!_FP_FRAC_ZEROP_##wc(X)) \
244 _FP_FRAC_SET_##wc(X, _FP_MINFRAC_##wc); \
251 if (diff <= _FP_WFRACBITS_##fs) \
252 _FP_FRAC_SRS_##wc(Y, diff, _FP_WFRACBITS_##fs); \
253 else if (!_FP_FRAC_ZEROP_##wc(Y)) \
254 _FP_FRAC_SET_##wc(Y, _FP_MINFRAC_##wc); \
259 R##_c = FP_CLS_NORMAL; \
261 if (X##_s == Y##_s) \
264 _FP_FRAC_ADD_##wc(R, X, Y); \
265 if (_FP_FRAC_OVERP_##wc(fs, R)) \
267 _FP_FRAC_SRS_##wc(R, 1, _FP_WFRACBITS_##fs); \
274 _FP_FRAC_SUB_##wc(R, X, Y); \
275 if (_FP_FRAC_ZEROP_##wc(R)) \
277 /* return an exact zero */ \
278 if (FP_ROUNDMODE == FP_RND_MINF) \
282 R##_c = FP_CLS_ZERO; \
286 if (_FP_FRAC_NEGP_##wc(R)) \
288 _FP_FRAC_SUB_##wc(R, Y, X); \
292 /* renormalize after subtraction */ \
293 _FP_FRAC_CLZ_##wc(diff, R); \
294 diff -= _FP_WFRACXBITS_##fs; \
298 _FP_FRAC_SLL_##wc(R, diff); \
305 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NAN): \
306 _FP_CHOOSENAN(fs, wc, R, X, Y, OP); \
309 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_ZERO): \
311 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NORMAL): \
312 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_INF): \
313 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_ZERO): \
314 _FP_FRAC_COPY_##wc(R, X); \
319 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NORMAL): \
321 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NAN): \
322 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NAN): \
323 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NAN): \
324 _FP_FRAC_COPY_##wc(R, Y); \
329 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_INF): \
330 if (X##_s != Y##_s) \
332 /* +INF + -INF => NAN */ \
333 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
334 R##_s = _FP_NANSIGN_##fs; \
335 R##_c = FP_CLS_NAN; \
336 FP_SET_EXCEPTION(FP_EX_INVALID | FP_EX_INVALID_ISI); \
341 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NORMAL): \
342 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_ZERO): \
344 R##_c = FP_CLS_INF; \
347 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_INF): \
348 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_INF): \
350 R##_c = FP_CLS_INF; \
353 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_ZERO): \
354 /* make sure the sign is correct */ \
355 if (FP_ROUNDMODE == FP_RND_MINF) \
356 R##_s = X##_s | Y##_s; \
358 R##_s = X##_s & Y##_s; \
359 R##_c = FP_CLS_ZERO; \
367 #define _FP_ADD(fs, wc, R, X, Y) _FP_ADD_INTERNAL(fs, wc, R, X, Y, '+')
368 #define _FP_SUB(fs, wc, R, X, Y) \
370 if (Y##_c != FP_CLS_NAN) Y##_s ^= 1; \
371 _FP_ADD_INTERNAL(fs, wc, R, X, Y, '-'); \
376 * Main negation routine. FIXME -- when we care about setting exception
377 * bits reliably, this will not do. We should examine all of the fp classes.
380 #define _FP_NEG(fs, wc, R, X) \
382 _FP_FRAC_COPY_##wc(R, X); \
390 * Main multiplication routine. The input values should be cooked.
393 #define _FP_MUL(fs, wc, R, X, Y) \
395 R##_s = X##_s ^ Y##_s; \
396 switch (_FP_CLS_COMBINE(X##_c, Y##_c)) \
398 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NORMAL): \
399 R##_c = FP_CLS_NORMAL; \
400 R##_e = X##_e + Y##_e + 1; \
402 _FP_MUL_MEAT_##fs(R,X,Y); \
404 if (_FP_FRAC_OVERP_##wc(fs, R)) \
405 _FP_FRAC_SRS_##wc(R, 1, _FP_WFRACBITS_##fs); \
410 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NAN): \
411 _FP_CHOOSENAN(fs, wc, R, X, Y, '*'); \
414 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NORMAL): \
415 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_INF): \
416 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_ZERO): \
419 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_INF): \
420 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NORMAL): \
421 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NORMAL): \
422 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_ZERO): \
423 _FP_FRAC_COPY_##wc(R, X); \
427 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NAN): \
428 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NAN): \
429 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NAN): \
432 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_INF): \
433 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_ZERO): \
434 _FP_FRAC_COPY_##wc(R, Y); \
438 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_ZERO): \
439 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_INF): \
440 R##_s = _FP_NANSIGN_##fs; \
441 R##_c = FP_CLS_NAN; \
442 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
443 FP_SET_EXCEPTION(FP_EX_INVALID | FP_EX_INVALID_IMZ);\
453 * Main division routine. The input values should be cooked.
456 #define _FP_DIV(fs, wc, R, X, Y) \
458 R##_s = X##_s ^ Y##_s; \
459 switch (_FP_CLS_COMBINE(X##_c, Y##_c)) \
461 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NORMAL): \
462 R##_c = FP_CLS_NORMAL; \
463 R##_e = X##_e - Y##_e; \
465 _FP_DIV_MEAT_##fs(R,X,Y); \
468 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NAN): \
469 _FP_CHOOSENAN(fs, wc, R, X, Y, '/'); \
472 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NORMAL): \
473 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_INF): \
474 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_ZERO): \
476 _FP_FRAC_COPY_##wc(R, X); \
480 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NAN): \
481 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NAN): \
482 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NAN): \
484 _FP_FRAC_COPY_##wc(R, Y); \
488 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_INF): \
489 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_INF): \
490 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NORMAL): \
491 R##_c = FP_CLS_ZERO; \
494 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_ZERO): \
495 FP_SET_EXCEPTION(FP_EX_DIVZERO); \
496 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_ZERO): \
497 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NORMAL): \
498 R##_c = FP_CLS_INF; \
501 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_INF): \
502 R##_s = _FP_NANSIGN_##fs; \
503 R##_c = FP_CLS_NAN; \
504 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
505 FP_SET_EXCEPTION(FP_EX_INVALID | FP_EX_INVALID_IDI);\
508 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_ZERO): \
509 R##_s = _FP_NANSIGN_##fs; \
510 R##_c = FP_CLS_NAN; \
511 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
512 FP_SET_EXCEPTION(FP_EX_INVALID | FP_EX_INVALID_ZDZ);\
522 * Main differential comparison routine. The inputs should be raw not
523 * cooked. The return is -1,0,1 for normal values, 2 otherwise.
526 #define _FP_CMP(fs, wc, ret, X, Y, un) \
528 /* NANs are unordered */ \
529 if ((X##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(X)) \
530 || (Y##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(Y))) \
539 __is_zero_x = (!X##_e && _FP_FRAC_ZEROP_##wc(X)) ? 1 : 0; \
540 __is_zero_y = (!Y##_e && _FP_FRAC_ZEROP_##wc(Y)) ? 1 : 0; \
542 if (__is_zero_x && __is_zero_y) \
544 else if (__is_zero_x) \
545 ret = Y##_s ? 1 : -1; \
546 else if (__is_zero_y) \
547 ret = X##_s ? -1 : 1; \
548 else if (X##_s != Y##_s) \
549 ret = X##_s ? -1 : 1; \
550 else if (X##_e > Y##_e) \
551 ret = X##_s ? -1 : 1; \
552 else if (X##_e < Y##_e) \
553 ret = X##_s ? 1 : -1; \
554 else if (_FP_FRAC_GT_##wc(X, Y)) \
555 ret = X##_s ? -1 : 1; \
556 else if (_FP_FRAC_GT_##wc(Y, X)) \
557 ret = X##_s ? 1 : -1; \
564 /* Simplification for strict equality. */
566 #define _FP_CMP_EQ(fs, wc, ret, X, Y) \
568 /* NANs are unordered */ \
569 if ((X##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(X)) \
570 || (Y##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(Y))) \
576 ret = !(X##_e == Y##_e \
577 && _FP_FRAC_EQ_##wc(X, Y) \
578 && (X##_s == Y##_s || !X##_e && _FP_FRAC_ZEROP_##wc(X))); \
583 * Main square root routine. The input value should be cooked.
586 #define _FP_SQRT(fs, wc, R, X) \
588 _FP_FRAC_DECL_##wc(T); _FP_FRAC_DECL_##wc(S); \
593 _FP_FRAC_COPY_##wc(R, X); \
595 R##_c = FP_CLS_NAN; \
600 R##_s = _FP_NANSIGN_##fs; \
601 R##_c = FP_CLS_NAN; /* NAN */ \
602 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
603 FP_SET_EXCEPTION(FP_EX_INVALID); \
608 R##_c = FP_CLS_INF; /* sqrt(+inf) = +inf */ \
613 R##_c = FP_CLS_ZERO; /* sqrt(+-0) = +-0 */ \
615 case FP_CLS_NORMAL: \
619 R##_c = FP_CLS_NAN; /* sNAN */ \
620 R##_s = _FP_NANSIGN_##fs; \
621 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
622 FP_SET_EXCEPTION(FP_EX_INVALID); \
625 R##_c = FP_CLS_NORMAL; \
627 _FP_FRAC_SLL_##wc(X, 1); \
628 R##_e = X##_e >> 1; \
629 _FP_FRAC_SET_##wc(S, _FP_ZEROFRAC_##wc); \
630 _FP_FRAC_SET_##wc(R, _FP_ZEROFRAC_##wc); \
631 q = _FP_OVERFLOW_##fs >> 1; \
632 _FP_SQRT_MEAT_##wc(R, S, T, X, q); \
637 * Convert from FP to integer
640 /* RSIGNED can have following values:
641 * 0: the number is required to be 0..(2^rsize)-1, if not, NV is set plus
642 * the result is either 0 or (2^rsize)-1 depending on the sign in such case.
643 * 1: the number is required to be -(2^(rsize-1))..(2^(rsize-1))-1, if not, NV is
644 * set plus the result is either -(2^(rsize-1)) or (2^(rsize-1))-1 depending
645 * on the sign in such case.
646 * 2: the number is required to be -(2^(rsize-1))..(2^(rsize-1))-1, if not, NV is
647 * set plus the result is truncated to fit into destination.
648 * -1: the number is required to be -(2^(rsize-1))..(2^rsize)-1, if not, NV is
649 * set plus the result is either -(2^(rsize-1)) or (2^(rsize-1))-1 depending
650 * on the sign in such case.
652 #define _FP_TO_INT(fs, wc, r, X, rsize, rsigned) \
656 case FP_CLS_NORMAL: \
659 FP_SET_EXCEPTION(FP_EX_INEXACT); \
663 else if (X##_e >= rsize - (rsigned > 0 || X##_s) \
664 || (!rsigned && X##_s)) \
670 if (X##_c != FP_CLS_NORMAL \
671 || X##_e >= rsize - 1 + _FP_WFRACBITS_##fs) \
675 _FP_FRAC_SLL_##wc(X, (X##_e - _FP_WFRACBITS_##fs + 1)); \
676 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
691 FP_SET_EXCEPTION(FP_EX_INVALID); \
695 if (_FP_W_TYPE_SIZE*wc < rsize) \
697 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
698 r <<= X##_e - _FP_WFRACBITS_##fs; \
702 if (X##_e >= _FP_WFRACBITS_##fs) \
703 _FP_FRAC_SLL_##wc(X, (X##_e - _FP_WFRACBITS_##fs + 1)); \
704 else if (X##_e < _FP_WFRACBITS_##fs - 1) \
706 _FP_FRAC_SRS_##wc(X, (_FP_WFRACBITS_##fs - X##_e - 2), \
707 _FP_WFRACBITS_##fs); \
708 if (_FP_FRAC_LOW_##wc(X) & 1) \
709 FP_SET_EXCEPTION(FP_EX_INEXACT); \
710 _FP_FRAC_SRL_##wc(X, 1); \
712 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
714 if (rsigned && X##_s) \
721 #define _FP_TO_INT_ROUND(fs, wc, r, X, rsize, rsigned) \
726 case FP_CLS_NORMAL: \
727 if (X##_e >= _FP_FRACBITS_##fs - 1) \
729 if (X##_e < rsize - 1 + _FP_WFRACBITS_##fs) \
731 if (X##_e >= _FP_WFRACBITS_##fs - 1) \
733 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
734 r <<= X##_e - _FP_WFRACBITS_##fs + 1; \
738 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS - X##_e \
739 + _FP_FRACBITS_##fs - 1); \
740 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
746 if (X##_e <= -_FP_WORKBITS - 1) \
747 _FP_FRAC_SET_##wc(X, _FP_MINFRAC_##wc); \
749 _FP_FRAC_SRS_##wc(X, _FP_FRACBITS_##fs - 1 - X##_e, \
750 _FP_WFRACBITS_##fs); \
752 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
753 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
755 if (rsigned && X##_s) \
757 if (X##_e >= rsize - (rsigned > 0 || X##_s) \
758 || (!rsigned && X##_s)) \
768 else if (rsigned != 2) \
774 FP_SET_EXCEPTION(FP_EX_INVALID); \
782 #define _FP_FROM_INT(fs, wc, X, r, rsize, rtype) \
786 unsigned rtype ur_; \
787 X##_c = FP_CLS_NORMAL; \
789 if ((X##_s = (r < 0))) \
790 ur_ = (unsigned rtype) -r; \
792 ur_ = (unsigned rtype) r; \
793 if (rsize <= _FP_W_TYPE_SIZE) \
794 __FP_CLZ(X##_e, ur_); \
796 __FP_CLZ_2(X##_e, (_FP_W_TYPE)(ur_ >> _FP_W_TYPE_SIZE), \
798 if (rsize < _FP_W_TYPE_SIZE) \
799 X##_e -= (_FP_W_TYPE_SIZE - rsize); \
800 X##_e = rsize - X##_e - 1; \
802 if (_FP_FRACBITS_##fs < rsize && _FP_WFRACBITS_##fs < X##_e) \
803 __FP_FRAC_SRS_1(ur_, (X##_e - _FP_WFRACBITS_##fs + 1), rsize);\
804 _FP_FRAC_DISASSEMBLE_##wc(X, ur_, rsize); \
805 if ((_FP_WFRACBITS_##fs - X##_e - 1) > 0) \
806 _FP_FRAC_SLL_##wc(X, (_FP_WFRACBITS_##fs - X##_e - 1)); \
810 X##_c = FP_CLS_ZERO, X##_s = 0; \
815 #define FP_CONV(dfs,sfs,dwc,swc,D,S) \
817 _FP_FRAC_CONV_##dwc##_##swc(dfs, sfs, D, S); \
827 /* Count leading zeros in a word. */
830 #if _FP_W_TYPE_SIZE < 64
831 /* this is just to shut the compiler up about shifts > word length -- PMM 02/1998 */
832 #define __FP_CLZ(r, x) \
834 _FP_W_TYPE _t = (x); \
835 r = _FP_W_TYPE_SIZE - 1; \
836 if (_t > 0xffff) r -= 16; \
837 if (_t > 0xffff) _t >>= 16; \
838 if (_t > 0xff) r -= 8; \
839 if (_t > 0xff) _t >>= 8; \
840 if (_t & 0xf0) r -= 4; \
841 if (_t & 0xf0) _t >>= 4; \
842 if (_t & 0xc) r -= 2; \
843 if (_t & 0xc) _t >>= 2; \
844 if (_t & 0x2) r -= 1; \
846 #else /* not _FP_W_TYPE_SIZE < 64 */
847 #define __FP_CLZ(r, x) \
849 _FP_W_TYPE _t = (x); \
850 r = _FP_W_TYPE_SIZE - 1; \
851 if (_t > 0xffffffff) r -= 32; \
852 if (_t > 0xffffffff) _t >>= 32; \
853 if (_t > 0xffff) r -= 16; \
854 if (_t > 0xffff) _t >>= 16; \
855 if (_t > 0xff) r -= 8; \
856 if (_t > 0xff) _t >>= 8; \
857 if (_t & 0xf0) r -= 4; \
858 if (_t & 0xf0) _t >>= 4; \
859 if (_t & 0xc) r -= 2; \
860 if (_t & 0xc) _t >>= 2; \
861 if (_t & 0x2) r -= 1; \
863 #endif /* not _FP_W_TYPE_SIZE < 64 */
864 #endif /* ndef __FP_CLZ */
866 #define _FP_DIV_HELP_imm(q, r, n, d) \
868 q = n / d, r = n % d; \
871 #endif /* __MATH_EMU_OP_COMMON_H__ */
This page took 0.048343 seconds and 6 git commands to generate.