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