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/nearbyintf.c
+++ new/usr/src/lib/libm/common/m9x/nearbyintf.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 nearbyintf = __nearbyintf
32 -#endif
33 31
34 32 #include "libm.h"
35 -#include "fenv_synonyms.h"
36 33 #include <fenv.h>
37 34
38 35 float
39 36 __nearbyintf(float x) {
40 37 union {
41 38 unsigned i;
42 39 float f;
43 40 } xx;
44 41 unsigned hx, sx, i, frac;
45 42 int rm;
46 43
47 44 xx.f = x;
48 45 sx = xx.i & 0x80000000;
49 46 hx = xx.i & ~0x80000000;
50 47
51 48 /* handle trivial cases */
52 49 if (hx >= 0x4b000000) { /* x is nan, inf, or already integral */
53 50 if (hx > 0x7f800000) /* x is nan */
54 51 return (x * x); /* + -> * for Cheetah */
55 52 return (x);
56 53 } else if (hx == 0) /* x is zero */
57 54 return (x);
58 55
59 56 /* get the rounding mode */
60 57 rm = fegetround();
61 58
62 59 /* flip the sense of directed roundings if x is negative */
63 60 if (sx && (rm == FE_UPWARD || rm == FE_DOWNWARD))
64 61 rm = (FE_UPWARD + FE_DOWNWARD) - rm;
65 62
66 63 /* handle |x| < 1 */
67 64 if (hx < 0x3f800000) {
68 65 if (rm == FE_UPWARD || (rm == FE_TONEAREST && hx > 0x3f000000))
69 66 xx.i = sx | 0x3f800000;
70 67 else
71 68 xx.i = sx;
72 69 return (xx.f);
73 70 }
74 71
75 72 /* round x at the integer bit */
76 73 i = 1 << (0x96 - (hx >> 23));
77 74 frac = hx & (i - 1);
78 75 if (!frac)
79 76 return (x);
80 77
81 78 hx &= ~(i - 1);
82 79 if (rm == FE_UPWARD || (rm == FE_TONEAREST && (frac > (i >> 1) ||
83 80 ((frac == (i >> 1)) && (hx & i)))))
84 81 xx.i = sx | (hx + i);
85 82 else
86 83 xx.i = sx | hx;
87 84 return (xx.f);
88 85 }
89 86
90 87 #if 0
91 88
92 89 /*
93 90 * Alternate implementations for SPARC, x86, using fp ops. These may
94 91 * be faster depending on how expensive saving and restoring the fp
95 92 * modes and status flags is.
96 93 */
97 94
98 95 #include "libm.h"
99 96 #include "fma.h"
100 97
101 98 #if defined(__sparc)
102 99
103 100 float
104 101 __nearbyintf(float x) {
105 102 union {
106 103 unsigned i;
107 104 float f;
108 105 } xx, yy;
109 106 float z;
110 107 unsigned hx, sx, fsr, oldfsr;
111 108 int rm;
112 109
113 110 xx.f = x;
114 111 sx = xx.i & 0x80000000;
115 112 hx = xx.i & ~0x80000000;
116 113
117 114 /* handle trivial cases */
118 115 if (hx >= 0x4b000000) /* x is nan, inf, or already integral */
119 116 return (x + 0.0f);
120 117 else if (hx == 0) /* x is zero */
121 118 return (x);
122 119
123 120 /* save the fsr */
124 121 __fenv_getfsr(&oldfsr);
125 122
126 123 /* handle |x| < 1 */
127 124 if (hx < 0x3f800000) {
128 125 /* flip the sense of directed roundings if x is negative */
129 126 rm = oldfsr >> 30;
130 127 if (sx)
131 128 rm ^= rm >> 1;
132 129 if (rm == FSR_RP || (rm == FSR_RN && hx > 0x3f000000))
133 130 xx.i = sx | 0x3f800000;
134 131 else
135 132 xx.i = sx;
136 133 return (xx.f);
137 134 }
138 135
139 136 /* clear the inexact trap */
140 137 fsr = oldfsr & ~FSR_NXM;
141 138 __fenv_setfsr(&fsr);
142 139
143 140 /* round x at the integer bit */
144 141 yy.i = sx | 0x4b000000;
145 142 z = (x + yy.f) - yy.f;
146 143
147 144 /* restore the old fsr */
148 145 __fenv_setfsr(&oldfsr);
149 146
150 147 return (z);
151 148 }
152 149
153 150 #elif defined(__x86)
154 151
155 152 /* inline template */
156 153 extern long double frndint(long double);
157 154
158 155 float
159 156 __nearbyintf(float x) {
160 157 long double z;
161 158 unsigned oldcwsw, cwsw;
162 159
163 160 /* save the control and status words, mask the inexact exception */
164 161 __fenv_getcwsw(&oldcwsw);
165 162 cwsw = oldcwsw | 0x00200000;
166 163 __fenv_setcwsw(&cwsw);
167 164
168 165 z = frndint((long double) x);
169 166
170 167 /*
171 168 * restore the control and status words, preserving all but the
172 169 * inexact flag
173 170 */
174 171 __fenv_getcwsw(&cwsw);
175 172 oldcwsw |= (cwsw & 0x1f);
176 173 __fenv_setcwsw(&oldcwsw);
177 174
178 175 /* note: the value of z is representable in single precision */
179 176 return (z);
180 177 }
181 178
182 179 #else
183 180 #error Unknown architecture
184 181 #endif
185 182
186 183 #endif
↓ open down ↓ |
141 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX