Print this page
5262 libm needs to be carefully unifdef'd
5268 libm doesn't need to hide symbols which are already local
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libm/common/m9x/fmaxf.c
+++ new/usr/src/lib/libm/common/m9x/fmaxf.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 fmaxf = __fmaxf
32 -#endif
33 31
34 32 /*
35 33 * fmax(x,y) returns the larger of x and y. If just one of the
36 34 * arguments is NaN, fmax returns the other argument. If both
37 35 * arguments are NaN, fmax returns NaN (ideally, one of the
38 36 * argument NaNs).
39 37 *
40 38 * C99 does not require that fmax(-0,+0) = fmax(+0,-0) = +0, but
41 39 * ideally fmax should satisfy this.
42 40 *
43 41 * C99 makes no mention of exceptions for fmax. I suppose ideally
44 42 * either fmax never raises any exceptions or else it raises the
45 43 * invalid operation exception if and only if some argument is a
46 44 * signaling NaN. In the former case, fmax should always return
47 45 * one of its arguments. In the latter, fmax shouldn't return a
48 46 * signaling NaN, although when both arguments are signaling NaNs,
49 47 * this ideal is at odds with the stipulation that fmax should
50 48 * always return one of its arguments.
51 49 *
52 50 * Commutativity of fmax follows from the properties listed above
53 51 * except when both arguments are NaN. In that case, fmax may be
54 52 * declared commutative by fiat because there is no portable way
55 53 * to tell different NaNs apart. Ideally fmax would be truly com-
56 54 * mutative for all arguments.
57 55 *
58 56 * On SPARC V8, fmax must involve tests and branches. Ideally,
59 57 * an implementation on SPARC V9 should avoid branching, using
60 58 * conditional moves instead where necessary, and be as efficient
61 59 * as possible in its use of other resources.
62 60 *
63 61 * It appears to be impossible to attain all of the aforementioned
64 62 * ideals simultaneously. The implementation below satisfies the
65 63 * following (on SPARC):
66 64 *
67 65 * 1. fmax(x,y) returns the larger of x and y if neither x nor y
68 66 * is NaN and the non-NaN argument if just one of x or y is NaN.
69 67 * If both x and y are NaN, fmax(x,y) returns x unchanged.
70 68 * 2. fmax(-0,+0) = fmax(+0,-0) = +0.
71 69 * 3. If either argument is a signaling NaN, fmax raises the invalid
72 70 * operation exception. Otherwise, it raises no exceptions.
73 71 */
74 72
75 73 #include "libm.h" /* for isgreaterequal macro */
76 74
77 75 float
78 76 __fmaxf(float x, float y) {
79 77 /*
80 78 * On SPARC v8plus/v9, this could be implemented as follows
81 79 * (assuming %f0 = x, %f1 = y, return value left in %f0):
82 80 *
83 81 * fcmps %fcc0,%f1,%f1
84 82 * fmovsu %fcc0,%f0,%f1
85 83 * fcmps %fcc0,%f0,%f1
86 84 * fmovsul %fcc0,%f1,%f0
87 85 * st %f0,[x]
88 86 * st %f1,[y]
89 87 * ld [x],%l0
90 88 * ld [y],%l1
91 89 * and %l0,%l1,%l2
92 90 * sethi %hi(0x80000000),%l3
93 91 * andn %l3,%l2,%l2
94 92 * andn %l0,%l2,%l0
95 93 * st %l0,[x]
96 94 * ld [x],%f0
97 95 *
98 96 * If VIS instructions are available, use this code instead:
99 97 *
100 98 * fcmps %fcc0,%f1,%f1
101 99 * fmovsu %fcc0,%f0,%f1
102 100 * fcmps %fcc0,%f0,%f1
103 101 * fmovsul %fcc0,%f1,%f0
104 102 * fands %f0,%f1,%f2
105 103 * fzeros %f3
106 104 * fnegs %f3,%f3
107 105 * fandnot2s %f3,%f2,%f2
108 106 * fandnot2s %f0,%f2,%f0
109 107 *
110 108 * If VIS 3.0 instructions are available, use this:
111 109 *
112 110 * flcmps %fcc0,%f0,%f1
113 111 * fmovslg %fcc0,%f1,%f0 ! move if %fcc0 is 1 or 2
114 112 */
115 113
116 114 union {
117 115 unsigned i;
118 116 float f;
119 117 } xx, yy;
120 118 unsigned s;
121 119
122 120 /* if y is nan, replace it by x */
123 121 if (y != y)
124 122 y = x;
125 123
126 124 /* if x is nan, replace it by y */
127 125 if (x != x)
128 126 x = y;
129 127
130 128 /* At this point, x and y are either both numeric, or both NaN */
131 129 if (!isnan(x) && !isgreaterequal(x, y))
132 130 x = y;
133 131
134 132 /*
135 133 * clear the sign of the result if either x or y has its sign clear
136 134 */
137 135 xx.f = x;
138 136 yy.f = y;
139 137 s = ~(xx.i & yy.i) & 0x80000000;
140 138 xx.i &= ~s;
141 139
142 140 return (xx.f);
143 141 }
↓ open down ↓ |
101 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX