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