Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libm Add sincos{,f,l} from FreeBSD



details:   https://anonhg.NetBSD.org/src/rev/4df3b252e488
branches:  trunk
changeset: 369655:4df3b252e488
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Aug 27 08:31:58 2022 +0000

description:
Add sincos{,f,l} from FreeBSD

diffstat:

 distrib/sets/lists/comp/mi     |    5 +-
 distrib/sets/lists/debug/mi    |    3 +-
 distrib/sets/lists/tests/mi    |    3 +-
 include/math.h                 |    6 +-
 lib/libm/Makefile              |    7 +-
 lib/libm/ld128/e_rem_pio2l.h   |  139 +++++++++++
 lib/libm/ld80/e_rem_pio2l.h    |  147 ++++++++++++
 lib/libm/man/sincos.3          |   85 +++++++
 lib/libm/noieee_src/n_sincos.c |   17 +-
 lib/libm/src/e_rem_pio2f.h     |   80 ++++++
 lib/libm/src/e_rem_pio2l.h     |  135 +++++++++++
 lib/libm/src/k_sincos.h        |   57 ++++
 lib/libm/src/k_sincosf.h       |   48 ++++
 lib/libm/src/k_sincosl.h       |  139 +++++++++++
 lib/libm/src/math_private.h    |   35 ++-
 lib/libm/src/namespace.h       |    5 +-
 lib/libm/src/s_sincos.c        |   90 +++++++
 lib/libm/src/s_sincosf.c       |  136 +++++++++++
 lib/libm/src/s_sincosl.c       |  116 +++++++++
 tests/lib/libm/Makefile        |    3 +-
 tests/lib/libm/t_sincos.c      |  478 +++++++++++++++++++++++++++++++++++++++++
 21 files changed, 1723 insertions(+), 11 deletions(-)

diffs (truncated from 1936 to 300 lines):

diff -r 7ba2952fd1d4 -r 4df3b252e488 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Sat Aug 27 08:30:06 2022 +0000
+++ b/distrib/sets/lists/comp/mi        Sat Aug 27 08:31:58 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2417 2022/07/22 15:43:36 wiz Exp $
+#      $NetBSD: mi,v 1.2418 2022/08/27 08:31:58 christos Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -10280,6 +10280,7 @@
 ./usr/share/man/cat3/simpleq_next.0            comp-obsolete           obsolete
 ./usr/share/man/cat3/simpleq_remove_head.0     comp-obsolete           obsolete
 ./usr/share/man/cat3/sin.0                     comp-c-catman           .cat
+./usr/share/man/cat3/sincos.0                  comp-c-catman           .cat
 ./usr/share/man/cat3/sinf.0                    comp-c-catman           .cat
 ./usr/share/man/cat3/sinh.0                    comp-c-catman           .cat
 ./usr/share/man/cat3/sinhf.0                   comp-c-catman           .cat
@@ -18562,6 +18563,7 @@
 ./usr/share/man/html3/sigsetops.html           comp-c-htmlman          html
 ./usr/share/man/html3/sigvec.html              comp-c-htmlman          html
 ./usr/share/man/html3/sin.html                 comp-c-htmlman          html
+./usr/share/man/html3/sincos.html              comp-c-htmlman          html
 ./usr/share/man/html3/sinf.html                        comp-c-htmlman          html
 ./usr/share/man/html3/sinh.html                        comp-c-htmlman          html
 ./usr/share/man/html3/sinhf.html               comp-c-htmlman          html
@@ -26878,6 +26880,7 @@
 ./usr/share/man/man3/simpleq_next.3            comp-obsolete           obsolete
 ./usr/share/man/man3/simpleq_remove_head.3     comp-obsolete           obsolete
 ./usr/share/man/man3/sin.3                     comp-c-man              .man
+./usr/share/man/man3/sincos.3                  comp-c-man              .man
 ./usr/share/man/man3/sinf.3                    comp-c-man              .man
 ./usr/share/man/man3/sinh.3                    comp-c-man              .man
 ./usr/share/man/man3/sinhf.3                   comp-c-man              .man
