/*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/sfcmp.c $Revision: 1.1 $25*26* Purpose:27* sgl_cmp: compare two values28*29* External Interfaces:30* sgl_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*/394041#include "float.h"42#include "sgl_float.h"4344/*45* sgl_cmp: compare two values46*/47int48sgl_fcmp (sgl_floating_point * leftptr, sgl_floating_point * rightptr,49unsigned int cond, unsigned int *status)5051/* The predicate to be tested */5253{54register unsigned int left, right;55register int xorresult;5657/* Create local copies of the numbers */58left = *leftptr;59right = *rightptr;6061/*62* Test for NaN63*/64if( (Sgl_exponent(left) == SGL_INFINITY_EXPONENT)65|| (Sgl_exponent(right) == SGL_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( ( (Sgl_exponent(left) == SGL_INFINITY_EXPONENT)71&& Sgl_isnotzero_mantissa(left)72&& (Exception(cond) || Sgl_isone_signaling(left)))73||74( (Sgl_exponent(right) == SGL_INFINITY_EXPONENT)75&& Sgl_isnotzero_mantissa(right)76&& (Exception(cond) || Sgl_isone_signaling(right)) ) )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( ((Sgl_exponent(left) == SGL_INFINITY_EXPONENT)89&& Sgl_isnotzero_mantissa(left))90||91((Sgl_exponent(right) == SGL_INFINITY_EXPONENT)92&& Sgl_isnotzero_mantissa(right)) )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 */102Sgl_xortointp1(left,right,xorresult);103if( xorresult < 0 )104{105/* left negative => less, left positive => greater.106* equal is possible if both operands are zeros. */107if( Sgl_iszero_exponentmantissa(left)108&& Sgl_iszero_exponentmantissa(right) )109{110Set_status_cbit(Equal(cond));111}112else if( Sgl_isone_sign(left) )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( Sgl_all(left) == Sgl_all(right) )124{125Set_status_cbit(Equal(cond));126}127else if( Sgl_iszero_sign(left) )128{129/* Positive compare */130if( Sgl_all(left) < Sgl_all(right) )131{132Set_status_cbit(Lessthan(cond));133}134else135{136Set_status_cbit(Greaterthan(cond));137}138}139else140{141/* Negative compare. Signed or unsigned compares142* both work the same. That distinction is only143* important when the sign bits differ. */144if( Sgl_all(left) > Sgl_all(right) )145{146Set_status_cbit(Lessthan(cond));147}148else149{150Set_status_cbit(Greaterthan(cond));151}152}153return(NOEXCEPTION);154}155156157