1 /* IEEE-754 double-precision functions for Xtensa
2 Copyright (C) 2006-2015 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. */
68 /* If x is a NaN, return it. Otherwise, return y. */
71 beqz a7, .Ladd_ynan_or_inf
81 /* Operand signs differ. Do a subtraction. */
88 .type __adddf3, @function
93 /* Check if the two operands have the same sign. */
95 bltz a7, .Ladd_opposite_signs
98 /* Check if either exponent == 0x7ff (i.e., NaN or Infinity). */
99 ball xh, a6, .Ladd_xnan_or_inf
100 ball yh, a6, .Ladd_ynan_or_inf
102 /* Compare the exponents. The smaller operand will be shifted
103 right by the exponent difference and added to the larger
107 bltu a7, a8, .Ladd_shiftx
110 /* Check if the smaller (or equal) exponent is zero. */
111 bnone yh, a6, .Ladd_yexpzero
113 /* Replace yh sign/exponent with 0x001. */
119 /* Compute the exponent difference. Optimize for difference < 32. */
121 bgeui a10, 32, .Ladd_bigshifty
123 /* Shift yh/yl right by the exponent difference. Any bits that are
124 shifted out of yl are saved in a9 for rounding the result. */
132 /* Do the 64-bit addition. */
138 /* Check if the add overflowed into the exponent. */
139 extui a10, xh, 20, 12
140 beq a10, a7, .Ladd_round
145 /* y is a subnormal value. Replace its sign/exponent with zero,
146 i.e., no implicit "1.0", and increment the apparent exponent
147 because subnormals behave as if they had the minimum (nonzero)
148 exponent. Test for the case when both exponents are zero. */
151 bnone xh, a6, .Ladd_bothexpzero
156 /* Both exponents are zero. Handle this as a special case. There
157 is no need to shift or round, and the normal code for handling
158 a carry into the exponent field will not work because it
159 assumes there is an implicit "1.0" that needs to be added. */
167 /* Exponent difference > 64 -- just return the bigger value. */
170 /* Shift yh/yl right by the exponent difference. Any bits that are
171 shifted out are saved in a9 for rounding the result. */
173 sll a11, yl /* lost bits shifted out of yl */
178 or a9, a9, a10 /* any positive, nonzero value will work */
182 /* Same as "yexpzero" except skip handling the case when both
183 exponents are zero. */
190 /* Same thing as the "shifty" code, but with x and y swapped. Also,
191 because the exponent difference is always nonzero in this version,
192 the shift sequence can use SLL and skip loading a constant zero. */
193 bnone xh, a6, .Ladd_xexpzero
201 bgeui a10, 32, .Ladd_bigshiftx
214 /* Check if the add overflowed into the exponent. */
215 extui a10, xh, 20, 12
216 bne a10, a8, .Ladd_carry
219 /* Round up if the leftover fraction is >= 1/2. */
222 beqz xl, .Ladd_roundcarry
224 /* Check if the leftover fraction is exactly 1/2. */
226 beqz a9, .Ladd_exactlyhalf
230 /* Mostly the same thing as "bigshifty".... */
231 bgeui a10, 64, .Ladd_returny
248 /* The addition has overflowed into the exponent field, so the
249 value needs to be renormalized. The mantissa of the result
250 can be recovered by subtracting the original exponent and
251 adding 0x100000 (which is the explicit "1.0" for the
252 mantissa of the non-shifted operand -- the "1.0" for the
253 shifted operand was already added). The mantissa can then
254 be shifted right by one bit. The explicit "1.0" of the
255 shifted mantissa then needs to be replaced by the exponent,
256 incremented by one to account for the normalizing shift.
257 It is faster to combine these operations: do the shift first
258 and combine the additions and subtractions. If x is the
259 original exponent, the result is:
260 shifted mantissa - (x << 19) + (1 << 19) + (x << 20)
262 shifted mantissa + ((x + 1) << 19)
263 Note that the exponent is incremented here by leaving the
264 explicit "1.0" of the mantissa in the exponent field. */
266 /* Shift xh/xl right by one bit. Save the lsb of xl. */
272 /* See explanation above. The original exponent is in a8. */
277 /* Return an Infinity if the exponent overflowed. */
278 ball xh, a6, .Ladd_infinity
280 /* Same thing as the "round" code except the msb of the leftover
281 fraction is bit 0 of a10, with the rest of the fraction in a9. */
284 beqz xl, .Ladd_roundcarry
285 beqz a9, .Ladd_exactlyhalf
289 /* Clear the mantissa. */
294 /* The sign bit may have been lost in a carry-out. Put it back. */
300 /* Round down to the nearest even value. */
306 /* xl is always zero when the rounding increment overflows, so
307 there's no need to round it to an even value. */
309 /* Overflow to the exponent is OK. */
316 /* Handle NaNs and Infinities. (This code is placed before the
317 start of the function just to keep it in range of the limited
318 branch displacements.) */
321 /* If y is neither Infinity nor NaN, return x. */
323 /* Both x and y are either NaN or Inf, so the result is NaN. */
324 movi a4, 0x80000 /* make it a quiet NaN */
329 /* Negate y and return it. */
335 .Lsub_opposite_signs:
336 /* Operand signs differ. Do an addition. */
343 .type __subdf3, @function
348 /* Check if the two operands have the same sign. */
350 bltz a7, .Lsub_opposite_signs
353 /* Check if either exponent == 0x7ff (i.e., NaN or Infinity). */
354 ball xh, a6, .Lsub_xnan_or_inf
355 ball yh, a6, .Lsub_ynan_or_inf
357 /* Compare the operands. In contrast to addition, the entire
358 value matters here. */
361 bltu xh, yh, .Lsub_xsmaller
362 beq xh, yh, .Lsub_compare_low
365 /* Check if the smaller (or equal) exponent is zero. */
366 bnone yh, a6, .Lsub_yexpzero
368 /* Replace yh sign/exponent with 0x001. */
374 /* Compute the exponent difference. Optimize for difference < 32. */
376 bgeui a10, 32, .Lsub_bigshifty
378 /* Shift yh/yl right by the exponent difference. Any bits that are
379 shifted out of yl are saved in a9 for rounding the result. */
387 /* Do the 64-bit subtraction. */
393 /* Subtract the leftover bits in a9 from zero and propagate any
394 borrow from xh/xl. */
401 /* Check if the subtract underflowed into the exponent. */
402 extui a10, xh, 20, 11
403 beq a10, a7, .Lsub_round
407 /* The high words are equal. Compare the low words. */
408 bltu xl, yl, .Lsub_xsmaller
409 bltu yl, xl, .Lsub_ysmaller
410 /* The operands are equal. Return 0.0. */
416 /* y is a subnormal value. Replace its sign/exponent with zero,
417 i.e., no implicit "1.0". Unless x is also a subnormal, increment
418 y's apparent exponent because subnormals behave as if they had
419 the minimum (nonzero) exponent. */
422 bnone xh, a6, .Lsub_yexpdiff
427 /* Exponent difference > 64 -- just return the bigger value. */
430 /* Shift yh/yl right by the exponent difference. Any bits that are
431 shifted out are saved in a9 for rounding the result. */
433 sll a11, yl /* lost bits shifted out of yl */
438 or a9, a9, a10 /* any positive, nonzero value will work */
442 /* Same thing as the "ysmaller" code, but with x and y swapped and
444 bnone xh, a6, .Lsub_xexpzero
452 bgeui a10, 32, .Lsub_bigshiftx
470 /* Subtract the leftover bits in a9 from zero and propagate any
471 borrow from xh/xl. */
478 /* Check if the subtract underflowed into the exponent. */
479 extui a10, xh, 20, 11
480 bne a10, a8, .Lsub_borrow
483 /* Round up if the leftover fraction is >= 1/2. */
486 beqz xl, .Lsub_roundcarry
488 /* Check if the leftover fraction is exactly 1/2. */
490 beqz a9, .Lsub_exactlyhalf
494 /* Same as "yexpzero". */
497 bnone yh, a6, .Lsub_xexpdiff
502 /* Mostly the same thing as "bigshifty", but with the sign bit of the
503 shifted value set so that the subsequent subtraction flips the
505 bgeui a10, 64, .Lsub_returny
511 slli xh, a6, 11 /* set sign bit of xh */
517 /* Negate and return y. */
524 /* The subtraction has underflowed into the exponent field, so the
525 value needs to be renormalized. Shift the mantissa left as
526 needed to remove any leading zeros and adjust the exponent
527 accordingly. If the exponent is not large enough to remove
528 all the leading zeros, the result will be a subnormal value. */
531 beqz a8, .Lsub_xhzero
532 do_nsau a6, a8, a7, a11
534 bge a6, a10, .Lsub_subnormal
538 /* Shift the mantissa (a8/xl/a9) left by a6. */
544 /* Combine the shifted mantissa with the sign and exponent,
545 decrementing the exponent by a6. (The exponent has already
546 been decremented by one due to the borrow from the subtraction,
547 but adding the mantissa will increment the exponent by one.) */
555 /* Round down to the nearest even value. */
561 /* xl is always zero when the rounding increment overflows, so
562 there's no need to round it to an even value. */
564 /* Overflow to the exponent is OK. */
568 /* When normalizing the result, all the mantissa bits in the high
569 word are zero. Shift by "20 + (leading zero count of xl) + 1". */
570 do_nsau a6, xl, a7, a11
572 blt a10, a6, .Lsub_subnormal
574 .Lsub_normalize_shift:
575 bltui a6, 32, .Lsub_shift_lt32
589 /* The exponent is too small to shift away all the leading zeros.
590 Set a6 to the current exponent (which has already been
591 decremented by the borrow) so that the exponent of the result
592 will be zero. Do not add 1 to a6 in this case, because: (1)
593 adding the mantissa will not increment the exponent, so there is
594 no need to subtract anything extra from the exponent to
595 compensate, and (2) the effective exponent of a subnormal is 1
596 not 0 so the shift amount must be 1 smaller than normal. */
598 j .Lsub_normalize_shift
600 #endif /* L_addsubdf3 */
605 #if !XCHAL_HAVE_MUL16 && !XCHAL_HAVE_MUL32 && !XCHAL_HAVE_MAC16
606 #define XCHAL_NO_MUL 1
611 /* Handle unusual cases (zeros, subnormals, NaNs and Infinities).
612 (This code is placed before the start of the function just to
613 keep it in range of the limited branch displacements.) */
616 /* Clear the sign bit of x. */
620 /* If x is zero, return zero. */
622 beqz a10, .Lmul_return_zero
624 /* Normalize x. Adjust the exponent in a8. */
625 beqz xh, .Lmul_xh_zero
626 do_nsau a10, xh, a11, a12
635 do_nsau a10, xl, a11, a12
640 bltz a10, .Lmul_xl_srl
650 /* Clear the sign bit of y. */
654 /* If y is zero, return zero. */
656 beqz a10, .Lmul_return_zero
658 /* Normalize y. Adjust the exponent in a9. */
659 beqz yh, .Lmul_yh_zero
660 do_nsau a10, yh, a11, a12
669 do_nsau a10, yl, a11, a12
674 bltz a10, .Lmul_yl_srl
684 /* Return zero with the appropriate sign bit. */
691 /* If y is zero, return NaN. */
695 movi a4, 0x80000 /* make it a quiet NaN */
699 /* If y is NaN, return y. */
700 bnall yh, a6, .Lmul_returnx
703 beqz a8, .Lmul_returnx
710 /* Set the sign bit and return. */
718 /* If x is zero, return NaN. */
719 bnez xl, .Lmul_returny
721 bnez a8, .Lmul_returny
722 movi a7, 0x80000 /* make it a quiet NaN */
728 .type __muldf3, @function
730 #if __XTENSA_CALL0_ABI__
738 /* This is not really a leaf function; allocate enough stack space
739 to allow CALL12s to a helper function. */
746 /* Get the sign of the result. */
749 /* Check for NaN and infinity. */
750 ball xh, a6, .Lmul_xnan_or_inf
751 ball yh, a6, .Lmul_ynan_or_inf
753 /* Extract the exponents. */
757 beqz a8, .Lmul_xexpzero
759 beqz a9, .Lmul_yexpzero
762 /* Add the exponents. */
765 /* Replace sign/exponent fields with explicit "1.0". */
772 /* Multiply 64x64 to 128 bits. The result ends up in xh/xl/a6.
773 The least-significant word of the result is thrown away except
774 that if it is nonzero, the lsb of a6 is set to 1. */
775 #if XCHAL_HAVE_MUL32_HIGH
777 /* Compute a6 with any carry-outs in a10. */
790 /* If the low word of the result is nonzero, set the lsb of a6. */
796 /* Compute xl with any carry-outs in a9. */
817 #else /* ! XCHAL_HAVE_MUL32_HIGH */
819 /* Break the inputs into 16-bit chunks and compute 16 32-bit partial
820 products. These partial products are:
845 where the input chunks are (hh, hl, lh, ll). If using the Mul16
846 or Mul32 multiplier options, these input chunks must be stored in
847 separate registers. For Mac16, the UMUL.AA.* opcodes can specify
848 that the inputs come from either half of the registers, so there
849 is no need to shift them out ahead of time. If there is no
850 multiply hardware, the 16-bit chunks can be extracted when setting
851 up the arguments to the separate multiply function. */
853 /* Save a7 since it is needed to hold a temporary value. */
855 #if __XTENSA_CALL0_ABI__ && XCHAL_NO_MUL
856 /* Calling a separate multiply function will clobber a0 and requires
857 use of a8 as a temporary, so save those values now. (The function
858 uses a custom ABI so nothing else needs to be saved.) */
863 #if XCHAL_HAVE_MUL16 || XCHAL_HAVE_MUL32
870 /* Get the high halves of the inputs into registers. */
881 #if XCHAL_HAVE_MUL32 && !XCHAL_HAVE_MUL16
882 /* Clear the high halves of the inputs. This does not matter
883 for MUL16 because the high bits are ignored. */
889 #endif /* MUL16 || MUL32 */
894 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
895 mul16u dst, xreg ## xhalf, yreg ## yhalf
897 #elif XCHAL_HAVE_MUL32
899 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
900 mull dst, xreg ## xhalf, yreg ## yhalf
902 #elif XCHAL_HAVE_MAC16
904 /* The preprocessor insists on inserting a space when concatenating after
905 a period in the definition of do_mul below. These macros are a workaround
906 using underscores instead of periods when doing the concatenation. */
907 #define umul_aa_ll umul.aa.ll
908 #define umul_aa_lh umul.aa.lh
909 #define umul_aa_hl umul.aa.hl
910 #define umul_aa_hh umul.aa.hh
912 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
913 umul_aa_ ## xhalf ## yhalf xreg, yreg; \
916 #else /* no multiply hardware */
918 #define set_arg_l(dst, src) \
919 extui dst, src, 0, 16
920 #define set_arg_h(dst, src) \
923 #if __XTENSA_CALL0_ABI__
924 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
925 set_arg_ ## xhalf (a13, xreg); \
926 set_arg_ ## yhalf (a14, yreg); \
927 call0 .Lmul_mulsi3; \
930 #define do_mul(dst, xreg, xhalf, yreg, yhalf) \
931 set_arg_ ## xhalf (a14, xreg); \
932 set_arg_ ## yhalf (a15, yreg); \
933 call12 .Lmul_mulsi3; \
935 #endif /* __XTENSA_CALL0_ABI__ */
937 #endif /* no multiply hardware */
939 /* Add pp1 and pp2 into a10 with carry-out in a9. */
940 do_mul(a10, xl, l, yl, h) /* pp 1 */
941 do_mul(a11, xl, h, yl, l) /* pp 2 */
947 /* Initialize a6 with a9/a10 shifted into position. Note that
948 this value can be safely incremented without any carry-outs. */
952 /* Compute the low word into a10. */
953 do_mul(a11, xl, l, yl, l) /* pp 0 */
959 /* Compute the contributions of pp0-5 to a6, with carry-outs in a9.
960 This is good enough to determine the low half of a6, so that any
961 nonzero bits from the low word of the result can be collapsed
962 into a6, freeing up a register. */
964 do_mul(a11, xl, l, yh, l) /* pp 3 */
969 do_mul(a11, xl, h, yl, h) /* pp 4 */
974 do_mul(a11, xh, l, yl, l) /* pp 5 */
979 /* Collapse any nonzero bits from the low word into a6. */
984 /* Add pp6-9 into a11 with carry-outs in a10. */
985 do_mul(a7, xl, l, yh, h) /* pp 6 */
986 do_mul(a11, xh, h, yl, l) /* pp 9 */
992 do_mul(a7, xl, h, yh, l) /* pp 7 */
997 do_mul(a7, xh, l, yl, h) /* pp 8 */
1002 /* Shift a10/a11 into position, and add low half of a11 to a6. */
1010 /* Add pp10-12 into xl with carry-outs in a9. */
1012 do_mul(xl, xl, h, yh, h) /* pp 10 */
1017 do_mul(a10, xh, l, yh, l) /* pp 11 */
1022 do_mul(a10, xh, h, yl, h) /* pp 12 */
1027 /* Add pp13-14 into a11 with carry-outs in a10. */
1028 do_mul(a11, xh, l, yh, h) /* pp 13 */
1029 do_mul(a7, xh, h, yh, l) /* pp 14 */
1035 /* Shift a10/a11 into position, and add low half of a11 to a6. */
1044 do_mul(xh, xh, h, yh, h) /* pp 15 */
1047 /* Restore values saved on the stack during the multiplication. */
1049 #if __XTENSA_CALL0_ABI__ && XCHAL_NO_MUL
1053 #endif /* ! XCHAL_HAVE_MUL32_HIGH */
1055 /* Shift left by 12 bits, unless there was a carry-out from the
1056 multiply, in which case, shift by 11 bits and increment the
1057 exponent. Note: It is convenient to use the constant 0x3ff
1058 instead of 0x400 when removing the extra exponent bias (so that
1059 it is easy to construct 0x7fe for the overflow check). Reverse
1060 the logic here to decrement the exponent sum by one unless there
1063 srli a5, xh, 21 - 12
1072 /* Subtract the extra bias from the exponent sum (plus one to account
1073 for the explicit "1.0" of the mantissa that will be added to the
1074 exponent in the final result). */
1078 /* Check for over/underflow. The value in a8 is one less than the
1079 final exponent, so values in the range 0..7fd are OK here. */
1080 slli a4, a4, 1 /* 0x7fe */
1081 bgeu a8, a4, .Lmul_overflow
1085 bgez a6, .Lmul_rounded
1087 beqz xl, .Lmul_roundcarry
1089 beqz a6, .Lmul_exactlyhalf
1092 /* Add the exponent to the mantissa. */
1097 /* Add the sign bit. */
1103 #if __XTENSA_CALL0_ABI__
1113 /* Round down to the nearest even value. */
1119 /* xl is always zero when the rounding increment overflows, so
1120 there's no need to round it to an even value. */
1122 /* Overflow is OK -- it will be added to the exponent. */
1126 bltz a8, .Lmul_underflow
1127 /* Return +/- Infinity. */
1128 addi a8, a4, 1 /* 0x7ff */
1134 /* Create a subnormal value, where the exponent field contains zero,
1135 but the effective exponent is 1. The value of a8 is one less than
1136 the actual exponent, so just negate it to get the shift amount. */
1140 bgeui a8, 32, .Lmul_bigshift
1142 /* Shift xh/xl right. Any bits that are shifted out of xl are saved
1143 in a6 (combined with the shifted-out bits currently in a6) for
1144 rounding the result. */
1151 bgeui a8, 64, .Lmul_flush_to_zero
1152 sll a10, xl /* lost bits shifted out of xl */
1158 /* Set the exponent to zero. */
1161 /* Pack any nonzero bits shifted out into a6. */
1162 beqz a9, .Lmul_round
1167 .Lmul_flush_to_zero:
1168 /* Return zero with the appropriate sign bit. */
1176 /* For Xtensa processors with no multiply hardware, this simplified
1177 version of _mulsi3 is used for multiplying 16-bit chunks of
1178 the floating-point mantissas. When using CALL0, this function
1179 uses a custom ABI: the inputs are passed in a13 and a14, the
1180 result is returned in a12, and a8 and a15 are clobbered. */
1184 .macro mul_mulsi3_body dst, src1, src2, tmp1, tmp2
1186 1: add \tmp1, \src2, \dst
1187 extui \tmp2, \src1, 0, 1
1188 movnez \dst, \tmp1, \tmp2
1190 do_addx2 \tmp1, \src2, \dst, \tmp1
1191 extui \tmp2, \src1, 1, 1
1192 movnez \dst, \tmp1, \tmp2
1194 do_addx4 \tmp1, \src2, \dst, \tmp1
1195 extui \tmp2, \src1, 2, 1
1196 movnez \dst, \tmp1, \tmp2
1198 do_addx8 \tmp1, \src2, \dst, \tmp1
1199 extui \tmp2, \src1, 3, 1
1200 movnez \dst, \tmp1, \tmp2
1202 srli \src1, \src1, 4
1203 slli \src2, \src2, 4
1206 #if __XTENSA_CALL0_ABI__
1207 mul_mulsi3_body a12, a13, a14, a15, a8
1209 /* The result will be written into a2, so save that argument in a4. */
1211 mul_mulsi3_body a2, a4, a3, a5, a6
1214 #endif /* XCHAL_NO_MUL */
1215 #endif /* L_muldf3 */
1222 /* Handle unusual cases (zeros, subnormals, NaNs and Infinities).
1223 (This code is placed before the start of the function just to
1224 keep it in range of the limited branch displacements.) */
1227 /* Clear the sign bit of y. */
1231 /* Check for division by zero. */
1233 beqz a10, .Ldiv_yzero
1235 /* Normalize y. Adjust the exponent in a9. */
1236 beqz yh, .Ldiv_yh_zero
1237 do_nsau a10, yh, a11, a9
1246 do_nsau a10, yl, a11, a9
1251 bltz a10, .Ldiv_yl_srl
1261 /* y is zero. Return NaN if x is also zero; otherwise, infinity. */
1269 movi a4, 0x80000 /* make it a quiet NaN */
1275 /* Clear the sign bit of x. */
1279 /* If x is zero, return zero. */
1281 beqz a10, .Ldiv_return_zero
1283 /* Normalize x. Adjust the exponent in a8. */
1284 beqz xh, .Ldiv_xh_zero
1285 do_nsau a10, xh, a11, a8
1294 do_nsau a10, xl, a11, a8
1299 bltz a10, .Ldiv_xl_srl
1309 /* Return zero with the appropriate sign bit. */
1316 /* Set the sign bit of the result. */
1320 /* If y is NaN or Inf, return NaN. */
1322 movi a4, 0x80000 /* make it a quiet NaN */
1327 /* If y is Infinity, return zero. */
1330 beqz a8, .Ldiv_return_zero
1331 /* y is NaN; return it. */
1342 .type __divdf3, @function
1347 /* Get the sign of the result. */
1350 /* Check for NaN and infinity. */
1351 ball xh, a6, .Ldiv_xnan_or_inf
1352 ball yh, a6, .Ldiv_ynan_or_inf
1354 /* Extract the exponents. */
1355 extui a8, xh, 20, 11
1356 extui a9, yh, 20, 11
1358 beqz a9, .Ldiv_yexpzero
1360 beqz a8, .Ldiv_xexpzero
1363 /* Subtract the exponents. */
1366 /* Replace sign/exponent fields with explicit "1.0". */
1373 /* Set SAR for left shift by one. */
1376 /* The first digit of the mantissa division must be a one.
1377 Shift x (and adjust the exponent) as needed to make this true. */
1379 beq yh, xh, .Ldiv_highequal1
1384 /* Do the first subtraction and shift. */
1392 /* Put the quotient into a10/a11. */
1396 /* Divide one bit at a time for 52 bits. */
1398 #if XCHAL_HAVE_LOOPS
1399 loop a9, .Ldiv_loopend
1402 /* Shift the quotient << 1. */
1406 /* Is this digit a 0 or 1? */
1408 beq xh, yh, .Ldiv_highequal2
1410 /* Output a 1 and subtract. */
1417 /* Shift the dividend << 1. */
1421 #if !XCHAL_HAVE_LOOPS
1427 /* Add the exponent bias (less one to account for the explicit "1.0"
1428 of the mantissa that will be added to the exponent in the final
1433 /* Check for over/underflow. The value in a8 is one less than the
1434 final exponent, so values in the range 0..7fd are OK here. */
1435 addmi a9, a9, 0x400 /* 0x7fe */
1436 bgeu a8, a9, .Ldiv_overflow
1439 /* Round. The remainder (<< 1) is in xh/xl. */
1440 bltu xh, yh, .Ldiv_rounded
1441 beq xh, yh, .Ldiv_highequal3
1444 beqz a11, .Ldiv_roundcarry
1448 /* Add the exponent to the mantissa. */
1453 /* Add the sign bit. */
1464 bltu xl, yl, .Ldiv_rounded
1465 bne xl, yl, .Ldiv_roundup
1467 /* Remainder is exactly half the divisor. Round even. */
1469 beqz a11, .Ldiv_roundcarry
1475 bltz a8, .Ldiv_underflow
1476 /* Return +/- Infinity. */
1477 addi a8, a9, 1 /* 0x7ff */
1483 /* Create a subnormal value, where the exponent field contains zero,
1484 but the effective exponent is 1. The value of a8 is one less than
1485 the actual exponent, so just negate it to get the shift amount. */
1488 bgeui a8, 32, .Ldiv_bigshift
1490 /* Shift a10/a11 right. Any bits that are shifted out of a11 are
1491 saved in a6 for rounding the result. */
1498 bgeui a8, 64, .Ldiv_flush_to_zero
1499 sll a9, a11 /* lost bits shifted out of a11 */
1505 /* Set the exponent to zero. */
1508 /* Pack any nonzero remainder (in xh/xl) into a6. */
1514 /* Round a10/a11 based on the bits shifted out into a6. */
1515 1: bgez a6, .Ldiv_rounded
1517 beqz a11, .Ldiv_roundcarry
1519 bnez a6, .Ldiv_rounded
1525 /* a11 is always zero when the rounding increment overflows, so
1526 there's no need to round it to an even value. */
1528 /* Overflow to the exponent field is OK. */
1531 .Ldiv_flush_to_zero:
1532 /* Return zero with the appropriate sign bit. */
1538 #endif /* L_divdf3 */
1542 /* Equal and Not Equal */
1547 .set __nedf2, __eqdf2
1548 .type __eqdf2, @function
1554 /* The values are equal but NaN != NaN. Check the exponent. */
1566 /* Check if the mantissas are nonzero. */
1571 /* Check if x and y are zero with different signs. */
1574 or a7, a7, xl /* xl == yl here */
1576 /* Equal if a7 == 0, where a7 is either abs(x | y) or the mantissa
1577 or x when exponent(x) = 0x7ff and x == y. */
1588 .type __gtdf2, @function
1593 1: bnall yh, a6, .Lle_cmp
1595 /* Check if y is a NaN. */
1602 /* Check if x is a NaN. */
1610 /* Less Than or Equal */
1614 .type __ledf2, @function
1619 1: bnall yh, a6, .Lle_cmp
1621 /* Check if y is a NaN. */
1628 /* Check if x is a NaN. */
1636 /* Check if x and y have different signs. */
1638 bltz a7, .Lle_diff_signs
1640 /* Check if x is negative. */
1643 /* Check if x <= y. */
1651 /* Check if y <= x. */
1661 /* Check if both x and y are zero. */
1672 /* Greater Than or Equal */
1676 .type __gedf2, @function
1681 1: bnall yh, a6, .Llt_cmp
1683 /* Check if y is a NaN. */
1690 /* Check if x is a NaN. */
1702 .type __ltdf2, @function
1707 1: bnall yh, a6, .Llt_cmp
1709 /* Check if y is a NaN. */
1716 /* Check if x is a NaN. */
1724 /* Check if x and y have different signs. */
1726 bltz a7, .Llt_diff_signs
1728 /* Check if x is negative. */
1731 /* Check if x < y. */
1739 /* Check if y < x. */
1749 /* Check if both x and y are nonzero. */
1764 .type __unorddf2, @function
1785 #endif /* L_cmpdf2 */
1791 .type __fixdfsi, @function
1795 /* Check for NaN and Infinity. */
1797 ball xh, a6, .Lfixdfsi_nan_or_inf
1799 /* Extract the exponent and check if 0 < (exp - 0x3fe) < 32. */
1800 extui a4, xh, 20, 11
1801 extui a5, a6, 19, 10 /* 0x3fe */
1803 bgei a4, 32, .Lfixdfsi_maxint
1804 blti a4, 1, .Lfixdfsi_zero
1806 /* Add explicit "1.0" and shift << 11. */
1811 /* Shift back to the right, based on the exponent. */
1812 ssl a4 /* shift by 32 - a4 */
1815 /* Negate the result if sign != 0. */
1820 .Lfixdfsi_nan_or_inf:
1821 /* Handle Infinity and NaN. */
1824 beqz a4, .Lfixdfsi_maxint
1826 /* Translate NaN to +maxint. */
1830 slli a4, a6, 11 /* 0x80000000 */
1831 addi a5, a4, -1 /* 0x7fffffff */
1840 #endif /* L_fixdfsi */
1846 .type __fixdfdi, @function
1850 /* Check for NaN and Infinity. */
1852 ball xh, a6, .Lfixdfdi_nan_or_inf
1854 /* Extract the exponent and check if 0 < (exp - 0x3fe) < 64. */
1855 extui a4, xh, 20, 11
1856 extui a5, a6, 19, 10 /* 0x3fe */
1858 bgei a4, 64, .Lfixdfdi_maxint
1859 blti a4, 1, .Lfixdfdi_zero
1861 /* Add explicit "1.0" and shift << 11. */
1867 /* Shift back to the right, based on the exponent. */
1868 ssl a4 /* shift by 64 - a4 */
1869 bgei a4, 32, .Lfixdfdi_smallshift
1874 /* Negate the result if sign != 0. */
1882 .Lfixdfdi_smallshift:
1887 .Lfixdfdi_nan_or_inf:
1888 /* Handle Infinity and NaN. */
1891 beqz a4, .Lfixdfdi_maxint
1893 /* Translate NaN to +maxint. */
1897 slli a7, a6, 11 /* 0x80000000 */
1903 1: addi xh, a7, -1 /* 0x7fffffff */
1912 #endif /* L_fixdfdi */
1917 .global __fixunsdfsi
1918 .type __fixunsdfsi, @function
1922 /* Check for NaN and Infinity. */
1924 ball xh, a6, .Lfixunsdfsi_nan_or_inf
1926 /* Extract the exponent and check if 0 <= (exp - 0x3ff) < 32. */
1927 extui a4, xh, 20, 11
1928 extui a5, a6, 20, 10 /* 0x3ff */
1930 bgei a4, 32, .Lfixunsdfsi_maxint
1931 bltz a4, .Lfixunsdfsi_zero
1933 /* Add explicit "1.0" and shift << 11. */
1938 /* Shift back to the right, based on the exponent. */
1940 beqi a4, 32, .Lfixunsdfsi_bigexp
1941 ssl a4 /* shift by 32 - a4 */
1944 /* Negate the result if sign != 0. */
1949 .Lfixunsdfsi_nan_or_inf:
1950 /* Handle Infinity and NaN. */
1953 beqz a4, .Lfixunsdfsi_maxint
1955 /* Translate NaN to 0xffffffff. */
1959 .Lfixunsdfsi_maxint:
1960 slli a4, a6, 11 /* 0x80000000 */
1961 movi a5, -1 /* 0xffffffff */
1970 .Lfixunsdfsi_bigexp:
1971 /* Handle unsigned maximum exponent case. */
1973 mov a2, a5 /* no shift needed */
1976 /* Return 0x80000000 if negative. */
1980 #endif /* L_fixunsdfsi */
1985 .global __fixunsdfdi
1986 .type __fixunsdfdi, @function
1990 /* Check for NaN and Infinity. */
1992 ball xh, a6, .Lfixunsdfdi_nan_or_inf
1994 /* Extract the exponent and check if 0 <= (exp - 0x3ff) < 64. */
1995 extui a4, xh, 20, 11
1996 extui a5, a6, 20, 10 /* 0x3ff */
1998 bgei a4, 64, .Lfixunsdfdi_maxint
1999 bltz a4, .Lfixunsdfdi_zero
2001 /* Add explicit "1.0" and shift << 11. */
2007 /* Shift back to the right, based on the exponent. */
2009 beqi a4, 64, .Lfixunsdfdi_bigexp
2010 ssl a4 /* shift by 64 - a4 */
2011 bgei a4, 32, .Lfixunsdfdi_smallshift
2015 .Lfixunsdfdi_shifted:
2016 /* Negate the result if sign != 0. */
2024 .Lfixunsdfdi_smallshift:
2027 j .Lfixunsdfdi_shifted
2029 .Lfixunsdfdi_nan_or_inf:
2030 /* Handle Infinity and NaN. */
2033 beqz a4, .Lfixunsdfdi_maxint
2035 /* Translate NaN to 0xffffffff.... */
2040 .Lfixunsdfdi_maxint:
2042 2: slli xh, a6, 11 /* 0x80000000 */
2051 .Lfixunsdfdi_bigexp:
2052 /* Handle unsigned maximum exponent case. */
2054 leaf_return /* no shift needed */
2056 #endif /* L_fixunsdfdi */
2061 .global __floatunsidf
2062 .type __floatunsidf, @function
2065 beqz a2, .Lfloatsidf_return_zero
2067 /* Set the sign to zero and jump to the floatsidf code. */
2069 j .Lfloatsidf_normalize
2073 .type __floatsidf, @function
2077 /* Check for zero. */
2078 beqz a2, .Lfloatsidf_return_zero
2080 /* Save the sign. */
2083 /* Get the absolute value. */
2091 .Lfloatsidf_normalize:
2092 /* Normalize with the first 1 bit in the msb. */
2093 do_nsau a4, a2, a5, a6
2097 /* Shift the mantissa into position. */
2099 slli xl, a5, (32 - 11)
2101 /* Set the exponent. */
2102 movi a5, 0x41d /* 0x3fe + 31 */
2107 /* Add the sign and return. */
2112 .Lfloatsidf_return_zero:
2116 #endif /* L_floatsidf */
2121 .global __floatundidf
2122 .type __floatundidf, @function
2126 /* Check for zero. */
2130 /* Set the sign to zero and jump to the floatdidf code. */
2132 j .Lfloatdidf_normalize
2136 .type __floatdidf, @function
2140 /* Check for zero. */
2144 /* Save the sign. */
2147 /* Get the absolute value. */
2148 bgez xh, .Lfloatdidf_normalize
2151 beqz xl, .Lfloatdidf_normalize
2154 .Lfloatdidf_normalize:
2155 /* Normalize with the first 1 bit in the msb of xh. */
2156 beqz xh, .Lfloatdidf_bigshift
2157 do_nsau a4, xh, a5, a6
2162 .Lfloatdidf_shifted:
2163 /* Shift the mantissa into position, with rounding bits in a6. */
2169 /* Set the exponent. */
2170 movi a5, 0x43d /* 0x3fe + 63 */
2179 /* Round up if the leftover fraction is >= 1/2. */
2182 beqz xl, .Lfloatdidf_roundcarry
2184 /* Check if the leftover fraction is exactly 1/2. */
2186 beqz a6, .Lfloatdidf_exactlyhalf
2189 .Lfloatdidf_bigshift:
2190 /* xh is zero. Normalize with first 1 bit of xl in the msb of xh. */
2191 do_nsau a4, xl, a5, a6
2196 j .Lfloatdidf_shifted
2198 .Lfloatdidf_exactlyhalf:
2199 /* Round down to the nearest even value. */
2204 .Lfloatdidf_roundcarry:
2205 /* xl is always zero when the rounding increment overflows, so
2206 there's no need to round it to an even value. */
2208 /* Overflow to the exponent is OK. */
2211 #endif /* L_floatdidf */
2216 .global __truncdfsf2
2217 .type __truncdfsf2, @function
2221 /* Adjust the exponent bias. */
2222 movi a4, (0x3ff - 0x7f) << 20
2225 /* Check for underflow. */
2227 bltz a6, .Ltrunc_underflow
2228 extui a6, a5, 20, 11
2229 beqz a6, .Ltrunc_underflow
2231 /* Check for overflow. */
2233 bge a6, a4, .Ltrunc_overflow
2235 /* Shift a5/xl << 3 into a5/a4. */
2241 /* Add the sign bit. */
2246 /* Round up if the leftover fraction is >= 1/2. */
2249 /* Overflow to the exponent is OK. The answer will be correct. */
2251 /* Check if the leftover fraction is exactly 1/2. */
2253 beqz a4, .Ltrunc_exactlyhalf
2256 .Ltrunc_exactlyhalf:
2257 /* Round down to the nearest even value. */
2263 /* Check if exponent == 0x7ff. */
2267 /* Check if mantissa is nonzero. */
2272 /* Shift a4 to set a bit in the mantissa, making a quiet NaN. */
2275 1: slli a4, a4, 4 /* 0xff000000 or 0xff800000 */
2276 /* Add the sign bit. */
2283 /* Find shift count for a subnormal. Flush to zero if >= 32. */
2284 extui a6, xh, 20, 11
2285 movi a5, 0x3ff - 0x7f
2290 /* Replace the exponent with an explicit "1.0". */
2291 slli a5, a5, 13 /* 0x700000 */
2296 /* Shift the mantissa left by 3 bits (into a5/a4). */
2301 /* Shift right by a6. */
2306 beqz a7, .Ltrunc_addsign
2307 or a4, a4, a6 /* any positive, nonzero value will work */
2310 /* Return +/- zero. */
2311 1: extui a2, xh, 31, 1
2315 #endif /* L_truncdfsf2 */
2317 #ifdef L_extendsfdf2
2320 .global __extendsfdf2
2321 .type __extendsfdf2, @function
2325 /* Save the sign bit and then shift it off. */
2330 /* Extract and check the exponent. */
2332 beqz a6, .Lextend_expzero
2334 beqi a6, 256, .Lextend_nan_or_inf
2336 /* Shift >> 3 into a4/xl. */
2338 slli xl, a2, (32 - 3)
2340 /* Adjust the exponent bias. */
2341 movi a6, (0x3ff - 0x7f) << 20
2344 /* Add the sign bit. */
2348 .Lextend_nan_or_inf:
2351 /* Check for NaN. */
2355 slli a6, a6, 11 /* 0x80000 */
2358 /* Add the sign and return. */
2366 /* Normalize it to have 8 zero bits before the first 1 bit. */
2367 do_nsau a7, a4, a2, a3
2372 /* Shift >> 3 into a4/xl. */
2373 slli xl, a4, (32 - 3)
2376 /* Set the exponent. */
2377 movi a6, 0x3fe - 0x7f
2382 /* Add the sign and return. */
2386 #endif /* L_extendsfdf2 */