Line 0
Link Here
|
|
|
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 LDBL_MANT_DIG == 64 /* ld80 version of k_sincosl.c. */ |
16 |
|
17 |
#if defined(__amd64__) || defined(__i386__) |
18 |
/* Long double constants are slow on these arches, and broken on i386. */ |
19 |
static const volatile double |
20 |
C1hi = 0.041666666666666664, /* 0x15555555555555.0p-57 */ |
21 |
C1lo = 2.2598839032744733e-18, /* 0x14d80000000000.0p-111 */ |
22 |
S1hi = -0.16666666666666666, /* -0x15555555555555.0p-55 */ |
23 |
S1lo = -9.2563760475949941e-18; /* -0x15580000000000.0p-109 */ |
24 |
#define S1 ((long double)S1hi + S1lo) |
25 |
#define C1 ((long double)C1hi + C1lo) |
26 |
#else |
27 |
static const long double |
28 |
C1 = 0.0416666666666666666136L; /* 0xaaaaaaaaaaaaaa9b.0p-68 */ |
29 |
S1 = -0.166666666666666666671L, /* -0xaaaaaaaaaaaaaaab.0p-66 */ |
30 |
#endif |
31 |
|
32 |
static const double |
33 |
C2 = -0.0013888888888888874, /* -0x16c16c16c16c10.0p-62 */ |
34 |
C3 = 0.000024801587301571716, /* 0x1a01a01a018e22.0p-68 */ |
35 |
C4 = -0.00000027557319215507120, /* -0x127e4fb7602f22.0p-74 */ |
36 |
C5 = 0.0000000020876754400407278, /* 0x11eed8caaeccf1.0p-81 */ |
37 |
C6 = -1.1470297442401303e-11, /* -0x19393412bd1529.0p-89 */ |
38 |
C7 = 4.7383039476436467e-14, /* 0x1aac9d9af5c43e.0p-97 */ |
39 |
S2 = 0.0083333333333333332, /* 0x11111111111111.0p-59 */ |
40 |
S3 = -0.00019841269841269427, /* -0x1a01a01a019f81.0p-65 */ |
41 |
S4 = 0.0000027557319223597490, /* 0x171de3a55560f7.0p-71 */ |
42 |
S5 = -0.000000025052108218074604, /* -0x1ae64564f16cad.0p-78 */ |
43 |
S6 = 1.6059006598854211e-10, /* 0x161242b90243b5.0p-85 */ |
44 |
S7 = -7.6429779983024564e-13, /* -0x1ae42ebd1b2e00.0p-93 */ |
45 |
S8 = 2.6174587166648325e-15; /* 0x179372ea0b3f64.0p-101 */ |
46 |
|
47 |
static inline void |
48 |
__kernel_sincosl(long double x, long double y, int iy, long double *sn, |
49 |
long double *cs) |
50 |
{ |
51 |
long double hz, r, v, w, z; |
52 |
|
53 |
z = x * x; |
54 |
v = z * x; |
55 |
/* |
56 |
* XXX Replace Horner scheme with an algorithm suitable for CPUs |
57 |
* with more complex pipelines. |
58 |
*/ |
59 |
r = S2 + z * (S3 + z * (S4 + z * (S5 + z * (S6 + z * (S7 + z * S8))))); |
60 |
|
61 |
if (iy == 0) |
62 |
*sn = x + v * (S1 + z * r); |
63 |
else |
64 |
*sn = x - ((z * (y / 2 - v * r) - y) - v * S1); |
65 |
|
66 |
hz = z / 2; |
67 |
w = 1 - hz; |
68 |
r = z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * (C6 + |
69 |
z * C7)))))); |
70 |
*cs = w + (((1 - w) - hz) + (z * r - x * y)); |
71 |
} |
72 |
|
73 |
#elif LDBL_MANT_DIG == 113 /* ld128 version of k_sincosl.c. */ |
74 |
|
75 |
static const long double |
76 |
C1 = 0.04166666666666666666666666666666658424671L, |
77 |
C2 = -0.001388888888888888888888888888863490893732L, |
78 |
C3 = 0.00002480158730158730158730158600795304914210L, |
79 |
C4 = -0.2755731922398589065255474947078934284324e-6L, |
80 |
C5 = 0.2087675698786809897659225313136400793948e-8L, |
81 |
C6 = -0.1147074559772972315817149986812031204775e-10L, |
82 |
C7 = 0.4779477332386808976875457937252120293400e-13L, |
83 |
S1 = -0.16666666666666666666666666666666666606732416116558L, |
84 |
S2 = 0.0083333333333333333333333333333331135404851288270047L, |
85 |
S3 = -0.00019841269841269841269841269839935785325638310428717L, |
86 |
S4 = 0.27557319223985890652557316053039946268333231205686e-5L, |
87 |
S5 = -0.25052108385441718775048214826384312253862930064745e-7L, |
88 |
S6 = 0.16059043836821614596571832194524392581082444805729e-9L, |
89 |
S7 = -0.76471637318198151807063387954939213287488216303768e-12L, |
90 |
S8 = 0.28114572543451292625024967174638477283187397621303e-14L; |
91 |
|
92 |
static const double |
93 |
C8 = -0.1561920696721507929516718307820958119868e-15, |
94 |
C9 = 0.4110317413744594971475941557607804508039e-18, |
95 |
C10 = -0.8896592467191938803288521958313920156409e-21, |
96 |
C11 = 0.1601061435794535138244346256065192782581e-23, |
97 |
S9 = -0.82206352458348947812512122163446202498005154296863e-17, |
98 |
S10 = 0.19572940011906109418080609928334380560135358385256e-19, |
99 |
S11 = -0.38680813379701966970673724299207480965452616911420e-22, |
100 |
S12 = 0.64038150078671872796678569586315881020659912139412e-25; |
101 |
|
102 |
static inline void |
103 |
__kernel_sincosl(long double x, long double y, int iy, long double *sn, |
104 |
long double *cs) |
105 |
{ |
106 |
long double hz, r, v, w, z; |
107 |
|
108 |
z = x * x; |
109 |
v = z * x; |
110 |
/* |
111 |
* XXX Replace Horner scheme with an algorithm suitable for CPUs |
112 |
* with more complex pipelines. |
113 |
*/ |
114 |
r = S2 + z * (S3 + z * (S4 + z * (S5 + z * (S6 + z * (S7 + z * (S8 + |
115 |
z * (S9 + z * (S10 + z * (S11 + z * S12))))))))); |
116 |
|
117 |
if (iy == 0) |
118 |
*sn = x + v * (S1 + z * r); |
119 |
else |
120 |
*cs = x - ((z * (y / 2 - v * r) - y) - v * S1); |
121 |
|
122 |
hz = z / 2; |
123 |
w = 1 - hz; |
124 |
r = z * (C1 + z * (C2 + z * (C3 + z * (C4 + z * (C5 + z * (C6 + |
125 |
z * (C7 + z * (C8 + z * (C9 + z * (C10 + z * C11)))))))))); |
126 |
|
127 |
*cs = w + (((1 - w) - hz) + (z * r - x * y)); |
128 |
} |
129 |
#else |
130 |
#error "Unsupported long double format" |
131 |
#endif |