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/lrintl.c
+++ new/usr/src/lib/libm/common/m9x/lrintl.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 lrintl = __lrintl
32 -#endif
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
40 38 #include "fma.h"
41 39 #include "fenv_inlines.h"
42 40
43 41 long
44 42 lrintl(long double x) {
45 43 union {
46 44 unsigned int i[4];
47 45 long double q;
48 46 } xx;
49 47 union {
50 48 unsigned int i;
51 49 float f;
52 50 } tt;
53 51 unsigned int hx, sx, frac, l, fsr;
54 52 int rm, j;
55 53 volatile float dummy;
56 54
57 55 xx.q = x;
58 56 sx = xx.i[0] & 0x80000000;
59 57 hx = xx.i[0] & ~0x80000000;
60 58
61 59 /* handle trivial cases */
62 60 if (hx > 0x401e0000) { /* |x| > 2^31 + ... or x is nan */
63 61 /* convert an out-of-range float */
64 62 tt.i = sx | 0x7f000000;
65 63 return ((long) tt.f);
66 64 } else if ((hx | xx.i[1] | xx.i[2] | xx.i[3]) == 0) /* x is zero */
67 65 return (0L);
68 66
69 67 /* get the rounding mode */
70 68 __fenv_getfsr32(&fsr);
71 69 rm = fsr >> 30;
72 70
73 71 /* flip the sense of directed roundings if x is negative */
74 72 if (sx)
75 73 rm ^= rm >> 1;
76 74
77 75 /* handle |x| < 1 */
78 76 if (hx < 0x3fff0000) {
79 77 dummy = 1.0e30F; /* x is nonzero, so raise inexact */
80 78 dummy += 1.0e-30F;
81 79 if (rm == FSR_RP || (rm == FSR_RN && (hx >= 0x3ffe0000 &&
82 80 ((hx & 0xffff) | xx.i[1] | xx.i[2] | xx.i[3]))))
83 81 return (sx ? -1L : 1L);
84 82 return (0L);
85 83 }
86 84
87 85 /* extract the integer and fractional parts of x */
88 86 j = 0x406f - (hx >> 16); /* 91 <= j <= 112 */
89 87 xx.i[0] = 0x10000 | (xx.i[0] & 0xffff);
90 88 if (j >= 96) { /* 96 <= j <= 112 */
91 89 l = xx.i[0] >> (j - 96);
92 90 frac = ((xx.i[0] << 1) << (127 - j)) | (xx.i[1] >> (j - 96));
93 91 if (((xx.i[1] << 1) << (127 - j)) | xx.i[2] | xx.i[3])
94 92 frac |= 1;
95 93 } else { /* 91 <= j <= 95 */
96 94 l = (xx.i[0] << (96 - j)) | (xx.i[1] >> (j - 64));
97 95 frac = (xx.i[1] << (96 - j)) | (xx.i[2] >> (j - 64));
98 96 if ((xx.i[2] << (96 - j)) | xx.i[3])
99 97 frac |= 1;
100 98 }
101 99
102 100 /* round */
103 101 if (frac && (rm == FSR_RP || (rm == FSR_RN && (frac > 0x80000000U ||
104 102 (frac == 0x80000000 && (l & 1))))))
105 103 l++;
106 104
107 105 /* check for result out of range (note that z is |x| at this point) */
108 106 if (l > 0x80000000U || (l == 0x80000000U && !sx)) {
109 107 tt.i = sx | 0x7f000000;
110 108 return ((long) tt.f);
111 109 }
112 110
113 111 /* raise inexact if need be */
114 112 if (frac) {
115 113 dummy = 1.0e30F;
116 114 dummy += 1.0e-30F;
117 115 }
118 116
119 117 /* negate result if need be */
120 118 if (sx)
121 119 l = -l;
122 120 return ((long) l);
123 121 }
124 122 #elif defined(__x86)
125 123 long
126 124 lrintl(long double x) {
127 125 /*
128 126 * Note: The following code works on x86 (in the default rounding
129 127 * precision mode), but one ought to just use the fistpl instruction
130 128 * instead.
131 129 */
132 130 union {
133 131 unsigned i[3];
134 132 long double e;
135 133 } xx, yy;
136 134 int ex;
137 135
138 136 xx.e = x;
139 137 ex = xx.i[2] & 0x7fff;
140 138 if (ex < 0x403e) { /* |x| < 2^63 */
141 139 /* add and subtract a power of two to round x to an integer */
142 140 yy.i[2] = (xx.i[2] & 0x8000) | 0x403e;
143 141 yy.i[1] = 0x80000000;
144 142 yy.i[0] = 0;
145 143 x = (x + yy.e) - yy.e;
146 144 }
147 145
148 146 /* now x is nan, inf, or integral */
149 147 return ((long) x);
150 148 }
151 149 #else
152 150 #error Unknown architecture
153 151 #endif /* defined(__sparc) || defined(__x86) */
154 152 #else
155 153 #error Unsupported architecture
156 154 #endif /* defined(_ILP32) */
↓ open down ↓ |
114 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX