Print this page
11210 libm should be cstyle(1ONBLD) clean
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/m9x/__fex_sparc.c
+++ new/usr/src/lib/libm/common/m9x/__fex_sparc.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.
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
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 23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 +
25 26 /*
26 27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 28 * Use is subject to license terms.
28 29 */
29 30
30 31 #if defined(__sparc)
31 32 #include <stdio.h>
32 33 #include <unistd.h>
33 34 #include <string.h>
34 35 #include <signal.h>
35 36 #include <siginfo.h>
36 37 #include <thread.h>
37 38 #include <ucontext.h>
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
38 39 #include <math.h>
39 40 #if defined(__SUNPRO_C)
40 41 #include <sunmath.h>
41 42 #endif
42 43 #include <fenv.h>
43 44
44 45 #include "fenv_inlines.h"
45 46 #include "libm_inlines.h"
46 47
47 48 #ifdef __sparcv9
49 +#define FPreg(X) &uap->uc_mcontext.fpregs.fpu_fr.fpu_regs[X]
48 50
49 -#define FPreg(X) &uap->uc_mcontext.fpregs.fpu_fr.fpu_regs[X]
50 -
51 -#define FPREG(X) &uap->uc_mcontext.fpregs.fpu_fr.fpu_dregs[(X>>1)| \
52 - ((X&1)<<4)]
53 -
51 +#define FPREG(X) &uap->uc_mcontext.fpregs.fpu_fr.fpu_dregs[(X >> 1) | \
52 + ((X & 1) << 4)]
54 53 #else
55 -
56 54 #include <sys/procfs.h>
57 55
58 -#define FPxreg(X) &((prxregset_t*)uap->uc_mcontext.xrs.xrs_ptr)->pr_un.pr_v8p.pr_xfr.pr_regs[X]
56 +#define FPxreg(X) & \
57 + ((prxregset_t *)uap->uc_mcontext.xrs.xrs_ptr)->pr_un.pr_v8p.pr_xfr. \
58 + pr_regs[X]
59 59
60 -#define FPreg(X) &uap->uc_mcontext.fpregs.fpu_fr.fpu_regs[X]
60 +#define FPreg(X) & uap->uc_mcontext.fpregs.fpu_fr.fpu_regs[X]
61 61
62 -#define FPREG(X) ((X & 1)? FPxreg(X - 1) : FPreg(X))
63 -
64 -#endif /* __sparcv9 */
62 +#define FPREG(X) ((X & 1) ? FPxreg(X - 1) : FPreg(X))
63 +#endif /* __sparcv9 */
65 64
66 65 #include "fex_handler.h"
67 66
68 67 /* avoid dependence on libsunmath */
69 68 static enum fp_class_type
70 69 my_fp_classl(long double *a)
71 70 {
72 - int msw = *(int*)a & ~0x80000000;
71 + int msw = *(int *)a & ~0x80000000;
73 72
74 73 if (msw >= 0x7fff0000) {
75 - if (((msw & 0xffff) | *(1+(int*)a) | *(2+(int*)a) | *(3+(int*)a)) == 0)
76 - return fp_infinity;
74 + if (((msw & 0xffff) | *(1 + (int *)a) | *(2 + (int *)a) | *(3 +
75 + (int *)a)) == 0)
76 + return (fp_infinity);
77 77 else if (msw & 0x8000)
78 - return fp_quiet;
78 + return (fp_quiet);
79 79 else
80 - return fp_signaling;
80 + return (fp_signaling);
81 81 } else if (msw < 0x10000) {
82 - if ((msw | *(1+(int*)a) | *(2+(int*)a) | *(3+(int*)a)) == 0)
83 - return fp_zero;
82 + if ((msw | *(1 + (int *)a) | *(2 + (int *)a) | *(3 +
83 + (int *)a)) == 0)
84 + return (fp_zero);
84 85 else
85 - return fp_subnormal;
86 - } else
87 - return fp_normal;
86 + return (fp_subnormal);
87 + } else {
88 + return (fp_normal);
89 + }
88 90 }
89 91
90 92 /*
91 -* Determine which type of invalid operation exception occurred
92 -*/
93 + * Determine which type of invalid operation exception occurred
94 + */
93 95 enum fex_exception
94 96 __fex_get_invalid_type(siginfo_t *sip, ucontext_t *uap)
95 97 {
96 - unsigned instr, opf, rs1, rs2;
97 - enum fp_class_type t1, t2;
98 + unsigned instr, opf, rs1, rs2;
99 + enum fp_class_type t1, t2;
98 100
99 101 /* parse the instruction which caused the exception */
100 102 instr = uap->uc_mcontext.fpregs.fpu_q->FQu.fpq.fpq_instr;
101 103 opf = (instr >> 5) & 0x1ff;
102 104 rs1 = (instr >> 14) & 0x1f;
103 105 rs2 = instr & 0x1f;
104 106
105 107 /* determine the classes of the operands */
106 108 switch (opf & 3) {
107 - case 1: /* single */
108 - t1 = fp_classf(*(float*)FPreg(rs1));
109 - t2 = fp_classf(*(float*)FPreg(rs2));
109 + case 1: /* single */
110 + t1 = fp_classf(*(float *)FPreg(rs1));
111 + t2 = fp_classf(*(float *)FPreg(rs2));
110 112 break;
111 113
112 - case 2: /* double */
113 - t1 = fp_class(*(double*)FPREG(rs1));
114 - t2 = fp_class(*(double*)FPREG(rs2));
114 + case 2: /* double */
115 + t1 = fp_class(*(double *)FPREG(rs1));
116 + t2 = fp_class(*(double *)FPREG(rs2));
115 117 break;
116 118
117 - case 3: /* quad */
118 - t1 = my_fp_classl((long double*)FPREG(rs1));
119 - t2 = my_fp_classl((long double*)FPREG(rs2));
119 + case 3: /* quad */
120 + t1 = my_fp_classl((long double *)FPREG(rs1));
121 + t2 = my_fp_classl((long double *)FPREG(rs2));
120 122 break;
121 123
122 - default: /* integer operands never cause an invalid operation */
123 - return (enum fex_exception) -1;
124 + default: /* integer operands never cause an invalid operation */
125 + return ((enum fex_exception)-1);
124 126 }
125 127
126 128 /* if rs2 is snan, return immediately */
127 129 if (t2 == fp_signaling)
128 - return fex_inv_snan;
130 + return (fex_inv_snan);
129 131
130 132 /* determine the type of operation */
131 133 switch ((instr >> 19) & 0x183f) {
132 134 case 0x1034: /* add, subtract, multiply, divide, square root, convert */
135 +
133 136 switch (opf & 0x1fc) {
134 137 case 0x40:
135 - case 0x44: /* add or subtract */
138 + case 0x44: /* add or subtract */
139 +
136 140 if (t1 == fp_signaling)
137 - return fex_inv_snan;
141 + return (fex_inv_snan);
138 142 else
139 - return fex_inv_isi;
143 + return (fex_inv_isi);
140 144
141 145 case 0x48:
142 146 case 0x68:
143 - case 0x6c: /* multiply */
147 + case 0x6c: /* multiply */
148 +
144 149 if (t1 == fp_signaling)
145 - return fex_inv_snan;
150 + return (fex_inv_snan);
146 151 else
147 - return fex_inv_zmi;
152 + return (fex_inv_zmi);
153 +
154 + case 0x4c: /* divide */
148 155
149 - case 0x4c: /* divide */
150 156 if (t1 == fp_signaling)
151 - return fex_inv_snan;
157 + return (fex_inv_snan);
152 158 else if (t1 == fp_zero)
153 - return fex_inv_zdz;
159 + return (fex_inv_zdz);
154 160 else
155 - return fex_inv_idi;
161 + return (fex_inv_idi);
156 162
157 - case 0x28: /* square root */
158 - return fex_inv_sqrt;
163 + case 0x28: /* square root */
164 + return (fex_inv_sqrt);
159 165
160 166 case 0x80:
161 - case 0xd0: /* convert to integer */
162 - return fex_inv_int;
167 + case 0xd0: /* convert to integer */
168 + return (fex_inv_int);
163 169 }
170 +
164 171 break;
165 172
166 - case 0x1035: /* compare */
173 + case 0x1035: /* compare */
174 +
167 175 if (t1 == fp_signaling)
168 - return fex_inv_snan;
176 + return (fex_inv_snan);
169 177 else
170 - return fex_inv_cmp;
178 + return (fex_inv_cmp);
171 179 }
172 180
173 - return (enum fex_exception) -1;
181 + return ((enum fex_exception)-1);
174 182 }
175 183
176 184 #ifdef __sparcv9
177 185 extern void _Qp_sqrt(long double *, const long double *);
178 186 #else
179 187 extern long double _Q_sqrt(long double);
180 188 #endif
181 189
182 190 /*
183 -* Get the operands, generate the default untrapped result with
184 -* exceptions, and set a code indicating the type of operation
185 -*/
191 + * Get the operands, generate the default untrapped result with
192 + * exceptions, and set a code indicating the type of operation
193 + */
186 194 void
187 195 __fex_get_op(siginfo_t *sip, ucontext_t *uap, fex_info_t *info)
188 196 {
189 - unsigned long fsr;
190 - unsigned instr, opf, rs1, rs2;
191 - volatile int c;
197 + unsigned long fsr;
198 + unsigned instr, opf, rs1, rs2;
199 + volatile int c;
192 200
193 201 /* parse the instruction which caused the exception */
194 202 instr = uap->uc_mcontext.fpregs.fpu_q->FQu.fpq.fpq_instr;
195 203 opf = (instr >> 5) & 0x1ff;
196 204 rs1 = (instr >> 14) & 0x1f;
197 205 rs2 = instr & 0x1f;
198 206
199 207 /* get the operands */
200 208 switch (opf & 3) {
201 - case 0: /* integer */
209 + case 0: /* integer */
202 210 info->op1.type = fex_nodata;
211 +
203 212 if (opf & 0x40) {
204 213 info->op2.type = fex_int;
205 - info->op2.val.i = *(int*)FPreg(rs2);
206 - }
207 - else {
214 + info->op2.val.i = *(int *)FPreg(rs2);
215 + } else {
208 216 info->op2.type = fex_llong;
209 - info->op2.val.l = *(long long*)FPREG(rs2);
217 + info->op2.val.l = *(long long *)FPREG(rs2);
210 218 }
219 +
211 220 break;
212 221
213 - case 1: /* single */
222 + case 1: /* single */
214 223 info->op1.type = info->op2.type = fex_float;
215 - info->op1.val.f = *(float*)FPreg(rs1);
216 - info->op2.val.f = *(float*)FPreg(rs2);
224 + info->op1.val.f = *(float *)FPreg(rs1);
225 + info->op2.val.f = *(float *)FPreg(rs2);
217 226 break;
218 227
219 - case 2: /* double */
228 + case 2: /* double */
220 229 info->op1.type = info->op2.type = fex_double;
221 - info->op1.val.d = *(double*)FPREG(rs1);
222 - info->op2.val.d = *(double*)FPREG(rs2);
230 + info->op1.val.d = *(double *)FPREG(rs1);
231 + info->op2.val.d = *(double *)FPREG(rs2);
223 232 break;
224 233
225 - case 3: /* quad */
234 + case 3: /* quad */
226 235 info->op1.type = info->op2.type = fex_ldouble;
227 - info->op1.val.q = *(long double*)FPREG(rs1);
228 - info->op2.val.q = *(long double*)FPREG(rs2);
236 + info->op1.val.q = *(long double *)FPREG(rs1);
237 + info->op2.val.q = *(long double *)FPREG(rs2);
229 238 break;
230 239 }
231 240
232 - /* initialize res to the default untrapped result and ex to the
233 - corresponding flags (assume trapping is disabled and flags
234 - are clear) */
241 + /*
242 + * initialize res to the default untrapped result and ex to the
243 + * corresponding flags (assume trapping is disabled and flags are
244 + * clear)
245 + */
235 246 info->op = fex_other;
236 247 info->res.type = fex_nodata;
248 +
237 249 switch ((instr >> 19) & 0x183f) {
238 - case 0x1035: /* compare */
250 + case 0x1035: /* compare */
239 251 info->op = fex_cmp;
252 +
240 253 switch (opf) {
241 - case 0x51: /* compare single */
254 + case 0x51: /* compare single */
242 255 c = (info->op1.val.f == info->op2.val.f);
243 256 break;
244 257
245 - case 0x52: /* compare double */
258 + case 0x52: /* compare double */
246 259 c = (info->op1.val.d == info->op2.val.d);
247 260 break;
248 261
249 - case 0x53: /* compare quad */
262 + case 0x53: /* compare quad */
250 263 c = (info->op1.val.q == info->op2.val.q);
251 264 break;
252 265
253 - case 0x55: /* compare single with exception */
266 + case 0x55: /* compare single with exception */
254 267 c = (info->op1.val.f < info->op2.val.f);
255 268 break;
256 269
257 - case 0x56: /* compare double with exception */
270 + case 0x56: /* compare double with exception */
258 271 c = (info->op1.val.d < info->op2.val.d);
259 272 break;
260 273
261 - case 0x57: /* compare quad with exception */
274 + case 0x57: /* compare quad with exception */
262 275 c = (info->op1.val.q < info->op2.val.q);
263 276 break;
264 277 }
278 +
265 279 break;
266 280
267 281 case 0x1034: /* add, subtract, multiply, divide, square root, convert */
282 +
268 283 switch (opf) {
269 - case 0x41: /* add single */
284 + case 0x41: /* add single */
270 285 info->op = fex_add;
271 286 info->res.type = fex_float;
272 287 info->res.val.f = info->op1.val.f + info->op2.val.f;
273 288 break;
274 289
275 - case 0x42: /* add double */
290 + case 0x42: /* add double */
276 291 info->op = fex_add;
277 292 info->res.type = fex_double;
278 293 info->res.val.d = info->op1.val.d + info->op2.val.d;
279 294 break;
280 295
281 - case 0x43: /* add quad */
296 + case 0x43: /* add quad */
282 297 info->op = fex_add;
283 298 info->res.type = fex_ldouble;
284 299 info->res.val.q = info->op1.val.q + info->op2.val.q;
285 300 break;
286 301
287 - case 0x45: /* subtract single */
302 + case 0x45: /* subtract single */
288 303 info->op = fex_sub;
289 304 info->res.type = fex_float;
290 305 info->res.val.f = info->op1.val.f - info->op2.val.f;
291 306 break;
292 307
293 - case 0x46: /* subtract double */
308 + case 0x46: /* subtract double */
294 309 info->op = fex_sub;
295 310 info->res.type = fex_double;
296 311 info->res.val.d = info->op1.val.d - info->op2.val.d;
297 312 break;
298 313
299 - case 0x47: /* subtract quad */
314 + case 0x47: /* subtract quad */
300 315 info->op = fex_sub;
301 316 info->res.type = fex_ldouble;
302 317 info->res.val.q = info->op1.val.q - info->op2.val.q;
303 318 break;
304 319
305 - case 0x49: /* multiply single */
320 + case 0x49: /* multiply single */
306 321 info->op = fex_mul;
307 322 info->res.type = fex_float;
308 323 info->res.val.f = info->op1.val.f * info->op2.val.f;
309 324 break;
310 325
311 - case 0x4a: /* multiply double */
326 + case 0x4a: /* multiply double */
312 327 info->op = fex_mul;
313 328 info->res.type = fex_double;
314 329 info->res.val.d = info->op1.val.d * info->op2.val.d;
315 330 break;
316 331
317 - case 0x4b: /* multiply quad */
332 + case 0x4b: /* multiply quad */
318 333 info->op = fex_mul;
319 334 info->res.type = fex_ldouble;
320 335 info->res.val.q = info->op1.val.q * info->op2.val.q;
321 336 break;
322 337
323 - case 0x69: /* fsmuld */
338 + case 0x69: /* fsmuld */
324 339 info->op = fex_mul;
325 340 info->res.type = fex_double;
326 - info->res.val.d = (double)info->op1.val.f * (double)info->op2.val.f;
341 + info->res.val.d = (double)info->op1.val.f *
342 + (double)info->op2.val.f;
327 343 break;
328 344
329 - case 0x6e: /* fdmulq */
345 + case 0x6e: /* fdmulq */
330 346 info->op = fex_mul;
331 347 info->res.type = fex_ldouble;
332 - info->res.val.q = (long double)info->op1.val.d *
333 - (long double)info->op2.val.d;
348 + info->res.val.q = (long double)info->op1.val.d * (long
349 + double)info->op2.val.d;
334 350 break;
335 351
336 - case 0x4d: /* divide single */
352 + case 0x4d: /* divide single */
337 353 info->op = fex_div;
338 354 info->res.type = fex_float;
339 355 info->res.val.f = info->op1.val.f / info->op2.val.f;
340 356 break;
341 357
342 - case 0x4e: /* divide double */
358 + case 0x4e: /* divide double */
343 359 info->op = fex_div;
344 360 info->res.type = fex_double;
345 361 info->res.val.d = info->op1.val.d / info->op2.val.d;
346 362 break;
347 363
348 - case 0x4f: /* divide quad */
364 + case 0x4f: /* divide quad */
349 365 info->op = fex_div;
350 366 info->res.type = fex_ldouble;
351 367 info->res.val.q = info->op1.val.q / info->op2.val.q;
352 368 break;
353 369
354 - case 0x29: /* square root single */
370 + case 0x29: /* square root single */
355 371 info->op = fex_sqrt;
356 372 info->op1 = info->op2;
357 373 info->op2.type = fex_nodata;
358 374 info->res.type = fex_float;
359 375 info->res.val.f = sqrtf(info->op1.val.f);
360 376 break;
361 377
362 - case 0x2a: /* square root double */
378 + case 0x2a: /* square root double */
363 379 info->op = fex_sqrt;
364 380 info->op1 = info->op2;
365 381 info->op2.type = fex_nodata;
366 382 info->res.type = fex_double;
367 383 info->res.val.d = sqrt(info->op1.val.d);
368 384 break;
369 385
370 - case 0x2b: /* square root quad */
386 + case 0x2b: /* square root quad */
371 387 info->op = fex_sqrt;
372 388 info->op1 = info->op2;
373 389 info->op2.type = fex_nodata;
374 390 info->res.type = fex_ldouble;
375 391 #ifdef __sparcv9
376 392 _Qp_sqrt(&info->res.val.q, &info->op1.val.q);
377 393 #else
378 394 info->res.val.q = _Q_sqrt(info->op1.val.q);
379 395 #endif
380 396 break;
381 397
382 - default: /* conversions */
398 + default: /* conversions */
383 399 info->op = fex_cnvt;
384 400 info->op1 = info->op2;
385 401 info->op2.type = fex_nodata;
402 +
386 403 switch (opf) {
387 - case 0xd1: /* convert single to int */
404 + case 0xd1: /* convert single to int */
388 405 info->res.type = fex_int;
389 - info->res.val.i = (int) info->op1.val.f;
406 + info->res.val.i = (int)info->op1.val.f;
390 407 break;
391 408
392 - case 0xd2: /* convert double to int */
409 + case 0xd2: /* convert double to int */
393 410 info->res.type = fex_int;
394 - info->res.val.i = (int) info->op1.val.d;
411 + info->res.val.i = (int)info->op1.val.d;
395 412 break;
396 413
397 - case 0xd3: /* convert quad to int */
414 + case 0xd3: /* convert quad to int */
398 415 info->res.type = fex_int;
399 - info->res.val.i = (int) info->op1.val.q;
416 + info->res.val.i = (int)info->op1.val.q;
400 417 break;
401 418
402 - case 0x81: /* convert single to long long */
419 + case 0x81: /* convert single to long long */
403 420 info->res.type = fex_llong;
404 - info->res.val.l = (long long) info->op1.val.f;
421 + info->res.val.l = (long long)info->op1.val.f;
405 422 break;
406 423
407 - case 0x82: /* convert double to long long */
424 + case 0x82: /* convert double to long long */
408 425 info->res.type = fex_llong;
409 - info->res.val.l = (long long) info->op1.val.d;
426 + info->res.val.l = (long long)info->op1.val.d;
410 427 break;
411 428
412 - case 0x83: /* convert quad to long long */
429 + case 0x83: /* convert quad to long long */
413 430 info->res.type = fex_llong;
414 - info->res.val.l = (long long) info->op1.val.q;
431 + info->res.val.l = (long long)info->op1.val.q;
415 432 break;
416 433
417 - case 0xc4: /* convert int to single */
434 + case 0xc4: /* convert int to single */
418 435 info->res.type = fex_float;
419 - info->res.val.f = (float) info->op1.val.i;
436 + info->res.val.f = (float)info->op1.val.i;
420 437 break;
421 438
422 - case 0x84: /* convert long long to single */
439 + case 0x84: /* convert long long to single */
423 440 info->res.type = fex_float;
424 - info->res.val.f = (float) info->op1.val.l;
441 + info->res.val.f = (float)info->op1.val.l;
425 442 break;
426 443
427 - case 0x88: /* convert long long to double */
444 + case 0x88: /* convert long long to double */
428 445 info->res.type = fex_double;
429 - info->res.val.d = (double) info->op1.val.l;
446 + info->res.val.d = (double)info->op1.val.l;
430 447 break;
431 448
432 - case 0xc6: /* convert double to single */
449 + case 0xc6: /* convert double to single */
433 450 info->res.type = fex_float;
434 - info->res.val.f = (float) info->op1.val.d;
451 + info->res.val.f = (float)info->op1.val.d;
435 452 break;
436 453
437 - case 0xc7: /* convert quad to single */
454 + case 0xc7: /* convert quad to single */
438 455 info->res.type = fex_float;
439 - info->res.val.f = (float) info->op1.val.q;
456 + info->res.val.f = (float)info->op1.val.q;
440 457 break;
441 458
442 - case 0xc9: /* convert single to double */
459 + case 0xc9: /* convert single to double */
443 460 info->res.type = fex_double;
444 - info->res.val.d = (double) info->op1.val.f;
461 + info->res.val.d = (double)info->op1.val.f;
445 462 break;
446 463
447 - case 0xcb: /* convert quad to double */
464 + case 0xcb: /* convert quad to double */
448 465 info->res.type = fex_double;
449 - info->res.val.d = (double) info->op1.val.q;
466 + info->res.val.d = (double)info->op1.val.q;
450 467 break;
451 468
452 - case 0xcd: /* convert single to quad */
469 + case 0xcd: /* convert single to quad */
453 470 info->res.type = fex_ldouble;
454 - info->res.val.q = (long double) info->op1.val.f;
471 + info->res.val.q = (long double)info->op1.val.f;
455 472 break;
456 473
457 - case 0xce: /* convert double to quad */
474 + case 0xce: /* convert double to quad */
458 475 info->res.type = fex_ldouble;
459 - info->res.val.q = (long double) info->op1.val.d;
476 + info->res.val.q = (long double)info->op1.val.d;
460 477 break;
461 478 }
462 479 }
480 +
463 481 break;
464 482 }
483 +
465 484 __fenv_getfsr(&fsr);
466 485 info->flags = (int)__fenv_get_ex(fsr);
467 486 __fenv_set_ex(fsr, 0);
468 487 __fenv_setfsr(&fsr);
469 488 }
470 489
471 490 /*
472 -* Store the specified result; if no result is given but the exception
473 -* is underflow or overflow, supply the default trapped result
474 -*/
491 + * Store the specified result; if no result is given but the exception
492 + * is underflow or overflow, supply the default trapped result
493 + */
475 494 void
476 495 __fex_st_result(siginfo_t *sip, ucontext_t *uap, fex_info_t *info)
477 496 {
478 - unsigned instr, opf, rs1, rs2, rd;
479 - long double qscl;
480 - double dscl;
481 - float fscl;
497 + unsigned instr, opf, rs1, rs2, rd;
498 + long double qscl;
499 + double dscl;
500 + float fscl;
482 501
483 502 /* parse the instruction which caused the exception */
484 503 instr = uap->uc_mcontext.fpregs.fpu_q->FQu.fpq.fpq_instr;
485 504 opf = (instr >> 5) & 0x1ff;
486 505 rs1 = (instr >> 14) & 0x1f;
487 506 rs2 = instr & 0x1f;
488 507 rd = (instr >> 25) & 0x1f;
489 508
490 509 /* if the instruction is a compare, just set fcc to unordered */
491 510 if (((instr >> 19) & 0x183f) == 0x1035) {
492 - if (rd == 0)
511 + if (rd == 0) {
493 512 uap->uc_mcontext.fpregs.fpu_fsr |= 0xc00;
494 - else {
513 + } else {
495 514 #ifdef __sparcv9
496 - uap->uc_mcontext.fpregs.fpu_fsr |= (3l << ((rd << 1) + 30));
515 + uap->uc_mcontext.fpregs.fpu_fsr |= (3l << ((rd << 1) +
516 + 30));
497 517 #else
498 - ((prxregset_t*)uap->uc_mcontext.xrs.xrs_ptr)->pr_un.pr_v8p.pr_xfsr |= (3 << ((rd - 1) << 1));
518 + ((prxregset_t *)uap->uc_mcontext.xrs.xrs_ptr)->pr_un.
519 + pr_v8p.pr_xfsr |= (3 << ((rd - 1) << 1));
499 520 #endif
500 521 }
522 +
501 523 return;
502 524 }
503 525
504 - /* if there is no result available, try to generate the untrapped
505 - default */
526 + /*
527 + * if there is no result available, try to generate the untrapped
528 + * default
529 + */
506 530 if (info->res.type == fex_nodata) {
507 531 /* set scale factors for exponent wrapping */
508 532 switch (sip->si_code) {
509 533 case FPE_FLTOVF:
510 - fscl = 1.262177448e-29f; /* 2^-96 */
511 - dscl = 6.441148769597133308e-232; /* 2^-768 */
512 - qscl = 8.778357852076208839765066529179033145e-3700l;/* 2^-12288 */
534 + /* 2^-96 */
535 + fscl = 1.262177448e-29f;
536 + /* 2^-768 */
537 + dscl = 6.441148769597133308e-232;
538 + /* 2^-12288 */
539 + qscl = 8.778357852076208839765066529179033145e-3700l;
513 540 break;
514 541
515 542 case FPE_FLTUND:
516 - fscl = 7.922816251e+28f; /* 2^96 */
517 - dscl = 1.552518092300708935e+231; /* 2^768 */
518 - qscl = 1.139165225263043370845938579315932009e+3699l;/* 2^12288 */
543 + /* 2^96 */
544 + fscl = 7.922816251e+28f;
545 + /* 2^768 */
546 + dscl = 1.552518092300708935e+231;
547 + /* 2^12288 */
548 + qscl = 1.139165225263043370845938579315932009e+3699l;
519 549 break;
520 550
521 551 default:
522 - /* user may have blown away the default result by mistake,
523 - so try to regenerate it */
552 +
553 + /*
554 + * user may have blown away the default result by
555 + * mistake, so try to regenerate it
556 + */
524 557 (void) __fex_get_op(sip, uap, info);
558 +
525 559 if (info->res.type != fex_nodata)
526 560 goto stuff;
561 +
527 562 /* couldn't do it */
528 563 return;
529 564 }
530 565
531 566 /* get the operands */
532 567 switch (opf & 3) {
533 - case 1: /* single */
534 - info->op1.val.f = *(float*)FPreg(rs1);
535 - info->op2.val.f = *(float*)FPreg(rs2);
568 + case 1: /* single */
569 + info->op1.val.f = *(float *)FPreg(rs1);
570 + info->op2.val.f = *(float *)FPreg(rs2);
536 571 break;
537 572
538 - case 2: /* double */
539 - info->op1.val.d = *(double*)FPREG(rs1);
540 - info->op2.val.d = *(double*)FPREG(rs2);
573 + case 2: /* double */
574 + info->op1.val.d = *(double *)FPREG(rs1);
575 + info->op2.val.d = *(double *)FPREG(rs2);
541 576 break;
542 577
543 - case 3: /* quad */
544 - info->op1.val.q = *(long double*)FPREG(rs1);
545 - info->op2.val.q = *(long double*)FPREG(rs2);
578 + case 3: /* quad */
579 + info->op1.val.q = *(long double *)FPREG(rs1);
580 + info->op2.val.q = *(long double *)FPREG(rs2);
546 581 break;
547 582 }
548 583
549 584 /* generate the wrapped result */
550 585 switch (opf) {
551 - case 0x41: /* add single */
586 + case 0x41: /* add single */
552 587 info->res.type = fex_float;
553 588 info->res.val.f = fscl * (fscl * info->op1.val.f +
554 - fscl * info->op2.val.f);
589 + fscl * info->op2.val.f);
555 590 break;
556 591
557 - case 0x42: /* add double */
592 + case 0x42: /* add double */
558 593 info->res.type = fex_double;
559 594 info->res.val.d = dscl * (dscl * info->op1.val.d +
560 - dscl * info->op2.val.d);
595 + dscl * info->op2.val.d);
561 596 break;
562 597
563 - case 0x43: /* add quad */
598 + case 0x43: /* add quad */
564 599 info->res.type = fex_ldouble;
565 600 info->res.val.q = qscl * (qscl * info->op1.val.q +
566 - qscl * info->op2.val.q);
601 + qscl * info->op2.val.q);
567 602 break;
568 603
569 - case 0x45: /* subtract single */
604 + case 0x45: /* subtract single */
570 605 info->res.type = fex_float;
571 606 info->res.val.f = fscl * (fscl * info->op1.val.f -
572 - fscl * info->op2.val.f);
607 + fscl * info->op2.val.f);
573 608 break;
574 609
575 - case 0x46: /* subtract double */
610 + case 0x46: /* subtract double */
576 611 info->res.type = fex_double;
577 612 info->res.val.d = dscl * (dscl * info->op1.val.d -
578 - dscl * info->op2.val.d);
613 + dscl * info->op2.val.d);
579 614 break;
580 615
581 - case 0x47: /* subtract quad */
616 + case 0x47: /* subtract quad */
582 617 info->res.type = fex_ldouble;
583 618 info->res.val.q = qscl * (qscl * info->op1.val.q -
584 - qscl * info->op2.val.q);
619 + qscl * info->op2.val.q);
585 620 break;
586 621
587 - case 0x49: /* multiply single */
622 + case 0x49: /* multiply single */
588 623 info->res.type = fex_float;
589 - info->res.val.f = (fscl * info->op1.val.f) *
590 - (fscl * info->op2.val.f);
624 + info->res.val.f = (fscl * info->op1.val.f) * (fscl *
625 + info->op2.val.f);
591 626 break;
592 627
593 - case 0x4a: /* multiply double */
628 + case 0x4a: /* multiply double */
594 629 info->res.type = fex_double;
595 - info->res.val.d = (dscl * info->op1.val.d) *
596 - (dscl * info->op2.val.d);
630 + info->res.val.d = (dscl * info->op1.val.d) * (dscl *
631 + info->op2.val.d);
597 632 break;
598 633
599 - case 0x4b: /* multiply quad */
634 + case 0x4b: /* multiply quad */
600 635 info->res.type = fex_ldouble;
601 - info->res.val.q = (qscl * info->op1.val.q) *
602 - (qscl * info->op2.val.q);
636 + info->res.val.q = (qscl * info->op1.val.q) * (qscl *
637 + info->op2.val.q);
603 638 break;
604 639
605 - case 0x4d: /* divide single */
640 + case 0x4d: /* divide single */
606 641 info->res.type = fex_float;
607 642 info->res.val.f = (fscl * info->op1.val.f) /
608 - (info->op2.val.f / fscl);
643 + (info->op2.val.f / fscl);
609 644 break;
610 645
611 - case 0x4e: /* divide double */
646 + case 0x4e: /* divide double */
612 647 info->res.type = fex_double;
613 648 info->res.val.d = (dscl * info->op1.val.d) /
614 - (info->op2.val.d / dscl);
649 + (info->op2.val.d / dscl);
615 650 break;
616 651
617 - case 0x4f: /* divide quad */
652 + case 0x4f: /* divide quad */
618 653 info->res.type = fex_ldouble;
619 654 info->res.val.q = (qscl * info->op1.val.q) /
620 - (info->op2.val.q / qscl);
655 + (info->op2.val.q / qscl);
621 656 break;
622 657
623 - case 0xc6: /* convert double to single */
658 + case 0xc6: /* convert double to single */
624 659 info->res.type = fex_float;
625 - info->res.val.f = (float) (fscl * (fscl * info->op1.val.d));
660 + info->res.val.f = (float)(fscl * (fscl *
661 + info->op1.val.d));
626 662 break;
627 663
628 - case 0xc7: /* convert quad to single */
664 + case 0xc7: /* convert quad to single */
629 665 info->res.type = fex_float;
630 - info->res.val.f = (float) (fscl * (fscl * info->op1.val.q));
666 + info->res.val.f = (float)(fscl * (fscl *
667 + info->op1.val.q));
631 668 break;
632 669
633 - case 0xcb: /* convert quad to double */
670 + case 0xcb: /* convert quad to double */
634 671 info->res.type = fex_double;
635 - info->res.val.d = (double) (dscl * (dscl * info->op1.val.q));
672 + info->res.val.d = (double)(dscl * (dscl *
673 + info->op1.val.q));
636 674 break;
637 675 }
638 676
639 677 if (info->res.type == fex_nodata)
640 678 /* couldn't do it */
641 679 return;
642 680 }
643 681
644 682 stuff:
645 683 /* stick the result in the destination */
646 - if (opf & 0x80) { /* conversion */
647 - if (opf & 0x10) { /* result is an int */
684 + if (opf & 0x80) { /* conversion */
685 + if (opf & 0x10) { /* result is an int */
648 686 switch (info->res.type) {
649 687 case fex_llong:
650 - info->res.val.i = (int) info->res.val.l;
688 + info->res.val.i = (int)info->res.val.l;
651 689 break;
652 690
653 691 case fex_float:
654 - info->res.val.i = (int) info->res.val.f;
692 + info->res.val.i = (int)info->res.val.f;
655 693 break;
656 694
657 695 case fex_double:
658 - info->res.val.i = (int) info->res.val.d;
696 + info->res.val.i = (int)info->res.val.d;
659 697 break;
660 698
661 699 case fex_ldouble:
662 - info->res.val.i = (int) info->res.val.q;
700 + info->res.val.i = (int)info->res.val.q;
663 701 break;
664 702
665 703 default:
666 704 break;
667 705 }
668 - *(int*)FPreg(rd) = info->res.val.i;
706 +
707 + *(int *)FPreg(rd) = info->res.val.i;
669 708 return;
670 709 }
671 710
672 711 switch (opf & 0xc) {
673 - case 0: /* result is long long */
712 + case 0: /* result is long long */
713 +
674 714 switch (info->res.type) {
675 715 case fex_int:
676 - info->res.val.l = (long long) info->res.val.i;
716 + info->res.val.l = (long long)info->res.val.i;
677 717 break;
678 718
679 719 case fex_float:
680 - info->res.val.l = (long long) info->res.val.f;
720 + info->res.val.l = (long long)info->res.val.f;
681 721 break;
682 722
683 723 case fex_double:
684 - info->res.val.l = (long long) info->res.val.d;
724 + info->res.val.l = (long long)info->res.val.d;
685 725 break;
686 726
687 727 case fex_ldouble:
688 - info->res.val.l = (long long) info->res.val.q;
728 + info->res.val.l = (long long)info->res.val.q;
689 729 break;
690 730
691 731 default:
692 732 break;
693 733 }
694 - *(long long*)FPREG(rd) = info->res.val.l;
734 +
735 + *(long long *)FPREG(rd) = info->res.val.l;
695 736 break;
696 737
697 - case 0x4: /* result is float */
738 + case 0x4: /* result is float */
739 +
698 740 switch (info->res.type) {
699 741 case fex_int:
700 - info->res.val.f = (float) info->res.val.i;
742 + info->res.val.f = (float)info->res.val.i;
701 743 break;
702 744
703 745 case fex_llong:
704 - info->res.val.f = (float) info->res.val.l;
746 + info->res.val.f = (float)info->res.val.l;
705 747 break;
706 748
707 749 case fex_double:
708 - info->res.val.f = (float) info->res.val.d;
750 + info->res.val.f = (float)info->res.val.d;
709 751 break;
710 752
711 753 case fex_ldouble:
712 - info->res.val.f = (float) info->res.val.q;
754 + info->res.val.f = (float)info->res.val.q;
713 755 break;
714 756
715 757 default:
716 758 break;
717 759 }
718 - *(float*)FPreg(rd) = info->res.val.f;
760 +
761 + *(float *)FPreg(rd) = info->res.val.f;
719 762 break;
720 763
721 - case 0x8: /* result is double */
764 + case 0x8: /* result is double */
765 +
722 766 switch (info->res.type) {
723 767 case fex_int:
724 - info->res.val.d = (double) info->res.val.i;
768 + info->res.val.d = (double)info->res.val.i;
725 769 break;
726 770
727 771 case fex_llong:
728 - info->res.val.d = (double) info->res.val.l;
772 + info->res.val.d = (double)info->res.val.l;
729 773 break;
730 774
731 775 case fex_float:
732 - info->res.val.d = (double) info->res.val.f;
776 + info->res.val.d = (double)info->res.val.f;
733 777 break;
734 778
735 779 case fex_ldouble:
736 - info->res.val.d = (double) info->res.val.q;
780 + info->res.val.d = (double)info->res.val.q;
737 781 break;
738 782
739 783 default:
740 784 break;
741 785 }
742 - *(double*)FPREG(rd) = info->res.val.d;
786 +
787 + *(double *)FPREG(rd) = info->res.val.d;
743 788 break;
744 789
745 - case 0xc: /* result is long double */
790 + case 0xc: /* result is long double */
791 +
746 792 switch (info->res.type) {
747 793 case fex_int:
748 - info->res.val.q = (long double) info->res.val.i;
794 + info->res.val.q = (long double)info->res.val.i;
749 795 break;
750 796
751 797 case fex_llong:
752 - info->res.val.q = (long double) info->res.val.l;
798 + info->res.val.q = (long double)info->res.val.l;
753 799 break;
754 800
755 801 case fex_float:
756 - info->res.val.q = (long double) info->res.val.f;
802 + info->res.val.q = (long double)info->res.val.f;
757 803 break;
758 804
759 805 case fex_double:
760 - info->res.val.q = (long double) info->res.val.d;
806 + info->res.val.q = (long double)info->res.val.d;
761 807 break;
762 808
763 809 default:
764 810 break;
765 811 }
766 - *(long double*)FPREG(rd) = info->res.val.q;
812 +
813 + *(long double *)FPREG(rd) = info->res.val.q;
767 814 break;
768 815 }
816 +
769 817 return;
770 818 }
771 819
772 - if ((opf & 0xf0) == 0x60) { /* fsmuld, fdmulq */
820 + if ((opf & 0xf0) == 0x60) { /* fsmuld, fdmulq */
773 821 switch (opf & 0xc0) {
774 - case 0x8: /* result is double */
822 + case 0x8: /* result is double */
823 +
775 824 switch (info->res.type) {
776 825 case fex_int:
777 - info->res.val.d = (double) info->res.val.i;
826 + info->res.val.d = (double)info->res.val.i;
778 827 break;
779 828
780 829 case fex_llong:
781 - info->res.val.d = (double) info->res.val.l;
830 + info->res.val.d = (double)info->res.val.l;
782 831 break;
783 832
784 833 case fex_float:
785 - info->res.val.d = (double) info->res.val.f;
834 + info->res.val.d = (double)info->res.val.f;
786 835 break;
787 836
788 837 case fex_ldouble:
789 - info->res.val.d = (double) info->res.val.q;
838 + info->res.val.d = (double)info->res.val.q;
790 839 break;
791 840
792 841 default:
793 842 break;
794 843 }
795 - *(double*)FPREG(rd) = info->res.val.d;
844 +
845 + *(double *)FPREG(rd) = info->res.val.d;
796 846 break;
797 847
798 - case 0xc: /* result is long double */
848 + case 0xc: /* result is long double */
849 +
799 850 switch (info->res.type) {
800 851 case fex_int:
801 - info->res.val.q = (long double) info->res.val.i;
852 + info->res.val.q = (long double)info->res.val.i;
802 853 break;
803 854
804 855 case fex_llong:
805 - info->res.val.q = (long double) info->res.val.l;
856 + info->res.val.q = (long double)info->res.val.l;
806 857 break;
807 858
808 859 case fex_float:
809 - info->res.val.q = (long double) info->res.val.f;
860 + info->res.val.q = (long double)info->res.val.f;
810 861 break;
811 862
812 863 case fex_double:
813 - info->res.val.q = (long double) info->res.val.d;
864 + info->res.val.q = (long double)info->res.val.d;
814 865 break;
815 866
816 867 default:
817 868 break;
818 869 }
819 - *(long double*)FPREG(rd) = info->res.val.q;
870 +
871 + *(long double *)FPREG(rd) = info->res.val.q;
820 872 break;
821 873 }
874 +
822 875 return;
823 876 }
824 877
825 - switch (opf & 3) { /* other arithmetic op */
826 - case 1: /* result is float */
878 + switch (opf & 3) { /* other arithmetic op */
879 + case 1: /* result is float */
880 +
827 881 switch (info->res.type) {
828 882 case fex_int:
829 - info->res.val.f = (float) info->res.val.i;
883 + info->res.val.f = (float)info->res.val.i;
830 884 break;
831 885
832 886 case fex_llong:
833 - info->res.val.f = (float) info->res.val.l;
887 + info->res.val.f = (float)info->res.val.l;
834 888 break;
835 889
836 890 case fex_double:
837 - info->res.val.f = (float) info->res.val.d;
891 + info->res.val.f = (float)info->res.val.d;
838 892 break;
839 893
840 894 case fex_ldouble:
841 - info->res.val.f = (float) info->res.val.q;
895 + info->res.val.f = (float)info->res.val.q;
842 896 break;
843 897
844 898 default:
845 899 break;
846 900 }
847 - *(float*)FPreg(rd) = info->res.val.f;
901 +
902 + *(float *)FPreg(rd) = info->res.val.f;
848 903 break;
849 904
850 - case 2: /* result is double */
905 + case 2: /* result is double */
906 +
851 907 switch (info->res.type) {
852 908 case fex_int:
853 - info->res.val.d = (double) info->res.val.i;
909 + info->res.val.d = (double)info->res.val.i;
854 910 break;
855 911
856 912 case fex_llong:
857 - info->res.val.d = (double) info->res.val.l;
913 + info->res.val.d = (double)info->res.val.l;
858 914 break;
859 915
860 916 case fex_float:
861 - info->res.val.d = (double) info->res.val.f;
917 + info->res.val.d = (double)info->res.val.f;
862 918 break;
863 919
864 920 case fex_ldouble:
865 - info->res.val.d = (double) info->res.val.q;
921 + info->res.val.d = (double)info->res.val.q;
866 922 break;
867 923
868 924 default:
869 925 break;
870 926 }
871 - *(double*)FPREG(rd) = info->res.val.d;
927 +
928 + *(double *)FPREG(rd) = info->res.val.d;
872 929 break;
873 930
874 - case 3: /* result is long double */
931 + case 3: /* result is long double */
932 +
875 933 switch (info->res.type) {
876 934 case fex_int:
877 - info->res.val.q = (long double) info->res.val.i;
935 + info->res.val.q = (long double)info->res.val.i;
878 936 break;
879 937
880 938 case fex_llong:
881 - info->res.val.q = (long double) info->res.val.l;
939 + info->res.val.q = (long double)info->res.val.l;
882 940 break;
883 941
884 942 case fex_float:
885 - info->res.val.q = (long double) info->res.val.f;
943 + info->res.val.q = (long double)info->res.val.f;
886 944 break;
887 945
888 946 case fex_double:
889 - info->res.val.q = (long double) info->res.val.d;
947 + info->res.val.q = (long double)info->res.val.d;
890 948 break;
891 949
892 950 default:
893 951 break;
894 952 }
895 - *(long double*)FPREG(rd) = info->res.val.q;
953 +
954 + *(long double *)FPREG(rd) = info->res.val.q;
896 955 break;
897 956 }
898 957 }
899 -#endif /* defined(__sparc) */
958 +#endif /* defined(__sparc) */
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX