Print this page
5224 snprintf rounding under [default] FE_TONEAREST
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libc/i386/fp/_base_il.c
+++ new/usr/src/lib/libc/i386/fp/_base_il.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
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #pragma ident "%Z%%M% %I% %E% SMI"
28 28
29 29 #include "lint.h"
30 30 #include "base_conversion.h"
|
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
31 31
32 32 /* The following should be coded as inline expansion templates. */
33 33
34 34 /*
35 35 * Multiplies two normal or subnormal doubles, returns result and exceptions.
36 36 */
37 37 double
38 38 __mul_set(double x, double y, int *pe) {
39 39 extern void _putsw(), _getsw();
40 40 int sw;
41 - double z;
41 + volatile double z;
42 42
43 43 _putsw(0);
44 + /*
45 + * NOTE: By declaring 'z' volatile above, we intend for the
46 + * compiler to not move this after the _getmxcsr() call, whose results
47 + * are only useful if they immediately follow the multiply.
48 + *
49 + * From the C11 spec:
50 + *
51 + * 134 - A volatile declaration may be used to describe an
52 + * object corresponding to a memory-mapped input/output port
53 + * or an object accessed by an asynchronously interrupting
54 + * function. Actions on objects so declared shall by an
55 + * implementation or reordered except as permitted by the
56 + * rules for evaluating expressions."
57 + */
44 58 z = x * y;
45 59 _getsw(&sw);
46 60 if ((sw & 0x3f) == 0) {
47 61 *pe = 0;
48 62 } else {
49 63 /* Result may not be exact. */
50 64 *pe = 1;
51 65 }
52 66 return (z);
53 67 }
54 68
55 69 /*
56 70 * Divides two normal or subnormal doubles x/y, returns result and exceptions.
57 71 */
58 72 double
59 73 __div_set(double x, double y, int *pe) {
60 74 extern void _putsw(), _getsw();
61 75 int sw;
62 - double z;
76 + volatile double z;
63 77
64 78 _putsw(0);
79 + /* NOTE: See __mul_set() above, same principle applies here. */
65 80 z = x / y;
66 81 _getsw(&sw);
67 82 if ((sw & 0x3f) == 0) {
68 83 *pe = 0;
69 84 } else {
70 85 *pe = 1;
71 86 }
72 87 return (z);
73 88 }
74 89
75 90 double
76 91 __dabs(double *d)
77 92 {
78 93 /* should use hardware fabs instruction */
79 94 return ((*d < 0.0) ? -*d : *d);
80 95 }
81 96
82 97 /*
83 98 * Returns IEEE mode/status and
84 99 * sets up standard environment for base conversion.
85 100 */
86 101 void
87 102 __get_ieee_flags(__ieee_flags_type *b) {
88 103 extern void _getcw(), _getsw(), _putcw();
89 104 int cw;
90 105
91 106 _getcw(&cw);
92 107 b->mode = cw;
93 108 _getsw(&b->status);
94 109 /*
95 110 * set CW to...
96 111 * RC (bits 10:11) 0 == round to nearest even
97 112 * PC (bits 8:9) 2 == round to double
98 113 * EM (bits 0:5) 0x3f == all exception trapping masked off
99 114 */
100 115 cw = (cw & ~0xf3f) | 0x23f;
101 116 _putcw(cw);
102 117 }
103 118
104 119 /*
105 120 * Restores previous IEEE mode/status
106 121 */
107 122 void
108 123 __set_ieee_flags(__ieee_flags_type *b) {
109 124 extern void _putcw(), _putsw();
110 125
111 126 _putcw(b->mode);
112 127 _putsw(b->status);
113 128 }
|
↓ open down ↓ |
39 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX