Lines Matching refs:a

4  * The code in this source file is derived from release 2a of the SoftFloat
9 * the SoftFloat-2a license
14 * taken to be licensed under the Softfloat-2a license unless specifically
18 static void partsN(return_nan)(FloatPartsN *a, float_status *s)
20 switch (a->cls) {
24 parts_default_nan(a, s);
26 parts_silence_nan(a, s);
31 parts_default_nan(a, s);
39 static FloatPartsN *partsN(pick_nan)(FloatPartsN *a, FloatPartsN *b,
42 if (is_snan(a->cls) || is_snan(b->cls)) {
47 parts_default_nan(a, s);
49 int cmp = frac_cmp(a, b);
51 cmp = a->sign < b->sign;
54 if (pickNaN(a->cls, b->cls, cmp > 0, s)) {
55 a = b;
57 if (is_snan(a->cls)) {
58 parts_silence_nan(a, s);
61 return a;
64 static FloatPartsN *partsN(pick_nan_muladd)(FloatPartsN *a, FloatPartsN *b,
74 which = pickNaNMulAdd(a->cls, b->cls, c->cls,
82 parts_default_nan(a, s);
83 return a;
90 a = b;
93 a = c;
98 if (is_snan(a->cls)) {
99 parts_silence_nan(a, s);
101 return a;
139 * Round and uncanonicalize a floating-point number by parts. There
209 /* ARM Alt HP eschews Inf and NaN for a wider exponent. */
336 * floating-point values `a' and `b'. The operation is performed
340 static FloatPartsN *partsN(addsub)(FloatPartsN *a, FloatPartsN *b,
344 int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
346 if (a->sign != b_sign) {
349 if (parts_sub_normal(a, b)) {
350 return a;
357 a->sign = s->float_rounding_mode == float_round_down;
358 return a;
366 if (a->cls != float_class_inf) {
372 return a;
376 parts_default_nan(a, s);
377 return a;
382 parts_add_normal(a, b);
383 return a;
387 return a;
395 a->cls = float_class_inf;
396 return a;
401 g_assert(a->cls == float_class_normal);
402 return a;
405 g_assert(a->cls == float_class_zero);
412 return parts_pick_nan(a, b, s);
416 * Returns the result of multiplying the floating-point values `a' and
420 static FloatPartsN *partsN(mul)(FloatPartsN *a, FloatPartsN *b,
423 int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
424 bool sign = a->sign ^ b->sign;
429 frac_mulw(&tmp, a, b);
430 frac_truncjam(a, &tmp);
432 a->exp += b->exp + 1;
433 if (!(a->frac_hi & DECOMPOSED_IMPLICIT_BIT)) {
434 frac_add(a, a, a);
435 a->exp -= 1;
438 a->sign = sign;
439 return a;
445 parts_default_nan(a, s);
446 return a;
450 return parts_pick_nan(a, b, s);
455 a->cls = float_class_inf;
456 a->sign = sign;
457 return a;
461 a->cls = float_class_zero;
462 a->sign = sign;
463 return a;
467 * Returns the result of multiplying the floating-point values `a' and
473 * difference between this and having the caller do a separate
476 * Requires A and C extracted into a double-sized structure to provide the
479 static FloatPartsN *partsN(muladd)(FloatPartsN *a, FloatPartsN *b,
485 ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
492 * off to the target-specific pick-a-NaN routine.
495 return parts_pick_nan_muladd(a, b, c, s, ab_mask, abc_mask);
503 a->sign ^= b->sign;
505 a->sign ^= 1;
515 if (c->cls == float_class_inf && a->sign != c->sign) {
524 *a = *c;
528 if (a->sign != c->sign) {
537 a->sign = c->sign;
542 p_widen.sign = a->sign;
543 p_widen.exp = a->exp + b->exp + 1;
544 frac_mulw(&p_widen, a, b);
556 if (a->sign == c->sign) {
564 frac_truncjam(a, &p_widen);
565 a->sign = p_widen.sign;
566 a->exp = p_widen.exp;
570 a->exp -= 1;
574 a->sign ^= 1;
576 return a;
579 a->sign = s->float_rounding_mode == float_round_down;
581 a->cls = float_class_zero;
585 a->cls = float_class_inf;
589 parts_default_nan(a, s);
590 return a;
594 * Returns the result of dividing the floating-point value `a' by the
598 static FloatPartsN *partsN(div)(FloatPartsN *a, FloatPartsN *b,
601 int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
602 bool sign = a->sign ^ b->sign;
605 a->sign = sign;
606 a->exp -= b->exp + frac_div(a, b);
607 return a;
622 return parts_pick_nan(a, b, s);
625 a->sign = sign;
628 if (a->cls == float_class_inf) {
629 return a;
633 if (a->cls == float_class_zero) {
634 return a;
639 a->cls = float_class_zero;
640 return a;
646 a->cls = float_class_inf;
647 return a;
650 parts_default_nan(a, s);
651 return a;
657 static FloatPartsN *partsN(modrem)(FloatPartsN *a, FloatPartsN *b,
660 int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
663 frac_modrem(a, b, mod_quot);
664 return a;
673 return parts_pick_nan(a, b, s);
677 if (a->cls == float_class_inf || b->cls == float_class_zero) {
679 parts_default_nan(a, s);
680 return a;
684 g_assert(b->cls == float_class_inf || a->cls == float_class_zero);
685 return a;
697 static void partsN(sqrt)(FloatPartsN *a, float_status *status,
710 if (unlikely(a->cls != float_class_normal)) {
711 switch (a->cls) {
714 parts_return_nan(a, status);
719 if (unlikely(a->sign)) {
728 if (unlikely(a->sign)) {
739 exp_odd = a->exp & 1;
740 index = extract64(a->frac_hi, 57, 6) | (!exp_odd << 6);
742 frac_shr(a, 1);
751 * The relative error (e = r0*sqrt(m)-1) of a linear estimate
752 * (r0 = a*m + b) is |e| < 0.085955 ~ 0x1.6p-4 at best;
753 * a table lookup is faster and needs one less iteration.
765 m64 = a->frac_hi;
797 a->frac_hi = (uint64_t)s32 << (64 - 25);
801 a->frac_hi += ((int32_t)(d1 ^ d2) < 0 ? -1 : 1);
822 a->frac_hi = s64 << (64 - 54);
826 a->frac_hi += ((int64_t)(d1 ^ d2) < 0 ? -1 : 1);
848 mul128To256(a->frac_hi, a->frac_lo, rh, rl, &sh, &sl, &discard, &discard);
861 sub128(a->frac_lo << 34, 0, d0h, d0l, &d0h, &d0l);
876 a->frac_lo = sl;
877 a->frac_hi = sh;
881 a->exp >>= 1;
882 if (!(a->frac_hi & DECOMPOSED_IMPLICIT_BIT)) {
883 frac_add(a, a, a);
885 a->exp += 1;
891 parts_default_nan(a, status);
895 * Rounds the floating-point value `a' to an integer, and returns the
896 * result as a floating-point value. The operation is performed
904 static bool partsN(round_to_int_normal)(FloatPartsN *a, FloatRoundMode rmode,
911 a->exp += scale;
913 if (a->exp < 0) {
920 if (a->exp == -1) {
923 frac_add(&tmp, a, a);
929 one = a->exp == -1;
935 one = !a->sign;
938 one = a->sign;
947 frac_clear(a);
948 a->exp = 0;
950 a->frac_hi = DECOMPOSED_IMPLICIT_BIT;
952 a->cls = float_class_zero;
957 if (a->exp >= frac_size) {
962 if (N > 64 && a->exp < N - 64) {
967 shift_adj = (N - 1) - (a->exp + 2);
968 frac_shrjam(a, shift_adj);
972 frac_lsb = DECOMPOSED_IMPLICIT_BIT >> (a->exp & 63);
979 if (!(a->frac_lo & rnd_mask)) {
981 frac_shl(a, shift_adj);
987 inc = ((a->frac_lo & rnd_even_mask) != frac_lsbm1 ? frac_lsbm1 : 0);
996 inc = a->sign ? 0 : rnd_mask;
999 inc = a->sign ? rnd_mask : 0;
1002 inc = a->frac_lo & frac_lsb ? 0 : rnd_mask;
1009 if (frac_addi(a, a, inc)) {
1010 frac_shr(a, 1);
1011 a->frac_hi |= DECOMPOSED_IMPLICIT_BIT;
1012 a->exp++;
1014 a->frac_lo &= ~rnd_mask;
1016 frac_addi(a, a, inc);
1017 a->frac_lo &= ~rnd_mask;
1019 frac_shl(a, shift_adj - 1);
1020 if (a->frac_hi & DECOMPOSED_IMPLICIT_BIT) {
1021 a->exp++;
1023 frac_add(a, a, a);
1029 static void partsN(round_to_int)(FloatPartsN *a, FloatRoundMode rmode,
1033 switch (a->cls) {
1036 parts_return_nan(a, s);
1042 if (parts_round_to_int_normal(a, rmode, scale, fmt->frac_size)) {
1052 * Returns the result of converting the floating-point value `a' to
1056 * rounded according to the current rounding mode. If `a' is a NaN,
1058 * conversion overflows, the largest integer with the same sign as `a'
1118 * Returns the result of converting the floating-point value `a' to
1122 * rounded according to the current rounding mode. If `a' is a NaN,
1125 * the 'a' is negative, the result is rounded and zero is returned;
1266 * Returns the result of converting the two's complement integer `a'
1270 static void partsN(sint_to_float)(FloatPartsN *p, int64_t a,
1273 uint64_t f = a;
1278 if (a == 0) {
1284 if (a < 0) {
1298 * Returns the result of converting the unsigned integer `a' to the
1302 static void partsN(uint_to_float)(FloatPartsN *p, uint64_t a,
1307 if (a == 0) {
1310 int shift = clz64(a);
1314 p->frac_hi = a << shift;
1321 static FloatPartsN *partsN(minmax)(FloatPartsN *a, FloatPartsN *b,
1324 int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
1331 * if one operand is a QNaN, and the other
1337 return is_nan(a->cls) ? b : a;
1345 * If both operands are NaNs, a QNaN is returned.
1346 * If either operand is a SNaN,
1349 * the SNaN is otherwise ignored and not converted to a QNaN.
1355 return is_nan(a->cls) ? b : a;
1358 return parts_pick_nan(a, b, s);
1361 a_exp = a->exp;
1365 switch (a->cls) {
1396 cmp = frac_cmp(a, b);
1404 if (a->sign != b->sign) {
1406 cmp = a->sign ? -1 : 1;
1407 } else if (a->sign) {
1416 return cmp < 0 ? b : a;
1422 static FloatRelation partsN(compare)(FloatPartsN *a, FloatPartsN *b,
1425 int ab_mask = float_cmask(a->cls) | float_cmask(b->cls);
1430 if (a->sign != b->sign) {
1433 if (a->exp == b->exp) {
1434 cmp = frac_cmp(a, b);
1435 } else if (a->exp < b->exp) {
1440 if (a->sign) {
1458 } else if (a->cls == float_class_zero) {
1466 if (a->sign == b->sign) {
1472 g_assert(a->cls == float_class_inf);
1476 return a->sign ? float_relation_less : float_relation_greater;
1484 static void partsN(scalbn)(FloatPartsN *a, int n, float_status *s)
1486 switch (a->cls) {
1489 parts_return_nan(a, s);
1495 a->exp += MIN(MAX(n, -0x10000), 0x10000);
1505 static void partsN(log2)(FloatPartsN *a, float_status *s, const FloatFmt *fmt)
1511 if (unlikely(a->cls != float_class_normal)) {
1512 switch (a->cls) {
1515 parts_return_nan(a, s);
1520 a->cls = float_class_inf;
1521 a->sign = 1;
1524 if (unlikely(a->sign)) {
1533 if (unlikely(a->sign)) {
1540 a_exp = a->exp;
1545 a0 = a->frac_hi;
1551 * When a_exp == -1, we're computing the log2 of a value [0.5,1.0).
1554 * this value from -1.0, we can see a catastrophic loss of precision,
1561 /* Don't compute a value overlapping the sticky bit */
1580 * When a_exp == 0, we're computing the log2 of a value
1583 * We need to compute more digits to produce a correct
1604 parts_sint_to_float(a, a_exp, 0, s);
1615 parts_sub_normal(a, &f);
1617 parts_add_normal(a, &f);
1619 *a = f;
1625 parts_default_nan(a, s);