public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* floor etc for AMD64
@ 2003-11-15 14:48 Andreas Jaeger
  2003-11-18  7:20 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Andreas Jaeger @ 2003-11-15 14:48 UTC (permalink / raw)
  To: GNU libc hacker

[-- Attachment #1: Type: text/plain, Size: 6905 bytes --]


floor was broken the same way that ceil was on AMD64.

I've added a test to libm-test.inc that caught this and added some
further long double functions for AMD64.

Ok to commit?

The testsuite on AMD64 passes all math tests.

Andreas

2003-11-15  Andreas Jaeger  <aj@suse.de>

	* sysdeps/x86_64/fpu/s_scalbnl.S: New.
	* sysdeps/x86_64/fpu/s_truncl.S: New.
	* sysdeps/x86_64/fpu/s_nearbyintl.S: New.
	* sysdeps/x86_64/fpu/s_floorl.S: New.
	* sysdeps/x86_64/fpu/s_ilogbl.S: New.
	* sysdeps/x86_64/fpu/e_remainderl.S: New.

	* math/libm-test.inc (floor_test): Test also +/-0.25.
	(ceil_test): Test -0.25.

============================================================
Index: math/libm-test.inc
--- math/libm-test.inc	14 Nov 2003 00:34:54 -0000	1.52
+++ math/libm-test.inc	15 Nov 2003 14:47:52 -0000
@@ -1626,6 +1626,7 @@ ceil_test (void)
   TEST_f_f (ceil, M_PIl, 4.0);
   TEST_f_f (ceil, -M_PIl, -3.0);
   TEST_f_f (ceil, 0.25, 1.0);
+  TEST_f_f (ceil, -0.25, minus_zero);
 
   END (ceil);
 }
@@ -2571,6 +2572,9 @@ floor_test (void)
 
   TEST_f_f (floor, M_PIl, 3.0);
   TEST_f_f (floor, -M_PIl, -4.0);
+
+  TEST_f_f (floor, 0.25, 0.0);
+  TEST_f_f (floor, -0.25, -1.0);
 
   END (floor);
 }