diff -r 7ba2952fd1d4 -r 4df3b252e488 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Sat Aug 27 08:30:06 2022 +0000
+++ b/distrib/sets/lists/debug/mi       Sat Aug 27 08:31:58 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.387 2022/06/06 10:56:27 nia Exp $
+# $NetBSD: mi,v 1.388 2022/08/27 08:31:58 christos Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -2311,6 +2311,7 @@
 ./usr/libdata/debug/usr/tests/lib/libm/t_round.debug                   tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libm/t_scalbn.debug                  tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libm/t_sin.debug                     tests-lib-debug         debug,atf,compattestfile
+./usr/libdata/debug/usr/tests/lib/libm/t_sincos.debug                  tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libm/t_sinh.debug                    tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libm/t_sqrt.debug                    tests-lib-debug         debug,atf,compattestfile
 ./usr/libdata/debug/usr/tests/lib/libm/t_tan.debug                     tests-lib-debug         debug,atf,compattestfile
diff -r 7ba2952fd1d4 -r 4df3b252e488 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Aug 27 08:30:06 2022 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Aug 27 08:31:58 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1219 2022/08/12 10:49:17 riastradh Exp $
+# $NetBSD: mi,v 1.1220 2022/08/27 08:31:58 christos Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3841,6 +3841,7 @@
 ./usr/tests/lib/libm/t_round                           tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libm/t_scalbn                          tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libm/t_sin                             tests-lib-tests         compattestfile,atf
+./usr/tests/lib/libm/t_sincos                          tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libm/t_sinh                            tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libm/t_sqrt                            tests-lib-tests         compattestfile,atf
 ./usr/tests/lib/libm/t_tan                             tests-lib-tests         compattestfile,atf
diff -r 7ba2952fd1d4 -r 4df3b252e488 include/math.h
--- a/include/math.h    Sat Aug 27 08:30:06 2022 +0000
+++ b/include/math.h    Sat Aug 27 08:31:58 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: math.h,v 1.66 2020/02/22 22:47:35 joerg Exp $  */
+/*     $NetBSD: math.h,v 1.67 2022/08/27 08:31:59 christos Exp $       */
 
 /*
  * ====================================================
@@ -553,6 +553,10 @@
  * float versions of BSD math library entry points
  */
 float  dremf(float, float);
+
+void           sincos(double, double *, double *);
+void           sincosf(float, float *, float *);
+void           sincosl(long double, long double *, long double *);
 #endif /* _NETBSD_SOURCE */
 
 #if defined(_NETBSD_SOURCE) || defined(_REENTRANT)
diff -r 7ba2952fd1d4 -r 4df3b252e488 lib/libm/Makefile
--- a/lib/libm/Makefile Sat Aug 27 08:30:06 2022 +0000
+++ b/lib/libm/Makefile Sat Aug 27 08:31:58 2022 +0000
@@ -1,4 +1,4 @@
-#  $NetBSD: Makefile,v 1.216 2022/06/23 16:42:50 martin Exp $
+#  $NetBSD: Makefile,v 1.217 2022/08/27 08:31:58 christos Exp $
 #
 #  @(#)Makefile 5.1beta 93/09/24
 #
@@ -282,7 +282,8 @@
        s_matherr.c s_modff.c s_modfl.c s_nearbyint.c s_nextafter.c s_nextafterl.c \
        s_nextafterf.c s_nexttowardf.c s_remquo.c s_remquof.c s_rint.c s_rintf.c \
        s_round.c s_roundf.c s_roundl.c s_scalbn.c \
-       s_scalbnf.c s_scalbnl.c s_signgam.c s_significand.c s_significandf.c s_sin.c \
+       s_scalbnf.c s_scalbnl.c s_signgam.c s_significand.c s_significandf.c \
+       s_sincos.c s_sincosf.c s_sincosl.c s_sin.c \
        s_sinf.c s_tan.c s_tanf.c s_tanh.c s_tanhf.c s_tgammaf.c \
        s_trunc.c s_truncf.c s_truncl.c \
        w_acos.c w_acosf.c w_acosh.c w_acoshf.c w_asin.c w_asinf.c w_atan2.c \
