Mail Archives: djgpp/2017/12/31/15:17:52
X-Authentication-Warning: | delorie.com: mail set sender to djgpp-bounces using -f
|
X-Recipient: | djgpp AT delorie DOT com
|
Message-ID: | <5A4946EB.3090500@gmx.de>
|
Date: | Sun, 31 Dec 2017 21:22:03 +0100
|
From: | "Juan Manuel Guerrero (juan DOT guerrero AT gmx DOT de) [via djgpp AT delorie DOT com]" <djgpp AT delorie DOT com>
|
User-Agent: | Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.13) Gecko/20101206 SUSE/3.1.7 Thunderbird/3.1.7
|
MIME-Version: | 1.0
|
To: | djgpp AT delorie DOT com
|
Subject: | Fixing various bugs in frexp.S
|
X-Provags-ID: | V03:K0:/8O5T/7mpRwDaapsn8dmk+1a0EY14sbaRTA59yW1etkuT3+1fhh
|
| QDhNngkuu43Iwo7poRvGEAUroR2YT1ljPymMgqEjvBDEmgPRgmJ4R+/CZVUYmojwXKxcd/U
|
| peEmh5+mMOjLchYE9wvIlFpfpCPkSIBqkne4riKeZBJuiBP1ZIBZJ5Jx1kWXDQ1b0XYsPMB
|
| VcVN0oK3gknyI2bWSyJaQ==
|
X-UI-Out-Filterresults: | notjunk:1;V01:K0:tyyIVmdZ3Vs=:U/tJGxm34hV2EzHnvKvSo+
|
| oLbIbljkIFVi0WcIGRExCLmv2oN4jaQOlgNRUWCNNv2c5brByjxfXvSsqXolzgrzNMQOla0Gc
|
| auYBHnqvRiVUzrKsU+rsRtqykp9+Yhzg7VYUwKxfReoBXOo86aF1lPTVGrYCCTWjQuUKnM9we
|
| spxfbVzQOqRB7hJyZSd8OuVb4M1yMbr5TARz3Wlm74rthqyWWI1EQj4k9u4dnUzx+rK8DOuWE
|
| 9M6Yhd60+DDW8FWo5xDV+rkAemKPlVNZuK6BLHurXrk/9tKciq60uOH/gLIycxL6wx52eAlYr
|
| CJTcmQdJeHdIh45JjkbPGEXPS/7FasUHP11Im2CMIBt8MiDv76Yk91kfYvZ1ONAltHpOj4BNz
|
| Ym9+jqsXMaJkfkLK6aqsC6HzMGg7GbRgcqW5nCZ471+qqHzJ6hfD18AQUnl9VQkrQpWIV1bh4
|
| qwUwD/pymQuWvlHypuNq5VcPfYeJ9JUx/fd9tdX6i0s3VgTox1STpqV3Zj+ZUAqdHI6jmdGV+
|
| A+orRPc97Odson5Z0S4vSXqysDGSBStesWJtfBVsQhxca8w7BE92CyVAEYteARelvg2oirFje
|
| shjIqMmDRXfLCA6+9l4CydPBdu/XjE29lNai2frD/SUFP/xknpm/fh8PGzlrAkgkKnSOa43FV
|
| +LGqpLxyd1saFIXfPowRsTeRRclc1Qli567dJ4ZrPxvumEBLSIroMIiJBlwonD0V2mh+NHFK5
|
| GAA3EYN3LufvB93Zjj0ZxumzbJfKWzwtG9vXTUqwkT8EQzxNeCOyo7F53Zr5lI+kgWRCB2HBm
|
| eNLjQM/jf+PhXiGz98PlolmrO9e1g==
|
Reply-To: | djgpp AT delorie DOT com
|
This is a multi-part message in MIME format.
--------------070408060806090508030602
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
The frexp function provided by libc.a has a couple of bugs:
- it sets errno to EDOM if the argument is either infinity or NaN
- it produces the wrong value if the argument is -0
- it returns NaN if the argument is infinity
- for NaN and infinity arguments no sign checks are done thus the
results are always positive
All these issues are serious deviations from the ansi/posix behavior.
With the patch below I have tried to fix these issues. If I do not get
any serious objection I will commite the patch in a couple of days.
Regards,
Juan M. Guerrero
diff -aprNU5 djgpp.orig/src/libc/ansi/math/frexp.S djgpp/src/libc/ansi/math/frexp.S
--- djgpp.orig/src/libc/ansi/math/frexp.S 2017-12-29 21:49:56 +0000
+++ djgpp/src/libc/ansi/math/frexp.S 2017-12-31 20:55:40 +0000
@@ -1,10 +1,18 @@
+/* Copyright (C) 2017 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 2011 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
-NaN:
+pos_NaN:
+ .long 0x7FC00000
+neg_NaN:
.long 0xFFC00000
+pos_inf:
+ .long 0x7F800000
+neg_inf:
+ .long 0xFF800000
+
onehalf:
.float 0.5
.globl _frexp
_frexp:
@@ -17,10 +25,11 @@ _frexp:
movl 12(%esp), %edx /* Load pointer to expon. */
movl 8(%esp), %eax
+ andl $0x7FFFFFFF, %eax
testl %eax, %eax /* Is x = 0 ? */
jnz inftest
movl 4(%esp), %eax
testl %eax, %eax
@@ -31,11 +40,11 @@ _frexp:
ret
inftest:
andl $0x7FF00000, %eax
cmpl $0x7FF00000, %eax
- je badarg /* +/- inf or NaN */
+ je badarg /* +/- inf or +/- NaN */
argok:
fldl 4(%esp)
fxtract
flds onehalf
@@ -44,10 +53,30 @@ argok:
fxch
fistpl (%edx)
incl (%edx)
ret
-badarg: /* arg is NaN */
- movl $1, _errno
+badarg: /* arg is +/- inf or +/- NaN */
movl $0, (%edx)
- flds NaN
+ movl 8(%esp), %eax
+ andl $0x800FFFFF, %eax
+ testl $0x80000000, %eax
+ jnz negarg
+
+ cmpl $0x00000000, %eax
+ je infarg
+ flds pos_NaN
+ ret
+
+infarg:
+ flds pos_inf
+ ret
+
+negarg: /* arg is - inf or - NaN */
+ cmpl $0x80000000, %eax
+ jnz nanarg
+ flds neg_inf
+ ret
+
+nanarg:
+ flds neg_NaN
ret
diff -aprNU5 djgpp.orig/src/libc/ansi/math/frexp.txh djgpp/src/libc/ansi/math/frexp.txh
--- djgpp.orig/src/libc/ansi/math/frexp.txh 2003-01-29 12:26:14 +0000
+++ djgpp/src/libc/ansi/math/frexp.txh 2017-12-31 20:53:38 +0000
@@ -16,14 +16,15 @@ range @code{[0.5,1)} and an exponent e,
It returns the value of the mantissa and stores the integer exponent in
@var{*pexp}.
@subheading Return Value
-The mantissa. If the value of @var{x} is @code{NaN} or @code{Inf}, the
-return value is @code{NaN}, zero is stored in @code{*pexp}, and
-@code{errno} is set to @code{EDOM}. If @var{x} is zero, @var{*pexp} and
-the return value are also both zero.
+The mantissa. If the value of @var{x} is @code{NaN}, the return value is
+@code{NaN} and zero is stored in @code{*pexp}. If the value of @var{x} is
+@code{Inf}, the return value is @code{Inf} and zero is stored in @code{*pexp}.
+If @var{x} is zero, @var{*pexp} and the return value are also both zero.
+@code{errno} is not modified.
@subheading Portability
@portability ansi, posix
--------------070408060806090508030602
Content-Type: text/x-patch;
name="frexp.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="frexp.patch"
diff -aprNU5 djgpp.orig/src/libc/ansi/math/frexp.S djgpp/src/libc/ansi/math/frexp.S
--- djgpp.orig/src/libc/ansi/math/frexp.S 2017-12-29 21:49:56 +0000
+++ djgpp/src/libc/ansi/math/frexp.S 2017-12-31 20:55:40 +0000
@@ -1,10 +1,18 @@
+/* Copyright (C) 2017 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 2011 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
-NaN:
+pos_NaN:
+ .long 0x7FC00000
+neg_NaN:
.long 0xFFC00000
+pos_inf:
+ .long 0x7F800000
+neg_inf:
+ .long 0xFF800000
+
onehalf:
.float 0.5
.globl _frexp
_frexp:
@@ -17,10 +25,11 @@ _frexp:
movl 12(%esp), %edx /* Load pointer to expon. */
movl 8(%esp), %eax
+ andl $0x7FFFFFFF, %eax
testl %eax, %eax /* Is x = 0 ? */
jnz inftest
movl 4(%esp), %eax
testl %eax, %eax
@@ -31,11 +40,11 @@ _frexp:
ret
inftest:
andl $0x7FF00000, %eax
cmpl $0x7FF00000, %eax
- je badarg /* +/- inf or NaN */
+ je badarg /* +/- inf or +/- NaN */
argok:
fldl 4(%esp)
fxtract
flds onehalf
@@ -44,10 +53,30 @@ argok:
fxch
fistpl (%edx)
incl (%edx)
ret
-badarg: /* arg is NaN */
- movl $1, _errno
+badarg: /* arg is +/- inf or +/- NaN */
movl $0, (%edx)
- flds NaN
+ movl 8(%esp), %eax
+ andl $0x800FFFFF, %eax
+ testl $0x80000000, %eax
+ jnz negarg
+
+ cmpl $0x00000000, %eax
+ je infarg
+ flds pos_NaN
+ ret
+
+infarg:
+ flds pos_inf
+ ret
+
+negarg: /* arg is - inf or - NaN */
+ cmpl $0x80000000, %eax
+ jnz nanarg
+ flds neg_inf
+ ret
+
+nanarg:
+ flds neg_NaN
ret
diff -aprNU5 djgpp.orig/src/libc/ansi/math/frexp.txh djgpp/src/libc/ansi/math/frexp.txh
--- djgpp.orig/src/libc/ansi/math/frexp.txh 2003-01-29 12:26:14 +0000
+++ djgpp/src/libc/ansi/math/frexp.txh 2017-12-31 20:53:38 +0000
@@ -16,14 +16,15 @@ range @code{[0.5,1)} and an exponent e,
It returns the value of the mantissa and stores the integer exponent in
@var{*pexp}.
@subheading Return Value
-The mantissa. If the value of @var{x} is @code{NaN} or @code{Inf}, the
-return value is @code{NaN}, zero is stored in @code{*pexp}, and
-@code{errno} is set to @code{EDOM}. If @var{x} is zero, @var{*pexp} and
-the return value are also both zero.
+The mantissa. If the value of @var{x} is @code{NaN}, the return value is
+@code{NaN} and zero is stored in @code{*pexp}. If the value of @var{x} is
+@code{Inf}, the return value is @code{Inf} and zero is stored in @code{*pexp}.
+If @var{x} is zero, @var{*pexp} and the return value are also both zero.
+@code{errno} is not modified.
@subheading Portability
@portability ansi, posix
--------------070408060806090508030602--
- Raw text -