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