@@ -354,7 +355,7 @@
        ieee_test.3 ilogb.3 isinff.3 j0.3 ldexp.3 lgamma.3 log.3 lrint.3 \
        math.3 modf.3 nextafter.3 pow.3 \
        remainder.3 rint.3 round.3 \
-       scalbn.3 sin.3 sinh.3 sqrt.3 \
+       scalbn.3 sincos.3 sin.3 sinh.3 sqrt.3 \
        tan.3 tanh.3 trunc.3 fmax.3 fdim.3
 
 # fenv.h interface
diff -r 7ba2952fd1d4 -r 4df3b252e488 lib/libm/ld128/e_rem_pio2l.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libm/ld128/e_rem_pio2l.h      Sat Aug 27 08:31:58 2022 +0000
@@ -0,0 +1,139 @@
+/* From: @(#)e_rem_pio2.c 1.4 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ *
+ * Optimized by Bruce D. Evans.
+ */
+
+#include <sys/cdefs.h>
+#if 0
+__FBSDID("$FreeBSD: head/lib/msun/ld128/e_rem_pio2l.h 336545 2018-07-20 12:42:24Z bde $");
+#endif
+
+/* ld128 version of __ieee754_rem_pio2l(x,y)
+ * 
+ * return the remainder of x rem pi/2 in y[0]+y[1] 
+ * use __kernel_rem_pio2()
+ */
+
+#include <float.h>
+#include <machine/ieee.h>
+
+#include "math.h"
+#include "math_private.h"
+
+#define        BIAS    (LDBL_MAX_EXP - 1)
+
+/*
+ * XXX need to verify that nonzero integer multiples of pi/2 within the
+ * range get no closer to a long double than 2**-140, or that
+ * ilogb(x) + ilogb(min_delta) < 45 - -140.
+ */
+/*
+ * invpio2:  113 bits of 2/pi
+ * pio2_1:   first  68 bits of pi/2
+ * pio2_1t:  pi/2 - pio2_1
+ * pio2_2:   second 68 bits of pi/2
+ * pio2_2t:  pi/2 - (pio2_1+pio2_2)
+ * pio2_3:   third  68 bits of pi/2
+ * pio2_3t:  pi/2 - (pio2_1+pio2_2+pio2_3)
+ */
+
+static const double
+zero =  0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */
+two24 =  1.67772160000000000000e+07; /* 0x41700000, 0x00000000 */
+
+static const long double
+invpio2 =  6.3661977236758134307553505349005747e-01L,  /*  0x145f306dc9c882a53f84eafa3ea6a.0p-113 */
+pio2_1  =  1.5707963267948966192292994253909555e+00L,  /*  0x1921fb54442d18469800000000000.0p-112 */
+pio2_1t =  2.0222662487959507323996846200947577e-21L,  /*  0x13198a2e03707344a4093822299f3.0p-181 */
+pio2_2  =  2.0222662487959507323994779168837751e-21L,  /*  0x13198a2e03707344a400000000000.0p-181 */
+pio2_2t =  2.0670321098263988236496903051604844e-43L,  /*  0x127044533e63a0105df531d89cd91.0p-254 */
+pio2_3  =  2.0670321098263988236499468110329591e-43L,  /*  0x127044533e63a0105e00000000000.0p-254 */
+pio2_3t = -2.5650587247459238361625433492959285e-65L;  /* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 */
+
+static inline __always_inline int
+__ieee754_rem_pio2l(long double x, long double *y)
+{
+       union ieee_ext_u u,u1;
+       long double z,w,t,r,fn;
+       double tx[5],ty[3];
+       int64_t n;
+       int e0,ex,i,j,nx;
+       int16_t expsign, expsign1;
+
+       u.extu_ld = x;
+       ex = u.extu_exp;
+       expsign = u.extu_exp | (u.extu_sign << 15);
+       if (ex < BIAS + 45 || (ex == BIAS + 45 &&
+           u.extu_frach < 0x921fb54442d1LL)) {
+           /* |x| ~< 2^45*(pi/2), medium size */
+           /* TODO: use only double precision for fn, as in expl(). */
+           fn = rnintl(x * invpio2);
+           n  = i64rint(fn);
+           r  = x-fn*pio2_1;
+           w  = fn*pio2_1t;    /* 1st round good to 180 bit */
+           {
+               union ieee_ext_u u2;
+               int ex1;
+               j  = ex;
+               y[0] = r-w; 
+               u2.extu_ld = y[0];
+               ex1 = u2.extu_exp;
+               i = j-ex1;
+               if(i>51) {  /* 2nd iteration needed, good to 248 */
+                   t  = r;
+                   w  = fn*pio2_2;     
+                   r  = t-w;
+                   w  = fn*pio2_2t-((t-r)-w);  
+                   y[0] = r-w;
+                   u2.extu_ld = y[0];
+                   ex1 = u2.extu_exp;
+                   i = j-ex1;
+                   if(i>119) { /* 3rd iteration need, 316 bits acc */
+                       t  = r; /* will cover all possible cases */
+                       w  = fn*pio2_3; 
+                       r  = t-w;
+                       w  = fn*pio2_3t-((t-r)-w);      
+                       y[0] = r-w;
+                   }
+               }
+           }
+           y[1] = (r-y[0])-w;
+           return n;
+       }
+    /* 
+     * all other (large) arguments
+     */
+       if(ex==0x7fff) {                /* x is inf or NaN */
+           y[0]=y[1]=x-x; return 0;
+       }
+    /* set z = scalbn(|x|,ilogb(x)-23) */
+       u1.extu_ld = x;
+       e0 = ex - BIAS - 23;            /* e0 = ilogb(|x|)-23; */
+       expsign1 = ex - e0;
+       u1.extu_exp = expsign1;
+       u1.extu_sign = expsign1 >> 15;
+       z = u1.extu_ld;
+       for(i=0;i<4;i++) {
+               tx[i] = (double)((int32_t)(z));
+               z     = (z-tx[i])*two24;
+       }
+       tx[4] = z;
+       nx = 5;
+       while(tx[nx-1]==zero) nx--;     /* skip zero term */
+       n  =  __kernel_rem_pio2(tx,ty,e0,nx,3);
+       t = (long double)ty[2] + ty[1];
+       r = t + ty[0];
+       w = ty[0] - (r - t);
+       if(expsign<0) {y[0] = -r; y[1] = -w; return -n;}
+       y[0] = r; y[1] = w; return n;
+}
diff -r 7ba2952fd1d4 -r 4df3b252e488 lib/libm/ld80/e_rem_pio2l.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libm/ld80/e_rem_pio2l.h       Sat Aug 27 08:31:58 2022 +0000
@@ -0,0 +1,147 @@
+/* From: @(#)e_rem_pio2.c 1.4 95/01/18 */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
+ *
+ * Developed at SunSoft, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice 
+ * is preserved.
+ * ====================================================
+ *
+ * Optimized by Bruce D. Evans.
+ */
+
+#include <sys/cdefs.h>
+#if 0
+__FBSDID("$FreeBSD: head/lib/msun/ld80/e_rem_pio2l.h 336545 2018-07-20 12:42:24Z bde $");
+#endif
+
+/* ld80 version of __ieee754_rem_pio2l(x,y)
+ * 
+ * return the remainder of x rem pi/2 in y[0]+y[1] 
+ * use __kernel_rem_pio2()
+ */
+
+#include <float.h>
+#include <machine/ieee.h>
+
+#include "math.h"
+#include "math_private.h"
+
+#define        BIAS    (LDBL_MAX_EXP - 1)
+
+/*
+ * invpio2:  64 bits of 2/pi
+ * pio2_1:   first  39 bits of pi/2
+ * pio2_1t:  pi/2 - pio2_1



Home | Main Index | Thread Index | Old Index