1 /* IEEE-754 double-precision functions for Xtensa
2 Copyright (C) 2006-2018 Free Software Foundation, Inc.
3 Contributed by Bob Wilson (bwilson@tensilica.com) at Tensilica.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
38 /* Warning! The branch displacements for some Xtensa branch instructions
39 are quite small, and this code has been carefully laid out to keep
40 branch targets in range. If you change anything, be sure to check that
41 the assembler is not relaxing anything to branch over a jump. */
47 .type __negdf2, @function
61 /* Handle NaNs and Infinities. (This code is placed before the
62 start of the function just to keep it in range of the limited
63 branch displacements.) */
66 /* If y is neither Infinity nor NaN, return x. */
67 bnall yh, a6, .Ladd_return_nan_or_inf
68 /* If x is a NaN, return it. Otherwise, return y. */
71 bnez a7, .Ladd_return_nan
78 .Ladd_return_nan_or_inf:
81 bnez a7, .Ladd_return_nan
85 movi a4, 0x80000 /* make it a quiet NaN */
90 /* Operand signs differ. Do a subtraction. */
97 .type __adddf3, @function
102 /* Check if the two operands have the same sign. */
104 bltz a7, .Ladd_opposite_signs
107 /* Check if either exponent == 0x7ff (i.e., NaN or Infinity). */
108 ball xh, a6, .Ladd_xnan_or_inf
109 ball yh, a6, .Ladd_ynan_or_inf
111 /* Compare the exponents. The smaller operand will be shifted
112 right by the exponent difference and added to the larger
116 bltu a7, a8, .Ladd_shiftx
119 /* Check if the smaller (or equal) exponent is zero. */
120 bnone yh, a6, .Ladd_yexpzero
122 /* Replace yh sign/exponent with 0x001. */
128 /* Compute the exponent difference. Optimize for difference < 32. */
130 bgeui a10, 32, .Ladd_bigshifty
132 /* Shift yh/yl right by the exponent difference. Any bits that are
133 shifted out of yl are saved in a9 for rounding the result. */
141 /* Do the 64-bit addition. */
147 /* Check if the add overflowed into the exponent. */
148 extui a10, xh, 20, 12
149 beq a10, a7, .Ladd_round
154 /* y is a subnormal value. Replace its sign/exponent with zero,
155 i.e., no implicit "1.0", and increment the apparent exponent
156 because subnormals behave as if they had the minimum (nonzero)
157 exponent. Test for the case when both exponents are zero. */
160 bnone xh, a6, .Ladd_bothexpzero
165 /* Both exponents are zero. Handle this as a special case. There
166 is no need to shift or round, and the normal code for handling
167 a carry into the exponent field will not work because it
168 assumes there is an implicit "1.0" that needs to be added. */
176 /* Exponent difference > 64 -- just return the bigger value. */
179 /* Shift yh/yl right by the exponent difference. Any bits that are
180 shifted out are saved in a9 for rounding the result. */
182 sll a11, yl /* lost bits shifted out of yl */
187 or a9, a9, a10 /* any positive, nonzero value will work */
191 /* Same as "yexpzero" except skip handling the case when both
192 exponents are zero. */
199 /* Same thing as the "shifty" code, but with x and y swapped. Also,
200 because the exponent difference is always nonzero in this version,
201 the shift sequence can use SLL and skip loading a constant zero. */
202 bnone xh, a6, .Ladd_xexpzero
210 bgeui a10, 32, .Ladd_bigshiftx
223 /* Check if the add overflowed into the exponent. */
224 extui a10, xh, 20, 12
225 bne a10, a8, .Ladd_carry
228 /* Round up if the leftover fraction is >= 1/2. */
231 beqz xl, .Ladd_roundcarry
233 /* Check if the leftover fraction is exactly 1/2. */
235 beqz a9, .Ladd_exactlyhalf
239 /* Mostly the same thing as "bigshifty".... */
240 bgeui a10, 64, .Ladd_returny
257 /* The addition has overflowed into the exponent field, so the
258 value needs to be renormalized. The mantissa of the result
259 can be recovered by subtracting the original exponent and
260 adding 0x100000 (which is the explicit "1.0" for the
261 mantissa of the non-shifted operand -- the "1.0" for the
262 shifted operand was already added). The mantissa can then
263 be shifted right by one bit. The explicit "1.0" of the
264 shifted mantissa then needs to be replaced by the exponent,
265 incremented by one to account for the normalizing shift.
266 It is faster to combine these operations: do the shift first
267 and combine the additions and subtractions. If x is the
268 original exponent, the result is:
269 shifted mantissa - (x << 19) + (1 << 19) + (x << 20)
271 shifted mantissa + ((x + 1) << 19)
272 Note that the exponent is incremented here by leaving the
273 explicit "1.0" of the mantissa in the exponent field. */
275 /* Shift xh/xl right by one bit. Save the lsb of xl. */
281 /* See explanation above. The original exponent is in a8. */
286 /* Return an Infinity if the exponent overflowed. */
287 ball xh, a6, .Ladd_infinity
289 /* Same thing as the "round" code except the msb of the leftover
290 fraction is bit 0 of a10, with the rest of the fraction in a9. */
293 beqz xl, .Ladd_roundcarry
294 beqz a9, .Ladd_exactlyhalf
298 /* Clear the mantissa. */
303 /* The sign bit may have been lost in a carry-out. Put it back. */
309 /* Round down to the nearest even value. */
315 /* xl is always zero when the rounding increment overflows, so
316 there's no need to round it to an even value. */
318 /* Overflow to the exponent is OK. */
325 /* Handle NaNs and Infinities. (This code is placed before the
326 start of the function just to keep it in range of the limited
327 branch displacements.) */
330 /* If y is neither Infinity nor NaN, return x. */
331 bnall yh, a6, .Lsub_return_nan_or_inf
334 /* Both x and y are either NaN or Inf, so the result is NaN. */
335 movi a4, 0x80000 /* make it a quiet NaN */
340 /* Negate y and return it. */
345 .Lsub_return_nan_or_inf:
348 bnez a7, .Lsub_return_nan
351 .Lsub_opposite_signs:
352 /* Operand signs differ. Do an addition. */
359 .type __subdf3, @function
364 /* Check if the two operands have the same sign. */
366 bltz a7, .Lsub_opposite_signs
369 /* Check if either exponent == 0x7ff (i.e., NaN or Infinity). */
370 ball xh, a6, .Lsub_xnan_or_inf
371 ball yh, a6, .Lsub_ynan_or_inf
373 /* Compare the operands. In contrast to addition, the entire
374 value matters here. */
377 bltu xh, yh, .Lsub_xsmaller
378 beq xh, yh, .Lsub_compare_low
381 /* Check if the smaller (or equal) exponent is zero. */
382 bnone yh, a6, .Lsub_yexpzero
384 /* Replace yh sign/exponent with 0x001. */
390 /* Compute the exponent difference. Optimize for difference < 32. */
392 bgeui a10, 32, .Lsub_bigshifty
394 /* Shift yh/yl right by the exponent difference. Any bits that are
395 shifted out of yl are saved in a9 for rounding the result. */
403 /* Do the 64-bit subtraction. */
409 /* Subtract the leftover bits in a9 from zero and propagate any
410 borrow from xh/xl. */
417 /* Check if the subtract underflowed into the exponent. */
418 extui a10, xh, 20, 11
419 beq a10, a7, .Lsub_round
423 /* The high words are equal. Compare the low words. */
424 bltu xl, yl, .Lsub_xsmaller
425 bltu yl, xl, .Lsub_ysmaller
426 /* The operands are equal. Return 0.0. */
432 /* y is a subnormal value. Replace its sign/exponent with zero,
433 i.e., no implicit "1.0". Unless x is also a subnormal, increment
434 y's apparent exponent because subnormals behave as if they had
435 the minimum (nonzero) exponent. */
438 bnone xh, a6, .Lsub_yexpdiff
443 /* Exponent difference > 64 -- just return the bigger value. */
446 /* Shift yh/yl right by the exponent difference. Any bits that are
447 shifted out are saved in a9 for rounding the result. */
449 sll a11, yl /* lost bits shifted out of yl */
454 or a9, a9, a10 /* any positive, nonzero value will work */
458 /* Same thing as the "ysmaller" code, but with x and y swapped and
460 bnone xh, a6, .Lsub_xexpzero
468 bgeui a10, 32, .Lsub_bigshiftx
486 /* Subtract the leftover bits in a9 from zero and propagate any
487 borrow from xh/xl. */
494 /* Check if the subtract underflowed into the exponent. */
495 extui a10, xh, 20, 11
496 bne a10, a8, .Lsub_borrow
499 /* Round up if the leftover fraction is >= 1/2. */
502 beqz xl, .Lsub_roundcarry
504 /* Check if the leftover fraction is exactly 1/2. */
506 beqz a9, .Lsub_exactlyhalf
510 /* Same as "yexpzero". */
513 bnone yh, a6, .Lsub_xexpdiff
518 /* Mostly the same thing as "bigshifty", but with the sign bit of the
519 shifted value set so that the subsequent subtraction flips the
521 bgeui a10, 64, .Lsub_returny
527 slli xh, a6, 11 /* set sign bit of xh */
533 /* Negate and return y. */
540 /* The subtraction has underflowed into the exponent field, so the
541 value needs to be renormalized. Shift the mantissa left as
542 needed to remove any leading zeros and adjust the exponent
543 accordingly. If the exponent is not large enough to remove
544 all the leading zeros, the result will be a subnormal value. */
547 beqz a8, .Lsub_xhzero
548 do_nsau a6, a8, a7, a11
550 bge a6, a10, .Lsub_subnormal
554 /* Shift the mantissa (a8/xl/a9) left by a6. */
560 /* Combine the shifted mantissa with the sign and exponent,
561 decrementing the exponent by a6. (The exponent has already
562 been decremented by one due to the borrow from the subtraction,
563 but adding the mantissa will increment the exponent by one.) */
571 /* Round down to the nearest even value. */
577 /* xl is always zero when the rounding increment overflows, so
578 there's no need to round it to an even value. */
580 /* Overflow to the exponent is OK. */
584 /* When normalizing the result, all the mantissa bits in the high
585 word are zero. Shift by "20 + (leading zero count of xl) + 1". */
586 do_nsau a6, xl, a7, a11
588 blt a10, a6, .Lsub_subnormal
590 .Lsub_normalize_shift:
591 bltui a6, 32, .Lsub_shift_lt32
605 /* The exponent is too small to shift away all the leading zeros.
606 Set a6 to the current exponent (which has already been
607 decremented by the borrow) so that the exponent of the result
608 will be zero. Do not add 1 to a6 in this case, because: (1)
609 adding the mantissa will not increment the exponent, so there is
610 no need to subtract anything extra from the exponent to
611 compensate, and (2) the effective exponent of a subnormal is 1
612 not 0 so the shift amount must be 1 smaller than normal. */
614 j .Lsub_normalize_shift
616 #endif /* L_addsubdf3 */
621 #if !XCHAL_HAVE_MUL16 && !XCHAL_HAVE_MUL32 && !XCHAL_HAVE_MAC16
622 #define XCHAL_NO_MUL 1
628 /* Handle unusual cases (zeros, subnormals, NaNs and Infinities).
629 (This code is placed before the start of the function just to
630 keep it in range of the limited branch displacements.) */
633 /* Clear the sign bit of x. */
637 /* If x is zero, return zero. */
639 beqz a10, .Lmul_return_zero
641 /* Normalize x. Adjust the exponent in a8. */
642 beqz xh, .Lmul_xh_zero
643 do_nsau a10, xh, a11, a12
652 do_nsau a10, xl, a11, a12
657 bltz a10, .Lmul_xl_srl
667 /* Clear the sign bit of y. */
671 /* If y is zero, return zero. */
673 beqz a10, .Lmul_return_zero
675 /* Normalize y. Adjust the exponent in a9. */
676 beqz yh, .Lmul_yh_zero
677 do_nsau a10, yh, a11, a12
686 do_nsau a10, yl, a11, a12
691 bltz a10, .Lmul_yl_srl
701 /* Return zero with the appropriate sign bit. */
708 /* If y is zero, return NaN. */
711 beqz a8, .Lmul_return_nan
713 /* If y is NaN, return y. */
714 bnall yh, a6, .Lmul_returnx
717 beqz a8, .Lmul_returnx
726 bnez a8, .Lmul_return_nan
727 /* Set the sign bit and return. */
735 /* If x is zero, return NaN. */
736 bnez xl, .Lmul_returny
738 bnez a8, .Lmul_returny
742 movi a4, 0x80000 /* make it a quiet NaN */
748 .type __muldf3, @function
750 #if __XTENSA_CALL0_ABI__
758 /* This is not really a leaf function; allocate enough stack space
759 to allow CALL12s to a helper function. */
766 /* Get the sign of the result. */
769 /* Check for NaN and infinity. */
770 ball xh, a6, .Lmul_xnan_or_inf
771 ball yh, a6, .Lmul_ynan_or_inf
773 /* Extract the exponents. */
777 beqz a8, .Lmul_xexpzero
779 beqz a9, .Lmul_yexpzero
782 /* Add the exponents. */
785 /* Replace sign/exponent fields with explicit "1.0". */
792 /* Multiply 64x64 to 128 bits. The result ends up in xh/xl/a6.
793 The least-significant word of the result is thrown away except
794 that if it is nonzero, the lsb of a6 is set to 1. */
795 #if XCHAL_HAVE_MUL32_HIGH
797 /* Compute a6 with any carry-outs in a10. */
810 /* If the low word of the result is nonzero, set the lsb of a6. */
816 /* Compute xl with any carry-outs in a9. */
837 #else /* ! XCHAL_HAVE_MUL32_HIGH */
839 /* Break the inputs into 16-bit chunks and compute 16 32-bit partial
840 products. These partial products are:
865 where the input chunks are (hh, hl, lh, ll). If using the Mul16
866 or Mul32 multiplier options, these input chunks must be stored in
867 separate registers. For Mac16, the UMUL.AA.* opcodes can specify
868 that the inputs come from either half of the registers, so there
869 is no need to shift them out ahead of time. If there is no
870 multiply hardware, the 16-bit chunks can be extracted when setting
871 up the arguments to the separate multiply function. */
873 /* Save a7 since it is needed to hold a temporary value. */
875 #if __XTENSA_CALL0_ABI__ && XCHAL_NO_MUL
876 /* Calling a separate multiply function will clobber a0 and requires
877 use of a8 as a temporary, so save those values now. (The function
878 uses a custom ABI so nothing else needs to be saved.) */
883 #if XCHAL_HAVE_MUL16 || XCHAL_HAVE_MUL32
890 /* Get the high halves of the inputs into registers. */
901 #if XCHAL_HAVE_MUL32 && !XCHAL_HAVE_MUL16
902 /* Clear the high halves of the inputs. This does not matter
903 for MUL16 because the high bits are ignored. */
909 #endif /* MUL16 || MUL32 */
914 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
915 mul16u dst, xreg ## xhalf, yreg ## yhalf
917 #elif XCHAL_HAVE_MUL32
919 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
920 mull dst, xreg ## xhalf, yreg ## yhalf
922 #elif XCHAL_HAVE_MAC16
924 /* The preprocessor insists on inserting a space when concatenating after
925 a period in the definition of do_mul below. These macros are a workaround
926 using underscores instead of periods when doing the concatenation. */
927 #define umul_aa_ll umul.aa.ll
928 #define umul_aa_lh umul.aa.lh
929 #define umul_aa_hl umul.aa.hl
930 #define umul_aa_hh umul.aa.hh
932 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
933 umul_aa_ ## xhalf ## yhalf xreg, yreg; \
936 #else /* no multiply hardware */
938 #define set_arg_l(dst, src) \
939 extui dst, src, 0, 16
940 #define set_arg_h(dst, src) \
943 #if __XTENSA_CALL0_ABI__
944 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
945 set_arg_ ## xhalf (a13, xreg); \
946 set_arg_ ## yhalf (a14, yreg); \
947 call0 .Lmul_mulsi3; \
950 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
951 set_arg_ ## xhalf (a14, xreg); \
952 set_arg_ ## yhalf (a15, yreg); \
953 call12 .Lmul_mulsi3; \
955 #endif /* __XTENSA_CALL0_ABI__ */
957 #endif /* no multiply hardware */
959 /* Add pp1 and pp2 into a10 with carry-out in a9. */
960 do_mul(a10, xl, l, yl, h) /* pp 1 */
961 do_mul(a11, xl, h, yl, l) /* pp 2 */
967 /* Initialize a6 with a9/a10 shifted into position. Note that
968 this value can be safely incremented without any carry-outs. */
972 /* Compute the low word into a10. */
973 do_mul(a11, xl, l, yl, l) /* pp 0 */
979 /* Compute the contributions of pp0-5 to a6, with carry-outs in a9.
980 This is good enough to determine the low half of a6, so that any
981 nonzero bits from the low word of the result can be collapsed
982 into a6, freeing up a register. */
984 do_mul(a11, xl, l, yh, l) /* pp 3 */
989 do_mul(a11, xl, h, yl, h) /* pp 4 */
994 do_mul(a11, xh, l, yl, l) /* pp 5 */
999 /* Collapse any nonzero bits from the low word into a6. */
1004 /* Add pp6-9 into a11 with carry-outs in a10. */
1005 do_mul(a7, xl, l, yh, h) /* pp 6 */
1006 do_mul(a11, xh, h, yl, l) /* pp 9 */
1012 do_mul(a7, xl, h, yh, l) /* pp 7 */
1017 do_mul(a7, xh, l, yl, h) /* pp 8 */
1022 /* Shift a10/a11 into position, and add low half of a11 to a6. */
1030 /* Add pp10-12 into xl with carry-outs in a9. */
1032 do_mul(xl, xl, h, yh, h) /* pp 10 */
1037 do_mul(a10, xh, l, yh, l) /* pp 11 */
1042 do_mul(a10, xh, h, yl, h) /* pp 12 */
1047 /* Add pp13-14 into a11 with carry-outs in a10. */
1048 do_mul(a11, xh, l, yh, h) /* pp 13 */
1049 do_mul(a7, xh, h, yh, l) /* pp 14 */
1055 /* Shift a10/a11 into position, and add low half of a11 to a6. */
1064 do_mul(xh, xh, h, yh, h) /* pp 15 */
1067 /* Restore values saved on the stack during the multiplication. */
1069 #if __XTENSA_CALL0_ABI__ && XCHAL_NO_MUL
1073 #endif /* ! XCHAL_HAVE_MUL32_HIGH */
1075 /* Shift left by 12 bits, unless there was a carry-out from the
1076 multiply, in which case, shift by 11 bits and increment the
1077 exponent. Note: It is convenient to use the constant 0x3ff
1078 instead of 0x400 when removing the extra exponent bias (so that
1079 it is easy to construct 0x7fe for the overflow check). Reverse
1080 the logic here to decrement the exponent sum by one unless there
1083 srli a5, xh, 21 - 12
1092 /* Subtract the extra bias from the exponent sum (plus one to account
1093 for the explicit "1.0" of the mantissa that will be added to the
1094 exponent in the final result). */
1098 /* Check for over/underflow. The value in a8 is one less than the
1099 final exponent, so values in the range 0..7fd are OK here. */
1100 slli a4, a4, 1 /* 0x7fe */
1101 bgeu a8, a4, .Lmul_overflow
1105 bgez a6, .Lmul_rounded
1107 beqz xl, .Lmul_roundcarry
1109 beqz a6, .Lmul_exactlyhalf
1112 /* Add the exponent to the mantissa. */
1117 /* Add the sign bit. */
1123 #if __XTENSA_CALL0_ABI__
1133 /* Round down to the nearest even value. */
1139 /* xl is always zero when the rounding increment overflows, so
1140 there's no need to round it to an even value. */
1142 /* Overflow is OK -- it will be added to the exponent. */
1146 bltz a8, .Lmul_underflow
1147 /* Return +/- Infinity. */
1148 addi a8, a4, 1 /* 0x7ff */
1154 /* Create a subnormal value, where the exponent field contains zero,
1155 but the effective exponent is 1. The value of a8 is one less than
1156 the actual exponent, so just negate it to get the shift amount. */
1160 bgeui a8, 32, .Lmul_bigshift
1162 /* Shift xh/xl right. Any bits that are shifted out of xl are saved
1163 in a6 (combined with the shifted-out bits currently in a6) for
1164 rounding the result. */
1171 bgeui a8, 64, .Lmul_flush_to_zero
1172 sll a10, xl /* lost bits shifted out of xl */
1178 /* Set the exponent to zero. */
1181 /* Pack any nonzero bits shifted out into a6. */
1182 beqz a9, .Lmul_round
1187 .Lmul_flush_to_zero:
1188 /* Return zero with the appropriate sign bit. */
1196 /* For Xtensa processors with no multiply hardware, this simplified
1197 version of _mulsi3 is used for multiplying 16-bit chunks of
1198 the floating-point mantissas. When using CALL0, this function
1199 uses a custom ABI: the inputs are passed in a13 and a14, the
1200 result is returned in a12, and a8 and a15 are clobbered. */
1204 .macro mul_mulsi3_body dst, src1, src2, tmp1, tmp2
1206 1: add \tmp1, \src2, \dst
1207 extui \tmp2, \src1, 0, 1
1208 movnez \dst, \tmp1, \tmp2
1210 do_addx2 \tmp1, \src2, \dst, \tmp1
1211 extui \tmp2, \src1, 1, 1
1212 movnez \dst, \tmp1, \tmp2
1214 do_addx4 \tmp1, \src2, \dst, \tmp1
1215 extui \tmp2, \src1, 2, 1
1216 movnez \dst, \tmp1, \tmp2
1218 do_addx8 \tmp1, \src2, \dst, \tmp1
1219 extui \tmp2, \src1, 3, 1
1220 movnez \dst, \tmp1, \tmp2
1222 srli \src1, \src1, 4
1223 slli \src2, \src2, 4
1226 #if __XTENSA_CALL0_ABI__
1227 mul_mulsi3_body a12, a13, a14, a15, a8
1229 /* The result will be written into a2, so save that argument in a4. */
1231 mul_mulsi3_body a2, a4, a3, a5, a6
1234 #endif /* XCHAL_NO_MUL */
1235 #endif /* L_muldf3 */
1241 #if XCHAL_HAVE_DFP_DIV
1246 .type __divdf3, @function
1293 /* Handle unusual cases (zeros, subnormals, NaNs and Infinities).
1294 (This code is placed before the start of the function just to
1295 keep it in range of the limited branch displacements.) */
1298 /* Clear the sign bit of y. */
1302 /* Check for division by zero. */
1304 beqz a10, .Ldiv_yzero
1306 /* Normalize y. Adjust the exponent in a9. */
1307 beqz yh, .Ldiv_yh_zero
1308 do_nsau a10, yh, a11, a9
1317 do_nsau a10, yl, a11, a9
1322 bltz a10, .Ldiv_yl_srl
1332 /* y is zero. Return NaN if x is also zero; otherwise, infinity. */
1340 movi a4, 0x80000 /* make it a quiet NaN */
1346 /* Clear the sign bit of x. */
1350 /* If x is zero, return zero. */
1352 beqz a10, .Ldiv_return_zero
1354 /* Normalize x. Adjust the exponent in a8. */
1355 beqz xh, .Ldiv_xh_zero
1356 do_nsau a10, xh, a11, a8
1365 do_nsau a10, xl, a11, a8
1370 bltz a10, .Ldiv_xl_srl
1380 /* Return zero with the appropriate sign bit. */
1387 /* Set the sign bit of the result. */
1391 /* If y is NaN or Inf, return NaN. */
1392 ball yh, a6, .Ldiv_return_nan
1395 bnez a8, .Ldiv_return_nan
1399 /* If y is Infinity, return zero. */
1402 beqz a8, .Ldiv_return_zero
1403 /* y is NaN; return it. */
1408 movi a4, 0x80000 /* make it a quiet NaN */
1418 .type __divdf3, @function
1423 /* Get the sign of the result. */
1426 /* Check for NaN and infinity. */
1427 ball xh, a6, .Ldiv_xnan_or_inf
1428 ball yh, a6, .Ldiv_ynan_or_inf
1430 /* Extract the exponents. */
1431 extui a8, xh, 20, 11
1432 extui a9, yh, 20, 11
1434 beqz a9, .Ldiv_yexpzero
1436 beqz a8, .Ldiv_xexpzero
1439 /* Subtract the exponents. */
1442 /* Replace sign/exponent fields with explicit "1.0". */
1449 /* Set SAR for left shift by one. */
1452 /* The first digit of the mantissa division must be a one.
1453 Shift x (and adjust the exponent) as needed to make this true. */
1455 beq yh, xh, .Ldiv_highequal1
1460 /* Do the first subtraction and shift. */
1468 /* Put the quotient into a10/a11. */
1472 /* Divide one bit at a time for 52 bits. */
1474 #if XCHAL_HAVE_LOOPS
1475 loop a9, .Ldiv_loopend
1478 /* Shift the quotient << 1. */
1482 /* Is this digit a 0 or 1? */
1484 beq xh, yh, .Ldiv_highequal2
1486 /* Output a 1 and subtract. */
1493 /* Shift the dividend << 1. */
1497 #if !XCHAL_HAVE_LOOPS
1503 /* Add the exponent bias (less one to account for the explicit "1.0"
1504 of the mantissa that will be added to the exponent in the final
1509 /* Check for over/underflow. The value in a8 is one less than the
1510 final exponent, so values in the range 0..7fd are OK here. */
1511 addmi a9, a9, 0x400 /* 0x7fe */
1512 bgeu a8, a9, .Ldiv_overflow
1515 /* Round. The remainder (<< 1) is in xh/xl. */
1516 bltu xh, yh, .Ldiv_rounded
1517 beq xh, yh, .Ldiv_highequal3
1520 beqz a11, .Ldiv_roundcarry
1524 /* Add the exponent to the mantissa. */
1529 /* Add the sign bit. */
1540 bltu xl, yl, .Ldiv_rounded
1541 bne xl, yl, .Ldiv_roundup
1543 /* Remainder is exactly half the divisor. Round even. */
1545 beqz a11, .Ldiv_roundcarry
1551 bltz a8, .Ldiv_underflow
1552 /* Return +/- Infinity. */
1553 addi a8, a9, 1 /* 0x7ff */
1559 /* Create a subnormal value, where the exponent field contains zero,
1560 but the effective exponent is 1. The value of a8 is one less than
1561 the actual exponent, so just negate it to get the shift amount. */
1564 bgeui a8, 32, .Ldiv_bigshift
1566 /* Shift a10/a11 right. Any bits that are shifted out of a11 are
1567 saved in a6 for rounding the result. */
1574 bgeui a8, 64, .Ldiv_flush_to_zero
1575 sll a9, a11 /* lost bits shifted out of a11 */
1581 /* Set the exponent to zero. */
1584 /* Pack any nonzero remainder (in xh/xl) into a6. */
1590 /* Round a10/a11 based on the bits shifted out into a6. */
1591 1: bgez a6, .Ldiv_rounded
1593 beqz a11, .Ldiv_roundcarry
1595 bnez a6, .Ldiv_rounded
1601 /* a11 is always zero when the rounding increment overflows, so
1602 there's no need to round it to an even value. */
1604 /* Overflow to the exponent field is OK. */
1607 .Ldiv_flush_to_zero:
1608 /* Return zero with the appropriate sign bit. */
1614 #endif /* XCHAL_HAVE_DFP_DIV */
1616 #endif /* L_divdf3 */
1620 /* Equal and Not Equal */
1625 .set __nedf2, __eqdf2
1626 .type __eqdf2, @function
1632 /* The values are equal but NaN != NaN. Check the exponent. */
1644 /* Check if the mantissas are nonzero. */
1649 /* Check if x and y are zero with different signs. */
1652 or a7, a7, xl /* xl == yl here */
1654 /* Equal if a7 == 0, where a7 is either abs(x | y) or the mantissa
1655 or x when exponent(x) = 0x7ff and x == y. */
1666 .type __gtdf2, @function
1671 1: bnall yh, a6, .Lle_cmp
1673 /* Check if y is a NaN. */
1680 /* Check if x is a NaN. */
1688 /* Less Than or Equal */
1692 .type __ledf2, @function
1697 1: bnall yh, a6, .Lle_cmp
1699 /* Check if y is a NaN. */
1706 /* Check if x is a NaN. */
1714 /* Check if x and y have different signs. */
1716 bltz a7, .Lle_diff_signs
1718 /* Check if x is negative. */
1721 /* Check if x <= y. */
1729 /* Check if y <= x. */
1739 /* Check if both x and y are zero. */
1750 /* Greater Than or Equal */
1754 .type __gedf2, @function
1759 1: bnall yh, a6, .Llt_cmp
1761 /* Check if y is a NaN. */
1768 /* Check if x is a NaN. */
1780 .type __ltdf2, @function
1785 1: bnall yh, a6, .Llt_cmp
1787 /* Check if y is a NaN. */
1794 /* Check if x is a NaN. */
1802 /* Check if x and y have different signs. */
1804 bltz a7, .Llt_diff_signs
1806 /* Check if x is negative. */
1809 /* Check if x < y. */
1817 /* Check if y < x. */
1827 /* Check if both x and y are nonzero. */
1842 .type __unorddf2, @function
1863 #endif /* L_cmpdf2 */
1869 .type __fixdfsi, @function
1873 /* Check for NaN and Infinity. */
1875 ball xh, a6, .Lfixdfsi_nan_or_inf
1877 /* Extract the exponent and check if 0 < (exp - 0x3fe) < 32. */
1878 extui a4, xh, 20, 11
1879 extui a5, a6, 19, 10 /* 0x3fe */
1881 bgei a4, 32, .Lfixdfsi_maxint
1882 blti a4, 1, .Lfixdfsi_zero
1884 /* Add explicit "1.0" and shift << 11. */
1889 /* Shift back to the right, based on the exponent. */
1890 ssl a4 /* shift by 32 - a4 */
1893 /* Negate the result if sign != 0. */
1898 .Lfixdfsi_nan_or_inf:
1899 /* Handle Infinity and NaN. */
1902 beqz a4, .Lfixdfsi_maxint
1904 /* Translate NaN to +maxint. */
1908 slli a4, a6, 11 /* 0x80000000 */
1909 addi a5, a4, -1 /* 0x7fffffff */
1918 #endif /* L_fixdfsi */
1924 .type __fixdfdi, @function
1928 /* Check for NaN and Infinity. */
1930 ball xh, a6, .Lfixdfdi_nan_or_inf
1932 /* Extract the exponent and check if 0 < (exp - 0x3fe) < 64. */
1933 extui a4, xh, 20, 11
1934 extui a5, a6, 19, 10 /* 0x3fe */
1936 bgei a4, 64, .Lfixdfdi_maxint
1937 blti a4, 1, .Lfixdfdi_zero
1939 /* Add explicit "1.0" and shift << 11. */
1945 /* Shift back to the right, based on the exponent. */
1946 ssl a4 /* shift by 64 - a4 */
1947 bgei a4, 32, .Lfixdfdi_smallshift
1952 /* Negate the result if sign != 0. */
1960 .Lfixdfdi_smallshift:
1965 .Lfixdfdi_nan_or_inf:
1966 /* Handle Infinity and NaN. */
1969 beqz a4, .Lfixdfdi_maxint
1971 /* Translate NaN to +maxint. */
1975 slli a7, a6, 11 /* 0x80000000 */
1981 1: addi xh, a7, -1 /* 0x7fffffff */
1990 #endif /* L_fixdfdi */
1995 .global __fixunsdfsi
1996 .type __fixunsdfsi, @function
2000 /* Check for NaN and Infinity. */
2002 ball xh, a6, .Lfixunsdfsi_nan_or_inf
2004 /* Extract the exponent and check if 0 <= (exp - 0x3ff) < 32. */
2005 extui a4, xh, 20, 11
2006 extui a5, a6, 20, 10 /* 0x3ff */
2008 bgei a4, 32, .Lfixunsdfsi_maxint
2009 bltz a4, .Lfixunsdfsi_zero
2011 /* Add explicit "1.0" and shift << 11. */
2016 /* Shift back to the right, based on the exponent. */
2018 beqi a4, 32, .Lfixunsdfsi_bigexp
2019 ssl a4 /* shift by 32 - a4 */
2022 /* Negate the result if sign != 0. */
2027 .Lfixunsdfsi_nan_or_inf:
2028 /* Handle Infinity and NaN. */
2031 beqz a4, .Lfixunsdfsi_maxint
2033 /* Translate NaN to 0xffffffff. */
2037 .Lfixunsdfsi_maxint:
2038 slli a4, a6, 11 /* 0x80000000 */
2039 movi a5, -1 /* 0xffffffff */
2048 .Lfixunsdfsi_bigexp:
2049 /* Handle unsigned maximum exponent case. */
2051 mov a2, a5 /* no shift needed */
2054 /* Return 0x80000000 if negative. */
2058 #endif /* L_fixunsdfsi */
2063 .global __fixunsdfdi
2064 .type __fixunsdfdi, @function
2068 /* Check for NaN and Infinity. */
2070 ball xh, a6, .Lfixunsdfdi_nan_or_inf
2072 /* Extract the exponent and check if 0 <= (exp - 0x3ff) < 64. */
2073 extui a4, xh, 20, 11
2074 extui a5, a6, 20, 10 /* 0x3ff */
2076 bgei a4, 64, .Lfixunsdfdi_maxint
2077 bltz a4, .Lfixunsdfdi_zero
2079 /* Add explicit "1.0" and shift << 11. */
2085 /* Shift back to the right, based on the exponent. */
2087 beqi a4, 64, .Lfixunsdfdi_bigexp
2088 ssl a4 /* shift by 64 - a4 */
2089 bgei a4, 32, .Lfixunsdfdi_smallshift
2093 .Lfixunsdfdi_shifted:
2094 /* Negate the result if sign != 0. */
2102 .Lfixunsdfdi_smallshift:
2105 j .Lfixunsdfdi_shifted
2107 .Lfixunsdfdi_nan_or_inf:
2108 /* Handle Infinity and NaN. */
2111 beqz a4, .Lfixunsdfdi_maxint
2113 /* Translate NaN to 0xffffffff.... */
2118 .Lfixunsdfdi_maxint:
2120 2: slli xh, a6, 11 /* 0x80000000 */
2129 .Lfixunsdfdi_bigexp:
2130 /* Handle unsigned maximum exponent case. */
2132 leaf_return /* no shift needed */
2134 #endif /* L_fixunsdfdi */
2139 .global __floatunsidf
2140 .type __floatunsidf, @function
2143 beqz a2, .Lfloatsidf_return_zero
2145 /* Set the sign to zero and jump to the floatsidf code. */
2147 j .Lfloatsidf_normalize
2151 .type __floatsidf, @function
2155 /* Check for zero. */
2156 beqz a2, .Lfloatsidf_return_zero
2158 /* Save the sign. */
2161 /* Get the absolute value. */
2169 .Lfloatsidf_normalize:
2170 /* Normalize with the first 1 bit in the msb. */
2171 do_nsau a4, a2, a5, a6
2175 /* Shift the mantissa into position. */
2177 slli xl, a5, (32 - 11)
2179 /* Set the exponent. */
2180 movi a5, 0x41d /* 0x3fe + 31 */
2185 /* Add the sign and return. */
2190 .Lfloatsidf_return_zero:
2194 #endif /* L_floatsidf */
2199 .global __floatundidf
2200 .type __floatundidf, @function
2204 /* Check for zero. */
2208 /* Set the sign to zero and jump to the floatdidf code. */
2210 j .Lfloatdidf_normalize
2214 .type __floatdidf, @function
2218 /* Check for zero. */
2222 /* Save the sign. */
2225 /* Get the absolute value. */
2226 bgez xh, .Lfloatdidf_normalize
2229 beqz xl, .Lfloatdidf_normalize
2232 .Lfloatdidf_normalize:
2233 /* Normalize with the first 1 bit in the msb of xh. */
2234 beqz xh, .Lfloatdidf_bigshift
2235 do_nsau a4, xh, a5, a6
2240 .Lfloatdidf_shifted:
2241 /* Shift the mantissa into position, with rounding bits in a6. */
2247 /* Set the exponent. */
2248 movi a5, 0x43d /* 0x3fe + 63 */
2257 /* Round up if the leftover fraction is >= 1/2. */
2260 beqz xl, .Lfloatdidf_roundcarry
2262 /* Check if the leftover fraction is exactly 1/2. */
2264 beqz a6, .Lfloatdidf_exactlyhalf
2267 .Lfloatdidf_bigshift:
2268 /* xh is zero. Normalize with first 1 bit of xl in the msb of xh. */
2269 do_nsau a4, xl, a5, a6
2274 j .Lfloatdidf_shifted
2276 .Lfloatdidf_exactlyhalf:
2277 /* Round down to the nearest even value. */
2282 .Lfloatdidf_roundcarry:
2283 /* xl is always zero when the rounding increment overflows, so
2284 there's no need to round it to an even value. */
2286 /* Overflow to the exponent is OK. */
2289 #endif /* L_floatdidf */
2294 .global __truncdfsf2
2295 .type __truncdfsf2, @function
2299 /* Adjust the exponent bias. */
2300 movi a4, (0x3ff - 0x7f) << 20
2303 /* Check for underflow. */
2305 bltz a6, .Ltrunc_underflow
2306 extui a6, a5, 20, 11
2307 beqz a6, .Ltrunc_underflow
2309 /* Check for overflow. */
2311 bge a6, a4, .Ltrunc_overflow
2313 /* Shift a5/xl << 3 into a5/a4. */
2319 /* Add the sign bit. */
2324 /* Round up if the leftover fraction is >= 1/2. */
2327 /* Overflow to the exponent is OK. The answer will be correct. */
2329 /* Check if the leftover fraction is exactly 1/2. */
2331 beqz a4, .Ltrunc_exactlyhalf
2334 .Ltrunc_exactlyhalf:
2335 /* Round down to the nearest even value. */
2341 /* Check if exponent == 0x7ff. */
2345 /* Check if mantissa is nonzero. */
2350 /* Shift a4 to set a bit in the mantissa, making a quiet NaN. */
2353 1: slli a4, a4, 4 /* 0xff000000 or 0xff800000 */
2354 /* Add the sign bit. */
2361 /* Find shift count for a subnormal. Flush to zero if >= 32. */
2362 extui a6, xh, 20, 11
2363 movi a5, 0x3ff - 0x7f
2368 /* Replace the exponent with an explicit "1.0". */
2369 slli a5, a5, 13 /* 0x700000 */
2374 /* Shift the mantissa left by 3 bits (into a5/a4). */
2379 /* Shift right by a6. */
2384 beqz a7, .Ltrunc_addsign
2385 or a4, a4, a6 /* any positive, nonzero value will work */
2388 /* Return +/- zero. */
2389 1: extui a2, xh, 31, 1
2393 #endif /* L_truncdfsf2 */
2395 #ifdef L_extendsfdf2
2398 .global __extendsfdf2
2399 .type __extendsfdf2, @function
2403 /* Save the sign bit and then shift it off. */
2408 /* Extract and check the exponent. */
2410 beqz a6, .Lextend_expzero
2412 beqi a6, 256, .Lextend_nan_or_inf
2414 /* Shift >> 3 into a4/xl. */
2416 slli xl, a2, (32 - 3)
2418 /* Adjust the exponent bias. */
2419 movi a6, (0x3ff - 0x7f) << 20
2422 /* Add the sign bit. */
2426 .Lextend_nan_or_inf:
2429 /* Check for NaN. */
2433 slli a6, a6, 11 /* 0x80000 */
2436 /* Add the sign and return. */
2444 /* Normalize it to have 8 zero bits before the first 1 bit. */
2445 do_nsau a7, a4, a2, a3
2450 /* Shift >> 3 into a4/xl. */
2451 slli xl, a4, (32 - 3)
2454 /* Set the exponent. */
2455 movi a6, 0x3fe - 0x7f
2460 /* Add the sign and return. */
2464 #endif /* L_extendsfdf2 */
2467 #if XCHAL_HAVE_DFP_SQRT
2472 .global __ieee754_sqrt
2473 .type __ieee754_sqrt, @function
2520 #endif /* XCHAL_HAVE_DFP_SQRT */
2522 #if XCHAL_HAVE_DFP_RECIP
2528 .type __recipdf2, @function
2551 #endif /* L_recipdf2 */
2552 #endif /* XCHAL_HAVE_DFP_RECIP */
2554 #if XCHAL_HAVE_DFP_RSQRT
2556 /* Reciprocal square root */
2560 .type __rsqrtdf2, @function
2589 #endif /* L_rsqrtdf2 */
2590 #endif /* XCHAL_HAVE_DFP_RSQRT */