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