Print this page
11210 libm should be cstyle(1ONBLD) clean
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/R/fmodf.c
+++ new/usr/src/lib/libm/common/R/fmodf.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
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
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
20 20 */
21 +
21 22 /*
22 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
23 24 */
25 +
24 26 /*
25 27 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
26 28 * Use is subject to license terms.
27 29 */
28 30
29 31 #pragma weak __fmodf = fmodf
30 32
31 33 #include "libm.h"
32 34
33 -/* INDENT OFF */
34 -static const int
35 - is = (int)0x80000000,
35 +static const int is = (int)0x80000000,
36 36 im = 0x007fffff,
37 37 ii = 0x7f800000,
38 38 iu = 0x00800000;
39 -/* INDENT ON */
40 39
41 -static const float zero = 0.0;
40 +static const float zero = 0.0;
42 41
43 42 float
44 -fmodf(float x, float y) {
45 - float w;
46 - int hx, ix, iy, iz, k, ny, nd;
43 +fmodf(float x, float y)
44 +{
45 + float w;
46 + int hx, ix, iy, iz, k, ny, nd;
47 47
48 48 hx = *(int *)&x;
49 49 ix = hx & 0x7fffffff;
50 50 iy = *(int *)&y & 0x7fffffff;
51 51
52 52 /* purge off exception values */
53 53 if (ix >= ii || iy > ii || iy == 0) {
54 54 w = x * y;
55 55 w = w / w;
56 56 } else if (ix <= iy) {
57 57 if (ix < iy)
58 - w = x; /* return x if |x|<|y| */
58 + w = x; /* return x if |x|<|y| */
59 59 else
60 60 w = zero * x; /* return sign(x)*0.0 */
61 61 } else {
62 - /* INDENT OFF */
62 +
63 63 /*
64 64 * scale x,y to "normal" with
65 65 * ny = exponent of y
66 66 * nd = exponent of x minus exponent of y
67 67 */
68 - /* INDENT ON */
69 68 ny = iy >> 23;
70 69 k = ix >> 23;
71 70
72 71 /* special case for subnormal y or x */
73 72 if (ny == 0) {
74 73 ny = 1;
74 +
75 75 while (iy < iu) {
76 76 ny -= 1;
77 77 iy += iy;
78 78 }
79 +
79 80 nd = k - ny;
81 +
80 82 if (k == 0) {
81 83 nd += 1;
84 +
82 85 while (ix < iu) {
83 86 nd -= 1;
84 87 ix += ix;
85 88 }
86 89 } else {
87 90 ix = iu | (ix & im);
88 91 }
89 92 } else {
90 93 nd = k - ny;
91 94 ix = iu | (ix & im);
92 95 iy = iu | (iy & im);
93 96 }
94 97
95 - /* fix point fmod for normalized ix and iy */
96 - /* INDENT OFF */
98 + /*
99 + * fix point fmod for normalized ix and iy
100 + */
101 +
102 + /* BEGIN CSTYLED */
97 103 /*
98 104 * while (nd--) {
99 - * iz = ix - iy;
105 + * iz = ix - iy;
100 106 * if (iz < 0)
101 107 * ix = ix + ix;
102 108 * else if (iz == 0) {
103 109 * *(int *) &w = is & hx;
104 110 * return w;
105 111 * }
106 112 * else
107 113 * ix = iz + iz;
108 114 * }
109 115 */
110 - /* INDENT ON */
111 - /* unroll the above loop 4 times to gain performance */
116 + /* END CSTYLED */
117 +
118 + /*
119 + * unroll the above loop 4 times to gain performance
120 + */
112 121 k = nd >> 2;
113 122 nd -= k << 2;
123 +
114 124 while (k--) {
115 125 iz = ix - iy;
126 +
116 127 if (iz >= 0)
117 128 ix = iz + iz;
118 129 else
119 130 ix += ix;
131 +
120 132 iz = ix - iy;
133 +
121 134 if (iz >= 0)
122 135 ix = iz + iz;
123 136 else
124 137 ix += ix;
138 +
125 139 iz = ix - iy;
140 +
126 141 if (iz >= 0)
127 142 ix = iz + iz;
128 143 else
129 144 ix += ix;
145 +
130 146 iz = ix - iy;
147 +
131 148 if (iz >= 0)
132 149 ix = iz + iz;
133 150 else
134 151 ix += ix;
152 +
135 153 if (iz == 0) {
136 154 *(int *)&w = is & hx;
137 155 return (w);
138 156 }
139 157 }
158 +
140 159 while (nd--) {
141 160 iz = ix - iy;
161 +
142 162 if (iz >= 0)
143 163 ix = iz + iz;
144 164 else
145 165 ix += ix;
146 166 }
167 +
147 168 /* end of unrolling */
148 169
149 170 iz = ix - iy;
171 +
150 172 if (iz >= 0)
151 173 ix = iz;
152 174
153 175 /* convert back to floating value and restore the sign */
154 176 if (ix == 0) {
155 177 *(int *)&w = is & hx;
156 178 return (w);
157 179 }
180 +
158 181 while (ix < iu) {
159 182 ix += ix;
160 183 ny -= 1;
161 184 }
185 +
162 186 while (ix > (iu + iu)) {
163 187 ny += 1;
164 188 ix >>= 1;
165 189 }
190 +
166 191 if (ny > 0) {
167 192 *(int *)&w = (is & hx) | (ix & im) | (ny << 23);
168 193 } else {
169 194 /* subnormal output */
170 195 k = -ny + 1;
171 196 ix >>= k;
172 197 *(int *)&w = (is & hx) | ix;
173 198 }
174 199 }
200 +
175 201 return (w);
176 202 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX