Print this page
5261 libm should stop using synonyms.h
5298 fabs is 0-sized, confuses dis(1) and others
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Approved by: Gordon Ross <gwr@nexenta.com>
5262 libm needs to be carefully unifdef'd
5268 libm doesn't need to hide symbols which are already local
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Approved by: Gordon Ross <gwr@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/m9x/llrintl.c
+++ new/usr/src/lib/libm/common/m9x/llrintl.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
↓ open down ↓ |
19 lines elided |
↑ open up ↑ |
20 20 */
21 21
22 22 /*
23 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25 /*
26 26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 27 * Use is subject to license terms.
28 28 */
29 29
30 -#if defined(ELFOBJ)
31 -#pragma weak llrintl = __llrintl
30 +#pragma weak __llrintl = llrintl
32 31 #if defined(__sparcv9) || defined(__amd64)
33 -#pragma weak lrintl = __llrintl
34 -#pragma weak __lrintl = __llrintl
35 -#endif
32 +#pragma weak lrintl = llrintl
33 +#pragma weak __lrintl = llrintl
36 34 #endif
37 35
38 36 #include "libm.h"
39 37
40 38 #if defined(__sparc)
41 39
42 40 #include "fma.h"
43 41 #include "fenv_inlines.h"
44 42
45 43 long long
46 44 llrintl(long double x) {
47 45 union {
48 46 unsigned i[4];
49 47 long double q;
50 48 } xx;
51 49 union {
52 50 unsigned i[2];
53 51 long long l;
54 52 } zz;
55 53 union {
56 54 unsigned i;
57 55 float f;
58 56 } tt;
59 57 unsigned int hx, sx, frac, fsr;
60 58 int rm, j;
61 59 volatile float dummy;
62 60
63 61 xx.q = x;
64 62 sx = xx.i[0] & 0x80000000;
65 63 hx = xx.i[0] & ~0x80000000;
66 64
67 65 /* handle trivial cases */
68 66 if (hx > 0x403e0000) { /* |x| > 2^63 + ... or x is nan */
69 67 /* convert an out-of-range float */
70 68 tt.i = sx | 0x7f000000;
71 69 return ((long long) tt.f);
72 70 } else if ((hx | xx.i[1] | xx.i[2] | xx.i[3]) == 0) /* x is zero */
73 71 return (0LL);
74 72
75 73 /* get the rounding mode */
76 74 __fenv_getfsr32(&fsr);
77 75 rm = fsr >> 30;
78 76
79 77 /* flip the sense of directed roundings if x is negative */
80 78 if (sx)
81 79 rm ^= rm >> 1;
82 80
83 81 /* handle |x| < 1 */
84 82 if (hx < 0x3fff0000) {
85 83 dummy = 1.0e30f; /* x is nonzero, so raise inexact */
86 84 dummy += 1.0e-30f;
87 85 if (rm == FSR_RP || (rm == FSR_RN && (hx >= 0x3ffe0000 &&
88 86 ((hx & 0xffff) | xx.i[1] | xx.i[2] | xx.i[3]))))
89 87 return (sx ? -1LL : 1LL);
90 88 return (0LL);
91 89 }
92 90
93 91 /* extract the integer and fractional parts of x */
94 92 j = 0x406f - (hx >> 16);
95 93 xx.i[0] = 0x10000 | (xx.i[0] & 0xffff);
96 94 if (j >= 96) {
97 95 zz.i[0] = 0;
98 96 zz.i[1] = xx.i[0] >> (j - 96);
99 97 frac = ((xx.i[0] << 1) << (127 - j)) | (xx.i[1] >> (j - 96));
100 98 if (((xx.i[1] << 1) << (127 - j)) | xx.i[2] | xx.i[3])
101 99 frac |= 1;
102 100 } else if (j >= 64) {
103 101 zz.i[0] = xx.i[0] >> (j - 64);
104 102 zz.i[1] = ((xx.i[0] << 1) << (95 - j)) | (xx.i[1] >> (j - 64));
105 103 frac = ((xx.i[1] << 1) << (95 - j)) | (xx.i[2] >> (j - 64));
106 104 if (((xx.i[2] << 1) << (95 - j)) | xx.i[3])
107 105 frac |= 1;
108 106 } else {
109 107 zz.i[0] = ((xx.i[0] << 1) << (63 - j)) | (xx.i[1] >> (j - 32));
110 108 zz.i[1] = ((xx.i[1] << 1) << (63 - j)) | (xx.i[2] >> (j - 32));
111 109 frac = ((xx.i[2] << 1) << (63 - j)) | (xx.i[3] >> (j - 32));
112 110 if ((xx.i[3] << 1) << (63 - j))
113 111 frac |= 1;
114 112 }
115 113
116 114 /* round */
117 115 if (frac && (rm == FSR_RP || (rm == FSR_RN && (frac > 0x80000000u ||
118 116 (frac == 0x80000000 && (zz.i[1] & 1)))))) {
119 117 if (++zz.i[1] == 0)
120 118 zz.i[0]++;
121 119 }
122 120
123 121 /* check for result out of range (note that z is |x| at this point) */
124 122 if (zz.i[0] > 0x80000000u || (zz.i[0] == 0x80000000 && (zz.i[1] ||
125 123 !sx))) {
126 124 tt.i = sx | 0x7f000000;
127 125 return ((long long) tt.f);
128 126 }
129 127
130 128 /* raise inexact if need be */
131 129 if (frac) {
132 130 dummy = 1.0e30F;
133 131 dummy += 1.0e-30F;
134 132 }
135 133
136 134 /* negate result if need be */
137 135 if (sx) {
138 136 zz.i[0] = ~zz.i[0];
139 137 zz.i[1] = -zz.i[1];
140 138 if (zz.i[1] == 0)
141 139 zz.i[0]++;
142 140 }
143 141 return (zz.l);
144 142 }
145 143 #elif defined(__x86)
146 144 long long
147 145 llrintl(long double x) {
148 146 /*
149 147 * Note: The following code works on x86 (in the default rounding
150 148 * precision mode), but one ought to just use the fistpll instruction
151 149 * instead.
152 150 */
153 151 union {
154 152 unsigned i[3];
155 153 long double e;
156 154 } xx, yy;
157 155 int ex;
158 156
159 157 xx.e = x;
160 158 ex = xx.i[2] & 0x7fff;
161 159
162 160 if (ex < 0x403e) { /* |x| < 2^63 */
163 161 /* add and subtract a power of two to round x to an integer */
164 162 yy.i[2] = (xx.i[2] & 0x8000) | 0x403e;
165 163 yy.i[1] = 0x80000000;
166 164 yy.i[0] = 0;
167 165 x = (x + yy.e) - yy.e;
168 166 }
169 167
170 168 /* now x is nan, inf, or integral */
171 169 return ((long long) x);
172 170 }
173 171 #else
174 172 #error Unknown architecture
175 173 #endif
↓ open down ↓ |
130 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX