libgcc: xtensa: fix NaN return from add/sub/mul/div helpers

Message ID 1516730152-8076-1-git-send-email-jcmvbkbc@gmail.com
State New
Headers show
Series
  • libgcc: xtensa: fix NaN return from add/sub/mul/div helpers
Related show

Commit Message

Max Filippov Jan. 23, 2018, 5:55 p.m.
libgcc/
2018-01-22  Max Filippov  <jcmvbkbc@gmail.com>

	* 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.
---
 libgcc/config/xtensa/ieee754-df.S | 54 ++++++++++++++++++++++++++++-----------
 libgcc/config/xtensa/ieee754-sf.S | 51 ++++++++++++++++++++++++------------
 2 files changed, 74 insertions(+), 31 deletions(-)

-- 
2.1.4

Comments

augustine.sterling@gmail.com Jan. 23, 2018, 9:07 p.m. | #1
On Tue, Jan 23, 2018 at 9:55 AM, Max Filippov <jcmvbkbc@gmail.com> wrote:
> libgcc/

> 2018-01-22  Max Filippov  <jcmvbkbc@gmail.com>

>

>         * 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.


This is fine. Please apply.
Max Filippov Jan. 23, 2018, 9:57 p.m. | #2
On Tue, Jan 23, 2018 at 1:07 PM, augustine.sterling@gmail.com
<augustine.sterling@gmail.com> wrote:
> On Tue, Jan 23, 2018 at 9:55 AM, Max Filippov <jcmvbkbc@gmail.com> wrote:

>> libgcc/

>> 2018-01-22  Max Filippov  <jcmvbkbc@gmail.com>

>>

>>         * 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.

>

> This is fine. Please apply.


Thanks, applied to trunk and backported to gcc-6 and gcc-7 branches.

-- Max

Patch

diff --git a/libgcc/config/xtensa/ieee754-df.S b/libgcc/config/xtensa/ieee754-df.S
index 9aa55d1f74a4..2662a6600751 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 659f183f6ba8..d48b230a7588 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