00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "tconfig.h"
00043 #include "coretypes.h"
00044 #include "tm.h"
00045 #include "config/fp-bit.h"
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 #ifdef DECLARE_LIBRARY_RENAMES
00076 DECLARE_LIBRARY_RENAMES
00077 #endif
00078
00079 #ifdef EXTENDED_FLOAT_STUBS
00080 extern void abort (void);
00081 void __extendsfxf2 (void) { abort(); }
00082 void __extenddfxf2 (void) { abort(); }
00083 void __truncxfdf2 (void) { abort(); }
00084 void __truncxfsf2 (void) { abort(); }
00085 void __fixxfsi (void) { abort(); }
00086 void __floatsixf (void) { abort(); }
00087 void __addxf3 (void) { abort(); }
00088 void __subxf3 (void) { abort(); }
00089 void __mulxf3 (void) { abort(); }
00090 void __divxf3 (void) { abort(); }
00091 void __negxf2 (void) { abort(); }
00092 void __eqxf2 (void) { abort(); }
00093 void __nexf2 (void) { abort(); }
00094 void __gtxf2 (void) { abort(); }
00095 void __gexf2 (void) { abort(); }
00096 void __lexf2 (void) { abort(); }
00097 void __ltxf2 (void) { abort(); }
00098
00099 void __extendsftf2 (void) { abort(); }
00100 void __extenddftf2 (void) { abort(); }
00101 void __trunctfdf2 (void) { abort(); }
00102 void __trunctfsf2 (void) { abort(); }
00103 void __fixtfsi (void) { abort(); }
00104 void __floatsitf (void) { abort(); }
00105 void __addtf3 (void) { abort(); }
00106 void __subtf3 (void) { abort(); }
00107 void __multf3 (void) { abort(); }
00108 void __divtf3 (void) { abort(); }
00109 void __negtf2 (void) { abort(); }
00110 void __eqtf2 (void) { abort(); }
00111 void __netf2 (void) { abort(); }
00112 void __gttf2 (void) { abort(); }
00113 void __getf2 (void) { abort(); }
00114 void __letf2 (void) { abort(); }
00115 void __lttf2 (void) { abort(); }
00116 #else
00117
00118
00119
00120 #ifdef NO_NANS
00121
00122 #define nan() 0
00123 #define isnan(x) 0
00124 #define isinf(x) 0
00125 #else
00126
00127 #if defined L_thenan_sf
00128 const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
00129 #elif defined L_thenan_df
00130 const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, {(fractype) 0} };
00131 #elif defined L_thenan_tf
00132 const fp_number_type __thenan_tf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
00133 #elif defined TFLOAT
00134 extern const fp_number_type __thenan_tf;
00135 #elif defined FLOAT
00136 extern const fp_number_type __thenan_sf;
00137 #else
00138 extern const fp_number_type __thenan_df;
00139 #endif
00140
00141 INLINE
00142 static fp_number_type *
00143 nan (void)
00144 {
00145
00146 #ifdef TFLOAT
00147 return (fp_number_type *) (& __thenan_tf);
00148 #elif defined FLOAT
00149 return (fp_number_type *) (& __thenan_sf);
00150 #else
00151 return (fp_number_type *) (& __thenan_df);
00152 #endif
00153 }
00154
00155 INLINE
00156 static int
00157 isnan ( fp_number_type * x)
00158 {
00159 return __builtin_expect (x->class == CLASS_SNAN || x->class == CLASS_QNAN,
00160 0);
00161 }
00162
00163 INLINE
00164 static int
00165 isinf ( fp_number_type * x)
00166 {
00167 return __builtin_expect (x->class == CLASS_INFINITY, 0);
00168 }
00169
00170 #endif
00171
00172 INLINE
00173 static int
00174 iszero ( fp_number_type * x)
00175 {
00176 return x->class == CLASS_ZERO;
00177 }
00178
00179 INLINE
00180 static void
00181 flip_sign ( fp_number_type * x)
00182 {
00183 x->sign = !x->sign;
00184 }
00185
00186
00187 INLINE
00188 static int
00189 clzusi (USItype n)
00190 {
00191 extern int __clzsi2 (USItype);
00192 if (sizeof (USItype) == sizeof (unsigned int))
00193 return __builtin_clz (n);
00194 else if (sizeof (USItype) == sizeof (unsigned long))
00195 return __builtin_clzl (n);
00196 else if (sizeof (USItype) == sizeof (unsigned long long))
00197 return __builtin_clzll (n);
00198 else
00199 return __clzsi2 (n);
00200 }
00201
00202 extern FLO_type pack_d ( fp_number_type * );
00203
00204 #if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
00205 FLO_type
00206 pack_d ( fp_number_type * src)
00207 {
00208 FLO_union_type dst;
00209 fractype fraction = src->fraction.ll;
00210 int sign = src->sign;
00211 int exp = 0;
00212
00213 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))
00214 {
00215
00216
00217
00218 exp = EXPMAX;
00219 fraction = ((fractype) 1 << FRACBITS) - 1;
00220 }
00221 else if (isnan (src))
00222 {
00223 exp = EXPMAX;
00224 if (src->class == CLASS_QNAN || 1)
00225 {
00226 #ifdef QUIET_NAN_NEGATED
00227 fraction |= QUIET_NAN - 1;
00228 #else
00229 fraction |= QUIET_NAN;
00230 #endif
00231 }
00232 }
00233 else if (isinf (src))
00234 {
00235 exp = EXPMAX;
00236 fraction = 0;
00237 }
00238 else if (iszero (src))
00239 {
00240 exp = 0;
00241 fraction = 0;
00242 }
00243 else if (fraction == 0)
00244 {
00245 exp = 0;
00246 }
00247 else
00248 {
00249 if (__builtin_expect (src->normal_exp < NORMAL_EXPMIN, 0))
00250 {
00251 #ifdef NO_DENORMALS
00252
00253
00254
00255 exp = 0;
00256 fraction = 0;
00257 #else
00258
00259
00260
00261
00262 int shift = NORMAL_EXPMIN - src->normal_exp;
00263
00264 exp = 0;
00265
00266 if (shift > FRAC_NBITS - NGARDS)
00267 {
00268
00269 fraction = 0;
00270 }
00271 else
00272 {
00273 int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
00274 fraction = (fraction >> shift) | lowbit;
00275 }
00276 if ((fraction & GARDMASK) == GARDMSB)
00277 {
00278 if ((fraction & (1 << NGARDS)))
00279 fraction += GARDROUND + 1;
00280 }
00281 else
00282 {
00283
00284 fraction += GARDROUND;
00285 }
00286
00287
00288 if (fraction >= IMPLICIT_1)
00289 {
00290 exp += 1;
00291 }
00292 fraction >>= NGARDS;
00293 #endif
00294 }
00295 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
00296 && __builtin_expect (src->normal_exp > EXPBIAS, 0))
00297 {
00298 exp = EXPMAX;
00299 fraction = 0;
00300 }
00301 else
00302 {
00303 exp = src->normal_exp + EXPBIAS;
00304 if (!ROUND_TOWARDS_ZERO)
00305 {
00306
00307
00308
00309 if ((fraction & GARDMASK) == GARDMSB)
00310 {
00311 if (fraction & (1 << NGARDS))
00312 fraction += GARDROUND + 1;
00313 }
00314 else
00315 {
00316
00317 fraction += GARDROUND;
00318 }
00319 if (fraction >= IMPLICIT_2)
00320 {
00321 fraction >>= 1;
00322 exp += 1;
00323 }
00324 }
00325 fraction >>= NGARDS;
00326
00327 if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
00328 {
00329
00330 exp = EXPMAX;
00331 fraction = ((fractype) 1 << FRACBITS) - 1;
00332 }
00333 }
00334 }
00335
00336
00337
00338
00339 #ifdef FLOAT_BIT_ORDER_MISMATCH
00340 dst.bits.fraction = fraction;
00341 dst.bits.exp = exp;
00342 dst.bits.sign = sign;
00343 #else
00344 # if defined TFLOAT && defined HALFFRACBITS
00345 {
00346 halffractype high, low, unity;
00347 int lowsign, lowexp;
00348
00349 unity = (halffractype) 1 << HALFFRACBITS;
00350
00351
00352
00353 high = (fraction >> (FRACBITS - HALFFRACBITS)) & (unity - 1);
00354 low = fraction & (unity * 2 - 1);
00355
00356
00357 lowexp = exp - HALFFRACBITS - 1;
00358 lowsign = sign;
00359
00360
00361
00362 if (exp < EXPMAX)
00363 if (low > unity || (low == unity && (high & 1) == 1))
00364 {
00365
00366 high++;
00367 if (high == unity)
00368 {
00369
00370 high = 0;
00371 exp++;
00372 }
00373 low = unity * 2 - low;
00374 lowsign ^= 1;
00375 }
00376
00377 high |= (halffractype) exp << HALFFRACBITS;
00378 high |= (halffractype) sign << (HALFFRACBITS + EXPBITS);
00379
00380 if (exp == EXPMAX || exp == 0 || low == 0)
00381 low = 0;
00382 else
00383 {
00384 while (lowexp > 0 && low < unity)
00385 {
00386 low <<= 1;
00387 lowexp--;
00388 }
00389
00390 if (lowexp <= 0)
00391 {
00392 halffractype roundmsb, round;
00393 int shift;
00394
00395 shift = 1 - lowexp;
00396 roundmsb = (1 << (shift - 1));
00397 round = low & ((roundmsb << 1) - 1);
00398
00399 low >>= shift;
00400 lowexp = 0;
00401
00402 if (round > roundmsb || (round == roundmsb && (low & 1) == 1))
00403 {
00404 low++;
00405 if (low == unity)
00406
00407 lowexp++;
00408 }
00409 }
00410
00411 low &= unity - 1;
00412 low |= (halffractype) lowexp << HALFFRACBITS;
00413 low |= (halffractype) lowsign << (HALFFRACBITS + EXPBITS);
00414 }
00415 dst.value_raw = ((fractype) high << HALFSHIFT) | low;
00416 }
00417 # else
00418 dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
00419 dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
00420 dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
00421 # endif
00422 #endif
00423
00424 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
00425 #ifdef TFLOAT
00426 {
00427 qrtrfractype tmp1 = dst.words[0];
00428 qrtrfractype tmp2 = dst.words[1];
00429 dst.words[0] = dst.words[3];
00430 dst.words[1] = dst.words[2];
00431 dst.words[2] = tmp2;
00432 dst.words[3] = tmp1;
00433 }
00434 #else
00435 {
00436 halffractype tmp = dst.words[0];
00437 dst.words[0] = dst.words[1];
00438 dst.words[1] = tmp;
00439 }
00440 #endif
00441 #endif
00442
00443 return dst.value;
00444 }
00445 #endif
00446
00447 #if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)
00448 void
00449 unpack_d (FLO_union_type * src, fp_number_type * dst)
00450 {
00451
00452
00453
00454 fractype fraction;
00455 int exp;
00456 int sign;
00457
00458 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
00459 FLO_union_type swapped;
00460
00461 #ifdef TFLOAT
00462 swapped.words[0] = src->words[3];
00463 swapped.words[1] = src->words[2];
00464 swapped.words[2] = src->words[1];
00465 swapped.words[3] = src->words[0];
00466 #else
00467 swapped.words[0] = src->words[1];
00468 swapped.words[1] = src->words[0];
00469 #endif
00470 src = &swapped;
00471 #endif
00472
00473 #ifdef FLOAT_BIT_ORDER_MISMATCH
00474 fraction = src->bits.fraction;
00475 exp = src->bits.exp;
00476 sign = src->bits.sign;
00477 #else
00478 # if defined TFLOAT && defined HALFFRACBITS
00479 {
00480 halffractype high, low;
00481
00482 high = src->value_raw >> HALFSHIFT;
00483 low = src->value_raw & (((fractype)1 << HALFSHIFT) - 1);
00484
00485 fraction = high & ((((fractype)1) << HALFFRACBITS) - 1);
00486 fraction <<= FRACBITS - HALFFRACBITS;
00487 exp = ((int)(high >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
00488 sign = ((int)(high >> (((HALFFRACBITS + EXPBITS))))) & 1;
00489
00490 if (exp != EXPMAX && exp != 0 && low != 0)
00491 {
00492 int lowexp = ((int)(low >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
00493 int lowsign = ((int)(low >> (((HALFFRACBITS + EXPBITS))))) & 1;
00494 int shift;
00495 fractype xlow;
00496
00497 xlow = low & ((((fractype)1) << HALFFRACBITS) - 1);
00498 if (lowexp)
00499 xlow |= (((halffractype)1) << HALFFRACBITS);
00500 else
00501 lowexp = 1;
00502 shift = (FRACBITS - HALFFRACBITS) - (exp - lowexp);
00503 if (shift > 0)
00504 xlow <<= shift;
00505 else if (shift < 0)
00506 xlow >>= -shift;
00507 if (sign == lowsign)
00508 fraction += xlow;
00509 else if (fraction >= xlow)
00510 fraction -= xlow;
00511 else
00512 {
00513
00514
00515
00516 fraction = (((fractype) 1 << FRACBITS) - xlow) << 1;
00517 exp--;
00518 }
00519 }
00520 }
00521 # else
00522 fraction = src->value_raw & ((((fractype)1) << FRACBITS) - 1);
00523 exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
00524 sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
00525 # endif
00526 #endif
00527
00528 dst->sign = sign;
00529 if (exp == 0)
00530 {
00531
00532 if (fraction == 0
00533 #ifdef NO_DENORMALS
00534 || 1
00535 #endif
00536 )
00537 {
00538
00539 dst->class = CLASS_ZERO;
00540 }
00541 else
00542 {
00543
00544
00545
00546 dst->normal_exp = exp - EXPBIAS + 1;
00547 fraction <<= NGARDS;
00548
00549 dst->class = CLASS_NUMBER;
00550 #if 1
00551 while (fraction < IMPLICIT_1)
00552 {
00553 fraction <<= 1;
00554 dst->normal_exp--;
00555 }
00556 #endif
00557 dst->fraction.ll = fraction;
00558 }
00559 }
00560 else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
00561 && __builtin_expect (exp == EXPMAX, 0))
00562 {
00563
00564 if (fraction == 0)
00565 {
00566
00567 dst->class = CLASS_INFINITY;
00568 }
00569 else
00570 {
00571
00572 #ifdef QUIET_NAN_NEGATED
00573 if ((fraction & QUIET_NAN) == 0)
00574 #else
00575 if (fraction & QUIET_NAN)
00576 #endif
00577 {
00578 dst->class = CLASS_QNAN;
00579 }
00580 else
00581 {
00582 dst->class = CLASS_SNAN;
00583 }
00584
00585 dst->fraction.ll = fraction;
00586 }
00587 }
00588 else
00589 {
00590
00591 dst->normal_exp = exp - EXPBIAS;
00592 dst->class = CLASS_NUMBER;
00593 dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
00594 }
00595 }
00596 #endif
00597
00598 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
00599 static fp_number_type *
00600 _fpadd_parts (fp_number_type * a,
00601 fp_number_type * b,
00602 fp_number_type * tmp)
00603 {
00604 intfrac tfraction;
00605
00606
00607 int a_normal_exp;
00608 int b_normal_exp;
00609 fractype a_fraction;
00610 fractype b_fraction;
00611
00612 if (isnan (a))
00613 {
00614 return a;
00615 }
00616 if (isnan (b))
00617 {
00618 return b;
00619 }
00620 if (isinf (a))
00621 {
00622
00623 if (isinf (b) && a->sign != b->sign)
00624 return nan ();
00625 return a;
00626 }
00627 if (isinf (b))
00628 {
00629 return b;
00630 }
00631 if (iszero (b))
00632 {
00633 if (iszero (a))
00634 {
00635 *tmp = *a;
00636 tmp->sign = a->sign & b->sign;
00637 return tmp;
00638 }
00639 return a;
00640 }
00641 if (iszero (a))
00642 {
00643 return b;
00644 }
00645
00646
00647
00648 {
00649 int diff;
00650 int sdiff;
00651
00652 a_normal_exp = a->normal_exp;
00653 b_normal_exp = b->normal_exp;
00654 a_fraction = a->fraction.ll;
00655 b_fraction = b->fraction.ll;
00656
00657 diff = a_normal_exp - b_normal_exp;
00658 sdiff = diff;
00659
00660 if (diff < 0)
00661 diff = -diff;
00662 if (diff < FRAC_NBITS)
00663 {
00664 if (sdiff > 0)
00665 {
00666 b_normal_exp += diff;
00667 LSHIFT (b_fraction, diff);
00668 }
00669 else if (sdiff < 0)
00670 {
00671 a_normal_exp += diff;
00672 LSHIFT (a_fraction, diff);
00673 }
00674 }
00675 else
00676 {
00677
00678 if (a_normal_exp > b_normal_exp)
00679 {
00680 b_normal_exp = a_normal_exp;
00681 b_fraction = 0;
00682 }
00683 else
00684 {
00685 a_normal_exp = b_normal_exp;
00686 a_fraction = 0;
00687 }
00688 }
00689 }
00690
00691 if (a->sign != b->sign)
00692 {
00693 if (a->sign)
00694 {
00695 tfraction = -a_fraction + b_fraction;
00696 }
00697 else
00698 {
00699 tfraction = a_fraction - b_fraction;
00700 }
00701 if (tfraction >= 0)
00702 {
00703 tmp->sign = 0;
00704 tmp->normal_exp = a_normal_exp;
00705 tmp->fraction.ll = tfraction;
00706 }
00707 else
00708 {
00709 tmp->sign = 1;
00710 tmp->normal_exp = a_normal_exp;
00711 tmp->fraction.ll = -tfraction;
00712 }
00713
00714
00715 while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
00716 {
00717 tmp->fraction.ll <<= 1;
00718 tmp->normal_exp--;
00719 }
00720 }
00721 else
00722 {
00723 tmp->sign = a->sign;
00724 tmp->normal_exp = a_normal_exp;
00725 tmp->fraction.ll = a_fraction + b_fraction;
00726 }
00727 tmp->class = CLASS_NUMBER;
00728
00729
00730
00731 if (tmp->fraction.ll >= IMPLICIT_2)
00732 {
00733 LSHIFT (tmp->fraction.ll, 1);
00734 tmp->normal_exp++;
00735 }
00736 return tmp;
00737
00738 }
00739
00740 FLO_type
00741 add (FLO_type arg_a, FLO_type arg_b)
00742 {
00743 fp_number_type a;
00744 fp_number_type b;
00745 fp_number_type tmp;
00746 fp_number_type *res;
00747 FLO_union_type au, bu;
00748
00749 au.value = arg_a;
00750 bu.value = arg_b;
00751
00752 unpack_d (&au, &a);
00753 unpack_d (&bu, &b);
00754
00755 res = _fpadd_parts (&a, &b, &tmp);
00756
00757 return pack_d (res);
00758 }
00759
00760 FLO_type
00761 sub (FLO_type arg_a, FLO_type arg_b)
00762 {
00763 fp_number_type a;
00764 fp_number_type b;
00765 fp_number_type tmp;
00766 fp_number_type *res;
00767 FLO_union_type au, bu;
00768
00769 au.value = arg_a;
00770 bu.value = arg_b;
00771
00772 unpack_d (&au, &a);
00773 unpack_d (&bu, &b);
00774
00775 b.sign ^= 1;
00776
00777 res = _fpadd_parts (&a, &b, &tmp);
00778
00779 return pack_d (res);
00780 }
00781 #endif
00782
00783 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
00784 static inline __attribute__ ((__always_inline__)) fp_number_type *
00785 _fpmul_parts ( fp_number_type * a,
00786 fp_number_type * b,
00787 fp_number_type * tmp)
00788 {
00789 fractype low = 0;
00790 fractype high = 0;
00791
00792 if (isnan (a))
00793 {
00794 a->sign = a->sign != b->sign;
00795 return a;
00796 }
00797 if (isnan (b))
00798 {
00799 b->sign = a->sign != b->sign;
00800 return b;
00801 }
00802 if (isinf (a))
00803 {
00804 if (iszero (b))
00805 return nan ();
00806 a->sign = a->sign != b->sign;
00807 return a;
00808 }
00809 if (isinf (b))
00810 {
00811 if (iszero (a))
00812 {
00813 return nan ();
00814 }
00815 b->sign = a->sign != b->sign;
00816 return b;
00817 }
00818 if (iszero (a))
00819 {
00820 a->sign = a->sign != b->sign;
00821 return a;
00822 }
00823 if (iszero (b))
00824 {
00825 b->sign = a->sign != b->sign;
00826 return b;
00827 }
00828
00829
00830
00831 {
00832 #if defined(NO_DI_MODE) || defined(TFLOAT)
00833 {
00834 fractype x = a->fraction.ll;
00835 fractype ylow = b->fraction.ll;
00836 fractype yhigh = 0;
00837 int bit;
00838
00839
00840 for (bit = 0; bit < FRAC_NBITS; bit++)
00841 {
00842 int carry;
00843
00844 if (x & 1)
00845 {
00846 carry = (low += ylow) < ylow;
00847 high += yhigh + carry;
00848 }
00849 yhigh <<= 1;
00850 if (ylow & FRACHIGH)
00851 {
00852 yhigh |= 1;
00853 }
00854 ylow <<= 1;
00855 x >>= 1;
00856 }
00857 }
00858 #elif defined(FLOAT)
00859
00860 {
00861 UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
00862
00863 high = answer >> BITS_PER_SI;
00864 low = answer;
00865 }
00866 #else
00867
00868
00869
00870 {
00871 USItype nl = a->fraction.ll;
00872 USItype nh = a->fraction.ll >> BITS_PER_SI;
00873 USItype ml = b->fraction.ll;
00874 USItype mh = b->fraction.ll >> BITS_PER_SI;
00875 UDItype pp_ll = (UDItype) ml * nl;
00876 UDItype pp_hl = (UDItype) mh * nl;
00877 UDItype pp_lh = (UDItype) ml * nh;
00878 UDItype pp_hh = (UDItype) mh * nh;
00879 UDItype res2 = 0;
00880 UDItype res0 = 0;
00881 UDItype ps_hh__ = pp_hl + pp_lh;
00882 if (ps_hh__ < pp_hl)
00883 res2 += (UDItype)1 << BITS_PER_SI;
00884 pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
00885 res0 = pp_ll + pp_hl;
00886 if (res0 < pp_ll)
00887 res2++;
00888 res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
00889 high = res2;
00890 low = res0;
00891 }
00892 #endif
00893 }
00894
00895 tmp->normal_exp = a->normal_exp + b->normal_exp
00896 + FRAC_NBITS - (FRACBITS + NGARDS);
00897 tmp->sign = a->sign != b->sign;
00898 while (high >= IMPLICIT_2)
00899 {
00900 tmp->normal_exp++;
00901 if (high & 1)
00902 {
00903 low >>= 1;
00904 low |= FRACHIGH;
00905 }
00906 high >>= 1;
00907 }
00908 while (high < IMPLICIT_1)
00909 {
00910 tmp->normal_exp--;
00911
00912 high <<= 1;
00913 if (low & FRACHIGH)
00914 high |= 1;
00915 low <<= 1;
00916 }
00917
00918 if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
00919 {
00920 if (high & (1 << NGARDS))
00921 {
00922
00923
00924
00925
00926
00927
00928 }
00929 else if (low)
00930 {
00931
00932
00933
00934
00935 high += GARDROUND + 1;
00936
00937
00938 high &= ~(fractype) GARDMASK;
00939 }
00940 }
00941 tmp->fraction.ll = high;
00942 tmp->class = CLASS_NUMBER;
00943 return tmp;
00944 }
00945
00946 FLO_type
00947 multiply (FLO_type arg_a, FLO_type arg_b)
00948 {
00949 fp_number_type a;
00950 fp_number_type b;
00951 fp_number_type tmp;
00952 fp_number_type *res;
00953 FLO_union_type au, bu;
00954
00955 au.value = arg_a;
00956 bu.value = arg_b;
00957
00958 unpack_d (&au, &a);
00959 unpack_d (&bu, &b);
00960
00961 res = _fpmul_parts (&a, &b, &tmp);
00962
00963 return pack_d (res);
00964 }
00965 #endif
00966
00967 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
00968 static inline __attribute__ ((__always_inline__)) fp_number_type *
00969 _fpdiv_parts (fp_number_type * a,
00970 fp_number_type * b)
00971 {
00972 fractype bit;
00973 fractype numerator;
00974 fractype denominator;
00975 fractype quotient;
00976
00977 if (isnan (a))
00978 {
00979 return a;
00980 }
00981 if (isnan (b))
00982 {
00983 return b;
00984 }
00985
00986 a->sign = a->sign ^ b->sign;
00987
00988 if (isinf (a) || iszero (a))
00989 {
00990 if (a->class == b->class)
00991 return nan ();
00992 return a;
00993 }
00994
00995 if (isinf (b))
00996 {
00997 a->fraction.ll = 0;
00998 a->normal_exp = 0;
00999 return a;
01000 }
01001 if (iszero (b))
01002 {
01003 a->class = CLASS_INFINITY;
01004 return a;
01005 }
01006
01007
01008
01009 {
01010
01011
01012
01013
01014 a->normal_exp = a->normal_exp - b->normal_exp;
01015 numerator = a->fraction.ll;
01016 denominator = b->fraction.ll;
01017
01018 if (numerator < denominator)
01019 {
01020
01021 numerator *= 2;
01022 a->normal_exp--;
01023 }
01024 bit = IMPLICIT_1;
01025 quotient = 0;
01026
01027 while (bit)
01028 {
01029 if (numerator >= denominator)
01030 {
01031 quotient |= bit;
01032 numerator -= denominator;
01033 }
01034 bit >>= 1;
01035 numerator *= 2;
01036 }
01037
01038 if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
01039 {
01040 if (quotient & (1 << NGARDS))
01041 {
01042
01043
01044
01045
01046 }
01047 else if (numerator)
01048 {
01049
01050
01051
01052
01053 quotient += GARDROUND + 1;
01054
01055
01056 quotient &= ~(fractype) GARDMASK;
01057 }
01058 }
01059
01060 a->fraction.ll = quotient;
01061 return (a);
01062 }
01063 }
01064
01065 FLO_type
01066 divide (FLO_type arg_a, FLO_type arg_b)
01067 {
01068 fp_number_type a;
01069 fp_number_type b;
01070 fp_number_type *res;
01071 FLO_union_type au, bu;
01072
01073 au.value = arg_a;
01074 bu.value = arg_b;
01075
01076 unpack_d (&au, &a);
01077 unpack_d (&bu, &b);
01078
01079 res = _fpdiv_parts (&a, &b);
01080
01081 return pack_d (res);
01082 }
01083 #endif
01084
01085 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df) \
01086 || defined(L_fpcmp_parts_tf)
01087
01088
01089
01090
01091
01092
01093 int
01094 __fpcmp_parts (fp_number_type * a, fp_number_type * b)
01095 {
01096 #if 0
01097
01098 if (isnan (a) && isnan (b))
01099 {
01100 return 1;
01101 }
01102 #endif
01103
01104 if (isnan (a) || isnan (b))
01105 {
01106 return 1;
01107 }
01108 if (isinf (a) && isinf (b))
01109 {
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119 return b->sign - a->sign;
01120 }
01121
01122 if (isinf (a))
01123 {
01124 return a->sign ? -1 : 1;
01125 }
01126 if (isinf (b))
01127 {
01128 return b->sign ? 1 : -1;
01129 }
01130 if (iszero (a) && iszero (b))
01131 {
01132 return 0;
01133 }
01134 if (iszero (a))
01135 {
01136 return b->sign ? 1 : -1;
01137 }
01138 if (iszero (b))
01139 {
01140 return a->sign ? -1 : 1;
01141 }
01142
01143 if (a->sign != b->sign)
01144 {
01145
01146 return a->sign ? -1 : 1;
01147 }
01148
01149 if (a->normal_exp > b->normal_exp)
01150 {
01151 return a->sign ? -1 : 1;
01152 }
01153 if (a->normal_exp < b->normal_exp)
01154 {
01155 return a->sign ? 1 : -1;
01156 }
01157
01158 if (a->fraction.ll > b->fraction.ll)
01159 {
01160 return a->sign ? -1 : 1;
01161 }
01162 if (a->fraction.ll < b->fraction.ll)
01163 {
01164 return a->sign ? 1 : -1;
01165 }
01166
01167 return 0;
01168 }
01169 #endif
01170
01171 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compoare_tf)
01172 CMPtype
01173 compare (FLO_type arg_a, FLO_type arg_b)
01174 {
01175 fp_number_type a;
01176 fp_number_type b;
01177 FLO_union_type au, bu;
01178
01179 au.value = arg_a;
01180 bu.value = arg_b;
01181
01182 unpack_d (&au, &a);
01183 unpack_d (&bu, &b);
01184
01185 return __fpcmp_parts (&a, &b);
01186 }
01187 #endif
01188
01189 #ifndef US_SOFTWARE_GOFAST
01190
01191
01192
01193 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
01194 CMPtype
01195 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
01196 {
01197 fp_number_type a;
01198 fp_number_type b;
01199 FLO_union_type au, bu;
01200
01201 au.value = arg_a;
01202 bu.value = arg_b;
01203
01204 unpack_d (&au, &a);
01205 unpack_d (&bu, &b);
01206
01207 if (isnan (&a) || isnan (&b))
01208 return 1;
01209
01210 return __fpcmp_parts (&a, &b) ;
01211 }
01212 #endif
01213
01214 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
01215 CMPtype
01216 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
01217 {
01218 fp_number_type a;
01219 fp_number_type b;
01220 FLO_union_type au, bu;
01221
01222 au.value = arg_a;
01223 bu.value = arg_b;
01224
01225 unpack_d (&au, &a);
01226 unpack_d (&bu, &b);
01227
01228 if (isnan (&a) || isnan (&b))
01229 return 1;
01230
01231 return __fpcmp_parts (&a, &b) ;
01232 }
01233 #endif
01234
01235 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
01236 CMPtype
01237 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
01238 {
01239 fp_number_type a;
01240 fp_number_type b;
01241 FLO_union_type au, bu;
01242
01243 au.value = arg_a;
01244 bu.value = arg_b;
01245
01246 unpack_d (&au, &a);
01247 unpack_d (&bu, &b);
01248
01249 if (isnan (&a) || isnan (&b))
01250 return -1;
01251
01252 return __fpcmp_parts (&a, &b);
01253 }
01254 #endif
01255
01256 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
01257 CMPtype
01258 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
01259 {
01260 fp_number_type a;
01261 fp_number_type b;
01262 FLO_union_type au, bu;
01263
01264 au.value = arg_a;
01265 bu.value = arg_b;
01266
01267 unpack_d (&au, &a);
01268 unpack_d (&bu, &b);
01269
01270 if (isnan (&a) || isnan (&b))
01271 return -1;
01272 return __fpcmp_parts (&a, &b) ;
01273 }
01274 #endif
01275
01276 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
01277 CMPtype
01278 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
01279 {
01280 fp_number_type a;
01281 fp_number_type b;
01282 FLO_union_type au, bu;
01283
01284 au.value = arg_a;
01285 bu.value = arg_b;
01286
01287 unpack_d (&au, &a);
01288 unpack_d (&bu, &b);
01289
01290 if (isnan (&a) || isnan (&b))
01291 return 1;
01292
01293 return __fpcmp_parts (&a, &b);
01294 }
01295 #endif
01296
01297 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
01298 CMPtype
01299 _le_f2 (FLO_type arg_a, FLO_type arg_b)
01300 {
01301 fp_number_type a;
01302 fp_number_type b;
01303 FLO_union_type au, bu;
01304
01305 au.value = arg_a;
01306 bu.value = arg_b;
01307
01308 unpack_d (&au, &a);
01309 unpack_d (&bu, &b);
01310
01311 if (isnan (&a) || isnan (&b))
01312 return 1;
01313
01314 return __fpcmp_parts (&a, &b) ;
01315 }
01316 #endif
01317
01318 #endif
01319
01320 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
01321 CMPtype
01322 _unord_f2 (FLO_type arg_a, FLO_type arg_b)
01323 {
01324 fp_number_type a;
01325 fp_number_type b;
01326 FLO_union_type au, bu;
01327
01328 au.value = arg_a;
01329 bu.value = arg_b;
01330
01331 unpack_d (&au, &a);
01332 unpack_d (&bu, &b);
01333
01334 return (isnan (&a) || isnan (&b));
01335 }
01336 #endif
01337
01338 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
01339 FLO_type
01340 si_to_float (SItype arg_a)
01341 {
01342 fp_number_type in;
01343
01344 in.class = CLASS_NUMBER;
01345 in.sign = arg_a < 0;
01346 if (!arg_a)
01347 {
01348 in.class = CLASS_ZERO;
01349 }
01350 else
01351 {
01352 USItype uarg;
01353 int shift;
01354 in.normal_exp = FRACBITS + NGARDS;
01355 if (in.sign)
01356 {
01357
01358
01359 if (arg_a == (- MAX_SI_INT - 1))
01360 {
01361 return (FLO_type)(- MAX_SI_INT - 1);
01362 }
01363 uarg = (-arg_a);
01364 }
01365 else
01366 uarg = arg_a;
01367
01368 in.fraction.ll = uarg;
01369 shift = clzusi (uarg) - (BITS_PER_SI - 1 - FRACBITS - NGARDS);
01370 if (shift > 0)
01371 {
01372 in.fraction.ll <<= shift;
01373 in.normal_exp -= shift;
01374 }
01375 }
01376 return pack_d (&in);
01377 }
01378 #endif
01379
01380 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
01381 FLO_type
01382 usi_to_float (USItype arg_a)
01383 {
01384 fp_number_type in;
01385
01386 in.sign = 0;
01387 if (!arg_a)
01388 {
01389 in.class = CLASS_ZERO;
01390 }
01391 else
01392 {
01393 int shift;
01394 in.class = CLASS_NUMBER;
01395 in.normal_exp = FRACBITS + NGARDS;
01396 in.fraction.ll = arg_a;
01397
01398 shift = clzusi (arg_a) - (BITS_PER_SI - 1 - FRACBITS - NGARDS);
01399 if (shift < 0)
01400 {
01401 fractype guard = in.fraction.ll & (((fractype)1 << -shift) - 1);
01402 in.fraction.ll >>= -shift;
01403 in.fraction.ll |= (guard != 0);
01404 in.normal_exp -= shift;
01405 }
01406 else if (shift > 0)
01407 {
01408 in.fraction.ll <<= shift;
01409 in.normal_exp -= shift;
01410 }
01411 }
01412 return pack_d (&in);
01413 }
01414 #endif
01415
01416 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
01417 SItype
01418 float_to_si (FLO_type arg_a)
01419 {
01420 fp_number_type a;
01421 SItype tmp;
01422 FLO_union_type au;
01423
01424 au.value = arg_a;
01425 unpack_d (&au, &a);
01426
01427 if (iszero (&a))
01428 return 0;
01429 if (isnan (&a))
01430 return 0;
01431
01432 if (isinf (&a))
01433 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
01434
01435 if (a.normal_exp < 0)
01436 return 0;
01437 if (a.normal_exp > BITS_PER_SI - 2)
01438 return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
01439 tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
01440 return a.sign ? (-tmp) : (tmp);
01441 }
01442 #endif
01443
01444 #if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
01445 #if defined US_SOFTWARE_GOFAST || defined(L_tf_to_usi)
01446
01447
01448
01449
01450
01451
01452 USItype
01453 float_to_usi (FLO_type arg_a)
01454 {
01455 fp_number_type a;
01456 FLO_union_type au;
01457
01458 au.value = arg_a;
01459 unpack_d (&au, &a);
01460
01461 if (iszero (&a))
01462 return 0;
01463 if (isnan (&a))
01464 return 0;
01465
01466 if (a.sign)
01467 return 0;
01468
01469 if (isinf (&a))
01470 return MAX_USI_INT;
01471
01472 if (a.normal_exp < 0)
01473 return 0;
01474 if (a.normal_exp > BITS_PER_SI - 1)
01475 return MAX_USI_INT;
01476 else if (a.normal_exp > (FRACBITS + NGARDS))
01477 return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
01478 else
01479 return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
01480 }
01481 #endif
01482 #endif
01483
01484 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
01485 FLO_type
01486 negate (FLO_type arg_a)
01487 {
01488 fp_number_type a;
01489 FLO_union_type au;
01490
01491 au.value = arg_a;
01492 unpack_d (&au, &a);
01493
01494 flip_sign (&a);
01495 return pack_d (&a);
01496 }
01497 #endif
01498
01499 #ifdef FLOAT
01500
01501 #if defined(L_make_sf)
01502 SFtype
01503 __make_fp(fp_class_type class,
01504 unsigned int sign,
01505 int exp,
01506 USItype frac)
01507 {
01508 fp_number_type in;
01509
01510 in.class = class;
01511 in.sign = sign;
01512 in.normal_exp = exp;
01513 in.fraction.ll = frac;
01514 return pack_d (&in);
01515 }
01516 #endif
01517
01518 #ifndef FLOAT_ONLY
01519
01520
01521
01522
01523
01524
01525 #if defined(L_sf_to_df)
01526 DFtype
01527 sf_to_df (SFtype arg_a)
01528 {
01529 fp_number_type in;
01530 FLO_union_type au;
01531
01532 au.value = arg_a;
01533 unpack_d (&au, &in);
01534
01535 return __make_dp (in.class, in.sign, in.normal_exp,
01536 ((UDItype) in.fraction.ll) << F_D_BITOFF);
01537 }
01538 #endif
01539
01540 #if defined(L_sf_to_tf) && defined(TMODES)
01541 TFtype
01542 sf_to_tf (SFtype arg_a)
01543 {
01544 fp_number_type in;
01545 FLO_union_type au;
01546
01547 au.value = arg_a;
01548 unpack_d (&au, &in);
01549
01550 return __make_tp (in.class, in.sign, in.normal_exp,
01551 ((UTItype) in.fraction.ll) << F_T_BITOFF);
01552 }
01553 #endif
01554
01555 #endif
01556 #endif
01557
01558 #ifndef FLOAT
01559
01560 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
01561
01562 #if defined(L_make_df)
01563 DFtype
01564 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
01565 {
01566 fp_number_type in;
01567
01568 in.class = class;
01569 in.sign = sign;
01570 in.normal_exp = exp;
01571 in.fraction.ll = frac;
01572 return pack_d (&in);
01573 }
01574 #endif
01575
01576 #if defined(L_df_to_sf)
01577 SFtype
01578 df_to_sf (DFtype arg_a)
01579 {
01580 fp_number_type in;
01581 USItype sffrac;
01582 FLO_union_type au;
01583
01584 au.value = arg_a;
01585 unpack_d (&au, &in);
01586
01587 sffrac = in.fraction.ll >> F_D_BITOFF;
01588
01589
01590
01591 if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
01592 sffrac |= 1;
01593
01594 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
01595 }
01596 #endif
01597
01598 #if defined(L_df_to_tf) && defined(TMODES) \
01599 && !defined(FLOAT) && !defined(TFLOAT)
01600 TFtype
01601 df_to_tf (DFtype arg_a)
01602 {
01603 fp_number_type in;
01604 FLO_union_type au;
01605
01606 au.value = arg_a;
01607 unpack_d (&au, &in);
01608
01609 return __make_tp (in.class, in.sign, in.normal_exp,
01610 ((UTItype) in.fraction.ll) << D_T_BITOFF);
01611 }
01612 #endif
01613
01614 #ifdef TFLOAT
01615 #if defined(L_make_tf)
01616 TFtype
01617 __make_tp(fp_class_type class,
01618 unsigned int sign,
01619 int exp,
01620 UTItype frac)
01621 {
01622 fp_number_type in;
01623
01624 in.class = class;
01625 in.sign = sign;
01626 in.normal_exp = exp;
01627 in.fraction.ll = frac;
01628 return pack_d (&in);
01629 }
01630 #endif
01631
01632 #if defined(L_tf_to_df)
01633 DFtype
01634 tf_to_df (TFtype arg_a)
01635 {
01636 fp_number_type in;
01637 UDItype sffrac;
01638 FLO_union_type au;
01639
01640 au.value = arg_a;
01641 unpack_d (&au, &in);
01642
01643 sffrac = in.fraction.ll >> D_T_BITOFF;
01644
01645
01646
01647 if ((in.fraction.ll & (((UTItype) 1 << D_T_BITOFF) - 1)) != 0)
01648 sffrac |= 1;
01649
01650 return __make_dp (in.class, in.sign, in.normal_exp, sffrac);
01651 }
01652 #endif
01653
01654 #if defined(L_tf_to_sf)
01655 SFtype
01656 tf_to_sf (TFtype arg_a)
01657 {
01658 fp_number_type in;
01659 USItype sffrac;
01660 FLO_union_type au;
01661
01662 au.value = arg_a;
01663 unpack_d (&au, &in);
01664
01665 sffrac = in.fraction.ll >> F_T_BITOFF;
01666
01667
01668
01669 if ((in.fraction.ll & (((UTItype) 1 << F_T_BITOFF) - 1)) != 0)
01670 sffrac |= 1;
01671
01672 return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
01673 }
01674 #endif
01675 #endif
01676
01677 #endif
01678 #endif