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