Print this page
5224 snprintf rounding under [default] FE_TONEAREST
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libc/amd64/fp/_base_il.c
+++ new/usr/src/lib/libc/amd64/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"
31 31 #include <sys/isa_defs.h>
32 32
33 33 #define CSR_DEFAULT 0x1f80
|
↓ open down ↓ |
33 lines elided |
↑ open up ↑ |
34 34
35 35 /* The following should be coded as inline expansion templates. */
36 36
37 37 /*
38 38 * Multiplies two normal or subnormal doubles, returns result and exceptions.
39 39 */
40 40 double
41 41 __mul_set(double x, double y, int *pe) {
42 42 extern void _putmxcsr(), _getmxcsr();
43 43 int csr;
44 - double z;
44 + volatile double z;
45 45
46 46 _putmxcsr(CSR_DEFAULT);
47 + /*
48 + * NOTE: By declaring 'z' volatile above, we intend for the
49 + * compiler to not move this after the _getmxcsr() call, whose results
50 + * are only useful if they immediately follow the multiply.
51 + *
52 + * From the C11 spec:
53 + *
54 + * 134 - A volatile declaration may be used to describe an
55 + * object corresponding to a memory-mapped input/output port
56 + * or an object accessed by an asynchronously interrupting
57 + * function. Actions on objects so declared shall by an
58 + * implementation or reordered except as permitted by the
59 + * rules for evaluating expressions."
60 + */
47 61 z = x * y;
48 62 _getmxcsr(&csr);
49 63 if ((csr & 0x3f) == 0) {
50 64 *pe = 0;
51 65 } else {
52 66 /* Result may not be exact. */
53 67 *pe = 1;
54 68 }
55 69 return (z);
56 70 }
57 71
58 72 /*
59 73 * Divides two normal or subnormal doubles x/y, returns result and exceptions.
60 74 */
61 75 double
62 76 __div_set(double x, double y, int *pe) {
63 77 extern void _putmxcsr(), _getmxcsr();
64 78 int csr;
65 - double z;
79 + volatile double z;
66 80
67 81 _putmxcsr(CSR_DEFAULT);
82 + /* NOTE: See __mul_set() above, same principle applies here. */
68 83 z = x / y;
69 84 _getmxcsr(&csr);
70 85 if ((csr & 0x3f) == 0) {
71 86 *pe = 0;
72 87 } else {
73 88 *pe = 1;
74 89 }
75 90 return (z);
76 91 }
77 92
78 93 double
79 94 __dabs(double *d)
80 95 {
81 96 /* should use hardware fabs instruction */
82 97 return ((*d < 0.0) ? -*d : *d);
83 98 }
84 99
85 100 /*
86 101 * Returns IEEE mode/status and
87 102 * sets up standard environment for base conversion.
88 103 */
89 104 void
90 105 __get_ieee_flags(__ieee_flags_type *b) {
91 106 extern void _getmxcsr(), _putmxcsr();
92 107
93 108 _getmxcsr(&b->status);
94 109
95 110 /* round-to-nearest, all exceptions masked, gradual underflow */
96 111 _putmxcsr(CSR_DEFAULT);
97 112 }
98 113
99 114 /*
100 115 * Restores previous IEEE mode/status
101 116 */
102 117 void
103 118 __set_ieee_flags(__ieee_flags_type *b) {
104 119 extern void _putmxcsr();
105 120
106 121 _putmxcsr(b->status);
107 122 }
|
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX