Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LV4VG-0002kk-FF for qemu-devel@nongnu.org; Thu, 05 Feb 2009 08:42:50 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LV4VF-0002kJ-NR for qemu-devel@nongnu.org; Thu, 05 Feb 2009 08:42:49 -0500 Received: from [199.232.76.173] (port=49956 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LV4VF-0002kA-E0 for qemu-devel@nongnu.org; Thu, 05 Feb 2009 08:42:49 -0500 Received: from savannah.gnu.org ([199.232.41.3]:36180 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LV4VF-0000CG-2x for qemu-devel@nongnu.org; Thu, 05 Feb 2009 08:42:49 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LV4VE-0008RS-8r for qemu-devel@nongnu.org; Thu, 05 Feb 2009 13:42:48 +0000 Received: from aurel32 by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LV4VD-0008RN-TU for qemu-devel@nongnu.org; Thu, 05 Feb 2009 13:42:48 +0000 MIME-Version: 1.0 Errors-To: aurel32 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Aurelien Jarno Message-Id: Date: Thu, 05 Feb 2009 13:42:47 +0000 Subject: [Qemu-devel] [6518] soft-float: add float32_log2() and float64_log2() Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6518 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6518 Author: aurel32 Date: 2009-02-05 13:42:47 +0000 (Thu, 05 Feb 2009) Log Message: ----------- soft-float: add float32_log2() and float64_log2() Signed-off-by: Aurelien Jarno Modified Paths: -------------- trunk/fpu/softfloat.c trunk/fpu/softfloat.h Modified: trunk/fpu/softfloat.c =================================================================== --- trunk/fpu/softfloat.c 2009-02-04 20:39:09 UTC (rev 6517) +++ trunk/fpu/softfloat.c 2009-02-05 13:42:47 UTC (rev 6518) @@ -2057,6 +2057,53 @@ } /*---------------------------------------------------------------------------- +| Returns the binary log of the single-precision floating-point value `a'. +| The operation is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ +float32 float32_log2( float32 a STATUS_PARAM ) +{ + flag aSign, zSign; + int16 aExp; + bits32 aSig, zSig, i; + + aSig = extractFloat32Frac( a ); + aExp = extractFloat32Exp( a ); + aSign = extractFloat32Sign( a ); + + if ( aExp == 0 ) { + if ( aSig == 0 ) return packFloat32( 1, 0xFF, 0 ); + normalizeFloat32Subnormal( aSig, &aExp, &aSig ); + } + if ( aSign ) { + float_raise( float_flag_invalid STATUS_VAR); + return float32_default_nan; + } + if ( aExp == 0xFF ) { + if ( aSig ) return propagateFloat32NaN( a, float32_zero STATUS_VAR ); + return a; + } + + aExp -= 0x7F; + aSig |= 0x00800000; + zSign = aExp < 0; + zSig = aExp << 23; + + for (i = 1 << 22; i > 0; i >>= 1) { + aSig = ( (bits64)aSig * aSig ) >> 23; + if ( aSig & 0x01000000 ) { + aSig >>= 1; + zSig |= i; + } + } + + if ( zSign ) + zSig = -zSig; + + return normalizeRoundAndPackFloat32( zSign, 0x85, zSig STATUS_VAR ); +} + +/*---------------------------------------------------------------------------- | Returns 1 if the single-precision floating-point value `a' is equal to | the corresponding value `b', and 0 otherwise. The comparison is performed | according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. @@ -3006,6 +3053,52 @@ } /*---------------------------------------------------------------------------- +| Returns the binary log of the double-precision floating-point value `a'. +| The operation is performed according to the IEC/IEEE Standard for Binary +| Floating-Point Arithmetic. +*----------------------------------------------------------------------------*/ +float64 float64_log2( float64 a STATUS_PARAM ) +{ + flag aSign, zSign; + int16 aExp; + bits64 aSig, aSig0, aSig1, zSig, i; + + aSig = extractFloat64Frac( a ); + aExp = extractFloat64Exp( a ); + aSign = extractFloat64Sign( a ); + + if ( aExp == 0 ) { + if ( aSig == 0 ) return packFloat64( 1, 0x7FF, 0 ); + normalizeFloat64Subnormal( aSig, &aExp, &aSig ); + } + if ( aSign ) { + float_raise( float_flag_invalid STATUS_VAR); + return float64_default_nan; + } + if ( aExp == 0x7FF ) { + if ( aSig ) return propagateFloat64NaN( a, float64_zero STATUS_VAR ); + return a; + } + + aExp -= 0x3FF; + aSig |= LIT64( 0x0010000000000000 ); + zSign = aExp < 0; + zSig = (bits64)aExp << 52; + for (i = 1LL << 51; i > 0; i >>= 1) { + mul64To128( aSig, aSig, &aSig0, &aSig1 ); + aSig = ( aSig0 << 12 ) | ( aSig1 >> 52 ); + if ( aSig & LIT64( 0x0020000000000000 ) ) { + aSig >>= 1; + zSig |= i; + } + } + + if ( zSign ) + zSig = -zSig; + return normalizeRoundAndPackFloat64( zSign, 0x408, zSig STATUS_VAR ); +} + +/*---------------------------------------------------------------------------- | Returns 1 if the double-precision floating-point value `a' is equal to the | corresponding value `b', and 0 otherwise. The comparison is performed | according to the IEC/IEEE Standard for Binary Floating-Point Arithmetic. Modified: trunk/fpu/softfloat.h =================================================================== --- trunk/fpu/softfloat.h 2009-02-04 20:39:09 UTC (rev 6517) +++ trunk/fpu/softfloat.h 2009-02-05 13:42:47 UTC (rev 6518) @@ -269,6 +269,7 @@ float32 float32_div( float32, float32 STATUS_PARAM ); float32 float32_rem( float32, float32 STATUS_PARAM ); float32 float32_sqrt( float32 STATUS_PARAM ); +float32 float32_log2( float32 STATUS_PARAM ); int float32_eq( float32, float32 STATUS_PARAM ); int float32_le( float32, float32 STATUS_PARAM ); int float32_lt( float32, float32 STATUS_PARAM ); @@ -339,6 +340,7 @@ float64 float64_div( float64, float64 STATUS_PARAM ); float64 float64_rem( float64, float64 STATUS_PARAM ); float64 float64_sqrt( float64 STATUS_PARAM ); +float64 float64_log2( float64 STATUS_PARAM ); int float64_eq( float64, float64 STATUS_PARAM ); int float64_le( float64, float64 STATUS_PARAM ); int float64_lt( float64, float64 STATUS_PARAM );