Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Linux/PA-RISC Project (http://www.parisc-linux.org/)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Floating-point emulation code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * BEGIN_DESC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  File:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *	@(#)	pa/spmath/dfcmp.c		$Revision: 1.1 $
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *  Purpose:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *	dbl_cmp: compare two values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  External Interfaces:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *	dbl_fcmp(leftptr, rightptr, cond, status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *  Internal Interfaces:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  *  Theory:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *	<<please update with a overview of the operation of this file>>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * END_DESC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include "float.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include "dbl_float.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * dbl_cmp: compare two values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) dbl_fcmp (dbl_floating_point * leftptr, dbl_floating_point * rightptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	  unsigned int cond, unsigned int *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)                                            
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)                        /* The predicate to be tested */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)                          
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)     {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43)     register unsigned int leftp1, leftp2, rightp1, rightp2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44)     register int xorresult;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45)         
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)     /* Create local copies of the numbers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)     Dbl_copyfromptr(leftptr,leftp1,leftp2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)     Dbl_copyfromptr(rightptr,rightp1,rightp2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)      * Test for NaN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)     if(    (Dbl_exponent(leftp1) == DBL_INFINITY_EXPONENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)         || (Dbl_exponent(rightp1) == DBL_INFINITY_EXPONENT) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	/* Check if a NaN is involved.  Signal an invalid exception when 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	 * comparing a signaling NaN or when comparing quiet NaNs and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	 * low bit of the condition is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)         if( ((Dbl_exponent(leftp1) == DBL_INFINITY_EXPONENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	    && Dbl_isnotzero_mantissa(leftp1,leftp2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	    && (Exception(cond) || Dbl_isone_signaling(leftp1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	   ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	    ((Dbl_exponent(rightp1) == DBL_INFINITY_EXPONENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	    && Dbl_isnotzero_mantissa(rightp1,rightp2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	    && (Exception(cond) || Dbl_isone_signaling(rightp1))) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	    if( Is_invalidtrap_enabled() ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	    	Set_status_cbit(Unordered(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		return(INVALIDEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	    else Set_invalidflag();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	    Set_status_cbit(Unordered(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	    return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	/* All the exceptional conditions are handled, now special case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	   NaN compares */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76)         else if( ((Dbl_exponent(leftp1) == DBL_INFINITY_EXPONENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	    && Dbl_isnotzero_mantissa(leftp1,leftp2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	   ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	    ((Dbl_exponent(rightp1) == DBL_INFINITY_EXPONENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	    && Dbl_isnotzero_mantissa(rightp1,rightp2)) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	    /* NaNs always compare unordered. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	    Set_status_cbit(Unordered(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	    return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	/* infinities will drop down to the normal compare mechanisms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88)     /* First compare for unequal signs => less or greater or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89)      * special equal case */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90)     Dbl_xortointp1(leftp1,rightp1,xorresult);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91)     if( xorresult < 0 )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)         /* left negative => less, left positive => greater.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)          * equal is possible if both operands are zeros. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)         if( Dbl_iszero_exponentmantissa(leftp1,leftp2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	  && Dbl_iszero_exponentmantissa(rightp1,rightp2) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)             {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	    Set_status_cbit(Equal(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	else if( Dbl_isone_sign(leftp1) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	    Set_status_cbit(Lessthan(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	    Set_status_cbit(Greaterthan(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)     /* Signs are the same.  Treat negative numbers separately
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)      * from the positives because of the reversed sense.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)     else if(Dbl_isequal(leftp1,leftp2,rightp1,rightp2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)         Set_status_cbit(Equal(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)     else if( Dbl_iszero_sign(leftp1) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)         /* Positive compare */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if( Dbl_allp1(leftp1) < Dbl_allp1(rightp1) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	    Set_status_cbit(Lessthan(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	else if( Dbl_allp1(leftp1) > Dbl_allp1(rightp1) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	    Set_status_cbit(Greaterthan(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	    /* Equal first parts.  Now we must use unsigned compares to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	     * resolve the two possibilities. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	    if( Dbl_allp2(leftp2) < Dbl_allp2(rightp2) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		Set_status_cbit(Lessthan(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	    else 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		Set_status_cbit(Greaterthan(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)     else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)         {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)         /* Negative compare.  Signed or unsigned compares
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)          * both work the same.  That distinction is only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)          * important when the sign bits differ. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if( Dbl_allp1(leftp1) > Dbl_allp1(rightp1) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	    Set_status_cbit(Lessthan(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	else if( Dbl_allp1(leftp1) < Dbl_allp1(rightp1) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	    Set_status_cbit(Greaterthan(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	    {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	    /* Equal first parts.  Now we must use unsigned compares to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	     * resolve the two possibilities. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	    if( Dbl_allp2(leftp2) > Dbl_allp2(rightp2) )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		Set_status_cbit(Lessthan(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	    else 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		Set_status_cbit(Greaterthan(cond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	    }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)         }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	return(NOEXCEPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)     }