This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Fix sinf, cosf, sincosf,tanf on x86 (BZ#13852)


This update fixes sinf, cosf, tanf and sincosf to not use the x87 fpu and 
thus work with large inputs as well. It adds a few new ULPS with 
values 1 or 2.

Tested on i386 and x86-64.

Andreas

2012-03-15  Andreas Jaeger  <aj@suse.de>

	[BZ #13852]
	* sysdeps/i386/fpu/e_rem_pio2f.c: Delete so that i386 uses the
	ieee754/flt-32 implementation for sin, cos and sincos.
	* sysdeps/i386/fpu/k_rem_pio2f.c: Likewise.
	* sysdeps/i386/fpu/s_cosf.S: Likewise.
	* sysdeps/i386/fpu/s_sincosf.S: Likewise.
	* sysdeps/i386/fpu/s_sinf.S: Likewise.
	* sysdeps/i386/fpu/s_tanf.S: Delete so that i386 uses the
	ieee754/flt-32 implementation for tan.

	* math/libm-test.inc (cos_test): Enable some large input tests for
	float as well
	(sin_test): Likewise.
	(sincos_test): Likewise.
	(tan_test): Add tests for large input.

	* sysdeps/i386/fpu/libm-test-ulps: Update.

diff --git a/math/libm-test.inc b/math/libm-test.inc
index 0337b60..ddc8ea5 100644
--- a/math/libm-test.inc
+++ b/math/libm-test.inc
@@ -2112,11 +2112,15 @@ cos_test (void)
 
   TEST_f_f (cos, 0.75L, 0.731688868873820886311838753000084544L);
 
+#ifndef TEST_LDOUBLE
+  /* Enable for long double once x86 and x86-64 implementations are fixed.  */
+  TEST_f_f (cos, 0x1p65, 0.998886220660580136106421721793L);
+  TEST_f_f (cos, -0x1p65, 0.998886220660580136106421721793L);
+#endif
+
 #ifdef TEST_DOUBLE
   TEST_f_f (cos, 0.80190127184058835, 0.69534156199418473);
   TEST_f_f (cos, 1e22, 0.5232147853951389454975944733847);
-  TEST_f_f (cos, 0x1p65, 0.998886220660580136106421721793);
-  TEST_f_f (cos, -0x1p65, 0.998886220660580136106421721793);
   TEST_f_f (cos, 0x1p1023, -0.8263698346141479945007856808117);
 #endif
 
@@ -6391,12 +6395,16 @@ sin_test (void)
   TEST_f_f (sin, -M_PI_2l, -1);
   TEST_f_f (sin, 0.75L, 0.681638760023334166733241952779893935L);
 
+#ifndef TEST_LDOUBLE
+  /* Enable for long double once x86 and x86-64 implementations are fixed.  */
+  TEST_f_f (sin, 0x1p65, -0.0471838762123546738051061498057L);
+  TEST_f_f (sin, -0x1p65, 0.0471838762123546738051061498057L);
+#endif
+
 #ifdef TEST_DOUBLE
   TEST_f_f (sin, 0.80190127184058835, 0.71867942238767868);
   TEST_f_f (sin, 2.522464e-1, 2.4957989804940911e-1);
   TEST_f_f (sin, 1e22, -0.8522008497671888017727058937530);
-  TEST_f_f (sin, 0x1p65, -0.0471838762123546738051061498057);
-  TEST_f_f (sin, -0x1p65, 0.0471838762123546738051061498057);
   TEST_f_f (sin, 0x1p1023, 0.5631277798508840248814522055909);
 #endif
 
@@ -6567,11 +6575,15 @@ sincos_test (void)
   TEST_extra (sincos, M_PI_6l*2.0, 0.86602540378443864676372317075293616L, 0.5);
   TEST_extra (sincos, 0.75L, 0.681638760023334166733241952779893935L, 0.731688868873820886311838753000084544L);
 
+#ifndef TEST_LDOUBLE
+  /* Enable for long double once x86 and x86-64 implementations are fixed.  */
+  TEST_extra (sincos, 0x1p65, -0.0471838762123546738051061498057L, 0.998886220660580136106421721793L);
+  TEST_extra (sincos, -0x1p65, 0.0471838762123546738051061498057L, 0.998886220660580136106421721793L);
+#endif
+
 #ifdef TEST_DOUBLE
   TEST_extra (sincos, 0.80190127184058835, 0.71867942238767868, 0.69534156199418473);
   TEST_extra (sincos, 1e22, -0.8522008497671888017727058937530, 0.5232147853951389454975944733847);
-  TEST_extra (sincos, 0x1p65, -0.0471838762123546738051061498057, 0.998886220660580136106421721793);
-  TEST_extra (sincos, -0x1p65, 0.0471838762123546738051061498057, 0.998886220660580136106421721793);
   TEST_extra (sincos, 0x1p1023, 0.5631277798508840248814522055909, -0.8263698346141479945007856808117);
 #endif
 
@@ -6772,6 +6784,13 @@ tan_test (void)
   TEST_f_f (tan, M_PI_4l, 1);
   TEST_f_f (tan, 0.75L, 0.931596459944072461165202756573936428L);
 
+#ifdef TEST_FLOAT
+  /* Enable for double and long double once x86 and x86-64
+     implementations are fixed.  */
+  TEST_f_f (tan, 0x1p65, -0.04723648723590479467984142193L);
+  TEST_f_f (tan, -0x1p65, 0.04723648723590479467984142193L);
+#endif
+
   END (tan);
 }
 
diff --git a/sysdeps/i386/fpu/e_rem_pio2f.c b/sysdeps/i386/fpu/e_rem_pio2f.c
deleted file mode 100644
index 1347b04..0000000
--- a/sysdeps/i386/fpu/e_rem_pio2f.c
+++ /dev/null
@@ -1,3 +0,0 @@
-/* Empty.  This file is only meant to avoid compiling the file with the
-   same name in the libm-ieee754 directory.  The code is not used since
-   there is an assembler version for all users of this file.  */
diff --git a/sysdeps/i386/fpu/k_rem_pio2f.c b/sysdeps/i386/fpu/k_rem_pio2f.c
deleted file mode 100644
index 1347b04..0000000
--- a/sysdeps/i386/fpu/k_rem_pio2f.c
+++ /dev/null
@@ -1,3 +0,0 @@
-/* Empty.  This file is only meant to avoid compiling the file with the
-   same name in the libm-ieee754 directory.  The code is not used since
-   there is an assembler version for all users of this file.  */
diff --git a/sysdeps/i386/fpu/libm-test-ulps b/sysdeps/i386/fpu/libm-test-ulps
index 0d25d75..73fc9a9 100644
--- a/sysdeps/i386/fpu/libm-test-ulps
+++ b/sysdeps/i386/fpu/libm-test-ulps
@@ -559,7 +559,9 @@ ldouble: 1
 # cos_downward
 Test "cos_downward (1) == 0.5403023058681397174009366074429766037323":
 double: 1
+float: 2
 idouble: 1
+ifloat: 2
 ildouble: 1
 ldouble: 1
 Test "cos_downward (10) == -0.8390715290764524522588639478240648345199":
@@ -567,6 +569,9 @@ double: 1
 float: 1
 idouble: 1
 ifloat: 1
+Test "cos_downward (2) == -0.4161468365471423869975682295007621897660":
+float: 1
+ifloat: 1
 Test "cos_downward (3) == -0.9899924966004454572715727947312613023937":
 double: 1
 idouble: 1
@@ -584,6 +589,8 @@ ifloat: 1
 ildouble: 1
 ldouble: 1
 Test "cos_downward (8) == -0.1455000338086135258688413818311946826093":
+float: 1
+ifloat: 1
 ildouble: 1
 ldouble: 1
 Test "cos_downward (9) == -0.9111302618846769883682947111811653112463":
@@ -595,6 +602,9 @@ ildouble: 1
 ldouble: 1
 
 # cos_tonearest
+Test "cos_tonearest (2) == -0.4161468365471423869975682295007621897660":
+float: 1
+ifloat: 1
 Test "cos_tonearest (8) == -0.1455000338086135258688413818311946826093":
 ildouble: 1
 ldouble: 1
@@ -774,6 +784,9 @@ ildouble: 1
 ldouble: 1
 
 # csin
+Test "Imaginary part of: csin (-2 - 3 i) == -9.15449914691142957346729954460983256 + 4.16890695996656435075481305885375484 i":
+float: 1
+ifloat: 1
 Test "Real part of: csin (0.75 + 1.25 i) == 1.28722291002649188575873510790565441 + 1.17210635989270256101081285116138863 i":
 float: 1
 ifloat: 1
@@ -1268,19 +1281,31 @@ idouble: 1
 ildouble: 1
 ldouble: 1
 
+# sin
+Test "sin (-0x1p65) == 0.0471838762123546738051061498057":
+float: 1
+ifloat: 1
+Test "sin (0x1p65) == -0.0471838762123546738051061498057":
+float: 1
+ifloat: 1
+
 # sin_downward
 Test "sin_downward (1) == 0.8414709848078965066525023216302989996226":
 ildouble: 1
 ldouble: 1
 Test "sin_downward (10) == -0.5440211108893698134047476618513772816836":
 double: 1
+float: 1
 idouble: 1
+ifloat: 1
 ildouble: 1
 ldouble: 1
 Test "sin_downward (2) == 0.9092974268256816953960198659117448427023":
 double: 1
 idouble: 1
 Test "sin_downward (3) == 0.1411200080598672221007448028081102798469":
+float: 1
+ifloat: 1
 ildouble: 1
 ldouble: 1
 Test "sin_downward (4) == -0.7568024953079282513726390945118290941359":
@@ -1315,6 +1340,9 @@ ildouble: 1
 ldouble: 1
 
 # sin_tonearest
+Test "sin_tonearest (1) == 0.8414709848078965066525023216302989996226":
+float: 1
+ifloat: 1
 Test "sin_tonearest (10) == -0.5440211108893698134047476618513772816836":
 ildouble: 1
 ldouble: 1
@@ -1399,8 +1427,17 @@ ifloat: 1
 Test "sin_upward (8) == 0.9893582466233817778081235982452886721164":
 float: 1
 ifloat: 1
+Test "sin_upward (9) == 0.4121184852417565697562725663524351793439":
+float: 1
+ifloat: 1
 
 # sincos
+Test "sincos (-0x1p65, &sin_res, &cos_res) puts 0.0471838762123546738051061498057 in sin_res":
+float: 1
+ifloat: 1
+Test "sincos (0x1p65, &sin_res, &cos_res) puts -0.0471838762123546738051061498057 in sin_res":
+float: 1
+ifloat: 1
 Test "sincos (M_PI_6l*2.0, &sin_res, &cos_res) puts 0.5 in cos_res":
 double: 1
 float: 1
@@ -1481,14 +1518,16 @@ ldouble: 7
 # tan
 Test "tan (pi/4) == 1":
 double: 1
+float: 1
 idouble: 1
+ifloat: 1
 
 # tan_downward
 Test "tan_downward (1) == 1.5574077246549022305069748074583601730873":
 double: 1
-float: 1
+float: 2
 idouble: 1
-ifloat: 1
+ifloat: 2
 Test "tan_downward (10) == 0.6483608274590866712591249330098086768169":
 float: 1
 ifloat: 1
@@ -1532,6 +1571,8 @@ Test "tan_tonearest (1) == 1.5574077246549022305069748074583601730873":
 ildouble: 1
 ldouble: 1
 Test "tan_tonearest (2) == -2.1850398632615189916433061023136825434320":
+float: 1
+ifloat: 1
 ildouble: 1
 ldouble: 1
 Test "tan_tonearest (6) == -0.2910061913847491570536995888681755428312":
@@ -1592,6 +1633,8 @@ ldouble: 1
 
 # tan_upward
 Test "tan_upward (1) == 1.5574077246549022305069748074583601730873":
+float: 1
+ifloat: 1
 ildouble: 1
 ldouble: 1
 Test "tan_upward (10) == 0.6483608274590866712591249330098086768169":
@@ -1986,13 +2029,15 @@ ldouble: 1
 
 Function: "cos_downward":
 double: 1
-float: 1
+float: 2
 idouble: 1
-ifloat: 1
+ifloat: 2
 ildouble: 1
 ldouble: 1
 
 Function: "cos_tonearest":
+float: 1
+ifloat: 1
 ildouble: 1
 ldouble: 1
 
@@ -2225,6 +2270,10 @@ ifloat: 1
 ildouble: 1
 ldouble: 1
 
+Function: "sin":
+float: 1
+ifloat: 1
+
 Function: "sin_downward":
 double: 1
 float: 1
@@ -2234,6 +2283,8 @@ ildouble: 1
 ldouble: 1
 
 Function: "sin_tonearest":
+float: 1
+ifloat: 1
 ildouble: 1
 ldouble: 1
 
@@ -2289,17 +2340,21 @@ ldouble: 27
 
 Function: "tan":
 double: 1
+float: 1
 idouble: 1
+ifloat: 1
 
 Function: "tan_downward":
 double: 1
-float: 1
+float: 2
 idouble: 1
-ifloat: 1
+ifloat: 2
 ildouble: 1
 ldouble: 1
 
 Function: "tan_tonearest":
+float: 1
+ifloat: 1
 ildouble: 1
 ldouble: 1
 
diff --git a/sysdeps/i386/fpu/s_cosf.S b/sysdeps/i386/fpu/s_cosf.S
deleted file mode 100644
index 578967a..0000000
--- a/sysdeps/i386/fpu/s_cosf.S
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Written by J.T. Conklin <jtc@netbsd.org>.
- * Fixed errno handling by Ulrich Drepper <drepper@redhat.com>.
- * Public domain.
- */
-
-#define __need_Emath
-#include <bits/errno.h>
-#include <machine/asm.h>
-
-RCSID("$NetBSD: s_cosf.S,v 1.3 1995/05/08 23:55:16 jtc Exp $")
-
-ENTRY(__cosf)
-	flds	4(%esp)
-	fxam
-	fstsw	%ax
-	movb	$0x45, %dh
-	andb	%ah, %dh
-	cmpb	$0x05, %dh
-	je	3f
-4:	fcos
-	fnstsw	%ax
-	testl	$0x400,%eax
-	jnz	1f
-	ret
-	.align ALIGNARG(4)
-1:	fldpi
-	fadd	%st(0)
-	fxch	%st(1)
-2:	fprem1
-	fnstsw	%ax
-	testl	$0x400,%eax
-	jnz	2b
-	fstp	%st(1)
-	fcos
-	ret
-3:
-#ifdef PIC
-	pushl	%ebx
-	cfi_adjust_cfa_offset (4)
-	cfi_rel_offset (ebx, 0)
-	LOAD_PIC_REG (bx)
-	call	__errno_location@PLT
-	movl	$EDOM, (%eax)
-	popl	%ebx
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (ebx)
-#else
-	call	__errno_location@PLT
-	movl	$EDOM, (%eax)
-#endif
-	jmp	4b
-END (__cosf)
-weak_alias (__cosf, cosf)
diff --git a/sysdeps/i386/fpu/s_sincosf.S b/sysdeps/i386/fpu/s_sincosf.S
deleted file mode 100644
index 677c7c4..0000000
--- a/sysdeps/i386/fpu/s_sincosf.S
+++ /dev/null
@@ -1,64 +0,0 @@
-/* Compute sine and cosine of argument.
-   Copyright (C) 1997, 2000 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, see
-   <http://www.gnu.org/licenses/>.  */
-
-#include <machine/asm.h>
-#include "bp-sym.h"
-#include "bp-asm.h"
-
-#define PARMS	LINKAGE		/* no space for saved regs */
-#define ANGLE	PARMS
-#define SINP	ANGLE+4
-#define COSP	SINP+PTR_SIZE
-
-	.text
-ENTRY (BP_SYM (__sincosf))
-	ENTER
-
-	flds	ANGLE(%esp)
-	fsincos
-	movl	SINP(%esp), %ecx
-	CHECK_BOUNDS_BOTH_WIDE (%ecx, SINP(%esp), $4)
-	movl	COSP(%esp), %edx
-	CHECK_BOUNDS_BOTH_WIDE (%edx, COSP(%esp), $4)
-	fnstsw	%ax
-	testl	$0x400,%eax
-	jnz	1f
-	fstps	(%edx)
-	fstps	(%ecx)
-
-	LEAVE
-	ret
-
-	.align ALIGNARG(4)
-1:	fldpi
-	fadd	%st(0)
-	fxch	%st(1)
-2:	fprem1
-	fnstsw	%ax
-	testl	$0x400,%eax
-	jnz	2b
-	fstp	%st(1)
-	fsincos
-	fstps	(%edx)
-	fstps	(%ecx)
-
-	LEAVE
-	ret
-END (BP_SYM (__sincosf))
-weak_alias (BP_SYM (__sincosf), BP_SYM (sincosf))
diff --git a/sysdeps/i386/fpu/s_sinf.S b/sysdeps/i386/fpu/s_sinf.S
deleted file mode 100644
index 67621f7..0000000
--- a/sysdeps/i386/fpu/s_sinf.S
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Written by J.T. Conklin <jtc@netbsd.org>.
- * Fixed errno handling by Ulrich Drepper <drepper@redhat.com>.
- * Public domain.
- */
-
-#define __need_Emath
-#include <bits/errno.h>
-#include <machine/asm.h>
-
-RCSID("$NetBSD: s_sinf.S,v 1.3 1995/05/09 00:27:53 jtc Exp $")
-
-ENTRY(__sinf)
-	flds	4(%esp)
-	fxam
-	fstsw	%ax
-	movb	$0x45, %dh
-	andb	%ah, %dh
-	cmpb	$0x05, %dh
-	je	3f
-4:	fsin
-	fnstsw	%ax
-	testl	$0x400,%eax
-	jnz	1f
-	ret
-	.align ALIGNARG(4)
-1:	fldpi
-	fadd	%st(0)
-	fxch	%st(1)
-2:	fprem1
-	fnstsw	%ax
-	testl	$0x400,%eax
-	jnz	2b
-	fstp	%st(1)
-	fsin
-	ret
-3:
-#ifdef PIC
-	pushl	%ebx
-	cfi_adjust_cfa_offset (4)
-	cfi_rel_offset (ebx, 0)
-	LOAD_PIC_REG (bx)
-	call	__errno_location@PLT
-	movl	$EDOM, (%eax)
-	popl	%ebx
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (ebx)
-#else
-	call	__errno_location@PLT
-	movl	$EDOM, (%eax)
-#endif
-	jmp	4b
-END (__sinf)
-weak_alias (__sinf, sinf)
diff --git a/sysdeps/i386/fpu/s_tanf.S b/sysdeps/i386/fpu/s_tanf.S
deleted file mode 100644
index 74bc22f..0000000
--- a/sysdeps/i386/fpu/s_tanf.S
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Written by J.T. Conklin <jtc@netbsd.org>.
- * Fixed errno handling by Ulrich Drepper <drepper@redhat.com>.
- * Public domain.
- */
-
-#define __need_Emath
-#include <bits/errno.h>
-#include <machine/asm.h>
-
-RCSID("$NetBSD: s_tanf.S,v 1.3 1995/05/09 00:31:09 jtc Exp $")
-
-ENTRY(__tanf)
-	flds	4(%esp)
-	fxam
-	fstsw	%ax
-	movb	$0x45, %dh
-	andb	%ah, %dh
-	cmpb	$0x05, %dh
-	je	3f
-4:	fptan
-	fnstsw	%ax
-	testl	$0x400,%eax
-	jnz	1f
-	fstp	%st(0)
-	ret
-1:	fldpi
-	fadd	%st(0)
-	fxch	%st(1)
-2:	fprem1
-	fstsw	%ax
-	testl	$0x400,%eax
-	jnz	2b
-	fstp	%st(1)
-	fptan
-	fstp	%st(0)
-	ret
-3:
-#ifdef PIC
-	pushl	%ebx
-	cfi_adjust_cfa_offset (4)
-	cfi_rel_offset (ebx, 0)
-	LOAD_PIC_REG (bx)
-	call	__errno_location@PLT
-	movl	$EDOM, (%eax)
-	popl	%ebx
-	cfi_adjust_cfa_offset (-4)
-	cfi_restore (ebx)
-#else
-	call	__errno_location@PLT
-	movl	$EDOM, (%eax)
-#endif
-	jmp	4b
-END (__tanf)
-weak_alias (__tanf, tanf)


-- 
 Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
  SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
   GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
    GPG fingerprint = 93A3 365E CE47 B889 DF7F  FED1 389A 563C C272 A126


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]