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/roundl.c
+++ new/usr/src/lib/libm/common/m9x/roundl.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 roundl = __roundl
32 -#endif
33 31
34 32 #include "libm.h"
35 33
36 34 #if defined(__sparc)
37 35 long double
38 36 roundl(long double x) {
39 37 union {
40 38 unsigned i[4];
41 39 long double q;
42 40 } xx;
43 41 unsigned hx, sx, v;
44 42 int j;
45 43
46 44 xx.q = x;
47 45 sx = xx.i[0] & 0x80000000;
48 46 hx = xx.i[0] & ~0x80000000;
49 47
50 48 /* handle trivial cases */
51 49 if (hx >= 0x406f0000) /* |x| >= 2^112 + ... or x is nan */
52 50 return (hx >= 0x7fff0000 ? x + x : x);
53 51
54 52 /* handle |x| < 1 */
55 53 if (hx < 0x3fff0000) {
56 54 if (hx >= 0x3ffe0000)
57 55 return (sx ? -1.0L : 1.0L);
58 56 return (sx ? -0.0L : 0.0L);
59 57 }
60 58
61 59 xx.i[0] = hx;
62 60 j = 0x406f - (hx >> 16); /* 1 <= j <= 112 */
63 61 if (j >= 96) { /* 96 <= j <= 112 */
64 62 v = (1U << (j - 96)) >> 1;
65 63 if (v) {
66 64 if (xx.i[0] & v)
67 65 xx.i[0] += v;
68 66 xx.i[0] &= ~(v - 1);
69 67 } else if (xx.i[1] & 0x80000000)
70 68 ++xx.i[0];
71 69 xx.i[1] = xx.i[2] = xx.i[3] = 0;
72 70 } else if (j >= 64) { /* 64 <= j <= 95 */
73 71 v = (1U << (j - 64)) >> 1;
74 72 if (v) {
75 73 if (xx.i[1] & v) {
76 74 xx.i[1] += v;
77 75 if (xx.i[1] < v)
78 76 ++xx.i[0];
79 77 }
80 78 xx.i[1] &= ~(v - 1);
81 79 } else if (xx.i[2] & 0x80000000) {
82 80 if (++xx.i[1] == 0)
83 81 ++xx.i[0];
84 82 }
85 83 xx.i[2] = xx.i[3] = 0;
86 84 } else if (j >= 32) { /* 32 <= j <= 63 */
87 85 v = (1U << (j - 32)) >> 1;
88 86 if (v) {
89 87 if (xx.i[2] & v) {
90 88 xx.i[2] += v;
91 89 if (xx.i[2] < v) {
92 90 if (++xx.i[1] == 0)
93 91 ++xx.i[0];
94 92 }
95 93 }
96 94 xx.i[2] &= ~(v - 1);
97 95 } else if (xx.i[3] & 0x80000000) {
98 96 if (++xx.i[2] == 0) {
99 97 if (++xx.i[1] == 0)
100 98 ++xx.i[0];
101 99 }
102 100 }
103 101 xx.i[3] = 0;
104 102 } else { /* 1 <= j <= 31 */
105 103 v = 1U << (j - 1);
106 104 if (xx.i[3] & v) {
107 105 xx.i[3] += v;
108 106 if (xx.i[3] < v) {
109 107 if (++xx.i[2] == 0) {
110 108 if (++xx.i[1] == 0)
111 109 ++xx.i[0];
112 110 }
113 111 }
114 112 }
115 113 xx.i[3] &= ~(v - 1);
116 114 }
117 115
118 116 /* negate result if need be */
119 117 if (sx)
120 118 xx.i[0] |= 0x80000000;
121 119 return (xx.q);
122 120 }
123 121 #elif defined(__x86)
124 122 long double
125 123 roundl(long double x) {
126 124 union {
127 125 unsigned i[3];
128 126 long double e;
129 127 } xx;
130 128 int ex, sx, i;
131 129
132 130 xx.e = x;
133 131 ex = xx.i[2] & 0x7fff;
134 132 sx = xx.i[2] & 0x8000;
135 133 if (ex < 0x403e) { /* |x| < 2^63 */
136 134 if (ex < 0x3fff) { /* |x| < 1 */
137 135 if (ex >= 0x3ffe)
138 136 return (sx ? -1.0L : 1.0L);
139 137 return (sx ? -0.0L : 0.0L);
140 138 }
141 139
142 140 /* round x at the integer bit */
143 141 if (ex < 0x401e) {
144 142 i = 1 << (0x401d - ex);
145 143 xx.i[1] = (xx.i[1] + i) & ~(i | (i - 1));
146 144 xx.i[0] = 0;
147 145 } else {
148 146 i = 1 << (0x403d - ex);
149 147 xx.i[0] += i;
150 148 if (xx.i[0] < i)
151 149 xx.i[1]++;
152 150 xx.i[0] &= ~(i | (i - 1));
153 151 }
154 152 if (xx.i[1] == 0) {
155 153 xx.i[2] = sx | ++ex;
156 154 xx.i[1] = 0x80000000U;
157 155 }
158 156 return (xx.e);
159 157 } else if (ex < 0x7fff) /* x is integral */
160 158 return (x);
161 159 else /* inf or nan */
162 160 return (x + x);
163 161 }
164 162 #else
165 163 #error Unknown architecture
166 164 #endif /* defined(__sparc) || defined(__x86) */
↓ open down ↓ |
124 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX