diff options
author | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2012-09-25 14:42:18 +0000 |
---|---|---|
committer | joseph <joseph@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2012-09-25 14:42:18 +0000 |
commit | aeb5b827c5f7ed858a5b15101d1a3893356cc6ba (patch) | |
tree | 5d8e4382197847df3cf875caac4994390b6f1094 /libc/sysdeps | |
parent | 598804b7d4191eddbaf24784c3b25a6c4d6f33cd (diff) | |
download | eglibc2-aeb5b827c5f7ed858a5b15101d1a3893356cc6ba.tar.gz |
Merge changes between r20391 and r20863 from /fsf/trunk.
git-svn-id: svn://svn.eglibc.org/trunk@20864 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/sysdeps')
46 files changed, 2679 insertions, 429 deletions
diff --git a/libc/sysdeps/generic/_G_config.h b/libc/sysdeps/generic/_G_config.h index 6f756829e..fc83565b9 100644 --- a/libc/sysdeps/generic/_G_config.h +++ b/libc/sysdeps/generic/_G_config.h @@ -18,7 +18,6 @@ # define __need_wint_t #endif #include <wchar.h> -#define _G_size_t size_t typedef struct { __off_t __pos; @@ -29,13 +28,7 @@ typedef struct __off64_t __pos; __mbstate_t __state; } _G_fpos64_t; -#define _G_ssize_t __ssize_t -#define _G_off_t __off_t #define _G_off64_t __off_t -#define _G_pid_t __pid_t -#define _G_uid_t __uid_t -#define _G_wchar_t wchar_t -#define _G_wint_t wint_t #define _G_stat64 stat #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T # include <gconv.h> @@ -50,25 +43,11 @@ typedef union } _G_iconv_t; #endif -typedef int _G_int16_t __attribute__ ((__mode__ (__HI__))); -typedef int _G_int32_t __attribute__ ((__mode__ (__SI__))); -typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__))); -typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__))); - -#define _G_HAVE_BOOL 1 - /* These library features are always available in the GNU C library. */ -#define _G_HAVE_ATEXIT 1 -#define _G_HAVE_SYS_WAIT 1 -#define _G_NEED_STDARG_H 1 #define _G_va_list __gnuc_va_list -#define _G_HAVE_PRINTF_FP 1 #define _G_HAVE_MMAP 1 -#define _G_HAVE_LONG_DOUBLE_IO 1 -#define _G_HAVE_IO_FILE_OPEN 1 -#define _G_HAVE_IO_GETLINE_INFO 1 #define _G_IO_IO_FILE_VERSION 0x20001 @@ -77,9 +56,4 @@ typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__))); #define _G_BUFSIZ 8192 -/* These are the vtbl details for ELF. */ -#define _G_NAMES_HAVE_UNDERSCORE 0 -#define _G_VTABLE_LABEL_PREFIX "_vt." -#define _G_VTABLE_LABEL_HAS_LENGTH 1 - #endif /* _G_config.h */ diff --git a/libc/sysdeps/generic/get-rounding-mode.h b/libc/sysdeps/generic/get-rounding-mode.h new file mode 100644 index 000000000..0ecaddd7b --- /dev/null +++ b/libc/sysdeps/generic/get-rounding-mode.h @@ -0,0 +1,124 @@ +/* Determine floating-point rounding mode within libc. Generic version. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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/>. */ + +#ifndef _GET_ROUNDING_MODE_H +#define _GET_ROUNDING_MODE_H 1 + +#include <fpu_control.h> + +/* Define values for FE_* modes not defined for this architecture. */ +#ifdef FE_DOWNWARD +# define ORIG_FE_DOWNWARD FE_DOWNWARD +#else +# define ORIG_FE_DOWNWARD 0 +#endif +#ifdef FE_TONEAREST +# define ORIG_FE_TONEAREST FE_TONEAREST +#else +# define ORIG_FE_TONEAREST 0 +#endif +#ifdef FE_TOWARDZERO +# define ORIG_FE_TOWARDZERO FE_TOWARDZERO +#else +# define ORIG_FE_TOWARDZERO 0 +#endif +#ifdef FE_UPWARD +# define ORIG_FE_UPWARD FE_UPWARD +#else +# define ORIG_FE_UPWARD 0 +#endif +#define FE_CONSTRUCT_DISTINCT_VALUE(X, Y, Z) \ + ((((X) & 1) | ((Y) & 2) | ((Z) & 4)) ^ 7) +#ifndef FE_DOWNWARD +# define FE_DOWNWARD FE_CONSTRUCT_DISTINCT_VALUE (ORIG_FE_TONEAREST, \ + ORIG_FE_TOWARDZERO, \ + ORIG_FE_UPWARD) +#endif +#ifndef FE_TONEAREST +# define FE_TONEAREST FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \ + ORIG_FE_TOWARDZERO, \ + ORIG_FE_UPWARD) +#endif +#ifndef FE_TOWARDZERO +# define FE_TOWARDZERO FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \ + FE_TONEAREST, \ + ORIG_FE_UPWARD) +#endif +#ifndef FE_UPWARD +# define FE_UPWARD FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \ + FE_TONEAREST, \ + FE_TOWARDZERO) +#endif + +/* Return the floating-point rounding mode. */ + +static inline int +get_rounding_mode (void) +{ +#if (defined _FPU_RC_DOWN \ + || defined _FPU_RC_NEAREST \ + || defined _FPU_RC_ZERO \ + || defined _FPU_RC_UP) + fpu_control_t fc; + const fpu_control_t mask = (0 +# ifdef _FPU_RC_DOWN + | _FPU_RC_DOWN +# endif +# ifdef _FPU_RC_NEAREST + | _FPU_RC_NEAREST +# endif +# ifdef _FPU_RC_ZERO + | _FPU_RC_ZERO +# endif +# ifdef _FPU_RC_UP + | _FPU_RC_UP +# endif + ); + + _FPU_GETCW (fc); + switch (fc & mask) + { +# ifdef _FPU_RC_DOWN + case _FPU_RC_DOWN: + return FE_DOWNWARD; +# endif + +# ifdef _FPU_RC_NEAREST + case _FPU_RC_NEAREST: + return FE_TONEAREST; +# endif + +# ifdef _FPU_RC_ZERO + case _FPU_RC_ZERO: + return FE_TOWARDZERO; +# endif + +# ifdef _FPU_RC_UP + case _FPU_RC_UP: + return FE_UPWARD; +# endif + + default: + abort (); + } +#else + return FE_TONEAREST; +#endif +} + +#endif /* get-rounding-mode.h */ diff --git a/libc/sysdeps/generic/malloc-sysdep.h b/libc/sysdeps/generic/malloc-sysdep.h new file mode 100644 index 000000000..bbc48c04f --- /dev/null +++ b/libc/sysdeps/generic/malloc-sysdep.h @@ -0,0 +1,25 @@ +/* System-specific malloc support functions. Generic version. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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/>. */ + +/* Force an unmap when the heap shrinks in a secure exec. This ensures that + the old data pages immediately cease to be accessible. */ +static inline bool +check_may_shrink_heap (void) +{ + return __libc_enable_secure; +} diff --git a/libc/sysdeps/gnu/_G_config.h b/libc/sysdeps/gnu/_G_config.h index 9d6e23bb4..4d3ae36c4 100644 --- a/libc/sysdeps/gnu/_G_config.h +++ b/libc/sysdeps/gnu/_G_config.h @@ -18,7 +18,6 @@ # define __need_wint_t #endif #include <wchar.h> -#define _G_size_t size_t typedef struct { __off_t __pos; @@ -29,13 +28,7 @@ typedef struct __off64_t __pos; __mbstate_t __state; } _G_fpos64_t; -#define _G_ssize_t __ssize_t -#define _G_off_t __off_t #define _G_off64_t __off64_t -#define _G_pid_t __pid_t -#define _G_uid_t __uid_t -#define _G_wchar_t wchar_t -#define _G_wint_t wint_t #define _G_stat64 stat64 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T # include <gconv.h> @@ -50,26 +43,12 @@ typedef union } _G_iconv_t; #endif -typedef int _G_int16_t __attribute__ ((__mode__ (__HI__))); -typedef int _G_int32_t __attribute__ ((__mode__ (__SI__))); -typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__))); -typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__))); - -#define _G_HAVE_BOOL 1 - /* These library features are always available in the GNU C library. */ -#define _G_HAVE_ATEXIT 1 -#define _G_HAVE_SYS_WAIT 1 -#define _G_NEED_STDARG_H 1 #define _G_va_list __gnuc_va_list -#define _G_HAVE_PRINTF_FP 1 #define _G_HAVE_MMAP 1 #define _G_HAVE_MREMAP 1 -#define _G_HAVE_LONG_DOUBLE_IO 1 -#define _G_HAVE_IO_FILE_OPEN 1 -#define _G_HAVE_IO_GETLINE_INFO 1 #define _G_IO_IO_FILE_VERSION 0x20001 @@ -83,11 +62,4 @@ typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__))); #define _G_BUFSIZ 8192 -/* These are the vtbl details for ELF. */ -#define _G_NAMES_HAVE_UNDERSCORE 0 -#define _G_VTABLE_LABEL_HAS_LENGTH 1 -#define _G_USING_THUNKS 1 -#define _G_VTABLE_LABEL_PREFIX "__vt_" -#define _G_VTABLE_LABEL_PREFIX_ID __vt_ - #endif /* _G_config.h */ diff --git a/libc/sysdeps/i386/fpu/libm-test-ulps b/libc/sysdeps/i386/fpu/libm-test-ulps index abd98a295..d35635ce0 100644 --- a/libc/sysdeps/i386/fpu/libm-test-ulps +++ b/libc/sysdeps/i386/fpu/libm-test-ulps @@ -2398,6 +2398,10 @@ ldouble: 1 Test "sin (-0x1p65) == 0.047183876212354673805106149805700013943218": float: 1 ifloat: 1 +Test "sin (0x1.fffff8p+127) == 4.85786063130487339701113680434728152037092e-02": +float: 1 +Test "sin (0x1p+127) == 6.23385512955870240370428801097126489001833e-01": +float: 1 Test "sin (0x1p65) == -0.047183876212354673805106149805700013943218": float: 1 ifloat: 1 @@ -2556,6 +2560,13 @@ ifloat: 1 Test "sincos (-0x1p65, &sin_res, &cos_res) puts 0.047183876212354673805106149805700013943218 in sin_res": float: 1 ifloat: 1 +Test "sincos (0x1.fffff8p+127, &sin_res, &cos_res) puts 4.85786063130487339701113680434728152037092e-02 in sin_res": +float: 1 +Test "sincos (0x1p+127, &sin_res, &cos_res) puts 6.23385512955870240370428801097126489001833e-01 in sin_res": +float: 1 +Test "sincos (0x1p+50, &sin_res, &cos_res) puts 8.68095904660550604334592502063501320395739e-01 in cos_res": +float: 1 +ifloat: 1 Test "sincos (0x1p65, &sin_res, &cos_res) puts -0.047183876212354673805106149805700013943218 in sin_res": float: 1 ifloat: 1 diff --git a/libc/sysdeps/i386/i686/fpu/multiarch/Makefile b/libc/sysdeps/i386/i686/fpu/multiarch/Makefile index 1de37fe4a..aa28f7284 100644 --- a/libc/sysdeps/i386/i686/fpu/multiarch/Makefile +++ b/libc/sysdeps/i386/i686/fpu/multiarch/Makefile @@ -1,3 +1,3 @@ ifeq ($(subdir),math) -libm-sysdep_routines += e_expf-sse2 e_expf-ia32 +libm-sysdep_routines += e_expf-sse2 e_expf-ia32 s_sinf-sse2 s_cosf-sse2 endif diff --git a/libc/sysdeps/i386/i686/fpu/multiarch/e_expf.c b/libc/sysdeps/i386/i686/fpu/multiarch/e_expf.c index 65858a311..1966400d1 100644 --- a/libc/sysdeps/i386/i686/fpu/multiarch/e_expf.c +++ b/libc/sysdeps/i386/i686/fpu/multiarch/e_expf.c @@ -1,3 +1,21 @@ +/* Multiple versions of expf + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 <init-arch.h> extern double __ieee754_expf_sse2 (double); diff --git a/libc/sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S b/libc/sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S new file mode 100644 index 000000000..405c6ea4c --- /dev/null +++ b/libc/sysdeps/i386/i686/fpu/multiarch/s_cosf-sse2.S @@ -0,0 +1,553 @@ +/* Optimized with sse2 version of cosf + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 <sysdep.h> +#define __need_Emath +#include <bits/errno.h> + +/* Short algorithm description: + * + * 1) if |x| == 0: return 1.0-|x|. + * 2) if |x| < 2^-27: return 1.0-|x|. + * 3) if |x| < 2^-5 : return 1.0+x^2*DP_COS2_0+x^5*DP_COS2_1. + * 4) if |x| < Pi/4: return 1.0+x^2*(C0+x^2*(C1+x^2*(C2+x^2*(C3+x^2*C4)))). + * 5) if |x| < 9*Pi/4: + * 5.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0x0e, n=k+3, + * t=|x|-j*Pi/4. + * 5.2) Reconstruction: + * s = (-1.0)^((n>>2)&1) + * if(n&2 != 0) { + * using cos(t) polynomial for |t|<Pi/4, result is + * s * (1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4))))). + * } else { + * using sin(t) polynomial for |t|<Pi/4, result is + * s * t * (1.0+t^2*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4))))). + * } + * 6) if |x| < 2^23, large args: + * 6.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0xfffffffe, n=k+3, + * t=|x|-j*Pi/4. + * 6.2) Reconstruction same as (5.2). + * 7) if |x| >= 2^23, very large args: + * 7.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0xfffffffe, n=k+3, + * t=|x|-j*Pi/4. + * 7.2) Reconstruction same as (5.2). + * 8) if x is Inf, return x-x, and set errno=EDOM. + * 9) if x is NaN, return x-x. + * + * Special cases: + * cos(+-0) = 1 not raising inexact, + * cos(subnormal) raises inexact, + * cos(min_normalized) raises inexact, + * cos(normalized) raises inexact, + * cos(Inf) = NaN, raises invalid, sets errno to EDOM, + * cos(NaN) = NaN. + */ + +#ifdef PIC +# define MO1(symbol) L(symbol)##@GOTOFF(%ebx) +# define MO2(symbol,reg2,_scale) L(symbol)##@GOTOFF(%ebx,reg2,_scale) +# define CFI_PUSH(REG) cfi_adjust_cfa_offset(4); cfi_rel_offset(REG,0) +# define CFI_POP(REG) cfi_adjust_cfa_offset(-4); cfi_restore(REG) +# define PUSH(REG) pushl REG; CFI_PUSH(REG) +# define POP(REG) popl REG; CFI_POP(REG) +# define ENTRANCE PUSH(%ebx); LOAD_PIC_REG(bx) +# define RETURN POP(%ebx); ret; CFI_PUSH(%ebx) +# define ARG_X 8(%esp) +#else +# define MO1(symbol) L(symbol) +# define MO2(symbol,reg2,_scale) L(symbol)(,reg2,_scale) +# define ENTRANCE +# define RETURN ret +# define ARG_X 4(%esp) +#endif + + .text +ENTRY(__cosf_sse2) + /* Input: single precision x on stack at address ARG_X */ + + ENTRANCE + movl ARG_X, %eax /* Bits of x */ + cvtss2sd ARG_X, %xmm0 /* DP x */ + andl $0x7fffffff, %eax /* |x| */ + + cmpl $0x3f490fdb, %eax /* |x|<Pi/4? */ + jb L(arg_less_pio4) + + /* Here if |x|>=Pi/4 */ + movd %eax, %xmm3 /* SP |x| */ + andpd MO1(DP_ABS_MASK),%xmm0 /* DP |x| */ + movss MO1(SP_INVPIO4), %xmm2 /* SP 1/(Pi/4) */ + + cmpl $0x40e231d6, %eax /* |x|<9*Pi/4? */ + jae L(large_args) + + /* Here if Pi/4<=|x|<9*Pi/4 */ + mulss %xmm3, %xmm2 /* SP |x|/(Pi/4) */ + cvttss2si %xmm2, %eax /* k, number of Pi/4 in x */ + addl $1, %eax /* k+1 */ + movl $0x0e, %edx + andl %eax, %edx /* j = (k+1)&0x0e */ + addl $2, %eax /* n */ + subsd MO2(PIO4J,%edx,8), %xmm0 /* t = |x| - j * Pi/4 */ + +L(reconstruction): + /* Input: %eax=n, %xmm0=t */ + testl $2, %eax /* n&2 != 0? */ + jz L(sin_poly) + +/*L(cos_poly):*/ + /* Here if cos(x) calculated using cos(t) polynomial for |t|<Pi/4: + * y = t*t; z = y*y; + * s = sign(x) * (-1.0)^((n>>2)&1) + * result = s * (1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4))))) + */ + shrl $2, %eax /* n>>2 */ + mulsd %xmm0, %xmm0 /* y=t^2 */ + andl $1, %eax /* (n>>2)&1 */ + movaps %xmm0, %xmm1 /* y */ + mulsd %xmm0, %xmm0 /* z=t^4 */ + + movsd MO1(DP_C4), %xmm4 /* C4 */ + mulsd %xmm0, %xmm4 /* z*C4 */ + movsd MO1(DP_C3), %xmm3 /* C3 */ + mulsd %xmm0, %xmm3 /* z*C3 */ + addsd MO1(DP_C2), %xmm4 /* C2+z*C4 */ + mulsd %xmm0, %xmm4 /* z*(C2+z*C4) */ + lea -8(%esp), %esp /* Borrow 4 bytes of stack frame */ + addsd MO1(DP_C1), %xmm3 /* C1+z*C3 */ + mulsd %xmm0, %xmm3 /* z*(C1+z*C3) */ + addsd MO1(DP_C0), %xmm4 /* C0+z*(C2+z*C4) */ + mulsd %xmm1, %xmm4 /* y*(C0+z*(C2+z*C4)) */ + + addsd %xmm4, %xmm3 /* y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + /* 1.0+y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + addsd MO1(DP_ONES), %xmm3 + + mulsd MO2(DP_ONES,%eax,8), %xmm3 /* DP result */ + movsd %xmm3, 0(%esp) /* Move result from sse... */ + fldl 0(%esp) /* ...to FPU. */ + /* Return back 4 bytes of stack frame */ + lea 8(%esp), %esp + RETURN + + .p2align 4 +L(sin_poly): + /* Here if cos(x) calculated using sin(t) polynomial for |t|<Pi/4: + * y = t*t; z = y*y; + * s = sign(x) * (-1.0)^((n>>2)&1) + * result = s * t * (1.0+t^2*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4))))) + */ + + movaps %xmm0, %xmm4 /* t */ + shrl $2, %eax /* n>>2 */ + mulsd %xmm0, %xmm0 /* y=t^2 */ + andl $1, %eax /* (n>>2)&1 */ + movaps %xmm0, %xmm1 /* y */ + mulsd %xmm0, %xmm0 /* z=t^4 */ + + movsd MO1(DP_S4), %xmm2 /* S4 */ + mulsd %xmm0, %xmm2 /* z*S4 */ + movsd MO1(DP_S3), %xmm3 /* S3 */ + mulsd %xmm0, %xmm3 /* z*S3 */ + lea -8(%esp), %esp /* Borrow 4 bytes of stack frame */ + addsd MO1(DP_S2), %xmm2 /* S2+z*S4 */ + mulsd %xmm0, %xmm2 /* z*(S2+z*S4) */ + addsd MO1(DP_S1), %xmm3 /* S1+z*S3 */ + mulsd %xmm0, %xmm3 /* z*(S1+z*S3) */ + addsd MO1(DP_S0), %xmm2 /* S0+z*(S2+z*S4) */ + mulsd %xmm1, %xmm2 /* y*(S0+z*(S2+z*S4)) */ + /* t*s, where s = sign(x) * (-1.0)^((n>>2)&1) */ + mulsd MO2(DP_ONES,%eax,8), %xmm4 + addsd %xmm2, %xmm3 /* y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + /* t*s*y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + mulsd %xmm4, %xmm3 + /* t*s*(1.0+y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + addsd %xmm4, %xmm3 + movsd %xmm3, 0(%esp) /* Move result from sse... */ + fldl 0(%esp) /* ...to FPU. */ + /* Return back 4 bytes of stack frame */ + lea 8(%esp), %esp + RETURN + + .p2align 4 +L(large_args): + /* Here if |x|>=9*Pi/4 */ + cmpl $0x7f800000, %eax /* x is Inf or NaN? */ + jae L(arg_inf_or_nan) + + /* Here if finite |x|>=9*Pi/4 */ + cmpl $0x4b000000, %eax /* |x|<2^23? */ + jae L(very_large_args) + + /* Here if 9*Pi/4<=|x|<2^23 */ + movsd MO1(DP_INVPIO4), %xmm1 /* 1/(Pi/4) */ + mulsd %xmm0, %xmm1 /* |x|/(Pi/4) */ + cvttsd2si %xmm1, %eax /* k=trunc(|x|/(Pi/4)) */ + addl $1, %eax /* k+1 */ + movl %eax, %edx + andl $0xfffffffe, %edx /* j=(k+1)&0xfffffffe */ + cvtsi2sdl %edx, %xmm4 /* DP j */ + movsd MO1(DP_PIO4HI), %xmm2 /* -PIO4HI = high part of -Pi/4 */ + mulsd %xmm4, %xmm2 /* -j*PIO4HI */ + movsd MO1(DP_PIO4LO), %xmm3 /* -PIO4LO = low part of -Pi/4 */ + addsd %xmm2, %xmm0 /* |x| - j*PIO4HI */ + addl $2, %eax /* n */ + mulsd %xmm3, %xmm4 /* j*PIO4LO */ + addsd %xmm4, %xmm0 /* t = |x| - j*PIO4HI - j*PIO4LO */ + jmp L(reconstruction) + + .p2align 4 +L(very_large_args): + /* Here if finite |x|>=2^23 */ + + /* bitpos = (ix>>23) - BIAS_32 + 59; */ + shrl $23, %eax /* eb = biased exponent of x */ + /* bitpos = eb - 0x7f + 59, where 0x7f is exponent bias */ + subl $68, %eax + movl $28, %ecx /* %cl=28 */ + movl %eax, %edx /* bitpos copy */ + + /* j = bitpos/28; */ + div %cl /* j in register %al=%ax/%cl */ + movapd %xmm0, %xmm3 /* |x| */ + /* clear unneeded remainder from %ah */ + andl $0xff, %eax + + imull $28, %eax, %ecx /* j*28 */ + movsd MO1(DP_HI_MASK), %xmm4 /* DP_HI_MASK */ + movapd %xmm0, %xmm5 /* |x| */ + mulsd -2*8+MO2(_FPI,%eax,8), %xmm3 /* tmp3 = FPI[j-2]*|x| */ + movapd %xmm0, %xmm1 /* |x| */ + mulsd -1*8+MO2(_FPI,%eax,8), %xmm5 /* tmp2 = FPI[j-1]*|x| */ + mulsd 0*8+MO2(_FPI,%eax,8), %xmm0 /* tmp0 = FPI[j]*|x| */ + addl $19, %ecx /* j*28+19 */ + mulsd 1*8+MO2(_FPI,%eax,8), %xmm1 /* tmp1 = FPI[j+1]*|x| */ + cmpl %ecx, %edx /* bitpos>=j*28+19? */ + jl L(very_large_skip1) + + /* Here if bitpos>=j*28+19 */ + andpd %xmm3, %xmm4 /* HI(tmp3) */ + subsd %xmm4, %xmm3 /* tmp3 = tmp3 - HI(tmp3) */ +L(very_large_skip1): + + movsd MO1(DP_2POW52), %xmm6 + movapd %xmm5, %xmm2 /* tmp2 copy */ + addsd %xmm3, %xmm5 /* tmp5 = tmp3 + tmp2 */ + movl $1, %edx + addsd %xmm5, %xmm6 /* tmp6 = tmp5 + 2^52 */ + movsd 8+MO1(DP_2POW52), %xmm4 + movd %xmm6, %eax /* k = I64_LO(tmp6); */ + addsd %xmm6, %xmm4 /* tmp4 = tmp6 - 2^52 */ + comisd %xmm5, %xmm4 /* tmp4 > tmp5? */ + jbe L(very_large_skip2) + + /* Here if tmp4 > tmp5 */ + subl $1, %eax /* k-- */ + addsd 8+MO1(DP_ONES), %xmm4 /* tmp4 -= 1.0 */ +L(very_large_skip2): + + andl %eax, %edx /* k&1 */ + subsd %xmm4, %xmm3 /* tmp3 -= tmp4 */ + addsd MO2(DP_ZERONE,%edx,8), %xmm3 /* t = DP_ZERONE[k&1] + tmp3 */ + addsd %xmm2, %xmm3 /* t += tmp2 */ + addsd %xmm3, %xmm0 /* t += tmp0 */ + addl $3, %eax /* n=k+3 */ + addsd %xmm1, %xmm0 /* t += tmp1 */ + mulsd MO1(DP_PIO4), %xmm0 /* t *= PI04 */ + + jmp L(reconstruction) /* end of very_large_args peth */ + + .p2align 4 +L(arg_less_pio4): + /* Here if |x|<Pi/4 */ + cmpl $0x3d000000, %eax /* |x|<2^-5? */ + jl L(arg_less_2pn5) + + /* Here if 2^-5<=|x|<Pi/4 */ + mulsd %xmm0, %xmm0 /* y=x^2 */ + movaps %xmm0, %xmm1 /* y */ + mulsd %xmm0, %xmm0 /* z=x^4 */ + movsd MO1(DP_C4), %xmm3 /* C4 */ + mulsd %xmm0, %xmm3 /* z*C4 */ + movsd MO1(DP_C3), %xmm5 /* C3 */ + mulsd %xmm0, %xmm5 /* z*C3 */ + addsd MO1(DP_C2), %xmm3 /* C2+z*C4 */ + mulsd %xmm0, %xmm3 /* z*(C2+z*C4) */ + addsd MO1(DP_C1), %xmm5 /* C1+z*C3 */ + mulsd %xmm0, %xmm5 /* z*(C1+z*C3) */ + addsd MO1(DP_C0), %xmm3 /* C0+z*(C2+z*C4) */ + mulsd %xmm1, %xmm3 /* y*(C0+z*(C2+z*C4)) */ + addsd %xmm5, %xmm3 /* y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + /* 1.0 + y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + addsd MO1(DP_ONES), %xmm3 + cvtsd2ss %xmm3, %xmm3 /* SP result */ + +L(epilogue): + lea -4(%esp), %esp /* Borrow 4 bytes of stack frame */ + movss %xmm3, 0(%esp) /* Move result from sse... */ + flds 0(%esp) /* ...to FPU. */ + /* Return back 4 bytes of stack frame */ + lea 4(%esp), %esp + RETURN + + .p2align 4 +L(arg_less_2pn5): + /* Here if |x|<2^-5 */ + cmpl $0x32000000, %eax /* |x|<2^-27? */ + jl L(arg_less_2pn27) + + /* Here if 2^-27<=|x|<2^-5 */ + mulsd %xmm0, %xmm0 /* DP x^2 */ + movsd MO1(DP_COS2_1), %xmm3 /* DP DP_COS2_1 */ + mulsd %xmm0, %xmm3 /* DP x^2*DP_COS2_1 */ + addsd MO1(DP_COS2_0), %xmm3 /* DP DP_COS2_0+x^2*DP_COS2_1 */ + mulsd %xmm0, %xmm3 /* DP x^2*DP_COS2_0+x^4*DP_COS2_1 */ + /* DP 1.0+x^2*DP_COS2_0+x^4*DP_COS2_1 */ + addsd MO1(DP_ONES), %xmm3 + cvtsd2ss %xmm3, %xmm3 /* SP result */ + jmp L(epilogue) + + .p2align 4 +L(arg_less_2pn27): + /* Here if |x|<2^-27 */ + movss ARG_X, %xmm0 /* x */ + andps MO1(SP_ABS_MASK),%xmm0 /* |x| */ + movss MO1(SP_ONE), %xmm3 /* 1.0 */ + subss %xmm0, %xmm3 /* result is 1.0-|x| */ + jmp L(epilogue) + + .p2align 4 +L(arg_inf_or_nan): + /* Here if |x| is Inf or NAN */ + jne L(skip_errno_setting) /* in case of x is NaN */ + + /* Here if x is Inf. Set errno to EDOM. */ + call JUMPTARGET(__errno_location) + movl $EDOM, (%eax) + + .p2align 4 +L(skip_errno_setting): + /* Here if |x| is Inf or NAN. Continued. */ + movss ARG_X, %xmm3 /* load x */ + subss %xmm3, %xmm3 /* Result is NaN */ + jmp L(epilogue) +END(__cosf_sse2) + + .section .rodata, "a" + .p2align 3 +L(PIO4J): /* Table of j*Pi/4, for j=0,1,..,10 */ + .long 0x00000000,0x00000000 + .long 0x54442d18,0x3fe921fb + .long 0x54442d18,0x3ff921fb + .long 0x7f3321d2,0x4002d97c + .long 0x54442d18,0x400921fb + .long 0x2955385e,0x400f6a7a + .long 0x7f3321d2,0x4012d97c + .long 0xe9bba775,0x4015fdbb + .long 0x54442d18,0x401921fb + .long 0xbeccb2bb,0x401c463a + .long 0x2955385e,0x401f6a7a + .type L(PIO4J), @object + ASM_SIZE_DIRECTIVE(L(PIO4J)) + + .p2align 3 +L(_FPI): /* 4/Pi broken into sum of positive DP values */ + .long 0x00000000,0x00000000 + .long 0x6c000000,0x3ff45f30 + .long 0x2a000000,0x3e3c9c88 + .long 0xa8000000,0x3c54fe13 + .long 0xd0000000,0x3aaf47d4 + .long 0x6c000000,0x38fbb81b + .long 0xe0000000,0x3714acc9 + .long 0x7c000000,0x3560e410 + .long 0x56000000,0x33bca2c7 + .long 0xac000000,0x31fbd778 + .long 0xe0000000,0x300b7246 + .long 0xe8000000,0x2e5d2126 + .long 0x48000000,0x2c970032 + .long 0xe8000000,0x2ad77504 + .long 0xe0000000,0x290921cf + .long 0xb0000000,0x274deb1c + .long 0xe0000000,0x25829a73 + .long 0xbe000000,0x23fd1046 + .long 0x10000000,0x2224baed + .long 0x8e000000,0x20709d33 + .long 0x80000000,0x1e535a2f + .long 0x64000000,0x1cef904e + .long 0x30000000,0x1b0d6398 + .long 0x24000000,0x1964ce7d + .long 0x16000000,0x17b908bf + .type L(_FPI), @object + ASM_SIZE_DIRECTIVE(L(_FPI)) + +/* Coefficients of polynomial + for cos(x)~=1.0+x^2*DP_COS2_0+x^4*DP_COS2_1, |x|<2^-5. */ + .p2align 3 +L(DP_COS2_0): + .long 0xff5cc6fd,0xbfdfffff + .type L(DP_COS2_0), @object + ASM_SIZE_DIRECTIVE(L(DP_COS2_0)) + + .p2align 3 +L(DP_COS2_1): + .long 0xb178dac5,0x3fa55514 + .type L(DP_COS2_1), @object + ASM_SIZE_DIRECTIVE(L(DP_COS2_1)) + + .p2align 3 +L(DP_ZERONE): + .long 0x00000000,0x00000000 /* 0.0 */ + .long 0x00000000,0xbff00000 /* 1.0 */ + .type L(DP_ZERONE),@object + ASM_SIZE_DIRECTIVE(L(DP_ZERONE)) + + .p2align 3 +L(DP_ONES): + .long 0x00000000,0x3ff00000 /* +1.0 */ + .long 0x00000000,0xbff00000 /* -1.0 */ + .type L(DP_ONES), @object + ASM_SIZE_DIRECTIVE(L(DP_ONES)) + +/* Coefficients of polynomial + for sin(t)~=t+t^3*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4)))), |t|<Pi/4. */ + .p2align 3 +L(DP_S3): + .long 0x64e6b5b4,0x3ec71d72 + .type L(DP_S3), @object + ASM_SIZE_DIRECTIVE(L(DP_S3)) + + .p2align 3 +L(DP_S1): + .long 0x10c2688b,0x3f811111 + .type L(DP_S1), @object + ASM_SIZE_DIRECTIVE(L(DP_S1)) + + .p2align 3 +L(DP_S4): + .long 0x1674b58a,0xbe5a947e + .type L(DP_S4), @object + ASM_SIZE_DIRECTIVE(L(DP_S4)) + + .p2align 3 +L(DP_S2): + .long 0x8b4bd1f9,0xbf2a019f + .type L(DP_S2), @object + ASM_SIZE_DIRECTIVE(L(DP_S2)) + + .p2align 3 +L(DP_S0): + .long 0x55551cd9,0xbfc55555 + .type L(DP_S0), @object + ASM_SIZE_DIRECTIVE(L(DP_S0)) + +/* Coefficients of polynomial + for cos(t)~=1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4)))), |t|<Pi/4. */ + .p2align 3 +L(DP_C3): + .long 0x9ac43cc0,0x3efa00eb + .type L(DP_C3), @object + ASM_SIZE_DIRECTIVE(L(DP_C3)) + + .p2align 3 +L(DP_C1): + .long 0x545c50c7,0x3fa55555 + .type L(DP_C1), @object + ASM_SIZE_DIRECTIVE(L(DP_C1)) + + .p2align 3 +L(DP_C4): + .long 0xdd8844d7,0xbe923c97 + .type L(DP_C4), @object + ASM_SIZE_DIRECTIVE(L(DP_C4)) + + .p2align 3 +L(DP_C2): + .long 0x348b6874,0xbf56c16b + .type L(DP_C2), @object + ASM_SIZE_DIRECTIVE(L(DP_C2)) + + .p2align 3 +L(DP_C0): + .long 0xfffe98ae,0xbfdfffff + .type L(DP_C0), @object + ASM_SIZE_DIRECTIVE(L(DP_C0)) + + .p2align 3 +L(DP_PIO4): + .long 0x54442d18,0x3fe921fb /* Pi/4 */ + .type L(DP_PIO4), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4)) + + .p2align 3 +L(DP_2POW52): + .long 0x00000000,0x43300000 /* +2^52 */ + .long 0x00000000,0xc3300000 /* -2^52 */ + .type L(DP_2POW52), @object + ASM_SIZE_DIRECTIVE(L(DP_2POW52)) + + .p2align 3 +L(DP_INVPIO4): + .long 0x6dc9c883,0x3ff45f30 /* 4/Pi */ + .type L(DP_INVPIO4), @object + ASM_SIZE_DIRECTIVE(L(DP_INVPIO4)) + + .p2align 3 +L(DP_PIO4HI): + .long 0x54000000,0xbfe921fb /* High part of Pi/4 */ + .type L(DP_PIO4HI), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4HI)) + + .p2align 3 +L(DP_PIO4LO): + .long 0x11A62633,0xbe010b46 /* Low part of Pi/4 */ + .type L(DP_PIO4LO), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4LO)) + + .p2align 2 +L(SP_INVPIO4): + .long 0x3fa2f983 /* 4/Pi */ + .type L(SP_INVPIO4), @object + ASM_SIZE_DIRECTIVE(L(SP_INVPIO4)) + + .p2align 4 +L(DP_ABS_MASK): /* Mask for getting DP absolute value */ + .long 0xffffffff,0x7fffffff + .long 0xffffffff,0x7fffffff + .type L(DP_ABS_MASK), @object + ASM_SIZE_DIRECTIVE(L(DP_ABS_MASK)) + + .p2align 3 +L(DP_HI_MASK): /* Mask for getting high 21 bits of DP value */ + .long 0x00000000,0xffffffff + .type L(DP_HI_MASK), @object + ASM_SIZE_DIRECTIVE(L(DP_HI_MASK)) + + .p2align 4 +L(SP_ABS_MASK): /* Mask for getting SP absolute value */ + .long 0x7fffffff,0x7fffffff + .long 0x7fffffff,0x7fffffff + .type L(SP_ABS_MASK), @object + ASM_SIZE_DIRECTIVE(L(SP_ABS_MASK)) + + .p2align 2 +L(SP_ONE): + .long 0x3f800000 /* 1.0 */ + .type L(SP_ONE), @object + ASM_SIZE_DIRECTIVE(L(SP_ONE)) + +weak_alias (__cosf, cosf) diff --git a/libc/sysdeps/i386/i686/fpu/multiarch/s_cosf.c b/libc/sysdeps/i386/i686/fpu/multiarch/s_cosf.c new file mode 100644 index 000000000..f07c3e510 --- /dev/null +++ b/libc/sysdeps/i386/i686/fpu/multiarch/s_cosf.c @@ -0,0 +1,29 @@ +/* Multiple versions of cosf + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 <init-arch.h> + +extern float __cosf_sse2 (float); +extern float __cosf_ia32 (float); +float __cosf (float); + +libm_ifunc (__cosf, HAS_SSE2 ? __cosf_sse2 : __cosf_ia32); +weak_alias (__cosf, cosf); + +#define COSF __cosf_ia32 +#include <sysdeps/ieee754/flt-32/s_cosf.c> diff --git a/libc/sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S b/libc/sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S new file mode 100644 index 000000000..49d59b597 --- /dev/null +++ b/libc/sysdeps/i386/i686/fpu/multiarch/s_sinf-sse2.S @@ -0,0 +1,566 @@ +/* Optimized with sse2 version of sinf + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 <sysdep.h> +#define __need_Emath +#include <bits/errno.h> + +/* Short algorithm description: + * + * 1) if |x| == 0: return x. + * 2) if |x| < 2^-27: return x-x*DP_SMALL, raise underflow only when needed. + * 3) if |x| < 2^-5 : return x+x^3*DP_SIN2_0+x^5*DP_SIN2_1. + * 4) if |x| < Pi/4: return x+x^3*(S0+x^2*(S1+x^2*(S2+x^2*(S3+x^2*S4)))). + * 5) if |x| < 9*Pi/4: + * 5.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0x0e, n=k+1, + * t=|x|-j*Pi/4. + * 5.2) Reconstruction: + * s = sign(x) * (-1.0)^((n>>2)&1) + * if(n&2 != 0) { + * using cos(t) polynomial for |t|<Pi/4, result is + * s * (1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4))))). + * } else { + * using sin(t) polynomial for |t|<Pi/4, result is + * s * t * (1.0+t^2*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4))))). + * } + * 6) if |x| < 2^23, large args: + * 6.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0xfffffffe, n=k+1, + * t=|x|-j*Pi/4. + * 6.2) Reconstruction same as (5.2). + * 7) if |x| >= 2^23, very large args: + * 7.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0xfffffffe, n=k+1, + * t=|x|-j*Pi/4. + * 7.2) Reconstruction same as (5.2). + * 8) if x is Inf, return x-x, and set errno=EDOM. + * 9) if x is NaN, return x-x. + * + * Special cases: + * sin(+-0) = +-0 not raising inexact/underflow, + * sin(subnormal) raises inexact/underflow, + * sin(min_normalized) raises inexact/underflow, + * sin(normalized) raises inexact, + * sin(Inf) = NaN, raises invalid, sets errno to EDOM, + * sin(NaN) = NaN. + */ + +#ifdef PIC +# define MO1(symbol) L(symbol)##@GOTOFF(%ebx) +# define MO2(symbol,reg2,_scale) L(symbol)##@GOTOFF(%ebx,reg2,_scale) +# define CFI_PUSH(REG) cfi_adjust_cfa_offset(4); cfi_rel_offset(REG,0) +# define CFI_POP(REG) cfi_adjust_cfa_offset(-4); cfi_restore(REG) +# define PUSH(REG) pushl REG; CFI_PUSH(REG) +# define POP(REG) popl REG; CFI_POP(REG) +# define ENTRANCE PUSH(%ebx); LOAD_PIC_REG(bx) +# define RETURN POP(%ebx); ret; CFI_PUSH(%ebx) +# define ARG_X 8(%esp) +#else +# define MO1(symbol) L(symbol) +# define MO2(symbol,reg2,_scale) L(symbol)(,reg2,_scale) +# define ENTRANCE +# define RETURN ret +# define ARG_X 4(%esp) +#endif + + .text +ENTRY(__sinf_sse2) + /* Input: single precision x on stack at address ARG_X */ + + ENTRANCE + movl ARG_X, %eax /* Bits of x */ + cvtss2sd ARG_X, %xmm0 /* DP x */ + andl $0x7fffffff, %eax /* |x| */ + + cmpl $0x3f490fdb, %eax /* |x|<Pi/4? */ + jb L(arg_less_pio4) + + /* Here if |x|>=Pi/4 */ + movd %eax, %xmm3 /* SP |x| */ + andpd MO1(DP_ABS_MASK),%xmm0 /* DP |x| */ + movss MO1(SP_INVPIO4), %xmm2 /* SP 1/(Pi/4) */ + + cmpl $0x40e231d6, %eax /* |x|<9*Pi/4? */ + jae L(large_args) + + /* Here if Pi/4<=|x|<9*Pi/4 */ + mulss %xmm3, %xmm2 /* SP |x|/(Pi/4) */ + movl ARG_X, %ecx /* Load x */ + cvttss2si %xmm2, %eax /* k, number of Pi/4 in x */ + shrl $31, %ecx /* sign of x */ + addl $1, %eax /* k+1 */ + movl $0x0e, %edx + andl %eax, %edx /* j = (k+1)&0x0e */ + subsd MO2(PIO4J,%edx,8), %xmm0 /* t = |x| - j * Pi/4 */ + +L(reconstruction): + /* Input: %eax=n, %xmm0=t, %ecx=sign(x) */ + testl $2, %eax /* n&2 != 0? */ + jz L(sin_poly) + +/*L(cos_poly):*/ + /* Here if sin(x) calculated using cos(t) polynomial for |t|<Pi/4: + * y = t*t; z = y*y; + * s = sign(x) * (-1.0)^((n>>2)&1) + * result = s * (1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4))))) + */ + shrl $2, %eax /* n>>2 */ + mulsd %xmm0, %xmm0 /* y=t^2 */ + andl $1, %eax /* (n>>2)&1 */ + movaps %xmm0, %xmm1 /* y */ + mulsd %xmm0, %xmm0 /* z=t^4 */ + + movsd MO1(DP_C4), %xmm4 /* C4 */ + mulsd %xmm0, %xmm4 /* z*C4 */ + xorl %eax, %ecx /* (-1.0)^((n>>2)&1) XOR sign(x) */ + movsd MO1(DP_C3), %xmm3 /* C3 */ + mulsd %xmm0, %xmm3 /* z*C3 */ + addsd MO1(DP_C2), %xmm4 /* C2+z*C4 */ + mulsd %xmm0, %xmm4 /* z*(C2+z*C4) */ + lea -8(%esp), %esp /* Borrow 4 bytes of stack frame */ + addsd MO1(DP_C1), %xmm3 /* C1+z*C3 */ + mulsd %xmm0, %xmm3 /* z*(C1+z*C3) */ + addsd MO1(DP_C0), %xmm4 /* C0+z*(C2+z*C4) */ + mulsd %xmm1, %xmm4 /* y*(C0+z*(C2+z*C4)) */ + + addsd %xmm4, %xmm3 /* y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + /* 1.0+y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + addsd MO1(DP_ONES), %xmm3 + + mulsd MO2(DP_ONES,%ecx,8), %xmm3 /* DP result */ + movsd %xmm3, 0(%esp) /* Move result from sse... */ + fldl 0(%esp) /* ...to FPU. */ + /* Return back 4 bytes of stack frame */ + lea 8(%esp), %esp + RETURN + + .p2align 4 +L(sin_poly): + /* Here if sin(x) calculated using sin(t) polynomial for |t|<Pi/4: + * y = t*t; z = y*y; + * s = sign(x) * (-1.0)^((n>>2)&1) + * result = s * t * (1.0+t^2*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4))))) + */ + + movaps %xmm0, %xmm4 /* t */ + shrl $2, %eax /* n>>2 */ + mulsd %xmm0, %xmm0 /* y=t^2 */ + andl $1, %eax /* (n>>2)&1 */ + movaps %xmm0, %xmm1 /* y */ + xorl %eax, %ecx /* (-1.0)^((n>>2)&1) XOR sign(x) */ + mulsd %xmm0, %xmm0 /* z=t^4 */ + + movsd MO1(DP_S4), %xmm2 /* S4 */ + mulsd %xmm0, %xmm2 /* z*S4 */ + movsd MO1(DP_S3), %xmm3 /* S3 */ + mulsd %xmm0, %xmm3 /* z*S3 */ + lea -8(%esp), %esp /* Borrow 4 bytes of stack frame */ + addsd MO1(DP_S2), %xmm2 /* S2+z*S4 */ + mulsd %xmm0, %xmm2 /* z*(S2+z*S4) */ + addsd MO1(DP_S1), %xmm3 /* S1+z*S3 */ + mulsd %xmm0, %xmm3 /* z*(S1+z*S3) */ + addsd MO1(DP_S0), %xmm2 /* S0+z*(S2+z*S4) */ + mulsd %xmm1, %xmm2 /* y*(S0+z*(S2+z*S4)) */ + /* t*s, where s = sign(x) * (-1.0)^((n>>2)&1) */ + mulsd MO2(DP_ONES,%ecx,8), %xmm4 + addsd %xmm2, %xmm3 /* y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + /* t*s*y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + mulsd %xmm4, %xmm3 + /* t*s*(1.0+y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + addsd %xmm4, %xmm3 + movsd %xmm3, 0(%esp) /* Move result from sse... */ + fldl 0(%esp) /* ...to FPU. */ + /* Return back 4 bytes of stack frame */ + lea 8(%esp), %esp + RETURN + + .p2align 4 +L(large_args): + /* Here if |x|>=9*Pi/4 */ + cmpl $0x7f800000, %eax /* x is Inf or NaN? */ + jae L(arg_inf_or_nan) + + /* Here if finite |x|>=9*Pi/4 */ + cmpl $0x4b000000, %eax /* |x|<2^23? */ + jae L(very_large_args) + + /* Here if 9*Pi/4<=|x|<2^23 */ + movsd MO1(DP_INVPIO4), %xmm1 /* 1/(Pi/4) */ + mulsd %xmm0, %xmm1 /* |x|/(Pi/4) */ + cvttsd2si %xmm1, %eax /* k=trunc(|x|/(Pi/4)) */ + addl $1, %eax /* k+1 */ + movl %eax, %edx + andl $0xfffffffe, %edx /* j=(k+1)&0xfffffffe */ + cvtsi2sdl %edx, %xmm4 /* DP j */ + movl ARG_X, %ecx /* Load x */ + movsd MO1(DP_PIO4HI), %xmm2 /* -PIO4HI = high part of -Pi/4 */ + shrl $31, %ecx /* sign bit of x */ + mulsd %xmm4, %xmm2 /* -j*PIO4HI */ + movsd MO1(DP_PIO4LO), %xmm3 /* -PIO4LO = low part of -Pi/4 */ + addsd %xmm2, %xmm0 /* |x| - j*PIO4HI */ + mulsd %xmm3, %xmm4 /* j*PIO4LO */ + addsd %xmm4, %xmm0 /* t = |x| - j*PIO4HI - j*PIO4LO */ + jmp L(reconstruction) + + .p2align 4 +L(very_large_args): + /* Here if finite |x|>=2^23 */ + + /* bitpos = (ix>>23) - BIAS_32 + 59; */ + shrl $23, %eax /* eb = biased exponent of x */ + /* bitpos = eb - 0x7f + 59, where 0x7f is exponent bias */ + subl $68, %eax + movl $28, %ecx /* %cl=28 */ + movl %eax, %edx /* bitpos copy */ + + /* j = bitpos/28; */ + div %cl /* j in register %al=%ax/%cl */ + movapd %xmm0, %xmm3 /* |x| */ + /* clear unneeded remainder from %ah */ + andl $0xff, %eax + + imull $28, %eax, %ecx /* j*28 */ + movsd MO1(DP_HI_MASK), %xmm4 /* DP_HI_MASK */ + movapd %xmm0, %xmm5 /* |x| */ + mulsd -2*8+MO2(_FPI,%eax,8), %xmm3 /* tmp3 = FPI[j-2]*|x| */ + movapd %xmm0, %xmm1 /* |x| */ + mulsd -1*8+MO2(_FPI,%eax,8), %xmm5 /* tmp2 = FPI[j-1]*|x| */ + mulsd 0*8+MO2(_FPI,%eax,8), %xmm0 /* tmp0 = FPI[j]*|x| */ + addl $19, %ecx /* j*28+19 */ + mulsd 1*8+MO2(_FPI,%eax,8), %xmm1 /* tmp1 = FPI[j+1]*|x| */ + cmpl %ecx, %edx /* bitpos>=j*28+19? */ + jl L(very_large_skip1) + + /* Here if bitpos>=j*28+19 */ + andpd %xmm3, %xmm4 /* HI(tmp3) */ + subsd %xmm4, %xmm3 /* tmp3 = tmp3 - HI(tmp3) */ +L(very_large_skip1): + + movsd MO1(DP_2POW52), %xmm6 + movapd %xmm5, %xmm2 /* tmp2 copy */ + addsd %xmm3, %xmm5 /* tmp5 = tmp3 + tmp2 */ + movl $1, %edx + addsd %xmm5, %xmm6 /* tmp6 = tmp5 + 2^52 */ + movsd 8+MO1(DP_2POW52), %xmm4 + movd %xmm6, %eax /* k = I64_LO(tmp6); */ + addsd %xmm6, %xmm4 /* tmp4 = tmp6 - 2^52 */ + movl ARG_X, %ecx /* Load x */ + comisd %xmm5, %xmm4 /* tmp4 > tmp5? */ + jbe L(very_large_skip2) + + /* Here if tmp4 > tmp5 */ + subl $1, %eax /* k-- */ + addsd 8+MO1(DP_ONES), %xmm4 /* tmp4 -= 1.0 */ +L(very_large_skip2): + + andl %eax, %edx /* k&1 */ + subsd %xmm4, %xmm3 /* tmp3 -= tmp4 */ + addsd MO2(DP_ZERONE,%edx,8), %xmm3 /* t = DP_ZERONE[k&1] + tmp3 */ + addsd %xmm2, %xmm3 /* t += tmp2 */ + shrl $31, %ecx /* sign of x */ + addsd %xmm3, %xmm0 /* t += tmp0 */ + addl $1, %eax /* n=k+1 */ + addsd %xmm1, %xmm0 /* t += tmp1 */ + mulsd MO1(DP_PIO4), %xmm0 /* t *= PI04 */ + + jmp L(reconstruction) /* end of very_large_args peth */ + + .p2align 4 +L(arg_less_pio4): + /* Here if |x|<Pi/4 */ + cmpl $0x3d000000, %eax /* |x|<2^-5? */ + jl L(arg_less_2pn5) + + /* Here if 2^-5<=|x|<Pi/4 */ + movaps %xmm0, %xmm3 /* x */ + mulsd %xmm0, %xmm0 /* y=x^2 */ + movaps %xmm0, %xmm1 /* y */ + mulsd %xmm0, %xmm0 /* z=x^4 */ + movsd MO1(DP_S4), %xmm4 /* S4 */ + mulsd %xmm0, %xmm4 /* z*S4 */ + movsd MO1(DP_S3), %xmm5 /* S3 */ + mulsd %xmm0, %xmm5 /* z*S3 */ + addsd MO1(DP_S2), %xmm4 /* S2+z*S4 */ + mulsd %xmm0, %xmm4 /* z*(S2+z*S4) */ + addsd MO1(DP_S1), %xmm5 /* S1+z*S3 */ + mulsd %xmm0, %xmm5 /* z*(S1+z*S3) */ + addsd MO1(DP_S0), %xmm4 /* S0+z*(S2+z*S4) */ + mulsd %xmm1, %xmm4 /* y*(S0+z*(S2+z*S4)) */ + mulsd %xmm3, %xmm5 /* x*z*(S1+z*S3) */ + mulsd %xmm3, %xmm4 /* x*y*(S0+z*(S2+z*S4)) */ + /* x*y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + addsd %xmm5, %xmm4 + /* x + x*y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + addsd %xmm4, %xmm3 + cvtsd2ss %xmm3, %xmm3 /* SP result */ + +L(epilogue): + lea -4(%esp), %esp /* Borrow 4 bytes of stack frame */ + movss %xmm3, 0(%esp) /* Move result from sse... */ + flds 0(%esp) /* ...to FPU. */ + /* Return back 4 bytes of stack frame */ + lea 4(%esp), %esp + RETURN + + .p2align 4 +L(arg_less_2pn5): + /* Here if |x|<2^-5 */ + cmpl $0x32000000, %eax /* |x|<2^-27? */ + jl L(arg_less_2pn27) + + /* Here if 2^-27<=|x|<2^-5 */ + movaps %xmm0, %xmm1 /* DP x */ + mulsd %xmm0, %xmm0 /* DP x^2 */ + movsd MO1(DP_SIN2_1), %xmm3 /* DP DP_SIN2_1 */ + mulsd %xmm0, %xmm3 /* DP x^2*DP_SIN2_1 */ + addsd MO1(DP_SIN2_0), %xmm3 /* DP DP_SIN2_0+x^2*DP_SIN2_1 */ + mulsd %xmm0, %xmm3 /* DP x^2*DP_SIN2_0+x^4*DP_SIN2_1 */ + mulsd %xmm1, %xmm3 /* DP x^3*DP_SIN2_0+x^5*DP_SIN2_1 */ + addsd %xmm1, %xmm3 /* DP x+x^3*DP_SIN2_0+x^5*DP_SIN2_1 */ + cvtsd2ss %xmm3, %xmm3 /* SP result */ + jmp L(epilogue) + + .p2align 4 +L(arg_less_2pn27): + movss ARG_X, %xmm3 /* SP x */ + cmpl $0, %eax /* x=0? */ + je L(epilogue) /* in case x=0 return sin(+-0)==+-0 */ + /* Here if |x|<2^-27 */ + /* + * Special cases here: + * sin(subnormal) raises inexact/underflow + * sin(min_normalized) raises inexact/underflow + * sin(normalized) raises inexact + */ + movaps %xmm0, %xmm3 /* Copy of DP x */ + mulsd MO1(DP_SMALL), %xmm0 /* x*DP_SMALL */ + subsd %xmm0, %xmm3 /* Result is x-x*DP_SMALL */ + cvtsd2ss %xmm3, %xmm3 /* Result converted to SP */ + jmp L(epilogue) + + .p2align 4 +L(arg_inf_or_nan): + /* Here if |x| is Inf or NAN */ + jne L(skip_errno_setting) /* in case of x is NaN */ + + /* Here if x is Inf. Set errno to EDOM. */ + call JUMPTARGET(__errno_location) + movl $EDOM, (%eax) + + .p2align 4 +L(skip_errno_setting): + /* Here if |x| is Inf or NAN. Continued. */ + movss ARG_X, %xmm3 /* load x */ + subss %xmm3, %xmm3 /* Result is NaN */ + jmp L(epilogue) +END(__sinf_sse2) + + .section .rodata, "a" + .p2align 3 +L(PIO4J): /* Table of j*Pi/4, for j=0,1,..,10 */ + .long 0x00000000,0x00000000 + .long 0x54442d18,0x3fe921fb + .long 0x54442d18,0x3ff921fb + .long 0x7f3321d2,0x4002d97c + .long 0x54442d18,0x400921fb + .long 0x2955385e,0x400f6a7a + .long 0x7f3321d2,0x4012d97c + .long 0xe9bba775,0x4015fdbb + .long 0x54442d18,0x401921fb + .long 0xbeccb2bb,0x401c463a + .long 0x2955385e,0x401f6a7a + .type L(PIO4J), @object + ASM_SIZE_DIRECTIVE(L(PIO4J)) + + .p2align 3 +L(_FPI): /* 4/Pi broken into sum of positive DP values */ + .long 0x00000000,0x00000000 + .long 0x6c000000,0x3ff45f30 + .long 0x2a000000,0x3e3c9c88 + .long 0xa8000000,0x3c54fe13 + .long 0xd0000000,0x3aaf47d4 + .long 0x6c000000,0x38fbb81b + .long 0xe0000000,0x3714acc9 + .long 0x7c000000,0x3560e410 + .long 0x56000000,0x33bca2c7 + .long 0xac000000,0x31fbd778 + .long 0xe0000000,0x300b7246 + .long 0xe8000000,0x2e5d2126 + .long 0x48000000,0x2c970032 + .long 0xe8000000,0x2ad77504 + .long 0xe0000000,0x290921cf + .long 0xb0000000,0x274deb1c + .long 0xe0000000,0x25829a73 + .long 0xbe000000,0x23fd1046 + .long 0x10000000,0x2224baed + .long 0x8e000000,0x20709d33 + .long 0x80000000,0x1e535a2f + .long 0x64000000,0x1cef904e + .long 0x30000000,0x1b0d6398 + .long 0x24000000,0x1964ce7d + .long 0x16000000,0x17b908bf + .type L(_FPI), @object + ASM_SIZE_DIRECTIVE(L(_FPI)) + +/* Coefficients of polynomial + for sin(x)~=x+x^3*DP_SIN2_0+x^5*DP_SIN2_1, |x|<2^-5. */ + .p2align 3 +L(DP_SIN2_0): + .long 0x5543d49d,0xbfc55555 + .type L(DP_SIN2_0), @object + ASM_SIZE_DIRECTIVE(L(DP_SIN2_0)) + + .p2align 3 +L(DP_SIN2_1): + .long 0x75cec8c5,0x3f8110f4 + .type L(DP_SIN2_1), @object + ASM_SIZE_DIRECTIVE(L(DP_SIN2_1)) + + .p2align 3 +L(DP_ZERONE): + .long 0x00000000,0x00000000 /* 0.0 */ + .long 0x00000000,0xbff00000 /* 1.0 */ + .type L(DP_ZERONE), @object + ASM_SIZE_DIRECTIVE(L(DP_ZERONE)) + + .p2align 3 +L(DP_ONES): + .long 0x00000000,0x3ff00000 /* +1.0 */ + .long 0x00000000,0xbff00000 /* -1.0 */ + .type L(DP_ONES), @object + ASM_SIZE_DIRECTIVE(L(DP_ONES)) + +/* Coefficients of polynomial + for sin(t)~=t+t^3*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4)))), |t|<Pi/4. */ + .p2align 3 +L(DP_S3): + .long 0x64e6b5b4,0x3ec71d72 + .type L(DP_S3), @object + ASM_SIZE_DIRECTIVE(L(DP_S3)) + + .p2align 3 +L(DP_S1): + .long 0x10c2688b,0x3f811111 + .type L(DP_S1), @object + ASM_SIZE_DIRECTIVE(L(DP_S1)) + + .p2align 3 +L(DP_S4): + .long 0x1674b58a,0xbe5a947e + .type L(DP_S4), @object + ASM_SIZE_DIRECTIVE(L(DP_S4)) + + .p2align 3 +L(DP_S2): + .long 0x8b4bd1f9,0xbf2a019f + .type L(DP_S2), @object + ASM_SIZE_DIRECTIVE(L(DP_S2)) + + .p2align 3 +L(DP_S0): + .long 0x55551cd9,0xbfc55555 + .type L(DP_S0), @object + ASM_SIZE_DIRECTIVE(L(DP_S0)) + + .p2align 3 +L(DP_SMALL): + .long 0x00000000,0x3cd00000 /* 2^(-50) */ + .type L(DP_SMALL), @object + ASM_SIZE_DIRECTIVE(L(DP_SMALL)) + +/* Coefficients of polynomial + for cos(t)~=1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4)))), |t|<Pi/4. */ + .p2align 3 +L(DP_C3): + .long 0x9ac43cc0,0x3efa00eb + .type L(DP_C3), @object + ASM_SIZE_DIRECTIVE(L(DP_C3)) + + .p2align 3 +L(DP_C1): + .long 0x545c50c7,0x3fa55555 + .type L(DP_C1), @object + ASM_SIZE_DIRECTIVE(L(DP_C1)) + + .p2align 3 +L(DP_C4): + .long 0xdd8844d7,0xbe923c97 + .type L(DP_C4), @object + ASM_SIZE_DIRECTIVE(L(DP_C4)) + + .p2align 3 +L(DP_C2): + .long 0x348b6874,0xbf56c16b + .type L(DP_C2), @object + ASM_SIZE_DIRECTIVE(L(DP_C2)) + + .p2align 3 +L(DP_C0): + .long 0xfffe98ae,0xbfdfffff + .type L(DP_C0), @object + ASM_SIZE_DIRECTIVE(L(DP_C0)) + + .p2align 3 +L(DP_PIO4): + .long 0x54442d18,0x3fe921fb /* Pi/4 */ + .type L(DP_PIO4), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4)) + + .p2align 3 +L(DP_2POW52): + .long 0x00000000,0x43300000 /* +2^52 */ + .long 0x00000000,0xc3300000 /* -2^52 */ + .type L(DP_2POW52), @object + ASM_SIZE_DIRECTIVE(L(DP_2POW52)) + + .p2align 3 +L(DP_INVPIO4): + .long 0x6dc9c883,0x3ff45f30 /* 4/Pi */ + .type L(DP_INVPIO4), @object + ASM_SIZE_DIRECTIVE(L(DP_INVPIO4)) + + .p2align 3 +L(DP_PIO4HI): + .long 0x54000000,0xbfe921fb /* High part of Pi/4 */ + .type L(DP_PIO4HI), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4HI)) + + .p2align 3 +L(DP_PIO4LO): + .long 0x11A62633,0xbe010b46 /* Low part of Pi/4 */ + .type L(DP_PIO4LO), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4LO)) + + .p2align 2 +L(SP_INVPIO4): + .long 0x3fa2f983 /* 4/Pi */ + .type L(SP_INVPIO4), @object + ASM_SIZE_DIRECTIVE(L(SP_INVPIO4)) + + .p2align 4 +L(DP_ABS_MASK): /* Mask for getting DP absolute value */ + .long 0xffffffff,0x7fffffff + .long 0xffffffff,0x7fffffff + .type L(DP_ABS_MASK), @object + ASM_SIZE_DIRECTIVE(L(DP_ABS_MASK)) + + .p2align 3 +L(DP_HI_MASK): /* Mask for getting high 21 bits of DP value */ + .long 0x00000000,0xffffffff + .type L(DP_HI_MASK), @object + ASM_SIZE_DIRECTIVE(L(DP_HI_MASK)) + +weak_alias (__sinf, sinf) diff --git a/libc/sysdeps/i386/i686/fpu/multiarch/s_sinf.c b/libc/sysdeps/i386/i686/fpu/multiarch/s_sinf.c new file mode 100644 index 000000000..80b2fd687 --- /dev/null +++ b/libc/sysdeps/i386/i686/fpu/multiarch/s_sinf.c @@ -0,0 +1,28 @@ +/* Multiple versions of sinf + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 <init-arch.h> + +extern float __sinf_sse2 (float); +extern float __sinf_ia32 (float); +float __sinf (float); + +libm_ifunc (__sinf, HAS_SSE2 ? __sinf_sse2 : __sinf_ia32); +weak_alias (__sinf, sinf); +#define SINF __sinf_ia32 +#include <sysdeps/ieee754/flt-32/s_sinf.c> diff --git a/libc/sysdeps/ieee754/flt-32/s_cosf.c b/libc/sysdeps/ieee754/flt-32/s_cosf.c index f4bd81904..864ab27a4 100644 --- a/libc/sysdeps/ieee754/flt-32/s_cosf.c +++ b/libc/sysdeps/ieee754/flt-32/s_cosf.c @@ -23,7 +23,13 @@ static char rcsid[] = "$NetBSD: s_cosf.c,v 1.4 1995/05/10 20:47:03 jtc Exp $"; static const float one=1.0; -float __cosf(float x) +#ifndef COSF +# define COSF_FUNC __cosf +#else +# define COSF_FUNC COSF +#endif + +float COSF_FUNC(float x) { float y[2],z=0.0; int32_t n,ix; @@ -53,4 +59,7 @@ float __cosf(float x) } } } + +#ifndef COSF weak_alias (__cosf, cosf) +#endif diff --git a/libc/sysdeps/ieee754/flt-32/s_sinf.c b/libc/sysdeps/ieee754/flt-32/s_sinf.c index 02fa29f23..916e34557 100644 --- a/libc/sysdeps/ieee754/flt-32/s_sinf.c +++ b/libc/sysdeps/ieee754/flt-32/s_sinf.c @@ -21,7 +21,13 @@ static char rcsid[] = "$NetBSD: s_sinf.c,v 1.4 1995/05/10 20:48:16 jtc Exp $"; #include <math.h> #include <math_private.h> -float __sinf(float x) +#ifndef SINF +# define SINF_FUNC __sinf +#else +# define SINF_FUNC SINF +#endif + +float SINF_FUNC(float x) { float y[2],z=0.0; int32_t n, ix; @@ -51,4 +57,7 @@ float __sinf(float x) } } } + +#ifndef SINF weak_alias (__sinf, sinf) +#endif diff --git a/libc/sysdeps/mach/bits/libc-lock.h b/libc/sysdeps/mach/bits/libc-lock.h index 110e25e96..94877e0ea 100644 --- a/libc/sysdeps/mach/bits/libc-lock.h +++ b/libc/sysdeps/mach/bits/libc-lock.h @@ -137,7 +137,6 @@ void *__libc_getspecific (__libc_key_t key); #define __libc_lock_lock_recursive __libc_lock_lock #define __rtld_lock_define_initialized_recursive __libc_lock_define_initialized -#define __rtld_lock_init_recursive __libc_lock_init #define __rtld_lock_fini_recursive __libc_lock_fini #define __rtld_lock_trylock_recursive __libc_lock_trylock #define __rtld_lock_unlock_recursive __libc_lock_unlock diff --git a/libc/sysdeps/mach/hurd/_G_config.h b/libc/sysdeps/mach/hurd/_G_config.h index 9ecd4aad3..b3a7db72a 100644 --- a/libc/sysdeps/mach/hurd/_G_config.h +++ b/libc/sysdeps/mach/hurd/_G_config.h @@ -18,7 +18,6 @@ # define __need_wint_t #endif #include <wchar.h> -#define _G_size_t size_t typedef struct { __off_t __pos; @@ -29,13 +28,7 @@ typedef struct __off64_t __pos; __mbstate_t __state; } _G_fpos64_t; -#define _G_ssize_t __ssize_t -#define _G_off_t __off_t #define _G_off64_t __off64_t -#define _G_pid_t __pid_t -#define _G_uid_t __uid_t -#define _G_wchar_t wchar_t -#define _G_wint_t wint_t #define _G_stat64 stat64 #if defined _LIBC || defined _GLIBCPP_USE_WCHAR_T # include <gconv.h> @@ -50,25 +43,11 @@ typedef union } _G_iconv_t; #endif -typedef int _G_int16_t __attribute__ ((__mode__ (__HI__))); -typedef int _G_int32_t __attribute__ ((__mode__ (__SI__))); -typedef unsigned int _G_uint16_t __attribute__ ((__mode__ (__HI__))); -typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__))); - -#define _G_HAVE_BOOL 1 - /* These library features are always available in the GNU C library. */ -#define _G_HAVE_ATEXIT 1 -#define _G_HAVE_SYS_WAIT 1 -#define _G_NEED_STDARG_H 1 #define _G_va_list __gnuc_va_list -#define _G_HAVE_PRINTF_FP 1 #define _G_HAVE_MMAP 1 -#define _G_HAVE_LONG_DOUBLE_IO 1 -#define _G_HAVE_IO_FILE_OPEN 1 -#define _G_HAVE_IO_GETLINE_INFO 1 #define _G_IO_IO_FILE_VERSION 0x20001 @@ -82,11 +61,4 @@ typedef unsigned int _G_uint32_t __attribute__ ((__mode__ (__SI__))); #define _G_BUFSIZ 8192 -/* These are the vtbl details for ELF. */ -#define _G_NAMES_HAVE_UNDERSCORE 0 -#define _G_VTABLE_LABEL_HAS_LENGTH 1 -#define _G_USING_THUNKS 1 -#define _G_VTABLE_LABEL_PREFIX "__vt_" -#define _G_VTABLE_LABEL_PREFIX_ID __vt_ - #endif /* _G_config.h */ diff --git a/libc/sysdeps/mach/hurd/bits/libc-lock.h b/libc/sysdeps/mach/hurd/bits/libc-lock.h index d18a10c45..e8cb71bfd 100644 --- a/libc/sysdeps/mach/hurd/bits/libc-lock.h +++ b/libc/sysdeps/mach/hurd/bits/libc-lock.h @@ -119,8 +119,6 @@ typedef struct __libc_lock_recursive_opaque__ __libc_lock_recursive_t; }) -#define __rtld_lock_init_recursive(NAME) \ - __libc_lock_init_recursive (NAME) #define __rtld_lock_initialize(NAME) \ (void) ((NAME) = (__rtld_lock_recursive_t) _RTLD_LOCK_RECURSIVE_INITIALIZER) #define __rtld_lock_trylock_recursive(NAME) \ diff --git a/libc/sysdeps/s390/fpu/get-rounding-mode.h b/libc/sysdeps/s390/fpu/get-rounding-mode.h new file mode 100644 index 000000000..3e427eca2 --- /dev/null +++ b/libc/sysdeps/s390/fpu/get-rounding-mode.h @@ -0,0 +1,37 @@ +/* Determine floating-point rounding mode within libc. S/390 version. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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/>. */ + +#ifndef _S390_GET_ROUNDING_MODE_H +#define _S390_GET_ROUNDING_MODE_H 1 + +#include <fenv.h> +#include <fenv_libc.h> +#include <fpu_control.h> + +/* Return the floating-point rounding mode. */ + +static inline int +get_rounding_mode (void) +{ + fpu_control_t fc; + + _FPU_GETCW (fc); + return fc & FPC_RM_MASK; +} + +#endif /* get-rounding-mode.h */ diff --git a/libc/sysdeps/s390/s390-32/multiarch/Makefile b/libc/sysdeps/s390/s390-32/multiarch/Makefile index 5b0cd49c7..9baeecda6 100644 --- a/libc/sysdeps/s390/s390-32/multiarch/Makefile +++ b/libc/sysdeps/s390/s390-32/multiarch/Makefile @@ -1,9 +1,3 @@ -ASFLAGS-.o += -Wa,-mzarch -ASFLAGS-.os += -Wa,-mzarch -ASFLAGS-.op += -Wa,-mzarch -ASFLAGS-.og += -Wa,-mzarch -ASFLAGS-.ob += -Wa,-mzarch -ASFLAGS-.oS += -Wa,-mzarch ifeq ($(subdir),string) sysdep_routines += ifunc-resolve memset memcpy memcmp endif diff --git a/libc/sysdeps/s390/s390-32/multiarch/ifunc-resolve.c b/libc/sysdeps/s390/s390-32/multiarch/ifunc-resolve.c index fd6e36706..f1bf8a3dc 100644 --- a/libc/sysdeps/s390/s390-32/multiarch/ifunc-resolve.c +++ b/libc/sysdeps/s390/s390-32/multiarch/ifunc-resolve.c @@ -32,14 +32,17 @@ ".globl __GI_" #FUNC "\n\t" \ ".set __GI_" #FUNC "," #FUNC "\n"); \ \ - extern void *FUNC##_z10; \ - extern void *FUNC##_z196; \ - extern void *FUNC##_g5; \ + /* Make the declarations of the optimized functions hidden in order + to prevent GOT slots being generated for them. */ \ + extern __attribute__((visibility("hidden"))) void *FUNC##_z196; \ + extern __attribute__((visibility("hidden"))) void *FUNC##_z10; \ + extern __attribute__((visibility("hidden"))) void *FUNC##_g5; \ \ void *resolve_##FUNC (unsigned long int dl_hwcap) \ { \ if ((dl_hwcap & HWCAP_S390_STFLE) \ - && (dl_hwcap & HWCAP_S390_HIGH_GPRS)) /* Implies zarch */ \ + && (dl_hwcap & HWCAP_S390_ZARCH) \ + && (dl_hwcap & HWCAP_S390_HIGH_GPRS)) \ { \ /* We want just 1 double word to be returned. */ \ register unsigned long reg0 asm("0") = 0; \ diff --git a/libc/sysdeps/s390/s390-32/multiarch/memcmp.S b/libc/sysdeps/s390/s390-32/multiarch/memcmp.S index cd8ea86b0..9ca88911c 100644 --- a/libc/sysdeps/s390/s390-32/multiarch/memcmp.S +++ b/libc/sysdeps/s390/s390-32/multiarch/memcmp.S @@ -31,6 +31,7 @@ ENTRY(memcmp_z196) .machine "z196" + .machinemode "zarch_nohighgprs" ltr %r4,%r4 je .L_Z196_4 ahi %r4,-1 @@ -64,6 +65,7 @@ END(memcmp_z196) ENTRY(memcmp_z10) .machine "z10" + .machinemode "zarch_nohighgprs" ltr %r4,%r4 je .L_Z10_4 ahi %r4,-1 diff --git a/libc/sysdeps/s390/s390-32/multiarch/memcpy.S b/libc/sysdeps/s390/s390-32/multiarch/memcpy.S index 40f4acfbb..7b85602aa 100644 --- a/libc/sysdeps/s390/s390-32/multiarch/memcpy.S +++ b/libc/sysdeps/s390/s390-32/multiarch/memcpy.S @@ -31,6 +31,7 @@ ENTRY(memcpy_z196) .machine "z196" + .machinemode "zarch_nohighgprs" llgfr %r4,%r4 ltgr %r4,%r4 je .L_Z196_4 @@ -61,6 +62,7 @@ END(memcpy_z196) ENTRY(memcpy_z10) .machine "z10" + .machinemode "zarch_nohighgprs" llgfr %r4,%r4 cgije %r4,0,.L_Z10_4 aghi %r4,-1 diff --git a/libc/sysdeps/s390/s390-32/multiarch/memset.S b/libc/sysdeps/s390/s390-32/multiarch/memset.S index 5ce7b4de8..ba43d671c 100644 --- a/libc/sysdeps/s390/s390-32/multiarch/memset.S +++ b/libc/sysdeps/s390/s390-32/multiarch/memset.S @@ -31,6 +31,7 @@ ENTRY(memset_z196) .machine "z196" + .machinemode "zarch_nohighgprs" llgfr %r4,%r4 ltgr %r4,%r4 je .L_Z196_4 @@ -62,6 +63,7 @@ END(memset_z196) ENTRY(memset_z10) .machine "z10" + .machinemode "zarch_nohighgprs" llgfr %r4,%r4 cgije %r4,0,.L_Z10_4 stc %r3,0(%r2) diff --git a/libc/sysdeps/s390/s390-64/multiarch/ifunc-resolve.c b/libc/sysdeps/s390/s390-64/multiarch/ifunc-resolve.c index f980bc939..5f5676490 100644 --- a/libc/sysdeps/s390/s390-64/multiarch/ifunc-resolve.c +++ b/libc/sysdeps/s390/s390-64/multiarch/ifunc-resolve.c @@ -32,9 +32,11 @@ ".globl __GI_" #FUNC "\n\t" \ ".set __GI_" #FUNC "," #FUNC "\n"); \ \ - extern void *FUNC##_z10; \ - extern void *FUNC##_z196; \ - extern void *FUNC##_z900; \ + /* Make the declarations of the optimized functions hidden in order + to prevent GOT slots being generated for them. */ \ + extern __attribute__((visibility("hidden"))) void *FUNC##_z196; \ + extern __attribute__((visibility("hidden"))) void *FUNC##_z10; \ + extern __attribute__((visibility("hidden"))) void *FUNC##_z900; \ \ void *resolve_##FUNC (unsigned long int dl_hwcap) \ { \ diff --git a/libc/sysdeps/sparc/bits/hwcap.h b/libc/sysdeps/sparc/bits/hwcap.h index d922d7b0e..74ca130bb 100644 --- a/libc/sysdeps/sparc/bits/hwcap.h +++ b/libc/sysdeps/sparc/bits/hwcap.h @@ -45,3 +45,6 @@ #define HWCAP_SPARC_IMA 0x00400000 #define HWCAP_SPARC_ASI_CACHE_SPARING \ 0x00800000 +#define HWCAP_SPARC_PAUSE 0x01000000 +#define HWCAP_SPARC_CBCOND 0x02000000 +#define HWCAP_SPARC_CRYPTO 0x04000000 diff --git a/libc/sysdeps/sparc/dl-procinfo.c b/libc/sysdeps/sparc/dl-procinfo.c index 6e107dd1d..8280e0179 100644 --- a/libc/sysdeps/sparc/dl-procinfo.c +++ b/libc/sysdeps/sparc/dl-procinfo.c @@ -46,13 +46,13 @@ #if !defined PROCINFO_DECL && defined SHARED ._dl_sparc_cap_flags #else -PROCINFO_CLASS const char _dl_sparc_cap_flags[24][11] +PROCINFO_CLASS const char _dl_sparc_cap_flags[27][11] #endif #ifndef PROCINFO_DECL = { "flush", "stbar", "swap", "muldiv", "v9", "ultra3", "v9v", "v9v2", "mul32", "div32", "fsmuld", "v8plus", "popc", "vis", "vis2", "ASIBlkInit", "fmaf", "vis3", "hpc", "random", "trans", "fjfmau", - "ima", "cspare" } + "ima", "cspare", "pause", "cbcond", "crypto" } #endif #if !defined SHARED || defined PROCINFO_DECL ; diff --git a/libc/sysdeps/sparc/dl-procinfo.h b/libc/sysdeps/sparc/dl-procinfo.h index 8ceb83072..6ae876828 100644 --- a/libc/sysdeps/sparc/dl-procinfo.h +++ b/libc/sysdeps/sparc/dl-procinfo.h @@ -24,7 +24,7 @@ #include <ldsodefs.h> #include <sysdep.h> -#define _DL_HWCAP_COUNT 24 +#define _DL_HWCAP_COUNT 27 static inline int __attribute__ ((unused)) diff --git a/libc/sysdeps/sparc/fpu/libm-test-ulps b/libc/sysdeps/sparc/fpu/libm-test-ulps index 74af9d571..b7dc3b483 100644 --- a/libc/sysdeps/sparc/fpu/libm-test-ulps +++ b/libc/sysdeps/sparc/fpu/libm-test-ulps @@ -1187,6 +1187,12 @@ idouble: 1 ifloat: 1 # cos +Test "cos (0x1p+120) == -9.25879022854837867303861764107414946730833e-01": +float: 1 +ifloat: 1 +Test "cos (0x1p+127) == 7.81914638714960072263910298466369236613162e-01": +float: 1 +ifloat: 1 Test "cos (M_PI_6l * 2.0) == 0.5": double: 1 idouble: 1 @@ -2490,6 +2496,12 @@ float: 1 ifloat: 1 # sincos +Test "sincos (0x1p+120, &sin_res, &cos_res) puts -9.25879022854837867303861764107414946730833e-01 in cos_res": +float: 1 +ifloat: 1 +Test "sincos (0x1p+127, &sin_res, &cos_res) puts 7.81914638714960072263910298466369236613162e-01 in cos_res": +float: 1 +ifloat: 1 Test "sincos (M_PI_6l*2.0, &sin_res, &cos_res) puts 0.5 in cos_res": double: 1 idouble: 1 diff --git a/libc/sysdeps/sparc/sparc32/sparcv9/addmul_1.S b/libc/sysdeps/sparc/sparc32/sparcv9/addmul_1.S new file mode 100644 index 000000000..563bfb1c0 --- /dev/null +++ b/libc/sysdeps/sparc/sparc32/sparcv9/addmul_1.S @@ -0,0 +1 @@ +#include <sparcv8/addmul_1.S> diff --git a/libc/sysdeps/sparc/sparc32/sparcv9/mul_1.S b/libc/sysdeps/sparc/sparc32/sparcv9/mul_1.S new file mode 100644 index 000000000..42284eada --- /dev/null +++ b/libc/sysdeps/sparc/sparc32/sparcv9/mul_1.S @@ -0,0 +1 @@ +#include <sparcv8/mul_1.S> diff --git a/libc/sysdeps/sparc/sparc32/sparcv9/submul_1.S b/libc/sysdeps/sparc/sparc32/sparcv9/submul_1.S new file mode 100644 index 000000000..de69533f6 --- /dev/null +++ b/libc/sysdeps/sparc/sparc32/sparcv9/submul_1.S @@ -0,0 +1 @@ +#include <sparcv8/submul_1.S> diff --git a/libc/sysdeps/unix/sysv/linux/clock_getcpuclockid.c b/libc/sysdeps/unix/sysv/linux/clock_getcpuclockid.c index 1cfdf3489..8700354a9 100644 --- a/libc/sysdeps/unix/sysv/linux/clock_getcpuclockid.c +++ b/libc/sysdeps/unix/sysv/linux/clock_getcpuclockid.c @@ -29,60 +29,24 @@ int clock_getcpuclockid (pid_t pid, clockid_t *clock_id) { -#ifdef __NR_clock_getres /* The clockid_t value is a simple computation from the PID. But we do a clock_getres call to validate it. */ const clockid_t pidclock = MAKE_PROCESS_CPUCLOCK (pid, CPUCLOCK_SCHED); -# if !(__ASSUME_POSIX_CPU_TIMERS > 0) - extern int __libc_missing_posix_cpu_timers attribute_hidden; - if (!__libc_missing_posix_cpu_timers) -# endif + INTERNAL_SYSCALL_DECL (err); + int r = INTERNAL_SYSCALL (clock_getres, err, 2, pidclock, NULL); + if (!INTERNAL_SYSCALL_ERROR_P (r, err)) { - INTERNAL_SYSCALL_DECL (err); - int r = INTERNAL_SYSCALL (clock_getres, err, 2, pidclock, NULL); - if (!INTERNAL_SYSCALL_ERROR_P (r, err)) - { - *clock_id = pidclock; - return 0; - } - - if (INTERNAL_SYSCALL_ERRNO (r, err) == EINVAL) - { -# if !(__ASSUME_POSIX_CPU_TIMERS > 0) - if (pidclock == MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED) - || INTERNAL_SYSCALL_ERROR_P (INTERNAL_SYSCALL - (clock_getres, err, 2, - MAKE_PROCESS_CPUCLOCK - (0, CPUCLOCK_SCHED), NULL), - err)) - /* The kernel doesn't support these clocks at all. */ - __libc_missing_posix_cpu_timers = 1; - else -# endif - /* The clock_getres system call checked the PID for us. */ - return ESRCH; - } - else - return INTERNAL_SYSCALL_ERRNO (r, err); + *clock_id = pidclock; + return 0; } -#endif - - /* We don't allow any process ID but our own. */ - if (pid != 0 && pid != getpid ()) - return EPERM; -#ifdef CLOCK_PROCESS_CPUTIME_ID - if (HAS_CPUCLOCK) + if (INTERNAL_SYSCALL_ERRNO (r, err) == EINVAL) { - /* Store the number. */ - *clock_id = CLOCK_PROCESS_CPUTIME_ID; - - return 0; + /* The clock_getres system call checked the PID for us. */ + return ESRCH; } -#endif - - /* We don't have a timer for that. */ - return ENOENT; + else + return INTERNAL_SYSCALL_ERRNO (r, err); } diff --git a/libc/sysdeps/unix/sysv/linux/clock_getres.c b/libc/sysdeps/unix/sysv/linux/clock_getres.c index 2bada33b4..1e87dd9a8 100644 --- a/libc/sysdeps/unix/sysv/linux/clock_getres.c +++ b/libc/sysdeps/unix/sysv/linux/clock_getres.c @@ -46,89 +46,11 @@ case CLOCK_MONOTONIC_COARSE: \ SYSCALL_GETRES -#ifdef __NR_clock_getres /* We handled the REALTIME clock here. */ -# define HANDLED_REALTIME 1 -# define HANDLED_CPUTIME 1 +#define HANDLED_REALTIME 1 +#define HANDLED_CPUTIME 1 -# if __ASSUME_POSIX_CPU_TIMERS > 0 - -# define SYSDEP_GETRES_CPU SYSCALL_GETRES -# define SYSDEP_GETRES_CPUTIME /* Default catches them too. */ - -# else - -extern int __libc_missing_posix_cpu_timers attribute_hidden; - -static int -maybe_syscall_getres_cpu (clockid_t clock_id, struct timespec *res) -{ - int e = EINVAL; - - if (!__libc_missing_posix_cpu_timers) - { - INTERNAL_SYSCALL_DECL (err); - int r = INTERNAL_VSYSCALL (clock_getres, err, 2, clock_id, res); - if (!INTERNAL_SYSCALL_ERROR_P (r, err)) - return 0; - - e = INTERNAL_SYSCALL_ERRNO (r, err); - if (e == EINVAL) - { - /* Check whether the kernel supports CPU clocks at all. - If not, record it for the future. */ - r = INTERNAL_VSYSCALL (clock_getres, err, 2, - MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED), - NULL); - if (INTERNAL_SYSCALL_ERROR_P (r, err)) - __libc_missing_posix_cpu_timers = 1; - } - } - - return e; -} - -# define SYSDEP_GETRES_CPU \ - retval = maybe_syscall_getres_cpu (clock_id, res); \ - if (retval == 0) \ - break; \ - if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \ - { \ - __set_errno (retval); \ - retval = -1; \ - break; \ - } \ - retval = -1 /* Otherwise continue on to the HP_TIMING version. */; - -static inline int -maybe_syscall_getres_cputime (clockid_t clock_id, struct timespec *res) -{ - return maybe_syscall_getres_cpu - (clock_id == CLOCK_THREAD_CPUTIME_ID - ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED) - : MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED), - res); -} - -# define SYSDEP_GETRES_CPUTIME \ - case CLOCK_PROCESS_CPUTIME_ID: \ - case CLOCK_THREAD_CPUTIME_ID: \ - retval = maybe_syscall_getres_cputime (clock_id, res); \ - if (retval == 0) \ - break; \ - if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \ - { \ - __set_errno (retval); \ - retval = -1; \ - break; \ - } \ - retval = hp_timing_getres (res); \ - break; -# if !HP_TIMING_AVAIL -# define hp_timing_getres(res) (__set_errno (EINVAL), -1) -# endif - -# endif -#endif +#define SYSDEP_GETRES_CPU SYSCALL_GETRES +#define SYSDEP_GETRES_CPUTIME /* Default catches them too. */ #include <sysdeps/posix/clock_getres.c> diff --git a/libc/sysdeps/unix/sysv/linux/clock_gettime.c b/libc/sysdeps/unix/sysv/linux/clock_gettime.c index e333d8d9e..05dfb9d09 100644 --- a/libc/sysdeps/unix/sysv/linux/clock_gettime.c +++ b/libc/sysdeps/unix/sysv/linux/clock_gettime.c @@ -49,99 +49,13 @@ retval = SYSCALL_GETTIME (clock_id, tp); \ break -#ifdef __NR_clock_gettime /* We handled the REALTIME clock here. */ -# define HANDLED_REALTIME 1 -# define HANDLED_CPUTIME 1 +#define HANDLED_REALTIME 1 +#define HANDLED_CPUTIME 1 -# if __ASSUME_POSIX_CPU_TIMERS > 0 - -# define SYSDEP_GETTIME_CPU(clock_id, tp) \ +#define SYSDEP_GETTIME_CPU(clock_id, tp) \ retval = SYSCALL_GETTIME (clock_id, tp); \ break -# define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */ - -# else - -int __libc_missing_posix_cpu_timers attribute_hidden; - -static int -maybe_syscall_gettime_cpu (clockid_t clock_id, struct timespec *tp) -{ - int e = EINVAL; - - if (!__libc_missing_posix_cpu_timers) - { - INTERNAL_SYSCALL_DECL (err); - int r = INTERNAL_GETTIME (clock_id, tp); - if (!INTERNAL_SYSCALL_ERROR_P (r, err)) - return 0; - - e = INTERNAL_SYSCALL_ERRNO (r, err); - if (e == EINVAL) - { -# ifdef HAVE_CLOCK_GETRES_VSYSCALL - /* Check whether the kernel supports CPU clocks at all. - If not, record it for the future. */ - r = INTERNAL_VSYSCALL (clock_getres, err, 2, - MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED), - NULL); -# else - /* Check whether the kernel supports CPU clocks at all. - If not, record it for the future. */ - r = INTERNAL_SYSCALL (clock_getres, err, 2, - MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED), - NULL); -# endif - if (INTERNAL_SYSCALL_ERROR_P (r, err)) - __libc_missing_posix_cpu_timers = 1; - } - } - - return e; -} - -# define SYSDEP_GETTIME_CPU(clock_id, tp) \ - retval = maybe_syscall_gettime_cpu (clock_id, tp); \ - if (retval == 0) \ - break; \ - if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \ - { \ - __set_errno (retval); \ - retval = -1; \ - break; \ - } \ - retval = -1 /* Otherwise continue on to the HP_TIMING version. */; - -static inline int -maybe_syscall_gettime_cputime (clockid_t clock_id, struct timespec *tp) -{ - return maybe_syscall_gettime_cpu - (clock_id == CLOCK_THREAD_CPUTIME_ID - ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED) - : MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED), - tp); -} - -# define SYSDEP_GETTIME_CPUTIME \ - case CLOCK_PROCESS_CPUTIME_ID: \ - case CLOCK_THREAD_CPUTIME_ID: \ - retval = maybe_syscall_gettime_cputime (clock_id, tp); \ - if (retval == 0) \ - break; \ - if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \ - { \ - __set_errno (retval); \ - retval = -1; \ - break; \ - } \ - retval = hp_timing_gettime (clock_id, tp); \ - break -# if !HP_TIMING_AVAIL -# define hp_timing_gettime(clock_id, tp) (__set_errno (EINVAL), -1) -# endif - -# endif -#endif +#define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */ #include <sysdeps/unix/clock_gettime.c> diff --git a/libc/sysdeps/unix/sysv/linux/clock_settime.c b/libc/sysdeps/unix/sysv/linux/clock_settime.c index f75ceca24..fde662177 100644 --- a/libc/sysdeps/unix/sysv/linux/clock_settime.c +++ b/libc/sysdeps/unix/sysv/linux/clock_settime.c @@ -31,38 +31,6 @@ # include <bits/libc-vdso.h> #endif -#if __ASSUME_POSIX_CPU_TIMERS <= 0 && defined __NR_clock_settime -extern int __libc_missing_posix_cpu_timers attribute_hidden; - -static int -maybe_syscall_settime_cpu (clockid_t clock_id, const struct timespec *tp) -{ - int e = EINVAL; - - if (!__libc_missing_posix_cpu_timers) - { - INTERNAL_SYSCALL_DECL (err); - int r = INTERNAL_SYSCALL (clock_settime, err, 2, clock_id, tp); - if (!INTERNAL_SYSCALL_ERROR_P (r, err)) - return 0; - - e = INTERNAL_SYSCALL_ERRNO (r, err); - if (e == EINVAL) - { - /* Check whether the kernel supports CPU clocks at all. - If not, record it for the future. */ - r = INTERNAL_VSYSCALL (clock_getres, err, 2, - MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED), - NULL); - if (INTERNAL_SYSCALL_ERROR_P (r, err)) - __libc_missing_posix_cpu_timers = 1; - } - } - - return e; -} -#endif - /* The REALTIME clock is definitely supported in the kernel. */ #define SYSDEP_SETTIME \ @@ -70,27 +38,11 @@ maybe_syscall_settime_cpu (clockid_t clock_id, const struct timespec *tp) retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp); \ break -#ifdef __NR_clock_settime /* We handled the REALTIME clock here. */ -# define HANDLED_REALTIME 1 -#endif +#define HANDLED_REALTIME 1 -#if __ASSUME_POSIX_CPU_TIMERS > 0 -# define HANDLED_CPUTIME 1 -# define SYSDEP_SETTIME_CPU \ +#define HANDLED_CPUTIME 1 +#define SYSDEP_SETTIME_CPU \ retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp) -#elif defined __NR_clock_settime -# define SYSDEP_SETTIME_CPU \ - retval = maybe_syscall_settime_cpu (clock_id, tp); \ - if (retval == 0) \ - break; \ - if (retval != EINVAL || !__libc_missing_posix_cpu_timers) \ - { \ - __set_errno (retval); \ - retval = -1; \ - break; \ - } \ - do { } while (0) -#endif #include <sysdeps/unix/clock_settime.c> diff --git a/libc/sysdeps/unix/sysv/linux/kernel-features.h b/libc/sysdeps/unix/sysv/linux/kernel-features.h index 33fca5c4f..61bf32d1b 100644 --- a/libc/sysdeps/unix/sysv/linux/kernel-features.h +++ b/libc/sysdeps/unix/sysv/linux/kernel-features.h @@ -57,9 +57,6 @@ MIPS n32). */ #define __ASSUME_GETDENTS64_SYSCALL 1 -/* Beginning with 2.6.12 the clock and timer supports CPU clocks. */ -#define __ASSUME_POSIX_CPU_TIMERS 1 - /* The statfs64 syscalls are available in 2.5.74 (but not for alpha). */ #define __ASSUME_STATFS64 1 diff --git a/libc/sysdeps/unix/sysv/linux/malloc-sysdep.h b/libc/sysdeps/unix/sysv/linux/malloc-sysdep.h new file mode 100644 index 000000000..f926aeaff --- /dev/null +++ b/libc/sysdeps/unix/sysv/linux/malloc-sysdep.h @@ -0,0 +1,57 @@ +/* System-specific malloc support functions. Linux version. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 <fcntl.h> +#include <not-cancel.h> + +/* The Linux kernel overcommits address space by default and if there is not + enough memory available, it uses various parameters to decide the process to + kill. It is however possible to disable or curb this overcommit behavior + by setting the proc sysctl vm.overcommit_memory to the value '2' and with + that, a process is only allowed to use the maximum of a pre-determined + fraction of the total address space. In such a case, we want to make sure + that we are judicious with our heap usage as well, and explicitly give away + the freed top of the heap to reduce our commit charge. See the proc(5) man + page to know more about overcommit behavior. + + Other than that, we also force an unmap in a secure exec. */ +static inline bool +check_may_shrink_heap (void) +{ + static int may_shrink_heap = -1; + + if (__builtin_expect (may_shrink_heap >= 0, 1)) + return may_shrink_heap; + + may_shrink_heap = __libc_enable_secure; + + if (__builtin_expect (may_shrink_heap == 0, 1)) + { + int fd = open_not_cancel_2 ("/proc/sys/vm/overcommit_memory", + O_RDONLY | O_CLOEXEC); + if (fd >= 0) + { + char val; + ssize_t n = read_not_cancel (fd, &val, 1); + may_shrink_heap = n > 0 && val == '2'; + close_not_cancel_no_status (fd); + } + } + + return may_shrink_heap; +} diff --git a/libc/sysdeps/unix/sysv/linux/ttyname.c b/libc/sysdeps/unix/sysv/linux/ttyname.c index 3dacd40c2..d3070c3ba 100644 --- a/libc/sysdeps/unix/sysv/linux/ttyname.c +++ b/libc/sysdeps/unix/sysv/linux/ttyname.c @@ -148,12 +148,6 @@ ttyname (int fd) } ssize_t len = __readlink (procname, ttyname_buf, buflen); - if (__builtin_expect (len == -1 && errno == ENOENT, 0)) - { - __set_errno (EBADF); - return NULL; - } - if (__builtin_expect (len != -1, 1)) { if ((size_t) len >= buflen) diff --git a/libc/sysdeps/unix/sysv/linux/ttyname_r.c b/libc/sysdeps/unix/sysv/linux/ttyname_r.c index 2dd678134..211ed189b 100644 --- a/libc/sysdeps/unix/sysv/linux/ttyname_r.c +++ b/libc/sysdeps/unix/sysv/linux/ttyname_r.c @@ -128,12 +128,6 @@ __ttyname_r (int fd, char *buf, size_t buflen) *_fitoa_word (fd, __stpcpy (procname, "/proc/self/fd/"), 10, 0) = '\0'; ssize_t ret = __readlink (procname, buf, buflen - 1); - if (__builtin_expect (ret == -1 && errno == ENOENT, 0)) - { - __set_errno (EBADF); - return EBADF; - } - if (__builtin_expect (ret == -1 && errno == ENAMETOOLONG, 0)) { __set_errno (ERANGE); diff --git a/libc/sysdeps/wordsize-64/Makefile b/libc/sysdeps/wordsize-64/Makefile index 9903f51f9..2fa934751 100644 --- a/libc/sysdeps/wordsize-64/Makefile +++ b/libc/sysdeps/wordsize-64/Makefile @@ -1,6 +1,3 @@ ifeq ($(subdir),misc) tests += tst-writev - -# Time enough for a large writev syscall to complete. -tst-writev-ENV = TIMEOUTFACTOR="10" endif diff --git a/libc/sysdeps/wordsize-64/tst-writev.c b/libc/sysdeps/wordsize-64/tst-writev.c index 49a809cfa..0bc2f70b6 100644 --- a/libc/sysdeps/wordsize-64/tst-writev.c +++ b/libc/sysdeps/wordsize-64/tst-writev.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Free Software Foundation, Inc. +/* Copyright (C) 2011-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ryan S. Arnold <rsa@us.ibm.com>, 2011. @@ -108,5 +108,8 @@ do_test (void) return 0; } +/* Time enough for a large writev syscall to complete. */ +#define TIMEOUT 20 + #define TEST_FUNCTION do_test () #include "../test-skeleton.c" diff --git a/libc/sysdeps/x86_64/Makefile b/libc/sysdeps/x86_64/Makefile index d4525bc7c..0acb69a17 100644 --- a/libc/sysdeps/x86_64/Makefile +++ b/libc/sysdeps/x86_64/Makefile @@ -41,7 +41,7 @@ $(objpfx)tst-quad2pie: $(objpfx)tst-quadmod2pie.o tests: $(objpfx)tst-xmmymm.out $(objpfx)tst-xmmymm.out: ../sysdeps/x86_64/tst-xmmymm.sh $(objpfx)ld.so @echo "Checking ld.so for SSE register use. This will take a few seconds..." - $(SHELL) -e $< $(objpfx) > $@ + $(SHELL) $< $(objpfx) > $@ endif ifeq ($(subdir),csu) diff --git a/libc/sysdeps/x86_64/dl-machine.h b/libc/sysdeps/x86_64/dl-machine.h index 9c27ecffd..d2654aa04 100644 --- a/libc/sysdeps/x86_64/dl-machine.h +++ b/libc/sysdeps/x86_64/dl-machine.h @@ -41,13 +41,9 @@ elf_machine_matches_host (const ElfW(Ehdr) *ehdr) static inline ElfW(Addr) __attribute__ ((unused)) elf_machine_dynamic (void) { - ElfW(Addr) addr; - - /* This works because we have our GOT address available in the small PIC - model. */ - addr = (ElfW(Addr)) &_DYNAMIC; - - return addr; + /* This produces an IP-relative reloc which is resolved at link time. */ + extern const ElfW(Addr) _GLOBAL_OFFSET_TABLE_[] attribute_hidden; + return _GLOBAL_OFFSET_TABLE_[0]; } @@ -55,31 +51,11 @@ elf_machine_dynamic (void) static inline ElfW(Addr) __attribute__ ((unused)) elf_machine_load_address (void) { - ElfW(Addr) addr; - - /* The easy way is just the same as on x86: - leaq _dl_start, %0 - leaq _dl_start(%%rip), %1 - subq %0, %1 - but this does not work with binutils since we then have - a R_X86_64_32S relocation in a shared lib. - - Instead we store the address of _dl_start in the data section - and compare it with the current value that we can get via - an RIP relative addressing mode. Note that this is the address - of _dl_start before any relocation performed at runtime. In case - the binary is prelinked the resulting "address" is actually a - load offset which is zero if the binary was loaded at the address - it is prelinked for. */ - - asm ("lea _dl_start(%%rip), %0\n\t" - "sub 1f(%%rip), %0\n\t" - ".section\t.data.rel.ro\n" - "1:\t" ASM_ADDR " _dl_start\n\t" - ".previous\n\t" - : "=r" (addr) : : "cc"); - - return addr; + /* Compute the difference between the runtime address of _DYNAMIC as seen + by an IP-relative reference, and the link-time address found in the + special unrelocated first GOT entry. */ + extern ElfW(Dyn) _DYNAMIC[] attribute_hidden; + return (ElfW(Addr)) &_DYNAMIC - elf_machine_dynamic (); } /* Set up the loaded object described by L so its unrelocated PLT diff --git a/libc/sysdeps/x86_64/fpu/libm-test-ulps b/libc/sysdeps/x86_64/fpu/libm-test-ulps index 8a3822113..b02b9e6ba 100644 --- a/libc/sysdeps/x86_64/fpu/libm-test-ulps +++ b/libc/sysdeps/x86_64/fpu/libm-test-ulps @@ -1208,6 +1208,8 @@ ifloat: 1 ildouble: 1 ldouble: 1 Test "cos_downward (10) == -0.8390715290764524522588639478240648345199": +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 Test "cos_downward (2) == -0.4161468365471423869975682295007621897660": @@ -1239,6 +1241,8 @@ ifloat: 1 ildouble: 1 ldouble: 1 Test "cos_downward (9) == -0.9111302618846769883682947111811653112463": +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 @@ -1285,15 +1289,22 @@ ildouble: 1 ldouble: 1 # cos_upward +Test "cos_upward (1) == 0.5403023058681397174009366074429766037323": +float: 1 +ifloat: 1 Test "cos_upward (10) == -0.8390715290764524522588639478240648345199": float: 1 ifloat: 1 ildouble: 1 ldouble: 1 Test "cos_upward (2) == -0.4161468365471423869975682295007621897660": +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 Test "cos_upward (3) == -0.9899924966004454572715727947312613023937": +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 Test "cos_upward (4) == -0.6536436208636119146391681830977503814241": @@ -1311,6 +1322,8 @@ Test "cos_upward (7) == 0.7539022543433046381411975217191820122183": float: 1 ifloat: 1 Test "cos_upward (8) == -0.1455000338086135258688413818311946826093": +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 Test "cos_upward (9) == -0.9111302618846769883682947111811653112463": @@ -2319,6 +2332,8 @@ Test "sin_downward (8) == 0.9893582466233817778081235982452886721164": ildouble: 1 ldouble: 1 Test "sin_downward (9) == 0.4121184852417565697562725663524351793439": +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 @@ -2374,6 +2389,8 @@ Test "sin_upward (1) == 0.8414709848078965066525023216302989996226": float: 1 ifloat: 1 Test "sin_upward (10) == -0.5440211108893698134047476618513772816836": +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 Test "sin_upward (2) == 0.9092974268256816953960198659117448427023": @@ -2382,6 +2399,8 @@ ifloat: 2 ildouble: 1 ldouble: 1 Test "sin_upward (3) == 0.1411200080598672221007448028081102798469": +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 Test "sin_upward (4) == -0.7568024953079282513726390945118290941359": @@ -2390,11 +2409,19 @@ ifloat: 1 ildouble: 1 ldouble: 1 Test "sin_upward (5) == -0.9589242746631384688931544061559939733525": +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 Test "sin_upward (6) == -0.2794154981989258728115554466118947596280": ildouble: 1 ldouble: 1 +Test "sin_upward (7) == 0.6569865987187890903969990915936351779369": +float: 1 +ifloat: 1 +Test "sin_upward (8) == 0.9893582466233817778081235982452886721164": +float: 1 +ifloat: 1 Test "sin_upward (9) == 0.4121184852417565697562725663524351793439": float: 1 ifloat: 1 @@ -2403,6 +2430,12 @@ ifloat: 1 Test "sincos (0.80190127184058835, &sin_res, &cos_res) puts 0.69534156199418473 in cos_res": double: 1 idouble: 1 +Test "sincos (0x1p+120, &sin_res, &cos_res) puts -9.25879022854837867303861764107414946730833e-01 in cos_res": +float: 1 +ifloat: 1 +Test "sincos (0x1p+127, &sin_res, &cos_res) puts 7.81914638714960072263910298466369236613162e-01 in cos_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 @@ -3052,8 +3085,8 @@ ildouble: 1 ldouble: 1 Function: "cos_upward": -float: 2 -ifloat: 2 +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 @@ -3412,8 +3445,8 @@ ildouble: 1 ldouble: 1 Function: "sin_upward": -float: 2 -ifloat: 2 +float: 1 +ifloat: 1 ildouble: 1 ldouble: 1 diff --git a/libc/sysdeps/x86_64/fpu/s_cosf.S b/libc/sysdeps/x86_64/fpu/s_cosf.S new file mode 100644 index 000000000..dc8c76a13 --- /dev/null +++ b/libc/sysdeps/x86_64/fpu/s_cosf.S @@ -0,0 +1,527 @@ +/* Optimized cosf function. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 <sysdep.h> +#define __need_Emath +#include <bits/errno.h> + +/* Short algorithm description: + * + * 1) if |x| == 0: return 1.0-|x|. + * 2) if |x| < 2^-27: return 1.0-|x|. + * 3) if |x| < 2^-5 : return 1.0+x^2*DP_COS2_0+x^5*DP_COS2_1. + * 4) if |x| < Pi/4: return 1.0+x^2*(C0+x^2*(C1+x^2*(C2+x^2*(C3+x^2*C4)))). + * 5) if |x| < 9*Pi/4: + * 5.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0x0e, n=k+3, + * t=|x|-j*Pi/4. + * 5.2) Reconstruction: + * s = (-1.0)^((n>>2)&1) + * if(n&2 != 0) { + * using cos(t) polynomial for |t|<Pi/4, result is + * s * (1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4))))). + * } else { + * using sin(t) polynomial for |t|<Pi/4, result is + * s * t * (1.0+t^2*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4))))). + * } + * 6) if |x| < 2^23, large args: + * 6.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0xfffffffe, n=k+3, + * t=|x|-j*Pi/4. + * 6.2) Reconstruction same as (5.2). + * 7) if |x| >= 2^23, very large args: + * 7.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0xfffffffe, n=k+3, + * t=|x|-j*Pi/4. + * 7.2) Reconstruction same as (5.2). + * 8) if x is Inf, return x-x, and set errno=EDOM. + * 9) if x is NaN, return x-x. + * + * Special cases: + * cos(+-0) = 1 not raising inexact, + * cos(subnormal) raises inexact, + * cos(min_normalized) raises inexact, + * cos(normalized) raises inexact, + * cos(Inf) = NaN, raises invalid, sets errno to EDOM, + * cos(NaN) = NaN. + */ + + .text +ENTRY(__cosf) + /* Input: single precision x in %xmm0 */ + + movd %xmm0, %eax /* Bits of x */ + movaps %xmm0, %xmm7 /* Copy of x */ + cvtss2sd %xmm0, %xmm0 /* DP x */ + movss L(SP_ABS_MASK)(%rip), %xmm3 + andl $0x7fffffff, %eax /* |x| */ + + cmpl $0x3f490fdb, %eax /* |x|<Pi/4? */ + jb L(arg_less_pio4) + + /* Here if |x|>=Pi/4 */ + andps %xmm7, %xmm3 /* SP |x| */ + andpd L(DP_ABS_MASK)(%rip), %xmm0 /* DP |x| */ + movss L(SP_INVPIO4)(%rip), %xmm2 /* SP 1/(Pi/4) */ + + cmpl $0x40e231d6, %eax /* |x|<9*Pi/4? */ + jae L(large_args) + + /* Here if Pi/4<=|x|<9*Pi/4 */ + mulss %xmm3, %xmm2 /* SP |x|/(Pi/4) */ + cvttss2si %xmm2, %eax /* k, number of Pi/4 in x */ + lea L(PIO4J)(%rip), %rsi + addl $1, %eax /* k+1 */ + movl $0x0e, %edx + andl %eax, %edx /* j = (k+1)&0x0e */ + addl $2, %eax /* n */ + subsd (%rsi,%rdx,8), %xmm0 /* t = |x| - j * Pi/4 */ + +L(reconstruction): + /* Input: %eax=n, %xmm0=t */ + testl $2, %eax /* n&2 != 0? */ + jz L(sin_poly) + +/*L(cos_poly):*/ + /* Here if cos(x) calculated using cos(t) polynomial for |t|<Pi/4: + * y = t*t; z = y*y; + * s = sign(x) * (-1.0)^((n>>2)&1) + * result = s * (1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4))))) + */ + shrl $2, %eax /* n>>2 */ + mulsd %xmm0, %xmm0 /* y=t^2 */ + andl $1, %eax /* (n>>2)&1 */ + movaps %xmm0, %xmm1 /* y */ + mulsd %xmm0, %xmm0 /* z=t^4 */ + + movsd L(DP_C4)(%rip), %xmm4 /* C4 */ + mulsd %xmm0, %xmm4 /* z*C4 */ + movsd L(DP_C3)(%rip), %xmm3 /* C3 */ + mulsd %xmm0, %xmm3 /* z*C3 */ + lea L(DP_ONES)(%rip), %rsi + addsd L(DP_C2)(%rip), %xmm4 /* C2+z*C4 */ + mulsd %xmm0, %xmm4 /* z*(C2+z*C4) */ + addsd L(DP_C1)(%rip), %xmm3 /* C1+z*C3 */ + mulsd %xmm0, %xmm3 /* z*(C1+z*C3) */ + addsd L(DP_C0)(%rip), %xmm4 /* C0+z*(C2+z*C4) */ + mulsd %xmm1, %xmm4 /* y*(C0+z*(C2+z*C4)) */ + + addsd %xmm4, %xmm3 /* y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + /* 1.0+y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + addsd L(DP_ONES)(%rip), %xmm3 + + mulsd (%rsi,%rax,8), %xmm3 /* DP result */ + cvtsd2ss %xmm3, %xmm0 /* SP result */ + ret + + .p2align 4 +L(sin_poly): + /* Here if cos(x) calculated using sin(t) polynomial for |t|<Pi/4: + * y = t*t; z = y*y; + * s = sign(x) * (-1.0)^((n>>2)&1) + * result = s * t * (1.0+t^2*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4))))) + */ + + movaps %xmm0, %xmm4 /* t */ + shrl $2, %eax /* n>>2 */ + mulsd %xmm0, %xmm0 /* y=t^2 */ + andl $1, %eax /* (n>>2)&1 */ + movaps %xmm0, %xmm1 /* y */ + mulsd %xmm0, %xmm0 /* z=t^4 */ + + movsd L(DP_S4)(%rip), %xmm2 /* S4 */ + mulsd %xmm0, %xmm2 /* z*S4 */ + movsd L(DP_S3)(%rip), %xmm3 /* S3 */ + mulsd %xmm0, %xmm3 /* z*S3 */ + lea L(DP_ONES)(%rip), %rsi + addsd L(DP_S2)(%rip), %xmm2 /* S2+z*S4 */ + mulsd %xmm0, %xmm2 /* z*(S2+z*S4) */ + addsd L(DP_S1)(%rip), %xmm3 /* S1+z*S3 */ + mulsd %xmm0, %xmm3 /* z*(S1+z*S3) */ + addsd L(DP_S0)(%rip), %xmm2 /* S0+z*(S2+z*S4) */ + mulsd %xmm1, %xmm2 /* y*(S0+z*(S2+z*S4)) */ + /* t*s, where s = sign(x) * (-1.0)^((n>>2)&1) */ + mulsd (%rsi,%rax,8), %xmm4 + /* y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + addsd %xmm2, %xmm3 + /* t*s*y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + mulsd %xmm4, %xmm3 + /* t*s*(1.0+y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + addsd %xmm4, %xmm3 + cvtsd2ss %xmm3, %xmm0 /* SP result */ + ret + + .p2align 4 +L(large_args): + /* Here if |x|>=9*Pi/4 */ + cmpl $0x7f800000, %eax /* x is Inf or NaN? */ + jae L(arg_inf_or_nan) + + /* Here if finite |x|>=9*Pi/4 */ + cmpl $0x4b000000, %eax /* |x|<2^23? */ + jae L(very_large_args) + + /* Here if 9*Pi/4<=|x|<2^23 */ + movsd L(DP_INVPIO4)(%rip), %xmm1 /* 1/(Pi/4) */ + mulsd %xmm0, %xmm1 /* |x|/(Pi/4) */ + cvttsd2si %xmm1, %eax /* k=trunc(|x|/(Pi/4)) */ + addl $1, %eax /* k+1 */ + movl %eax, %edx + andl $0xfffffffe, %edx /* j=(k+1)&0xfffffffe */ + cvtsi2sdl %edx, %xmm4 /* DP j */ + movsd L(DP_PIO4HI)(%rip), %xmm2 /* -PIO4HI = high part of -Pi/4 */ + mulsd %xmm4, %xmm2 /* -j*PIO4HI */ + movsd L(DP_PIO4LO)(%rip), %xmm3 /* -PIO4LO = low part of -Pi/4 */ + addsd %xmm2, %xmm0 /* |x| - j*PIO4HI */ + addl $2, %eax /* n */ + mulsd %xmm3, %xmm4 /* j*PIO4LO */ + addsd %xmm4, %xmm0 /* t = |x| - j*PIO4HI - j*PIO4LO */ + jmp L(reconstruction) + + .p2align 4 +L(very_large_args): + /* Here if finite |x|>=2^23 */ + + /* bitpos = (ix>>23) - BIAS_32 + 59; */ + shrl $23, %eax /* eb = biased exponent of x */ + /* bitpos = eb - 0x7f + 59, where 0x7f is exponent bias */ + subl $68, %eax + movl $28, %ecx /* %cl=28 */ + movl %eax, %edx /* bitpos copy */ + + /* j = bitpos/28; */ + div %cl /* j in register %al=%ax/%cl */ + movapd %xmm0, %xmm3 /* |x| */ + /* clear unneeded remainder from %ah */ + andl $0xff, %eax + + imull $28, %eax, %ecx /* j*28 */ + lea L(_FPI)(%rip), %rsi + movsd L(DP_HI_MASK)(%rip), %xmm4 /* DP_HI_MASK */ + movapd %xmm0, %xmm5 /* |x| */ + mulsd -16(%rsi,%rax,8), %xmm3 /* tmp3 = FPI[j-2]*|x| */ + movapd %xmm0, %xmm1 /* |x| */ + mulsd -8(%rsi,%rax,8), %xmm5 /* tmp2 = FPI[j-1]*|x| */ + mulsd (%rsi,%rax,8), %xmm0 /* tmp0 = FPI[j]*|x| */ + addl $19, %ecx /* j*28+19 */ + mulsd 8(%rsi,%rax,8), %xmm1 /* tmp1 = FPI[j+1]*|x| */ + cmpl %ecx, %edx /* bitpos>=j*28+19? */ + jl L(very_large_skip1) + + /* Here if bitpos>=j*28+19 */ + andpd %xmm3, %xmm4 /* HI(tmp3) */ + subsd %xmm4, %xmm3 /* tmp3 = tmp3 - HI(tmp3) */ +L(very_large_skip1): + + movsd L(DP_2POW52)(%rip), %xmm6 + movapd %xmm5, %xmm2 /* tmp2 copy */ + addsd %xmm3, %xmm5 /* tmp5 = tmp3 + tmp2 */ + movl $1, %edx + addsd %xmm5, %xmm6 /* tmp6 = tmp5 + 2^52 */ + movsd 8+L(DP_2POW52)(%rip), %xmm4 + movd %xmm6, %eax /* k = I64_LO(tmp6); */ + addsd %xmm6, %xmm4 /* tmp4 = tmp6 - 2^52 */ + comisd %xmm5, %xmm4 /* tmp4 > tmp5? */ + jbe L(very_large_skip2) + + /* Here if tmp4 > tmp5 */ + subl $1, %eax /* k-- */ + addsd 8+L(DP_ONES)(%rip), %xmm4 /* tmp4 -= 1.0 */ +L(very_large_skip2): + + andl %eax, %edx /* k&1 */ + lea L(DP_ZERONE)(%rip), %rsi + subsd %xmm4, %xmm3 /* tmp3 -= tmp4 */ + addsd (%rsi,%rdx,8), %xmm3 /* t = DP_ZERONE[k&1] + tmp3 */ + addsd %xmm2, %xmm3 /* t += tmp2 */ + addsd %xmm3, %xmm0 /* t += tmp0 */ + addl $3, %eax /* n=k+3 */ + addsd %xmm1, %xmm0 /* t += tmp1 */ + mulsd L(DP_PIO4)(%rip), %xmm0 /* t *= PI04 */ + + jmp L(reconstruction) /* end of very_large_args peth */ + + .p2align 4 +L(arg_less_pio4): + /* Here if |x|<Pi/4 */ + cmpl $0x3d000000, %eax /* |x|<2^-5? */ + jl L(arg_less_2pn5) + + /* Here if 2^-5<=|x|<Pi/4 */ + mulsd %xmm0, %xmm0 /* y=x^2 */ + movaps %xmm0, %xmm1 /* y */ + mulsd %xmm0, %xmm0 /* z=x^4 */ + movsd L(DP_C4)(%rip), %xmm3 /* C4 */ + mulsd %xmm0, %xmm3 /* z*C4 */ + movsd L(DP_C3)(%rip), %xmm5 /* C3 */ + mulsd %xmm0, %xmm5 /* z*C3 */ + addsd L(DP_C2)(%rip), %xmm3 /* C2+z*C4 */ + mulsd %xmm0, %xmm3 /* z*(C2+z*C4) */ + addsd L(DP_C1)(%rip), %xmm5 /* C1+z*C3 */ + mulsd %xmm0, %xmm5 /* z*(C1+z*C3) */ + addsd L(DP_C0)(%rip), %xmm3 /* C0+z*(C2+z*C4) */ + mulsd %xmm1, %xmm3 /* y*(C0+z*(C2+z*C4)) */ + /* y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + addsd %xmm5, %xmm3 + /* 1.0 + y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + addsd L(DP_ONES)(%rip), %xmm3 + cvtsd2ss %xmm3, %xmm0 /* SP result */ + ret + + .p2align 4 +L(arg_less_2pn5): + /* Here if |x|<2^-5 */ + cmpl $0x32000000, %eax /* |x|<2^-27? */ + jl L(arg_less_2pn27) + + /* Here if 2^-27<=|x|<2^-5 */ + mulsd %xmm0, %xmm0 /* DP x^2 */ + movsd L(DP_COS2_1)(%rip), %xmm3 /* DP DP_COS2_1 */ + mulsd %xmm0, %xmm3 /* DP x^2*DP_COS2_1 */ + addsd L(DP_COS2_0)(%rip), %xmm3 /* DP DP_COS2_0+x^2*DP_COS2_1 */ + mulsd %xmm0, %xmm3 /* DP x^2*DP_COS2_0+x^4*DP_COS2_1 */ + /* DP 1.0+x^2*DP_COS2_0+x^4*DP_COS2_1 */ + addsd L(DP_ONES)(%rip), %xmm3 + cvtsd2ss %xmm3, %xmm0 /* SP result */ + ret + + .p2align 4 +L(arg_less_2pn27): + /* Here if |x|<2^-27 */ + andps L(SP_ABS_MASK)(%rip),%xmm7 /* |x| */ + movss L(SP_ONE)(%rip), %xmm0 /* 1.0 */ + subss %xmm7, %xmm0 /* result is 1.0-|x| */ + ret + + .p2align 4 +L(arg_inf_or_nan): + /* Here if |x| is Inf or NAN */ + jne L(skip_errno_setting) /* in case of x is NaN */ + + /* Here if x is Inf. Set errno to EDOM. */ + call JUMPTARGET(__errno_location) + movl $EDOM, (%rax) + + .p2align 4 +L(skip_errno_setting): + /* Here if |x| is Inf or NAN. Continued. */ + movaps %xmm7, %xmm0 /* load x */ + subss %xmm0, %xmm0 /* Result is NaN */ + ret +END(__cosf) + + .section .rodata, "a" + .p2align 3 +L(PIO4J): /* Table of j*Pi/4, for j=0,1,..,10 */ + .long 0x00000000,0x00000000 + .long 0x54442d18,0x3fe921fb + .long 0x54442d18,0x3ff921fb + .long 0x7f3321d2,0x4002d97c + .long 0x54442d18,0x400921fb + .long 0x2955385e,0x400f6a7a + .long 0x7f3321d2,0x4012d97c + .long 0xe9bba775,0x4015fdbb + .long 0x54442d18,0x401921fb + .long 0xbeccb2bb,0x401c463a + .long 0x2955385e,0x401f6a7a + .type L(PIO4J), @object + ASM_SIZE_DIRECTIVE(L(PIO4J)) + + .p2align 3 +L(_FPI): /* 4/Pi broken into sum of positive DP values */ + .long 0x00000000,0x00000000 + .long 0x6c000000,0x3ff45f30 + .long 0x2a000000,0x3e3c9c88 + .long 0xa8000000,0x3c54fe13 + .long 0xd0000000,0x3aaf47d4 + .long 0x6c000000,0x38fbb81b + .long 0xe0000000,0x3714acc9 + .long 0x7c000000,0x3560e410 + .long 0x56000000,0x33bca2c7 + .long 0xac000000,0x31fbd778 + .long 0xe0000000,0x300b7246 + .long 0xe8000000,0x2e5d2126 + .long 0x48000000,0x2c970032 + .long 0xe8000000,0x2ad77504 + .long 0xe0000000,0x290921cf + .long 0xb0000000,0x274deb1c + .long 0xe0000000,0x25829a73 + .long 0xbe000000,0x23fd1046 + .long 0x10000000,0x2224baed + .long 0x8e000000,0x20709d33 + .long 0x80000000,0x1e535a2f + .long 0x64000000,0x1cef904e + .long 0x30000000,0x1b0d6398 + .long 0x24000000,0x1964ce7d + .long 0x16000000,0x17b908bf + .type L(_FPI), @object + ASM_SIZE_DIRECTIVE(L(_FPI)) + +/* Coefficients of polynomial + for cos(x)~=1.0+x^2*DP_COS2_0+x^4*DP_COS2_1, |x|<2^-5. */ + .p2align 3 +L(DP_COS2_0): + .long 0xff5cc6fd,0xbfdfffff + .type L(DP_COS2_0), @object + ASM_SIZE_DIRECTIVE(L(DP_COS2_0)) + + .p2align 3 +L(DP_COS2_1): + .long 0xb178dac5,0x3fa55514 + .type L(DP_COS2_1), @object + ASM_SIZE_DIRECTIVE(L(DP_COS2_1)) + + .p2align 3 +L(DP_ZERONE): + .long 0x00000000,0x00000000 /* 0.0 */ + .long 0x00000000,0xbff00000 /* 1.0 */ + .type L(DP_ZERONE), @object + ASM_SIZE_DIRECTIVE(L(DP_ZERONE)) + + .p2align 3 +L(DP_ONES): + .long 0x00000000,0x3ff00000 /* +1.0 */ + .long 0x00000000,0xbff00000 /* -1.0 */ + .type L(DP_ONES), @object + ASM_SIZE_DIRECTIVE(L(DP_ONES)) + +/* Coefficients of polynomial + for sin(t)~=t+t^3*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4)))), |t|<Pi/4. */ + .p2align 3 +L(DP_S3): + .long 0x64e6b5b4,0x3ec71d72 + .type L(DP_S3), @object + ASM_SIZE_DIRECTIVE(L(DP_S3)) + + .p2align 3 +L(DP_S1): + .long 0x10c2688b,0x3f811111 + .type L(DP_S1), @object + ASM_SIZE_DIRECTIVE(L(DP_S1)) + + .p2align 3 +L(DP_S4): + .long 0x1674b58a,0xbe5a947e + .type L(DP_S4), @object + ASM_SIZE_DIRECTIVE(L(DP_S4)) + + .p2align 3 +L(DP_S2): + .long 0x8b4bd1f9,0xbf2a019f + .type L(DP_S2),@object + ASM_SIZE_DIRECTIVE(L(DP_S2)) + + .p2align 3 +L(DP_S0): + .long 0x55551cd9,0xbfc55555 + .type L(DP_S0), @object + ASM_SIZE_DIRECTIVE(L(DP_S0)) + +/* Coefficients of polynomial + for cos(t)~=1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4)))), |t|<Pi/4. */ + .p2align 3 +L(DP_C3): + .long 0x9ac43cc0,0x3efa00eb + .type L(DP_C3), @object + ASM_SIZE_DIRECTIVE(L(DP_C3)) + + .p2align 3 +L(DP_C1): + .long 0x545c50c7,0x3fa55555 + .type L(DP_C1), @object + ASM_SIZE_DIRECTIVE(L(DP_C1)) + + .p2align 3 +L(DP_C4): + .long 0xdd8844d7,0xbe923c97 + .type L(DP_C4), @object + ASM_SIZE_DIRECTIVE(L(DP_C4)) + + .p2align 3 +L(DP_C2): + .long 0x348b6874,0xbf56c16b + .type L(DP_C2), @object + ASM_SIZE_DIRECTIVE(L(DP_C2)) + + .p2align 3 +L(DP_C0): + .long 0xfffe98ae,0xbfdfffff + .type L(DP_C0), @object + ASM_SIZE_DIRECTIVE(L(DP_C0)) + + .p2align 3 +L(DP_PIO4): + .long 0x54442d18,0x3fe921fb /* Pi/4 */ + .type L(DP_PIO4), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4)) + + .p2align 3 +L(DP_2POW52): + .long 0x00000000,0x43300000 /* +2^52 */ + .long 0x00000000,0xc3300000 /* -2^52 */ + .type L(DP_2POW52), @object + ASM_SIZE_DIRECTIVE(L(DP_2POW52)) + + .p2align 3 +L(DP_INVPIO4): + .long 0x6dc9c883,0x3ff45f30 /* 4/Pi */ + .type L(DP_INVPIO4), @object + ASM_SIZE_DIRECTIVE(L(DP_INVPIO4)) + + .p2align 3 +L(DP_PIO4HI): + .long 0x54000000,0xbfe921fb /* High part of Pi/4 */ + .type L(DP_PIO4HI), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4HI)) + + .p2align 3 +L(DP_PIO4LO): + .long 0x11A62633,0xbe010b46 /* Low part of Pi/4 */ + .type L(DP_PIO4LO), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4LO)) + + .p2align 2 +L(SP_INVPIO4): + .long 0x3fa2f983 /* 4/Pi */ + .type L(SP_INVPIO4), @object + ASM_SIZE_DIRECTIVE(L(SP_INVPIO4)) + + .p2align 4 +L(DP_ABS_MASK): /* Mask for getting DP absolute value */ + .long 0xffffffff,0x7fffffff + .long 0xffffffff,0x7fffffff + .type L(DP_ABS_MASK), @object + ASM_SIZE_DIRECTIVE(L(DP_ABS_MASK)) + + .p2align 3 +L(DP_HI_MASK): /* Mask for getting high 21 bits of DP value */ + .long 0x00000000,0xffffffff + .type L(DP_HI_MASK), @object + ASM_SIZE_DIRECTIVE(L(DP_HI_MASK)) + + .p2align 4 +L(SP_ABS_MASK): /* Mask for getting SP absolute value */ + .long 0x7fffffff,0x7fffffff + .long 0x7fffffff,0x7fffffff + .type L(SP_ABS_MASK), @object + ASM_SIZE_DIRECTIVE(L(SP_ABS_MASK)) + + .p2align 2 +L(SP_ONE): + .long 0x3f800000 /* 1.0 */ + .type L(SP_ONE), @object + ASM_SIZE_DIRECTIVE(L(SP_ONE)) + +weak_alias(__cosf, cosf) diff --git a/libc/sysdeps/x86_64/fpu/s_sinf.S b/libc/sysdeps/x86_64/fpu/s_sinf.S new file mode 100644 index 000000000..9a6c87ff7 --- /dev/null +++ b/libc/sysdeps/x86_64/fpu/s_sinf.S @@ -0,0 +1,553 @@ +/* Optimized sinf function. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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 <sysdep.h> +#define __need_Emath +#include <bits/errno.h> + +/* Short algorithm description: + * + * 1) if |x| == 0: return x. + * 2) if |x| < 2^-27: return x-x*DP_SMALL, raise underflow only when needed. + * 3) if |x| < 2^-5 : return x+x^3*DP_SIN2_0+x^5*DP_SIN2_1. + * 4) if |x| < Pi/4: return x+x^3*(S0+x^2*(S1+x^2*(S2+x^2*(S3+x^2*S4)))). + * 5) if |x| < 9*Pi/4: + * 5.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0x0e, n=k+1, + * t=|x|-j*Pi/4. + * 5.2) Reconstruction: + * s = sign(x) * (-1.0)^((n>>2)&1) + * if(n&2 != 0) { + * using cos(t) polynomial for |t|<Pi/4, result is + * s * (1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4))))). + * } else { + * using sin(t) polynomial for |t|<Pi/4, result is + * s * t * (1.0+t^2*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4))))). + * } + * 6) if |x| < 2^23, large args: + * 6.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0xfffffffe, n=k+1, + * t=|x|-j*Pi/4. + * 6.2) Reconstruction same as (5.2). + * 7) if |x| >= 2^23, very large args: + * 7.1) Range reduction: k=trunc(|x|/(Pi/4)), j=(k+1)&0xfffffffe, n=k+1, + * t=|x|-j*Pi/4. + * 7.2) Reconstruction same as (5.2). + * 8) if x is Inf, return x-x, and set errno=EDOM. + * 9) if x is NaN, return x-x. + * + * Special cases: + * sin(+-0) = +-0 not raising inexact/underflow, + * sin(subnormal) raises inexact/underflow, + * sin(min_normalized) raises inexact/underflow, + * sin(normalized) raises inexact, + * sin(Inf) = NaN, raises invalid, sets errno to EDOM, + * sin(NaN) = NaN. + */ + + .text +ENTRY(__sinf) + /* Input: single precision x in %xmm0 */ + + movd %xmm0, %eax /* Bits of x */ + movaps %xmm0, %xmm7 /* Copy of x */ + cvtss2sd %xmm0, %xmm0 /* DP x */ + movss L(SP_ABS_MASK)(%rip), %xmm3 + movl %eax, %edi /* Copy of x bits */ + andl $0x7fffffff, %eax /* |x| */ + + cmpl $0x3f490fdb, %eax /* |x|<Pi/4? */ + jb L(arg_less_pio4) + + /* Here if |x|>=Pi/4 */ + andps %xmm7, %xmm3 /* SP |x| */ + andpd L(DP_ABS_MASK)(%rip),%xmm0 /* DP |x| */ + movss L(SP_INVPIO4)(%rip), %xmm2 /* SP 1/(Pi/4) */ + + cmpl $0x40e231d6, %eax /* |x|<9*Pi/4? */ + jae L(large_args) + + /* Here if Pi/4<=|x|<9*Pi/4 */ + mulss %xmm3, %xmm2 /* SP |x|/(Pi/4) */ + movl %edi, %ecx /* Load x */ + cvttss2si %xmm2, %eax /* k, number of Pi/4 in x */ + lea L(PIO4J)(%rip), %rsi + shrl $31, %ecx /* sign of x */ + addl $1, %eax /* k+1 */ + movl $0x0e, %edx + andl %eax, %edx /* j = (k+1)&0x0e */ + subsd (%rsi,%rdx,8), %xmm0 /* t = |x| - j * Pi/4 */ + +L(reconstruction): + /* Input: %eax=n, %xmm0=t, %ecx=sign(x) */ + testl $2, %eax /* n&2 != 0? */ + jz L(sin_poly) + +/*L(cos_poly):*/ + /* Here if sin(x) calculated using cos(t) polynomial for |t|<Pi/4: + * y = t*t; z = y*y; + * s = sign(x) * (-1.0)^((n>>2)&1) + * result = s * (1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4))))) + */ + shrl $2, %eax /* n>>2 */ + mulsd %xmm0, %xmm0 /* y=t^2 */ + andl $1, %eax /* (n>>2)&1 */ + movaps %xmm0, %xmm1 /* y */ + mulsd %xmm0, %xmm0 /* z=t^4 */ + + movsd L(DP_C4)(%rip), %xmm4 /* C4 */ + mulsd %xmm0, %xmm4 /* z*C4 */ + xorl %eax, %ecx /* (-1.0)^((n>>2)&1) XOR sign(x) */ + movsd L(DP_C3)(%rip), %xmm3 /* C3 */ + mulsd %xmm0, %xmm3 /* z*C3 */ + lea L(DP_ONES)(%rip), %rsi + addsd L(DP_C2)(%rip), %xmm4 /* C2+z*C4 */ + mulsd %xmm0, %xmm4 /* z*(C2+z*C4) */ + addsd L(DP_C1)(%rip), %xmm3 /* C1+z*C3 */ + mulsd %xmm0, %xmm3 /* z*(C1+z*C3) */ + addsd L(DP_C0)(%rip), %xmm4 /* C0+z*(C2+z*C4) */ + mulsd %xmm1, %xmm4 /* y*(C0+z*(C2+z*C4)) */ + + /* y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + addsd %xmm4, %xmm3 + /* 1.0+y*(C0+y*(C1+y*(C2+y*(C3+y*C4)))) */ + addsd L(DP_ONES)(%rip), %xmm3 + + mulsd (%rsi,%rcx,8), %xmm3 /* DP result */ + cvtsd2ss %xmm3, %xmm0 /* SP result */ + ret + + .p2align 4 +L(sin_poly): + /* Here if sin(x) calculated using sin(t) polynomial for |t|<Pi/4: + * y = t*t; z = y*y; + * s = sign(x) * (-1.0)^((n>>2)&1) + * result = s * t * (1.0+t^2*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4))))) + */ + + movaps %xmm0, %xmm4 /* t */ + shrl $2, %eax /* n>>2 */ + mulsd %xmm0, %xmm0 /* y=t^2 */ + andl $1, %eax /* (n>>2)&1 */ + movaps %xmm0, %xmm1 /* y */ + xorl %eax, %ecx /* (-1.0)^((n>>2)&1) XOR sign(x) */ + mulsd %xmm0, %xmm0 /* z=t^4 */ + + movsd L(DP_S4)(%rip), %xmm2 /* S4 */ + mulsd %xmm0, %xmm2 /* z*S4 */ + movsd L(DP_S3)(%rip), %xmm3 /* S3 */ + mulsd %xmm0, %xmm3 /* z*S3 */ + lea L(DP_ONES)(%rip), %rsi + addsd L(DP_S2)(%rip), %xmm2 /* S2+z*S4 */ + mulsd %xmm0, %xmm2 /* z*(S2+z*S4) */ + addsd L(DP_S1)(%rip), %xmm3 /* S1+z*S3 */ + mulsd %xmm0, %xmm3 /* z*(S1+z*S3) */ + addsd L(DP_S0)(%rip), %xmm2 /* S0+z*(S2+z*S4) */ + mulsd %xmm1, %xmm2 /* y*(S0+z*(S2+z*S4)) */ + /* t*s, where s = sign(x) * (-1.0)^((n>>2)&1) */ + mulsd (%rsi,%rcx,8), %xmm4 + /* y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + addsd %xmm2, %xmm3 + /* t*s*y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + mulsd %xmm4, %xmm3 + /* t*s*(1.0+y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + addsd %xmm4, %xmm3 + cvtsd2ss %xmm3, %xmm0 /* SP result */ + ret + + .p2align 4 +L(large_args): + /* Here if |x|>=9*Pi/4 */ + cmpl $0x7f800000, %eax /* x is Inf or NaN? */ + jae L(arg_inf_or_nan) + + /* Here if finite |x|>=9*Pi/4 */ + cmpl $0x4b000000, %eax /* |x|<2^23? */ + jae L(very_large_args) + + /* Here if 9*Pi/4<=|x|<2^23 */ + movsd L(DP_INVPIO4)(%rip), %xmm1 /* 1/(Pi/4) */ + mulsd %xmm0, %xmm1 /* |x|/(Pi/4) */ + cvttsd2si %xmm1, %eax /* k=trunc(|x|/(Pi/4)) */ + addl $1, %eax /* k+1 */ + movl %eax, %edx + andl $0xfffffffe, %edx /* j=(k+1)&0xfffffffe */ + cvtsi2sdl %edx, %xmm4 /* DP j */ + movl %edi, %ecx /* Load x */ + movsd L(DP_PIO4HI)(%rip), %xmm2 /* -PIO4HI = high part of -Pi/4 */ + shrl $31, %ecx /* sign bit of x */ + mulsd %xmm4, %xmm2 /* -j*PIO4HI */ + movsd L(DP_PIO4LO)(%rip), %xmm3 /* -PIO4LO = low part of -Pi/4 */ + addsd %xmm2, %xmm0 /* |x| - j*PIO4HI */ + mulsd %xmm3, %xmm4 /* j*PIO4LO */ + addsd %xmm4, %xmm0 /* t = |x| - j*PIO4HI - j*PIO4LO */ + jmp L(reconstruction) + + .p2align 4 +L(very_large_args): + /* Here if finite |x|>=2^23 */ + + /* bitpos = (ix>>23) - BIAS_32 + 59; */ + shrl $23, %eax /* eb = biased exponent of x */ + /* bitpos = eb - 0x7f + 59, where 0x7f is exponent bias */ + subl $68, %eax + movl $28, %ecx /* %cl=28 */ + movl %eax, %edx /* bitpos copy */ + + /* j = bitpos/28; */ + div %cl /* j in register %al=%ax/%cl */ + movapd %xmm0, %xmm3 /* |x| */ + /* clear unneeded remainder from %ah */ + andl $0xff, %eax + + imull $28, %eax, %ecx /* j*28 */ + lea L(_FPI)(%rip), %rsi + movsd L(DP_HI_MASK)(%rip), %xmm4 /* DP_HI_MASK */ + movapd %xmm0, %xmm5 /* |x| */ + mulsd -16(%rsi,%rax,8), %xmm3 /* tmp3 = FPI[j-2]*|x| */ + movapd %xmm0, %xmm1 /* |x| */ + mulsd -8(%rsi,%rax,8), %xmm5 /* tmp2 = FPI[j-1]*|x| */ + mulsd (%rsi,%rax,8), %xmm0 /* tmp0 = FPI[j]*|x| */ + addl $19, %ecx /* j*28+19 */ + mulsd 8(%rsi,%rax,8), %xmm1 /* tmp1 = FPI[j+1]*|x| */ + cmpl %ecx, %edx /* bitpos>=j*28+19? */ + jl L(very_large_skip1) + + /* Here if bitpos>=j*28+19 */ + andpd %xmm3, %xmm4 /* HI(tmp3) */ + subsd %xmm4, %xmm3 /* tmp3 = tmp3 - HI(tmp3) */ +L(very_large_skip1): + + movsd L(DP_2POW52)(%rip), %xmm6 + movapd %xmm5, %xmm2 /* tmp2 copy */ + addsd %xmm3, %xmm5 /* tmp5 = tmp3 + tmp2 */ + movl $1, %edx + addsd %xmm5, %xmm6 /* tmp6 = tmp5 + 2^52 */ + movsd 8+L(DP_2POW52)(%rip), %xmm4 + movd %xmm6, %eax /* k = I64_LO(tmp6); */ + addsd %xmm6, %xmm4 /* tmp4 = tmp6 - 2^52 */ + movl %edi, %ecx /* Load x */ + comisd %xmm5, %xmm4 /* tmp4 > tmp5? */ + jbe L(very_large_skip2) + + /* Here if tmp4 > tmp5 */ + subl $1, %eax /* k-- */ + addsd 8+L(DP_ONES)(%rip), %xmm4 /* tmp4 -= 1.0 */ +L(very_large_skip2): + + andl %eax, %edx /* k&1 */ + lea L(DP_ZERONE)(%rip), %rsi + subsd %xmm4, %xmm3 /* tmp3 -= tmp4 */ + addsd (%rsi,%rdx,8), %xmm3 /* t = DP_ZERONE[k&1] + tmp3 */ + addsd %xmm2, %xmm3 /* t += tmp2 */ + shrl $31, %ecx /* sign of x */ + addsd %xmm3, %xmm0 /* t += tmp0 */ + addl $1, %eax /* n=k+1 */ + addsd %xmm1, %xmm0 /* t += tmp1 */ + mulsd L(DP_PIO4)(%rip), %xmm0 /* t *= PI04 */ + + jmp L(reconstruction) /* end of very_large_args peth */ + + .p2align 4 +L(arg_less_pio4): + /* Here if |x|<Pi/4 */ + cmpl $0x3d000000, %eax /* |x|<2^-5? */ + jl L(arg_less_2pn5) + + /* Here if 2^-5<=|x|<Pi/4 */ + movaps %xmm0, %xmm3 /* x */ + mulsd %xmm0, %xmm0 /* y=x^2 */ + movaps %xmm0, %xmm1 /* y */ + mulsd %xmm0, %xmm0 /* z=x^4 */ + movsd L(DP_S4)(%rip), %xmm4 /* S4 */ + mulsd %xmm0, %xmm4 /* z*S4 */ + movsd L(DP_S3)(%rip), %xmm5 /* S3 */ + mulsd %xmm0, %xmm5 /* z*S3 */ + addsd L(DP_S2)(%rip), %xmm4 /* S2+z*S4 */ + mulsd %xmm0, %xmm4 /* z*(S2+z*S4) */ + addsd L(DP_S1)(%rip), %xmm5 /* S1+z*S3 */ + mulsd %xmm0, %xmm5 /* z*(S1+z*S3) */ + addsd L(DP_S0)(%rip), %xmm4 /* S0+z*(S2+z*S4) */ + mulsd %xmm1, %xmm4 /* y*(S0+z*(S2+z*S4)) */ + mulsd %xmm3, %xmm5 /* x*z*(S1+z*S3) */ + mulsd %xmm3, %xmm4 /* x*y*(S0+z*(S2+z*S4)) */ + /* x*y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + addsd %xmm5, %xmm4 + /* x + x*y*(S0+y*(S1+y*(S2+y*(S3+y*S4)))) */ + addsd %xmm4, %xmm3 + cvtsd2ss %xmm3, %xmm0 /* SP result */ + ret + + .p2align 4 +L(arg_less_2pn5): + /* Here if |x|<2^-5 */ + cmpl $0x32000000, %eax /* |x|<2^-27? */ + jl L(arg_less_2pn27) + + /* Here if 2^-27<=|x|<2^-5 */ + movaps %xmm0, %xmm1 /* DP x */ + mulsd %xmm0, %xmm0 /* DP x^2 */ + movsd L(DP_SIN2_1)(%rip), %xmm3 /* DP DP_SIN2_1 */ + mulsd %xmm0, %xmm3 /* DP x^2*DP_SIN2_1 */ + addsd L(DP_SIN2_0)(%rip), %xmm3 /* DP DP_SIN2_0+x^2*DP_SIN2_1 */ + mulsd %xmm0, %xmm3 /* DP x^2*DP_SIN2_0+x^4*DP_SIN2_1 */ + mulsd %xmm1, %xmm3 /* DP x^3*DP_SIN2_0+x^5*DP_SIN2_1 */ + addsd %xmm1, %xmm3 /* DP x+x^3*DP_SIN2_0+x^5*DP_SIN2_1 */ + cvtsd2ss %xmm3, %xmm0 /* SP result */ + ret + + .p2align 4 +L(arg_less_2pn27): + cmpl $0, %eax /* x=0? */ + je L(arg_zero) /* in case x=0 return sin(+-0)==+-0 */ + /* Here if |x|<2^-27 */ + /* + * Special cases here: + * sin(subnormal) raises inexact/underflow + * sin(min_normalized) raises inexact/underflow + * sin(normalized) raises inexact + */ + movaps %xmm0, %xmm3 /* Copy of DP x */ + mulsd L(DP_SMALL)(%rip), %xmm0 /* x*DP_SMALL */ + subsd %xmm0, %xmm3 /* Result is x-x*DP_SMALL */ + cvtsd2ss %xmm3, %xmm0 /* Result converted to SP */ + ret + + .p2align 4 +L(arg_zero): + movaps %xmm7, %xmm0 /* SP x */ + ret + + .p2align 4 +L(arg_inf_or_nan): + /* Here if |x| is Inf or NAN */ + jne L(skip_errno_setting) /* in case of x is NaN */ + + /* Here if x is Inf. Set errno to EDOM. */ + call JUMPTARGET(__errno_location) + movl $EDOM, (%rax) + + .p2align 4 +L(skip_errno_setting): + /* Here if |x| is Inf or NAN. Continued. */ + movaps %xmm7, %xmm0 /* load x */ + subss %xmm0, %xmm0 /* Result is NaN */ + ret +END(__sinf) + + .section .rodata, "a" + .p2align 3 +L(PIO4J): /* Table of j*Pi/4, for j=0,1,..,10 */ + .long 0x00000000,0x00000000 + .long 0x54442d18,0x3fe921fb + .long 0x54442d18,0x3ff921fb + .long 0x7f3321d2,0x4002d97c + .long 0x54442d18,0x400921fb + .long 0x2955385e,0x400f6a7a + .long 0x7f3321d2,0x4012d97c + .long 0xe9bba775,0x4015fdbb + .long 0x54442d18,0x401921fb + .long 0xbeccb2bb,0x401c463a + .long 0x2955385e,0x401f6a7a + .type L(PIO4J), @object + ASM_SIZE_DIRECTIVE(L(PIO4J)) + + .p2align 3 +L(_FPI): /* 4/Pi broken into sum of positive DP values */ + .long 0x00000000,0x00000000 + .long 0x6c000000,0x3ff45f30 + .long 0x2a000000,0x3e3c9c88 + .long 0xa8000000,0x3c54fe13 + .long 0xd0000000,0x3aaf47d4 + .long 0x6c000000,0x38fbb81b + .long 0xe0000000,0x3714acc9 + .long 0x7c000000,0x3560e410 + .long 0x56000000,0x33bca2c7 + .long 0xac000000,0x31fbd778 + .long 0xe0000000,0x300b7246 + .long 0xe8000000,0x2e5d2126 + .long 0x48000000,0x2c970032 + .long 0xe8000000,0x2ad77504 + .long 0xe0000000,0x290921cf + .long 0xb0000000,0x274deb1c + .long 0xe0000000,0x25829a73 + .long 0xbe000000,0x23fd1046 + .long 0x10000000,0x2224baed + .long 0x8e000000,0x20709d33 + .long 0x80000000,0x1e535a2f + .long 0x64000000,0x1cef904e + .long 0x30000000,0x1b0d6398 + .long 0x24000000,0x1964ce7d + .long 0x16000000,0x17b908bf + .type L(_FPI), @object + ASM_SIZE_DIRECTIVE(L(_FPI)) + +/* Coefficients of polynomial + for sin(x)~=x+x^3*DP_SIN2_0+x^5*DP_SIN2_1, |x|<2^-5. */ + .p2align 3 +L(DP_SIN2_0): + .long 0x5543d49d,0xbfc55555 + .type L(DP_SIN2_0), @object + ASM_SIZE_DIRECTIVE(L(DP_SIN2_0)) + + .p2align 3 +L(DP_SIN2_1): + .long 0x75cec8c5,0x3f8110f4 + .type L(DP_SIN2_1), @object + ASM_SIZE_DIRECTIVE(L(DP_SIN2_1)) + + .p2align 3 +L(DP_ZERONE): + .long 0x00000000,0x00000000 /* 0.0 */ + .long 0x00000000,0xbff00000 /* 1.0 */ + .type L(DP_ZERONE), @object + ASM_SIZE_DIRECTIVE(L(DP_ZERONE)) + + .p2align 3 +L(DP_ONES): + .long 0x00000000,0x3ff00000 /* +1.0 */ + .long 0x00000000,0xbff00000 /* -1.0 */ + .type L(DP_ONES), @object + ASM_SIZE_DIRECTIVE(L(DP_ONES)) + +/* Coefficients of polynomial + for sin(t)~=t+t^3*(S0+t^2*(S1+t^2*(S2+t^2*(S3+t^2*S4)))), |t|<Pi/4. */ + .p2align 3 +L(DP_S3): + .long 0x64e6b5b4,0x3ec71d72 + .type L(DP_S3), @object + ASM_SIZE_DIRECTIVE(L(DP_S3)) + + .p2align 3 +L(DP_S1): + .long 0x10c2688b,0x3f811111 + .type L(DP_S1), @object + ASM_SIZE_DIRECTIVE(L(DP_S1)) + + .p2align 3 +L(DP_S4): + .long 0x1674b58a,0xbe5a947e + .type L(DP_S4), @object + ASM_SIZE_DIRECTIVE(L(DP_S4)) + + .p2align 3 +L(DP_S2): + .long 0x8b4bd1f9,0xbf2a019f + .type L(DP_S2), @object + ASM_SIZE_DIRECTIVE(L(DP_S2)) + + .p2align 3 +L(DP_S0): + .long 0x55551cd9,0xbfc55555 + .type L(DP_S0), @object + ASM_SIZE_DIRECTIVE(L(DP_S0)) + + .p2align 3 +L(DP_SMALL): + .long 0x00000000,0x3cd00000 /* 2^(-50) */ + .type L(DP_SMALL), @object + ASM_SIZE_DIRECTIVE(L(DP_SMALL)) + +/* Coefficients of polynomial + for cos(t)~=1.0+t^2*(C0+t^2*(C1+t^2*(C2+t^2*(C3+t^2*C4)))), |t|<Pi/4. */ + .p2align 3 +L(DP_C3): + .long 0x9ac43cc0,0x3efa00eb + .type L(DP_C3), @object + ASM_SIZE_DIRECTIVE(L(DP_C3)) + + .p2align 3 +L(DP_C1): + .long 0x545c50c7,0x3fa55555 + .type L(DP_C1), @object + ASM_SIZE_DIRECTIVE(L(DP_C1)) + + .p2align 3 +L(DP_C4): + .long 0xdd8844d7,0xbe923c97 + .type L(DP_C4), @object + ASM_SIZE_DIRECTIVE(L(DP_C4)) + + .p2align 3 +L(DP_C2): + .long 0x348b6874,0xbf56c16b + .type L(DP_C2), @object + ASM_SIZE_DIRECTIVE(L(DP_C2)) + + .p2align 3 +L(DP_C0): + .long 0xfffe98ae,0xbfdfffff + .type L(DP_C0), @object + ASM_SIZE_DIRECTIVE(L(DP_C0)) + + .p2align 3 +L(DP_PIO4): + .long 0x54442d18,0x3fe921fb /* Pi/4 */ + .type L(DP_PIO4), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4)) + + .p2align 3 +L(DP_2POW52): + .long 0x00000000,0x43300000 /* +2^52 */ + .long 0x00000000,0xc3300000 /* -2^52 */ + .type L(DP_2POW52), @object + ASM_SIZE_DIRECTIVE(L(DP_2POW52)) + + .p2align 3 +L(DP_INVPIO4): + .long 0x6dc9c883,0x3ff45f30 /* 4/Pi */ + .type L(DP_INVPIO4), @object + ASM_SIZE_DIRECTIVE(L(DP_INVPIO4)) + + .p2align 3 +L(DP_PIO4HI): + .long 0x54000000,0xbfe921fb /* High part of Pi/4 */ + .type L(DP_PIO4HI), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4HI)) + + .p2align 3 +L(DP_PIO4LO): + .long 0x11A62633,0xbe010b46 /* Low part of Pi/4 */ + .type L(DP_PIO4LO), @object + ASM_SIZE_DIRECTIVE(L(DP_PIO4LO)) + + .p2align 2 +L(SP_INVPIO4): + .long 0x3fa2f983 /* 4/Pi */ + .type L(SP_INVPIO4), @object + ASM_SIZE_DIRECTIVE(L(SP_INVPIO4)) + + .p2align 4 +L(DP_ABS_MASK): /* Mask for getting DP absolute value */ + .long 0xffffffff,0x7fffffff + .long 0xffffffff,0x7fffffff + .type L(DP_ABS_MASK), @object + ASM_SIZE_DIRECTIVE(L(DP_ABS_MASK)) + + .p2align 3 +L(DP_HI_MASK): /* Mask for getting high 21 bits of DP value */ + .long 0x00000000,0xffffffff + .type L(DP_HI_MASK),@object + ASM_SIZE_DIRECTIVE(L(DP_HI_MASK)) + + .p2align 4 +L(SP_ABS_MASK): /* Mask for getting SP absolute value */ + .long 0x7fffffff,0x7fffffff + .long 0x7fffffff,0x7fffffff + .type L(SP_ABS_MASK), @object + ASM_SIZE_DIRECTIVE(L(SP_ABS_MASK)) + +weak_alias(__sinf, sinf) diff --git a/libc/sysdeps/x86_64/tst-xmmymm.sh b/libc/sysdeps/x86_64/tst-xmmymm.sh index da8af7e68..64efc6e02 100755 --- a/libc/sysdeps/x86_64/tst-xmmymm.sh +++ b/libc/sysdeps/x86_64/tst-xmmymm.sh @@ -1,4 +1,24 @@ #! /bin/bash +# Make sure no code in ld.so uses xmm/ymm registers on x86-64. +# Copyright (C) 2009-2012 Free Software Foundation, Inc. +# This file is part of the GNU C Library. + +# 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/>. + +set -e + objpfx="$1" tmp=$(mktemp ${objpfx}tst-xmmymm.XXXXXX) |