1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
5 * Floating-point emulation code
6 * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
12 * @(#) pa/spmath/sfcmp.c $Revision: 1.1 $
15 * sgl_cmp: compare two values
17 * External Interfaces:
18 * sgl_fcmp(leftptr, rightptr, cond, status)
20 * Internal Interfaces:
23 * <<please update with a overview of the operation of this file>>
30 #include "sgl_float.h"
33 * sgl_cmp: compare two values
36 sgl_fcmp (sgl_floating_point
* leftptr
, sgl_floating_point
* rightptr
,
37 unsigned int cond
, unsigned int *status
)
39 /* The predicate to be tested */
42 register unsigned int left
, right
;
43 register int xorresult
;
45 /* Create local copies of the numbers */
52 if( (Sgl_exponent(left
) == SGL_INFINITY_EXPONENT
)
53 || (Sgl_exponent(right
) == SGL_INFINITY_EXPONENT
) )
55 /* Check if a NaN is involved. Signal an invalid exception when
56 * comparing a signaling NaN or when comparing quiet NaNs and the
57 * low bit of the condition is set */
58 if( ( (Sgl_exponent(left
) == SGL_INFINITY_EXPONENT
)
59 && Sgl_isnotzero_mantissa(left
)
60 && (Exception(cond
) || Sgl_isone_signaling(left
)))
62 ( (Sgl_exponent(right
) == SGL_INFINITY_EXPONENT
)
63 && Sgl_isnotzero_mantissa(right
)
64 && (Exception(cond
) || Sgl_isone_signaling(right
)) ) )
66 if( Is_invalidtrap_enabled() ) {
67 Set_status_cbit(Unordered(cond
));
68 return(INVALIDEXCEPTION
);
70 else Set_invalidflag();
71 Set_status_cbit(Unordered(cond
));
74 /* All the exceptional conditions are handled, now special case
76 else if( ((Sgl_exponent(left
) == SGL_INFINITY_EXPONENT
)
77 && Sgl_isnotzero_mantissa(left
))
79 ((Sgl_exponent(right
) == SGL_INFINITY_EXPONENT
)
80 && Sgl_isnotzero_mantissa(right
)) )
82 /* NaNs always compare unordered. */
83 Set_status_cbit(Unordered(cond
));
86 /* infinities will drop down to the normal compare mechanisms */
88 /* First compare for unequal signs => less or greater or
89 * special equal case */
90 Sgl_xortointp1(left
,right
,xorresult
);
93 /* left negative => less, left positive => greater.
94 * equal is possible if both operands are zeros. */
95 if( Sgl_iszero_exponentmantissa(left
)
96 && Sgl_iszero_exponentmantissa(right
) )
98 Set_status_cbit(Equal(cond
));
100 else if( Sgl_isone_sign(left
) )
102 Set_status_cbit(Lessthan(cond
));
106 Set_status_cbit(Greaterthan(cond
));
109 /* Signs are the same. Treat negative numbers separately
110 * from the positives because of the reversed sense. */
111 else if( Sgl_all(left
) == Sgl_all(right
) )
113 Set_status_cbit(Equal(cond
));
115 else if( Sgl_iszero_sign(left
) )
117 /* Positive compare */
118 if( Sgl_all(left
) < Sgl_all(right
) )
120 Set_status_cbit(Lessthan(cond
));
124 Set_status_cbit(Greaterthan(cond
));
129 /* Negative compare. Signed or unsigned compares
130 * both work the same. That distinction is only
131 * important when the sign bits differ. */
132 if( Sgl_all(left
) > Sgl_all(right
) )
134 Set_status_cbit(Lessthan(cond
));
138 Set_status_cbit(Greaterthan(cond
));