/*1* Linux/PA-RISC Project (http://www.parisc-linux.org/)2*3* Floating-point emulation code4* Copyright (C) 2001 Hewlett-Packard (Paul Bame) <[email protected]>5*6* This program is free software; you can redistribute it and/or modify7* it under the terms of the GNU General Public License as published by8* the Free Software Foundation; either version 2, or (at your option)9* any later version.10*11* This program is distributed in the hope that it will be useful,12* but WITHOUT ANY WARRANTY; without even the implied warranty of13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the14* GNU General Public License for more details.15*16* You should have received a copy of the GNU General Public License17* along with this program; if not, write to the Free Software18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA19*/20/*21* BEGIN_DESC22*23* File:24* @(#) pa/spmath/dfcmp.c $Revision: 1.1 $25*26* Purpose:27* dbl_cmp: compare two values28*29* External Interfaces:30* dbl_fcmp(leftptr, rightptr, cond, status)31*32* Internal Interfaces:33*34* Theory:35* <<please update with a overview of the operation of this file>>36*37* END_DESC38*/39404142#include "float.h"43#include "dbl_float.h"4445/*46* dbl_cmp: compare two values47*/48int49dbl_fcmp (dbl_floating_point * leftptr, dbl_floating_point * rightptr,50unsigned int cond, unsigned int *status)5152/* The predicate to be tested */5354{55register unsigned int leftp1, leftp2, rightp1, rightp2;56register int xorresult;5758/* Create local copies of the numbers */59Dbl_copyfromptr(leftptr,leftp1,leftp2);60Dbl_copyfromptr(rightptr,rightp1,rightp2);61/*62* Test for NaN63*/64if( (Dbl_exponent(leftp1) == DBL_INFINITY_EXPONENT)65|| (Dbl_exponent(rightp1) == DBL_INFINITY_EXPONENT) )66{67/* Check if a NaN is involved. Signal an invalid exception when68* comparing a signaling NaN or when comparing quiet NaNs and the69* low bit of the condition is set */70if( ((Dbl_exponent(leftp1) == DBL_INFINITY_EXPONENT)71&& Dbl_isnotzero_mantissa(leftp1,leftp2)72&& (Exception(cond) || Dbl_isone_signaling(leftp1)))73||74((Dbl_exponent(rightp1) == DBL_INFINITY_EXPONENT)75&& Dbl_isnotzero_mantissa(rightp1,rightp2)76&& (Exception(cond) || Dbl_isone_signaling(rightp1))) )77{78if( Is_invalidtrap_enabled() ) {79Set_status_cbit(Unordered(cond));80return(INVALIDEXCEPTION);81}82else Set_invalidflag();83Set_status_cbit(Unordered(cond));84return(NOEXCEPTION);85}86/* All the exceptional conditions are handled, now special case87NaN compares */88else if( ((Dbl_exponent(leftp1) == DBL_INFINITY_EXPONENT)89&& Dbl_isnotzero_mantissa(leftp1,leftp2))90||91((Dbl_exponent(rightp1) == DBL_INFINITY_EXPONENT)92&& Dbl_isnotzero_mantissa(rightp1,rightp2)) )93{94/* NaNs always compare unordered. */95Set_status_cbit(Unordered(cond));96return(NOEXCEPTION);97}98/* infinities will drop down to the normal compare mechanisms */99}100/* First compare for unequal signs => less or greater or101* special equal case */102Dbl_xortointp1(leftp1,rightp1,xorresult);103if( xorresult < 0 )104{105/* left negative => less, left positive => greater.106* equal is possible if both operands are zeros. */107if( Dbl_iszero_exponentmantissa(leftp1,leftp2)108&& Dbl_iszero_exponentmantissa(rightp1,rightp2) )109{110Set_status_cbit(Equal(cond));111}112else if( Dbl_isone_sign(leftp1) )113{114Set_status_cbit(Lessthan(cond));115}116else117{118Set_status_cbit(Greaterthan(cond));119}120}121/* Signs are the same. Treat negative numbers separately122* from the positives because of the reversed sense. */123else if(Dbl_isequal(leftp1,leftp2,rightp1,rightp2))124{125Set_status_cbit(Equal(cond));126}127else if( Dbl_iszero_sign(leftp1) )128{129/* Positive compare */130if( Dbl_allp1(leftp1) < Dbl_allp1(rightp1) )131{132Set_status_cbit(Lessthan(cond));133}134else if( Dbl_allp1(leftp1) > Dbl_allp1(rightp1) )135{136Set_status_cbit(Greaterthan(cond));137}138else139{140/* Equal first parts. Now we must use unsigned compares to141* resolve the two possibilities. */142if( Dbl_allp2(leftp2) < Dbl_allp2(rightp2) )143{144Set_status_cbit(Lessthan(cond));145}146else147{148Set_status_cbit(Greaterthan(cond));149}150}151}152else153{154/* Negative compare. Signed or unsigned compares155* both work the same. That distinction is only156* important when the sign bits differ. */157if( Dbl_allp1(leftp1) > Dbl_allp1(rightp1) )158{159Set_status_cbit(Lessthan(cond));160}161else if( Dbl_allp1(leftp1) < Dbl_allp1(rightp1) )162{163Set_status_cbit(Greaterthan(cond));164}165else166{167/* Equal first parts. Now we must use unsigned compares to168* resolve the two possibilities. */169if( Dbl_allp2(leftp2) > Dbl_allp2(rightp2) )170{171Set_status_cbit(Lessthan(cond));172}173else174{175Set_status_cbit(Greaterthan(cond));176}177}178}179return(NOEXCEPTION);180}181182183