From: Max Filippov Date: Tue, 23 Jan 2018 21:42:52 +0000 (+0000) Subject: libgcc: xtensa: fix NaN return from add/sub/mul/div helpers X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0889f16859b68006ddc5dd4d9658b2c6fb93083c;p=gcc.git libgcc: xtensa: fix NaN return from add/sub/mul/div helpers libgcc/ 2018-01-23 Max Filippov * config/xtensa/ieee754-df.S (__addsf3, __subsf3, __mulsf3) (__divsf3): Make NaN return value quiet. * config/xtensa/ieee754-sf.S (__adddf3, __subdf3, __muldf3) (__divdf3): Make NaN return value quiet. From-SVN: r257002 --- diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog index f27ea4fd79c..778a455ca71 100644 --- a/libgcc/ChangeLog +++ b/libgcc/ChangeLog @@ -1,3 +1,10 @@ +2018-01-23 Max Filippov + + * config/xtensa/ieee754-df.S (__addsf3, __subsf3, __mulsf3) + (__divsf3): Make NaN return value quiet. + * config/xtensa/ieee754-sf.S (__adddf3, __subdf3, __muldf3) + (__divdf3): Make NaN return value quiet. + 2018-01-22 Sebastian Perta * config/rl78/anddi3.S: New assembly file. diff --git a/libgcc/config/xtensa/ieee754-df.S b/libgcc/config/xtensa/ieee754-df.S index 9aa55d1f74a..2662a660075 100644 --- a/libgcc/config/xtensa/ieee754-df.S +++ b/libgcc/config/xtensa/ieee754-df.S @@ -64,17 +64,26 @@ __adddf3_aux: .Ladd_xnan_or_inf: /* If y is neither Infinity nor NaN, return x. */ - bnall yh, a6, 1f + bnall yh, a6, .Ladd_return_nan_or_inf /* If x is a NaN, return it. Otherwise, return y. */ slli a7, xh, 12 or a7, a7, xl - beqz a7, .Ladd_ynan_or_inf -1: leaf_return + bnez a7, .Ladd_return_nan .Ladd_ynan_or_inf: /* Return y. */ mov xh, yh mov xl, yl + +.Ladd_return_nan_or_inf: + slli a7, xh, 12 + or a7, a7, xl + bnez a7, .Ladd_return_nan + leaf_return + +.Ladd_return_nan: + movi a4, 0x80000 /* make it a quiet NaN */ + or xh, xh, a4 leaf_return .Ladd_opposite_signs: @@ -319,17 +328,24 @@ __subdf3_aux: .Lsub_xnan_or_inf: /* If y is neither Infinity nor NaN, return x. */ - bnall yh, a6, 1f + bnall yh, a6, .Lsub_return_nan_or_inf + +.Lsub_return_nan: /* Both x and y are either NaN or Inf, so the result is NaN. */ movi a4, 0x80000 /* make it a quiet NaN */ or xh, xh, a4 -1: leaf_return + leaf_return .Lsub_ynan_or_inf: /* Negate y and return it. */ slli a7, a6, 11 xor xh, yh, a7 mov xl, yl + +.Lsub_return_nan_or_inf: + slli a7, xh, 12 + or a7, a7, xl + bnez a7, .Lsub_return_nan leaf_return .Lsub_opposite_signs: @@ -692,10 +708,7 @@ __muldf3_aux: /* If y is zero, return NaN. */ bnez yl, 1f slli a8, yh, 1 - bnez a8, 1f - movi a4, 0x80000 /* make it a quiet NaN */ - or xh, xh, a4 - j .Lmul_done + beqz a8, .Lmul_return_nan 1: /* If y is NaN, return y. */ bnall yh, a6, .Lmul_returnx @@ -708,6 +721,9 @@ __muldf3_aux: mov xl, yl .Lmul_returnx: + slli a8, xh, 12 + or a8, a8, xl + bnez a8, .Lmul_return_nan /* Set the sign bit and return. */ extui a7, a7, 31, 1 slli xh, xh, 1 @@ -720,8 +736,11 @@ __muldf3_aux: bnez xl, .Lmul_returny slli a8, xh, 1 bnez a8, .Lmul_returny - movi a7, 0x80000 /* make it a quiet NaN */ - or xh, yh, a7 + mov xh, yh + +.Lmul_return_nan: + movi a4, 0x80000 /* make it a quiet NaN */ + or xh, xh, a4 j .Lmul_done .align 4 @@ -1370,10 +1389,11 @@ __divdf3_aux: slli a7, a7, 31 xor xh, xh, a7 /* If y is NaN or Inf, return NaN. */ - bnall yh, a6, 1f - movi a4, 0x80000 /* make it a quiet NaN */ - or xh, xh, a4 -1: leaf_return + ball yh, a6, .Ldiv_return_nan + slli a8, xh, 12 + or a8, a8, xl + bnez a8, .Ldiv_return_nan + leaf_return .Ldiv_ynan_or_inf: /* If y is Infinity, return zero. */ @@ -1383,6 +1403,10 @@ __divdf3_aux: /* y is NaN; return it. */ mov xh, yh mov xl, yl + +.Ldiv_return_nan: + movi a4, 0x80000 /* make it a quiet NaN */ + or xh, xh, a4 leaf_return .Ldiv_highequal1: diff --git a/libgcc/config/xtensa/ieee754-sf.S b/libgcc/config/xtensa/ieee754-sf.S index 659f183f6ba..d48b230a758 100644 --- a/libgcc/config/xtensa/ieee754-sf.S +++ b/libgcc/config/xtensa/ieee754-sf.S @@ -64,15 +64,23 @@ __addsf3_aux: .Ladd_xnan_or_inf: /* If y is neither Infinity nor NaN, return x. */ - bnall a3, a6, 1f + bnall a3, a6, .Ladd_return_nan_or_inf /* If x is a NaN, return it. Otherwise, return y. */ slli a7, a2, 9 - beqz a7, .Ladd_ynan_or_inf -1: leaf_return + bnez a7, .Ladd_return_nan .Ladd_ynan_or_inf: /* Return y. */ mov a2, a3 + +.Ladd_return_nan_or_inf: + slli a7, a2, 9 + bnez a7, .Ladd_return_nan + leaf_return + +.Ladd_return_nan: + movi a6, 0x400000 /* make it a quiet NaN */ + or a2, a2, a6 leaf_return .Ladd_opposite_signs: @@ -265,16 +273,22 @@ __subsf3_aux: .Lsub_xnan_or_inf: /* If y is neither Infinity nor NaN, return x. */ - bnall a3, a6, 1f + bnall a3, a6, .Lsub_return_nan_or_inf /* Both x and y are either NaN or Inf, so the result is NaN. */ + +.Lsub_return_nan: movi a4, 0x400000 /* make it a quiet NaN */ or a2, a2, a4 -1: leaf_return + leaf_return .Lsub_ynan_or_inf: /* Negate y and return it. */ slli a7, a6, 8 xor a2, a3, a7 + +.Lsub_return_nan_or_inf: + slli a7, a2, 9 + bnez a7, .Lsub_return_nan leaf_return .Lsub_opposite_signs: @@ -537,11 +551,7 @@ __mulsf3_aux: .Lmul_xnan_or_inf: /* If y is zero, return NaN. */ slli a8, a3, 1 - bnez a8, 1f - movi a4, 0x400000 /* make it a quiet NaN */ - or a2, a2, a4 - j .Lmul_done -1: + beqz a8, .Lmul_return_nan /* If y is NaN, return y. */ bnall a3, a6, .Lmul_returnx slli a8, a3, 9 @@ -551,6 +561,8 @@ __mulsf3_aux: mov a2, a3 .Lmul_returnx: + slli a8, a2, 9 + bnez a8, .Lmul_return_nan /* Set the sign bit and return. */ extui a7, a7, 31, 1 slli a2, a2, 1 @@ -562,8 +574,11 @@ __mulsf3_aux: /* If x is zero, return NaN. */ slli a8, a2, 1 bnez a8, .Lmul_returny - movi a7, 0x400000 /* make it a quiet NaN */ - or a2, a3, a7 + mov a2, a3 + +.Lmul_return_nan: + movi a4, 0x400000 /* make it a quiet NaN */ + or a2, a2, a4 j .Lmul_done .align 4 @@ -995,10 +1010,10 @@ __divsf3_aux: slli a7, a7, 31 xor a2, a2, a7 /* If y is NaN or Inf, return NaN. */ - bnall a3, a6, 1f - movi a4, 0x400000 /* make it a quiet NaN */ - or a2, a2, a4 -1: leaf_return + ball a3, a6, .Ldiv_return_nan + slli a7, a2, 9 + bnez a7, .Ldiv_return_nan + leaf_return .Ldiv_ynan_or_inf: /* If y is Infinity, return zero. */ @@ -1006,6 +1021,10 @@ __divsf3_aux: beqz a8, .Ldiv_return_zero /* y is NaN; return it. */ mov a2, a3 + +.Ldiv_return_nan: + movi a4, 0x400000 /* make it a quiet NaN */ + or a2, a2, a4 leaf_return .align 4