============================================================
Index: sysdeps/x86_64/fpu/s_scalbnl.S
--- sysdeps/x86_64/fpu/s_scalbnl.S	created
+++ sysdeps/x86_64/fpu/s_scalbnl.S	2003-11-15 15:12:53.000000000 +0100	1.1
@@ -0,0 +1,18 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Changes for long double by Ulrich Drepper <drepper@cygnus.com>
+ * Changes for x86-64 by Andreas Jaeger <aj@suse.de>	
+ * Public domain.
+ */
+
+#include <machine/asm.h>
+
+ENTRY(__scalbnl)
+	movl	%edi,-4(%rsp)
+	fildl	-4(%rsp)
+	fldt	8(%rsp)
+	fscale
+	fstp	%st(1)
+	ret
+END (__scalbnl)
+weak_alias (__scalbnl, scalbnl)
============================================================
Index: sysdeps/x86_64/fpu/s_truncl.S
--- sysdeps/x86_64/fpu/s_truncl.S	created
+++ sysdeps/x86_64/fpu/s_truncl.S	2003-11-15 15:04:07.000000000 +0100	1.1
@@ -0,0 +1,34 @@
+/* Truncate long double value.
+   Copyright (C) 1997, 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <machine/asm.h>
+
+ENTRY(__truncl)
+	fldt	8(%rsp)
+	fstcw	-4(%rsp)
+	movl	$0xc00, %edx
+	orl	-4(%rsp), %edx
+	movl	%edx, -8(%rsp)
+	fldcw	-8(%rsp)
+	frndint
+	fldcw	-4(%rsp)
+	ret
+END(__truncl)
+weak_alias (__truncl, truncl)
============================================================
Index: sysdeps/x86_64/fpu/s_nearbyintl.S
--- sysdeps/x86_64/fpu/s_nearbyintl.S	created
+++ sysdeps/x86_64/fpu/s_nearbyintl.S	2003-11-15 14:59:18.000000000 +0100	1.1
@@ -0,0 +1,21 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+/* Adapted for use as nearbyint by Ulrich Drepper <drepper@cygnus.com>.  */
+
+#include <machine/asm.h>
+
+ENTRY(__nearbyintl)
+	fldt	8(%rsp)
+	fnstcw	-4(%rsp)
+	movl	-4(%rsp), %eax
+	orl	$0x20, %eax
+	movl	%eax, -8(%rsp)
+	fldcw	-8(%rsp)
+	frndint
+	fclex
+	fldcw	-4(%rsp)
+	ret
+END (__nearbyintl)
+weak_alias (__nearbyintl, nearbyintl)
============================================================
Index: sysdeps/x86_64/fpu/s_floorl.S
--- sysdeps/x86_64/fpu/s_floorl.S	created
+++ sysdeps/x86_64/fpu/s_floorl.S	2003-11-15 14:53:36.000000000 +0100	1.1
@@ -0,0 +1,30 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Changes for long double by Ulrich Drepper <drepper@cygnus.com>
+ * Changes for x86-64 by Andreas Jaeger <aj@suse.de>	
+ * Public domain.
+ */
+
+#include <machine/asm.h>
+
+ENTRY(__floorl)
+	fldt	8(%rsp)
+
+	fstcw	-4(%rsp)		/* store fpu control word */
+
+	/* We use here %edx although only the low 1 bits are defined.
+	   But none of the operations should care and they are faster
+	   than the 16 bit operations.  */
+	movl	$0x400,%edx		/* round towards -oo */
+	orl	-4(%rsp),%edx
+	andl	$0xf7ff,%edx
+	movl	%edx,-8(%rsp)
+	fldcw	-8(%rsp)		/* load modified control word */
+
+	frndint				/* round */
+
+	fldcw	-4(%rsp)		/* restore original control word */
+
+	ret
+END (__floorl)
+weak_alias (__floorl, floorl)
============================================================
Index: sysdeps/x86_64/fpu/e_remainderl.S
--- sysdeps/x86_64/fpu/e_remainderl.S	created
+++ sysdeps/x86_64/fpu/e_remainderl.S	2003-11-15 15:46:14.000000000 +0100	1.1
@@ -0,0 +1,20 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ *
+ * Adapted for `long double' by Ulrich Drepper <drepper@cygnus.com>.
+ * Adapted for x86-64 by Andreas Jaeger <aj@suse.de>.
+ */
+
+#include <machine/asm.h>
+
+ENTRY(__ieee754_remainderl)
+	fldt	24(%rsp)
+	fldt	8(%rsp)
+1:	fprem1
+	fstsw	%ax
+	testl	$0x400,%eax
+	jnz	1b
+	fstp	%st(1)
+	ret
+END (__ieee754_remainderl)
============================================================
Index: sysdeps/x86_64/fpu/s_ilogbl.S
--- sysdeps/x86_64/fpu/s_ilogbl.S	created
+++ sysdeps/x86_64/fpu/s_ilogbl.S	2003-11-15 15:34:39.000000000 +0100	1.1
@@ -0,0 +1,35 @@
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Changes for long double by Ulrich Drepper <drepper@cygnus.com>
+ * Adapted for x86-64 by Andreas Jaeger <aj@suse.de>.
+ * Public domain.
+ */
+
+#include <machine/asm.h>
+
+ENTRY(__ilogbl)
+	fldt	8(%rsp)
+/* I added the following ugly construct because ilogb(+-Inf) is
+   required to return INT_MAX in ISO C99.
+   -- jakub@redhat.com.  */
+	fxam			/* Is NaN or +-Inf?  */
+	fstsw   %ax
+	movb    $0x45, %dh
+	andb    %ah, %dh
+	cmpb    $0x05, %dh
+	je      1f		/* Is +-Inf, jump.  */
+
+	fxtract
+	fstp	%st
+
+	fistpl	-4(%rsp)
+	fwait
+	movl	-4(%rsp),%eax
+
+	ret
+
+1:	fstp	%st
+	movl	$0x7fffffff, %eax
+	ret
+END (__ilogbl)
+weak_alias (__ilogbl, ilogbl)

-- 
 Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj
  SuSE Linux AG, Deutschherrnstr. 15-19, 90429 Nürnberg, Germany
   GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: floor etc for AMD64
  2003-11-15 14:48 floor etc for AMD64 Andreas Jaeger
@ 2003-11-18  7:20 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2003-11-18  7:20 UTC (permalink / raw)
  To: Andreas Jaeger; +Cc: GNU libc hacker

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andreas Jaeger wrote:

> I've added a test to libm-test.inc that caught this and added some
> further long double functions for AMD64.

Thanks, I've added the patch.

- -- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/ucgs2ijCOnn/RHQRAvl+AKC2G8PcAfu0oBHNRY8GDKHdiCvT3gCgxz78
s5scCST7X4N6e4keA41t9B8=
=79fU
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-11-18  7:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-15 14:48 floor etc for AMD64 Andreas Jaeger
2003-11-18  7:20 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).