// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Linux/PA-RISC Project (http://www.parisc-linux.org/)3*4* Floating-point emulation code5* Copyright (C) 2001 Hewlett-Packard (Paul Bame) <[email protected]>6*/7/*8* BEGIN_DESC9*10* File:11* @(#) pa/spmath/sfcmp.c $Revision: 1.1 $12*13* Purpose:14* sgl_cmp: compare two values15*16* External Interfaces:17* sgl_fcmp(leftptr, rightptr, cond, status)18*19* Internal Interfaces:20*21* Theory:22* <<please update with a overview of the operation of this file>>23*24* END_DESC25*/262728#include "float.h"29#include "sgl_float.h"3031/*32* sgl_cmp: compare two values33*/34int35sgl_fcmp (sgl_floating_point * leftptr, sgl_floating_point * rightptr,36unsigned int cond, unsigned int *status)3738/* The predicate to be tested */3940{41register unsigned int left, right;42register int xorresult;4344/* Create local copies of the numbers */45left = *leftptr;46right = *rightptr;4748/*49* Test for NaN50*/51if( (Sgl_exponent(left) == SGL_INFINITY_EXPONENT)52|| (Sgl_exponent(right) == SGL_INFINITY_EXPONENT) )53{54/* Check if a NaN is involved. Signal an invalid exception when55* comparing a signaling NaN or when comparing quiet NaNs and the56* low bit of the condition is set */57if( ( (Sgl_exponent(left) == SGL_INFINITY_EXPONENT)58&& Sgl_isnotzero_mantissa(left)59&& (Exception(cond) || Sgl_isone_signaling(left)))60||61( (Sgl_exponent(right) == SGL_INFINITY_EXPONENT)62&& Sgl_isnotzero_mantissa(right)63&& (Exception(cond) || Sgl_isone_signaling(right)) ) )64{65if( Is_invalidtrap_enabled() ) {66Set_status_cbit(Unordered(cond));67return(INVALIDEXCEPTION);68}69else Set_invalidflag();70Set_status_cbit(Unordered(cond));71return(NOEXCEPTION);72}73/* All the exceptional conditions are handled, now special case74NaN compares */75else if( ((Sgl_exponent(left) == SGL_INFINITY_EXPONENT)76&& Sgl_isnotzero_mantissa(left))77||78((Sgl_exponent(right) == SGL_INFINITY_EXPONENT)79&& Sgl_isnotzero_mantissa(right)) )80{81/* NaNs always compare unordered. */82Set_status_cbit(Unordered(cond));83return(NOEXCEPTION);84}85/* infinities will drop down to the normal compare mechanisms */86}87/* First compare for unequal signs => less or greater or88* special equal case */89Sgl_xortointp1(left,right,xorresult);90if( xorresult < 0 )91{92/* left negative => less, left positive => greater.93* equal is possible if both operands are zeros. */94if( Sgl_iszero_exponentmantissa(left)95&& Sgl_iszero_exponentmantissa(right) )96{97Set_status_cbit(Equal(cond));98}99else if( Sgl_isone_sign(left) )100{101Set_status_cbit(Lessthan(cond));102}103else104{105Set_status_cbit(Greaterthan(cond));106}107}108/* Signs are the same. Treat negative numbers separately109* from the positives because of the reversed sense. */110else if( Sgl_all(left) == Sgl_all(right) )111{112Set_status_cbit(Equal(cond));113}114else if( Sgl_iszero_sign(left) )115{116/* Positive compare */117if( Sgl_all(left) < Sgl_all(right) )118{119Set_status_cbit(Lessthan(cond));120}121else122{123Set_status_cbit(Greaterthan(cond));124}125}126else127{128/* Negative compare. Signed or unsigned compares129* both work the same. That distinction is only130* important when the sign bits differ. */131if( Sgl_all(left) > Sgl_all(right) )132{133Set_status_cbit(Lessthan(cond));134}135else136{137Set_status_cbit(Greaterthan(cond));138}139}140return(NOEXCEPTION);141}142143144