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