1 /*-
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
5  *
6  * Developed at SunSoft, a Sun Microsystems, Inc. business.
7  * Permission to use, copy, modify, and distribute this
8  * software is freely granted, provided that this notice
9  * is preserved.
10  * ====================================================
11  *
12  * k_sinl.c and k_cosl.c merged by Steven G. Kargl
13  */
14 
15 #if defined(__amd64__) || defined(__i386__)
16 /* Long double constants are slow on these arches, and broken on i386. */
17 static const volatile double
18 C1hi = 0.041666666666666664,		/*  0x15555555555555.0p-57 */
19 C1lo = 2.2598839032744733e-18,		/*  0x14d80000000000.0p-111 */
20 S1hi = -0.16666666666666666,		/* -0x15555555555555.0p-55 */
21 S1lo = -9.2563760475949941e-18;		/* -0x15580000000000.0p-109 */
22 #define	S1	((long double)S1hi + S1lo)
23 #define	C1	((long double)C1hi + C1lo)
24 #else
25 static const long double
26 C1 =  0.0416666666666666666136L;	/*  0xaaaaaaaaaaaaaa9b.0p-68 */
27 S1 = -0.166666666666666666671L,		/* -0xaaaaaaaaaaaaaaab.0p-66 */
28 #endif
29 
30 static const double
31 C2 = -0.0013888888888888874,		/* -0x16c16c16c16c10.0p-62 */
32 C3 =  0.000024801587301571716,		/*  0x1a01a01a018e22.0p-68 */
33 C4 = -0.00000027557319215507120,	/* -0x127e4fb7602f22.0p-74 */
34 C5 =  0.0000000020876754400407278,	/*  0x11eed8caaeccf1.0p-81 */
35 C6 = -1.1470297442401303e-11,		/* -0x19393412bd1529.0p-89 */
36 C7 =  4.7383039476436467e-14,		/*  0x1aac9d9af5c43e.0p-97 */
37 S2 =  0.0083333333333333332,		/*  0x11111111111111.0p-59 */
38 S3 = -0.00019841269841269427,		/* -0x1a01a01a019f81.0p-65 */
39 S4 =  0.0000027557319223597490,		/*  0x171de3a55560f7.0p-71 */
40 S5 = -0.000000025052108218074604,	/* -0x1ae64564f16cad.0p-78 */
41 S6 =  1.6059006598854211e-10,		/*  0x161242b90243b5.0p-85 */
42 S7 = -7.6429779983024564e-13,		/* -0x1ae42ebd1b2e00.0p-93 */
43 S8 =  2.6174587166648325e-15;		/*  0x179372ea0b3f64.0p-101 */
44 
45 static inline void
46 __kernel_sincosl(long double x, long double y, int iy, long double *sn,
47     long double *cs)
48 {
49 	long double hz, r, v, w, z;
50 
51 	z = x * x;
52 	v = z * x;
53 	/*
54 	 * XXX Replace Horner scheme with an algorithm suitable for CPUs
55 	 * with more complex pipelines.
56 	 */
57 	r = S2 + z * (S3 + z * (S4 + z * (S5 + z * (S6 + z * (S7 + z * S8)))));
58 
59 	if (iy == 0)
60 		*sn = x + v * (S1 + z * r);
61 	else
62 		*sn = x - ((z * (y / 2 - v * r) - y) - v * S1);
63 
64 	hz = z / 2;
65 	w = 1 - hz;
66 	r = z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * (C6 +
67 	    z * C7))))));
68 	*cs = w + (((1 - w) - hz) + (z * r - x * y));
69 }
70