Print this page
5261 libm should stop using synonyms.h
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 -#pragma weak llrintl = __llrintl
30 +#pragma weak __llrintl = llrintl
31 31 #if defined(__sparcv9) || defined(__amd64)
32 -#pragma weak lrintl = __llrintl
33 -#pragma weak __lrintl = __llrintl
32 +#pragma weak lrintl = llrintl
33 +#pragma weak __lrintl = llrintl
34 34 #endif
35 35
36 36 #include "libm.h"
37 37
38 38 #if defined(__sparc)
39 39
40 40 #include "fma.h"
41 41 #include "fenv_inlines.h"
42 42
43 43 long long
44 44 llrintl(long double x) {
45 45 union {
46 46 unsigned i[4];
47 47 long double q;
48 48 } xx;
49 49 union {
50 50 unsigned i[2];
51 51 long long l;
52 52 } zz;
53 53 union {
54 54 unsigned i;
55 55 float f;
56 56 } tt;
57 57 unsigned int hx, sx, frac, fsr;
58 58 int rm, j;
59 59 volatile float dummy;
60 60
61 61 xx.q = x;
62 62 sx = xx.i[0] & 0x80000000;
63 63 hx = xx.i[0] & ~0x80000000;
64 64
65 65 /* handle trivial cases */
66 66 if (hx > 0x403e0000) { /* |x| > 2^63 + ... or x is nan */
67 67 /* convert an out-of-range float */
68 68 tt.i = sx | 0x7f000000;
69 69 return ((long long) tt.f);
70 70 } else if ((hx | xx.i[1] | xx.i[2] | xx.i[3]) == 0) /* x is zero */
71 71 return (0LL);
72 72
73 73 /* get the rounding mode */
74 74 __fenv_getfsr32(&fsr);
75 75 rm = fsr >> 30;
76 76
77 77 /* flip the sense of directed roundings if x is negative */
78 78 if (sx)
79 79 rm ^= rm >> 1;
80 80
81 81 /* handle |x| < 1 */
82 82 if (hx < 0x3fff0000) {
83 83 dummy = 1.0e30f; /* x is nonzero, so raise inexact */
84 84 dummy += 1.0e-30f;
85 85 if (rm == FSR_RP || (rm == FSR_RN && (hx >= 0x3ffe0000 &&
86 86 ((hx & 0xffff) | xx.i[1] | xx.i[2] | xx.i[3]))))
87 87 return (sx ? -1LL : 1LL);
88 88 return (0LL);
89 89 }
90 90
91 91 /* extract the integer and fractional parts of x */
92 92 j = 0x406f - (hx >> 16);
93 93 xx.i[0] = 0x10000 | (xx.i[0] & 0xffff);
94 94 if (j >= 96) {
95 95 zz.i[0] = 0;
96 96 zz.i[1] = xx.i[0] >> (j - 96);
97 97 frac = ((xx.i[0] << 1) << (127 - j)) | (xx.i[1] >> (j - 96));
98 98 if (((xx.i[1] << 1) << (127 - j)) | xx.i[2] | xx.i[3])
99 99 frac |= 1;
100 100 } else if (j >= 64) {
101 101 zz.i[0] = xx.i[0] >> (j - 64);
102 102 zz.i[1] = ((xx.i[0] << 1) << (95 - j)) | (xx.i[1] >> (j - 64));
103 103 frac = ((xx.i[1] << 1) << (95 - j)) | (xx.i[2] >> (j - 64));
104 104 if (((xx.i[2] << 1) << (95 - j)) | xx.i[3])
105 105 frac |= 1;
106 106 } else {
107 107 zz.i[0] = ((xx.i[0] << 1) << (63 - j)) | (xx.i[1] >> (j - 32));
108 108 zz.i[1] = ((xx.i[1] << 1) << (63 - j)) | (xx.i[2] >> (j - 32));
109 109 frac = ((xx.i[2] << 1) << (63 - j)) | (xx.i[3] >> (j - 32));
110 110 if ((xx.i[3] << 1) << (63 - j))
111 111 frac |= 1;
112 112 }
113 113
114 114 /* round */
115 115 if (frac && (rm == FSR_RP || (rm == FSR_RN && (frac > 0x80000000u ||
116 116 (frac == 0x80000000 && (zz.i[1] & 1)))))) {
117 117 if (++zz.i[1] == 0)
118 118 zz.i[0]++;
119 119 }
120 120
121 121 /* check for result out of range (note that z is |x| at this point) */
122 122 if (zz.i[0] > 0x80000000u || (zz.i[0] == 0x80000000 && (zz.i[1] ||
123 123 !sx))) {
124 124 tt.i = sx | 0x7f000000;
125 125 return ((long long) tt.f);
126 126 }
127 127
128 128 /* raise inexact if need be */
129 129 if (frac) {
130 130 dummy = 1.0e30F;
131 131 dummy += 1.0e-30F;
132 132 }
133 133
134 134 /* negate result if need be */
135 135 if (sx) {
136 136 zz.i[0] = ~zz.i[0];
137 137 zz.i[1] = -zz.i[1];
138 138 if (zz.i[1] == 0)
139 139 zz.i[0]++;
140 140 }
141 141 return (zz.l);
142 142 }
143 143 #elif defined(__x86)
144 144 long long
145 145 llrintl(long double x) {
146 146 /*
147 147 * Note: The following code works on x86 (in the default rounding
148 148 * precision mode), but one ought to just use the fistpll instruction
149 149 * instead.
150 150 */
151 151 union {
152 152 unsigned i[3];
153 153 long double e;
154 154 } xx, yy;
155 155 int ex;
156 156
157 157 xx.e = x;
158 158 ex = xx.i[2] & 0x7fff;
159 159
160 160 if (ex < 0x403e) { /* |x| < 2^63 */
161 161 /* add and subtract a power of two to round x to an integer */
162 162 yy.i[2] = (xx.i[2] & 0x8000) | 0x403e;
163 163 yy.i[1] = 0x80000000;
164 164 yy.i[0] = 0;
165 165 x = (x + yy.e) - yy.e;
166 166 }
167 167
168 168 /* now x is nan, inf, or integral */
169 169 return ((long long) x);
170 170 }
171 171 #else
172 172 #error Unknown architecture
173 173 #endif
↓ open down ↓ |
130 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX