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 truely 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); \
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); \
143 if (_FP_FRAC_HIGH_##fs(X) \
144 & (_FP_OVERFLOW_##fs >> 1)) \
147 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
152 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
153 FP_SET_EXCEPTION(FP_EX_UNDERFLOW); \
158 /* underflow to zero */ \
160 if (!_FP_FRAC_ZEROP_##wc(X)) \
162 _FP_FRAC_SET_##wc(X, _FP_MINFRAC_##wc); \
164 _FP_FRAC_LOW_##wc(X) >>= (_FP_WORKBITS); \
166 FP_SET_EXCEPTION(FP_EX_UNDERFLOW); \
173 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
177 X##_e = _FP_EXPMAX_##fs; \
178 _FP_FRAC_SET_##wc(X, _FP_ZEROFRAC_##wc); \
182 X##_e = _FP_EXPMAX_##fs; \
183 if (!_FP_KEEPNANFRACP) \
185 _FP_FRAC_SET_##wc(X, _FP_NANFRAC_##fs); \
186 X##_s = _FP_NANSIGN_##fs; \
189 _FP_FRAC_HIGH_RAW_##fs(X) |= _FP_QNANBIT_##fs; \
194 /* This one accepts raw argument and not cooked, returns
195 * 1 if X is a signaling NaN.
197 #define _FP_ISSIGNAN(fs, wc, X) \
200 if (X##_e == _FP_EXPMAX_##fs) \
202 if (!_FP_FRAC_ZEROP_##wc(X) \
203 && !(_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs)) \
214 * Main addition routine. The input values should be cooked.
217 #define _FP_ADD_INTERNAL(fs, wc, R, X, Y, OP) \
219 switch (_FP_CLS_COMBINE(X##_c, Y##_c)) \
221 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NORMAL): \
223 /* shift the smaller number so that its exponent matches the larger */ \
224 _FP_I_TYPE diff = X##_e - Y##_e; \
229 if (diff <= _FP_WFRACBITS_##fs) \
230 _FP_FRAC_SRS_##wc(X, diff, _FP_WFRACBITS_##fs); \
231 else if (!_FP_FRAC_ZEROP_##wc(X)) \
232 _FP_FRAC_SET_##wc(X, _FP_MINFRAC_##wc); \
239 if (diff <= _FP_WFRACBITS_##fs) \
240 _FP_FRAC_SRS_##wc(Y, diff, _FP_WFRACBITS_##fs); \
241 else if (!_FP_FRAC_ZEROP_##wc(Y)) \
242 _FP_FRAC_SET_##wc(Y, _FP_MINFRAC_##wc); \
247 R##_c = FP_CLS_NORMAL; \
249 if (X##_s == Y##_s) \
252 _FP_FRAC_ADD_##wc(R, X, Y); \
253 if (_FP_FRAC_OVERP_##wc(fs, R)) \
255 _FP_FRAC_SRS_##wc(R, 1, _FP_WFRACBITS_##fs); \
262 _FP_FRAC_SUB_##wc(R, X, Y); \
263 if (_FP_FRAC_ZEROP_##wc(R)) \
265 /* return an exact zero */ \
266 if (FP_ROUNDMODE == FP_RND_MINF) \
270 R##_c = FP_CLS_ZERO; \
274 if (_FP_FRAC_NEGP_##wc(R)) \
276 _FP_FRAC_SUB_##wc(R, Y, X); \
280 /* renormalize after subtraction */ \
281 _FP_FRAC_CLZ_##wc(diff, R); \
282 diff -= _FP_WFRACXBITS_##fs; \
286 _FP_FRAC_SLL_##wc(R, diff); \
293 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NAN): \
294 _FP_CHOOSENAN(fs, wc, R, X, Y, OP); \
297 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_ZERO): \
299 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NORMAL): \
300 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_INF): \
301 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_ZERO): \
302 _FP_FRAC_COPY_##wc(R, X); \
307 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NORMAL): \
309 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NAN): \
310 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NAN): \
311 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NAN): \
312 _FP_FRAC_COPY_##wc(R, Y); \
317 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_INF): \
318 if (X##_s != Y##_s) \
320 /* +INF + -INF => NAN */ \
321 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
322 R##_s = _FP_NANSIGN_##fs; \
323 R##_c = FP_CLS_NAN; \
324 FP_SET_EXCEPTION(FP_EX_INVALID); \
329 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NORMAL): \
330 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_ZERO): \
332 R##_c = FP_CLS_INF; \
335 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_INF): \
336 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_INF): \
338 R##_c = FP_CLS_INF; \
341 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_ZERO): \
342 /* make sure the sign is correct */ \
343 if (FP_ROUNDMODE == FP_RND_MINF) \
344 R##_s = X##_s | Y##_s; \
346 R##_s = X##_s & Y##_s; \
347 R##_c = FP_CLS_ZERO; \
355 #define _FP_ADD(fs, wc, R, X, Y) _FP_ADD_INTERNAL(fs, wc, R, X, Y, '+')
356 #define _FP_SUB(fs, wc, R, X, Y) \
358 if (Y##_c != FP_CLS_NAN) Y##_s ^= 1; \
359 _FP_ADD_INTERNAL(fs, wc, R, X, Y, '-'); \
364 * Main negation routine. FIXME -- when we care about setting exception
365 * bits reliably, this will not do. We should examine all of the fp classes.
368 #define _FP_NEG(fs, wc, R, X) \
370 _FP_FRAC_COPY_##wc(R, X); \
378 * Main multiplication routine. The input values should be cooked.
381 #define _FP_MUL(fs, wc, R, X, Y) \
383 R##_s = X##_s ^ Y##_s; \
384 switch (_FP_CLS_COMBINE(X##_c, Y##_c)) \
386 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NORMAL): \
387 R##_c = FP_CLS_NORMAL; \
388 R##_e = X##_e + Y##_e + 1; \
390 _FP_MUL_MEAT_##fs(R,X,Y); \
392 if (_FP_FRAC_OVERP_##wc(fs, R)) \
393 _FP_FRAC_SRS_##wc(R, 1, _FP_WFRACBITS_##fs); \
398 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NAN): \
399 _FP_CHOOSENAN(fs, wc, R, X, Y, '*'); \
402 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NORMAL): \
403 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_INF): \
404 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_ZERO): \
407 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_INF): \
408 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NORMAL): \
409 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NORMAL): \
410 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_ZERO): \
411 _FP_FRAC_COPY_##wc(R, X); \
415 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NAN): \
416 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NAN): \
417 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NAN): \
420 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_INF): \
421 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_ZERO): \
422 _FP_FRAC_COPY_##wc(R, Y); \
426 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_ZERO): \
427 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_INF): \
428 R##_s = _FP_NANSIGN_##fs; \
429 R##_c = FP_CLS_NAN; \
430 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
431 FP_SET_EXCEPTION(FP_EX_INVALID); \
441 * Main division routine. The input values should be cooked.
444 #define _FP_DIV(fs, wc, R, X, Y) \
446 R##_s = X##_s ^ Y##_s; \
447 switch (_FP_CLS_COMBINE(X##_c, Y##_c)) \
449 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NORMAL): \
450 R##_c = FP_CLS_NORMAL; \
451 R##_e = X##_e - Y##_e; \
453 _FP_DIV_MEAT_##fs(R,X,Y); \
456 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NAN): \
457 _FP_CHOOSENAN(fs, wc, R, X, Y, '/'); \
460 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_NORMAL): \
461 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_INF): \
462 case _FP_CLS_COMBINE(FP_CLS_NAN,FP_CLS_ZERO): \
464 _FP_FRAC_COPY_##wc(R, X); \
468 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_NAN): \
469 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NAN): \
470 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NAN): \
472 _FP_FRAC_COPY_##wc(R, Y); \
476 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_INF): \
477 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_INF): \
478 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_NORMAL): \
479 R##_c = FP_CLS_ZERO; \
482 case _FP_CLS_COMBINE(FP_CLS_NORMAL,FP_CLS_ZERO): \
483 FP_SET_EXCEPTION(FP_EX_DIVZERO); \
484 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_ZERO): \
485 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_NORMAL): \
486 R##_c = FP_CLS_INF; \
489 case _FP_CLS_COMBINE(FP_CLS_INF,FP_CLS_INF): \
490 case _FP_CLS_COMBINE(FP_CLS_ZERO,FP_CLS_ZERO): \
491 R##_s = _FP_NANSIGN_##fs; \
492 R##_c = FP_CLS_NAN; \
493 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
494 FP_SET_EXCEPTION(FP_EX_INVALID); \
504 * Main differential comparison routine. The inputs should be raw not
505 * cooked. The return is -1,0,1 for normal values, 2 otherwise.
508 #define _FP_CMP(fs, wc, ret, X, Y, un) \
510 /* NANs are unordered */ \
511 if ((X##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(X)) \
512 || (Y##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(Y))) \
521 __is_zero_x = (!X##_e && _FP_FRAC_ZEROP_##wc(X)) ? 1 : 0; \
522 __is_zero_y = (!Y##_e && _FP_FRAC_ZEROP_##wc(Y)) ? 1 : 0; \
524 if (__is_zero_x && __is_zero_y) \
526 else if (__is_zero_x) \
527 ret = Y##_s ? 1 : -1; \
528 else if (__is_zero_y) \
529 ret = X##_s ? -1 : 1; \
530 else if (X##_s != Y##_s) \
531 ret = X##_s ? -1 : 1; \
532 else if (X##_e > Y##_e) \
533 ret = X##_s ? -1 : 1; \
534 else if (X##_e < Y##_e) \
535 ret = X##_s ? 1 : -1; \
536 else if (_FP_FRAC_GT_##wc(X, Y)) \
537 ret = X##_s ? -1 : 1; \
538 else if (_FP_FRAC_GT_##wc(Y, X)) \
539 ret = X##_s ? 1 : -1; \
546 /* Simplification for strict equality. */
548 #define _FP_CMP_EQ(fs, wc, ret, X, Y) \
550 /* NANs are unordered */ \
551 if ((X##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(X)) \
552 || (Y##_e == _FP_EXPMAX_##fs && !_FP_FRAC_ZEROP_##wc(Y))) \
558 ret = !(X##_e == Y##_e \
559 && _FP_FRAC_EQ_##wc(X, Y) \
560 && (X##_s == Y##_s || !X##_e && _FP_FRAC_ZEROP_##wc(X))); \
565 * Main square root routine. The input value should be cooked.
568 #define _FP_SQRT(fs, wc, R, X) \
570 _FP_FRAC_DECL_##wc(T); _FP_FRAC_DECL_##wc(S); \
575 _FP_FRAC_COPY_##wc(R, X); \
577 R##_c = FP_CLS_NAN; \
582 R##_s = _FP_NANSIGN_##fs; \
583 R##_c = FP_CLS_NAN; /* NAN */ \
584 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
585 FP_SET_EXCEPTION(FP_EX_INVALID); \
590 R##_c = FP_CLS_INF; /* sqrt(+inf) = +inf */ \
595 R##_c = FP_CLS_ZERO; /* sqrt(+-0) = +-0 */ \
597 case FP_CLS_NORMAL: \
601 R##_c = FP_CLS_NAN; /* sNAN */ \
602 R##_s = _FP_NANSIGN_##fs; \
603 _FP_FRAC_SET_##wc(R, _FP_NANFRAC_##fs); \
604 FP_SET_EXCEPTION(FP_EX_INVALID); \
607 R##_c = FP_CLS_NORMAL; \
609 _FP_FRAC_SLL_##wc(X, 1); \
610 R##_e = X##_e >> 1; \
611 _FP_FRAC_SET_##wc(S, _FP_ZEROFRAC_##wc); \
612 _FP_FRAC_SET_##wc(R, _FP_ZEROFRAC_##wc); \
613 q = _FP_OVERFLOW_##fs >> 1; \
614 _FP_SQRT_MEAT_##wc(R, S, T, X, q); \
619 * Convert from FP to integer
622 /* RSIGNED can have following values:
623 * 0: the number is required to be 0..(2^rsize)-1, if not, NV is set plus
624 * the result is either 0 or (2^rsize)-1 depending on the sign in such case.
625 * 1: the number is required to be -(2^(rsize-1))..(2^(rsize-1))-1, if not, NV is
626 * set plus the result is either -(2^(rsize-1)) or (2^(rsize-1))-1 depending
627 * on the sign in such case.
628 * 2: the number is required to be -(2^(rsize-1))..(2^(rsize-1))-1, if not, NV is
629 * set plus the result is truncated to fit into destination.
630 * -1: the number is required to be -(2^(rsize-1))..(2^rsize)-1, if not, NV is
631 * set plus the result is either -(2^(rsize-1)) or (2^(rsize-1))-1 depending
632 * on the sign in such case.
634 #define _FP_TO_INT(fs, wc, r, X, rsize, rsigned) \
638 case FP_CLS_NORMAL: \
641 FP_SET_EXCEPTION(FP_EX_INEXACT); \
645 else if (X##_e >= rsize - (rsigned > 0 || X##_s) \
646 || (!rsigned && X##_s)) \
652 if (X##_c != FP_CLS_NORMAL \
653 || X##_e >= rsize - 1 + _FP_WFRACBITS_##fs) \
657 _FP_FRAC_SLL_##wc(X, (X##_e - _FP_WFRACBITS_##fs + 1)); \
658 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
673 FP_SET_EXCEPTION(FP_EX_INVALID); \
677 if (_FP_W_TYPE_SIZE*wc < rsize) \
679 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
680 r <<= X##_e - _FP_WFRACBITS_##fs; \
684 if (X##_e >= _FP_WFRACBITS_##fs) \
685 _FP_FRAC_SLL_##wc(X, (X##_e - _FP_WFRACBITS_##fs + 1)); \
686 else if (X##_e < _FP_WFRACBITS_##fs - 1) \
688 _FP_FRAC_SRS_##wc(X, (_FP_WFRACBITS_##fs - X##_e - 2), \
689 _FP_WFRACBITS_##fs); \
690 if (_FP_FRAC_LOW_##wc(X) & 1) \
691 FP_SET_EXCEPTION(FP_EX_INEXACT); \
692 _FP_FRAC_SRL_##wc(X, 1); \
694 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
696 if (rsigned && X##_s) \
703 #define _FP_TO_INT_ROUND(fs, wc, r, X, rsize, rsigned) \
708 case FP_CLS_NORMAL: \
709 if (X##_e >= _FP_FRACBITS_##fs - 1) \
711 if (X##_e < rsize - 1 + _FP_WFRACBITS_##fs) \
713 if (X##_e >= _FP_WFRACBITS_##fs - 1) \
715 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
716 r <<= X##_e - _FP_WFRACBITS_##fs + 1; \
720 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS - X##_e \
721 + _FP_FRACBITS_##fs - 1); \
722 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
728 if (X##_e <= -_FP_WORKBITS - 1) \
729 _FP_FRAC_SET_##wc(X, _FP_MINFRAC_##wc); \
731 _FP_FRAC_SRS_##wc(X, _FP_FRACBITS_##fs - 1 - X##_e, \
732 _FP_WFRACBITS_##fs); \
734 _FP_FRAC_SRL_##wc(X, _FP_WORKBITS); \
735 _FP_FRAC_ASSEMBLE_##wc(r, X, rsize); \
737 if (rsigned && X##_s) \
739 if (X##_e >= rsize - (rsigned > 0 || X##_s) \
740 || (!rsigned && X##_s)) \
750 else if (rsigned != 2) \
756 FP_SET_EXCEPTION(FP_EX_INVALID); \
764 #define _FP_FROM_INT(fs, wc, X, r, rsize, rtype) \
768 unsigned rtype ur_; \
769 X##_c = FP_CLS_NORMAL; \
771 if ((X##_s = (r < 0))) \
772 ur_ = (unsigned rtype) -r; \
774 ur_ = (unsigned rtype) r; \
775 if (rsize <= _FP_W_TYPE_SIZE) \
776 __FP_CLZ(X##_e, ur_); \
778 __FP_CLZ_2(X##_e, (_FP_W_TYPE)(ur_ >> _FP_W_TYPE_SIZE), \
780 if (rsize < _FP_W_TYPE_SIZE) \
781 X##_e -= (_FP_W_TYPE_SIZE - rsize); \
782 X##_e = rsize - X##_e - 1; \
784 if (_FP_FRACBITS_##fs < rsize && _FP_WFRACBITS_##fs < X##_e) \
785 __FP_FRAC_SRS_1(ur_, (X##_e - _FP_WFRACBITS_##fs + 1), rsize);\
786 _FP_FRAC_DISASSEMBLE_##wc(X, ur_, rsize); \
787 if ((_FP_WFRACBITS_##fs - X##_e - 1) > 0) \
788 _FP_FRAC_SLL_##wc(X, (_FP_WFRACBITS_##fs - X##_e - 1)); \
792 X##_c = FP_CLS_ZERO, X##_s = 0; \
797 #define FP_CONV(dfs,sfs,dwc,swc,D,S) \
799 _FP_FRAC_CONV_##dwc##_##swc(dfs, sfs, D, S); \
809 /* Count leading zeros in a word. */
812 #if _FP_W_TYPE_SIZE < 64
813 /* this is just to shut the compiler up about shifts > word length -- PMM 02/1998 */
814 #define __FP_CLZ(r, x) \
816 _FP_W_TYPE _t = (x); \
817 r = _FP_W_TYPE_SIZE - 1; \
818 if (_t > 0xffff) r -= 16; \
819 if (_t > 0xffff) _t >>= 16; \
820 if (_t > 0xff) r -= 8; \
821 if (_t > 0xff) _t >>= 8; \
822 if (_t & 0xf0) r -= 4; \
823 if (_t & 0xf0) _t >>= 4; \
824 if (_t & 0xc) r -= 2; \
825 if (_t & 0xc) _t >>= 2; \
826 if (_t & 0x2) r -= 1; \
828 #else /* not _FP_W_TYPE_SIZE < 64 */
829 #define __FP_CLZ(r, x) \
831 _FP_W_TYPE _t = (x); \
832 r = _FP_W_TYPE_SIZE - 1; \
833 if (_t > 0xffffffff) r -= 32; \
834 if (_t > 0xffffffff) _t >>= 32; \
835 if (_t > 0xffff) r -= 16; \
836 if (_t > 0xffff) _t >>= 16; \
837 if (_t > 0xff) r -= 8; \
838 if (_t > 0xff) _t >>= 8; \
839 if (_t & 0xf0) r -= 4; \
840 if (_t & 0xf0) _t >>= 4; \
841 if (_t & 0xc) r -= 2; \
842 if (_t & 0xc) _t >>= 2; \
843 if (_t & 0x2) r -= 1; \
845 #endif /* not _FP_W_TYPE_SIZE < 64 */
846 #endif /* ndef __FP_CLZ */
848 #define _FP_DIV_HELP_imm(q, r, n, d) \
850 q = n / d, r = n % d; \
853 #endif /* __MATH_EMU_OP_COMMON_H__ */