5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25 /*
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
28 */
29
30 #pragma weak fminf = __fminf
31
32 #include "libm.h" /* for islessequal macro */
33
34 float
35 __fminf(float x, float y) {
36 /*
37 * On SPARC v8plus/v9, this could be implemented as follows
38 * (assuming %f0 = x, %f1 = y, return value left in %f0):
39 *
40 * fcmps %fcc0,%f1,%f1
41 * fmovsu %fcc0,%f0,%f1
42 * fcmps %fcc0,%f0,%f1
43 * fmovsug %fcc0,%f1,%f0
44 * st %f0,[x]
45 * st %f1,[y]
46 * ld [x],%l0
47 * ld [y],%l1
48 * or %l0,%l1,%l2
49 * sethi %hi(0x80000000),%l3
50 * and %l3,%l2,%l2
51 * or %l0,%l2,%l0
52 * st %l0,[x]
53 * ld [x],%f0
54 *
55 * If VIS instructions are available, use this code instead:
57 * fcmps %fcc0,%f1,%f1
58 * fmovsu %fcc0,%f0,%f1
59 * fcmps %fcc0,%f0,%f1
60 * fmovsug %fcc0,%f1,%f0
61 * fors %f0,%f1,%f2
62 * fzeros %f3
63 * fnegs %f3,%f3
64 * fands %f3,%f2,%f2
65 * fors %f0,%f2,%f0
66 *
67 * If VIS 3.0 instructions are available, use this:
68 *
69 * flcmps %fcc0,%f0,%f1
70 * fmovsge %fcc0,%f1,%f0 ! move if %fcc0 is 0 or 2
71 */
72
73 union {
74 unsigned i;
75 float f;
76 } xx, yy;
77 unsigned s;
78
79 /* if y is nan, replace it by x */
80 if (y != y)
81 y = x;
82
83 /* if x is nan, replace it by y */
84 if (x != x)
85 x = y;
86
87 /* At this point, x and y are either both numeric, or both NaN */
88 if (!isnan(x) && !islessequal(x, y))
89 x = y;
90
91 /*
92 * set the sign of the result if either x or y has its sign set
93 */
94 xx.f = x;
95 yy.f = y;
96 s = (xx.i | yy.i) & 0x80000000;
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
24 */
25
26 /*
27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
29 */
30
31 #pragma weak fminf = __fminf
32
33 #include "libm.h" /* for islessequal macro */
34
35 float
36 __fminf(float x, float y)
37 {
38 /*
39 * On SPARC v8plus/v9, this could be implemented as follows
40 * (assuming %f0 = x, %f1 = y, return value left in %f0):
41 *
42 * fcmps %fcc0,%f1,%f1
43 * fmovsu %fcc0,%f0,%f1
44 * fcmps %fcc0,%f0,%f1
45 * fmovsug %fcc0,%f1,%f0
46 * st %f0,[x]
47 * st %f1,[y]
48 * ld [x],%l0
49 * ld [y],%l1
50 * or %l0,%l1,%l2
51 * sethi %hi(0x80000000),%l3
52 * and %l3,%l2,%l2
53 * or %l0,%l2,%l0
54 * st %l0,[x]
55 * ld [x],%f0
56 *
57 * If VIS instructions are available, use this code instead:
59 * fcmps %fcc0,%f1,%f1
60 * fmovsu %fcc0,%f0,%f1
61 * fcmps %fcc0,%f0,%f1
62 * fmovsug %fcc0,%f1,%f0
63 * fors %f0,%f1,%f2
64 * fzeros %f3
65 * fnegs %f3,%f3
66 * fands %f3,%f2,%f2
67 * fors %f0,%f2,%f0
68 *
69 * If VIS 3.0 instructions are available, use this:
70 *
71 * flcmps %fcc0,%f0,%f1
72 * fmovsge %fcc0,%f1,%f0 ! move if %fcc0 is 0 or 2
73 */
74
75 union {
76 unsigned i;
77 float f;
78 } xx, yy;
79
80 unsigned s;
81
82 /* if y is nan, replace it by x */
83 if (y != y)
84 y = x;
85
86 /* if x is nan, replace it by y */
87 if (x != x)
88 x = y;
89
90 /* At this point, x and y are either both numeric, or both NaN */
91 if (!isnan(x) && !islessequal(x, y))
92 x = y;
93
94 /*
95 * set the sign of the result if either x or y has its sign set
96 */
97 xx.f = x;
98 yy.f = y;
99 s = (xx.i | yy.i) & 0x80000000;
|