Print this page
5262 libm needs to be carefully unifdef'd
5268 libm doesn't need to hide symbols which are already local
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/m9x/llroundl.c
+++ new/usr/src/lib/libm/common/m9x/llroundl.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 30 #pragma weak llroundl = __llroundl
32 31 #if defined(__sparcv9) || defined(__amd64)
33 32 #pragma weak lroundl = __llroundl
34 33 #pragma weak __lroundl = __llroundl
35 34 #endif
36 -#endif
37 35
38 36 #include "libm.h"
39 37
40 38 #if defined(__sparc)
41 39 long long
42 40 llroundl(long double x) {
43 41 union {
44 42 unsigned i[4];
45 43 long double q;
46 44 } xx;
47 45 union {
48 46 unsigned i[2];
49 47 long long l;
50 48 } zz;
51 49 union {
52 50 unsigned i;
53 51 float f;
54 52 } tt;
55 53 unsigned hx, sx, frac;
56 54 int j;
57 55
58 56 xx.q = x;
59 57 sx = xx.i[0] & 0x80000000;
60 58 hx = xx.i[0] & ~0x80000000;
61 59
62 60 /* handle trivial cases */
63 61 if (hx > 0x403e0000) { /* |x| > 2^63 + ... or x is nan */
64 62 /* convert an out-of-range float */
65 63 tt.i = sx | 0x7f000000;
66 64 return ((long long) tt.f);
67 65 }
68 66
69 67 /* handle |x| < 1 */
70 68 if (hx < 0x3fff0000) {
71 69 if (hx >= 0x3ffe0000)
72 70 return (sx ? -1LL : 1LL);
73 71 return (0LL);
74 72 }
75 73
76 74 /* extract the integer and fractional parts of x */
77 75 j = 0x406f - (hx >> 16);
78 76 xx.i[0] = 0x10000 | (xx.i[0] & 0xffff);
79 77 if (j >= 96) {
80 78 zz.i[0] = 0;
81 79 zz.i[1] = xx.i[0] >> (j - 96);
82 80 frac = ((xx.i[0] << 1) << (127 - j)) | (xx.i[1] >> (j - 96));
83 81 if (((xx.i[1] << 1) << (127 - j)) | xx.i[2] | xx.i[3])
84 82 frac |= 1;
85 83 } else if (j >= 64) {
86 84 zz.i[0] = xx.i[0] >> (j - 64);
87 85 zz.i[1] = ((xx.i[0] << 1) << (95 - j)) | (xx.i[1] >> (j - 64));
88 86 frac = ((xx.i[1] << 1) << (95 - j)) | (xx.i[2] >> (j - 64));
89 87 if (((xx.i[2] << 1) << (95 - j)) | xx.i[3])
90 88 frac |= 1;
91 89 } else {
92 90 zz.i[0] = ((xx.i[0] << 1) << (63 - j)) | (xx.i[1] >> (j - 32));
93 91 zz.i[1] = ((xx.i[1] << 1) << (63 - j)) | (xx.i[2] >> (j - 32));
94 92 frac = ((xx.i[2] << 1) << (63 - j)) | (xx.i[3] >> (j - 32));
95 93 if ((xx.i[3] << 1) << (63 - j))
96 94 frac |= 1;
97 95 }
98 96
99 97 /* round */
100 98 if (frac >= 0x80000000u) {
101 99 if (++zz.i[1] == 0)
102 100 zz.i[0]++;
103 101 }
104 102
105 103 /* check for result out of range (note that z is |x| at this point) */
106 104 if (zz.i[0] > 0x80000000u || (zz.i[0] == 0x80000000 && (zz.i[1] ||
107 105 !sx))) {
108 106 tt.i = sx | 0x7f000000;
109 107 return ((long long) tt.f);
110 108 }
111 109
112 110 /* negate result if need be */
113 111 if (sx) {
114 112 zz.i[0] = ~zz.i[0];
115 113 zz.i[1] = -zz.i[1];
116 114 if (zz.i[1] == 0)
117 115 zz.i[0]++;
118 116 }
119 117
120 118 return (zz.l);
121 119 }
122 120 #elif defined(__x86)
123 121 long long
124 122 llroundl(long double x) {
125 123 union {
126 124 unsigned i[3];
127 125 long double e;
128 126 } xx;
129 127 int ex, sx, i;
130 128
131 129 xx.e = x;
132 130 ex = xx.i[2] & 0x7fff;
133 131 sx = xx.i[2] & 0x8000;
134 132
135 133 if (ex < 0x403e) { /* |x| < 2^63 */
136 134 /* handle |x| < 1 */
137 135 if (ex < 0x3fff) {
138 136 if (ex >= 0x3ffe)
139 137 return (sx ? -1LL : 1LL);
140 138 return (0LL);
141 139 }
142 140
143 141 /* round x at the integer bit */
144 142 if (ex < 0x401e) {
145 143 i = 1 << (0x401d - ex);
146 144 xx.i[1] = (xx.i[1] + i) & ~(i | (i - 1));
147 145 xx.i[0] = 0;
148 146 } else {
149 147 i = 1 << (0x403d - ex);
150 148 xx.i[0] += i;
151 149 if (xx.i[0] < i)
152 150 xx.i[1]++;
153 151 xx.i[0] &= ~(i | (i - 1));
154 152 }
155 153 if (xx.i[1] == 0) {
156 154 xx.i[2] = sx | ++ex;
157 155 xx.i[1] = 0x80000000U;
158 156 }
159 157 }
160 158
161 159 /* now x is nan, inf, or integral */
162 160 return ((long long) xx.e);
163 161 }
164 162 #else
165 163 #error Unknown architecture
166 164 #endif
↓ open down ↓ |
120 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX