aboutsummaryrefslogtreecommitdiff
path: root/softfloat/f32_sqrt.c
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@s141.Millennium.Berkeley.EDU>2011-06-19 20:47:29 -0700
committerAndrew Waterman <waterman@s141.Millennium.Berkeley.EDU>2011-06-19 20:47:29 -0700
commit77452a26e7d95d29dbaa797595ae683f03a3345b (patch)
treee7aaae682f73a20ceb4d3366528b0cd38378f49d /softfloat/f32_sqrt.c
parent740f981cfd55604d46598144dccac26dd53f643c (diff)
downloadspike-77452a26e7d95d29dbaa797595ae683f03a3345b.zip
spike-77452a26e7d95d29dbaa797595ae683f03a3345b.tar.gz
spike-77452a26e7d95d29dbaa797595ae683f03a3345b.tar.bz2
temporary undoing of renaming
Diffstat (limited to 'softfloat/f32_sqrt.c')
-rwxr-xr-xsoftfloat/f32_sqrt.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/softfloat/f32_sqrt.c b/softfloat/f32_sqrt.c
new file mode 100755
index 0000000..c9eb907
--- /dev/null
+++ b/softfloat/f32_sqrt.c
@@ -0,0 +1,74 @@
+
+#include <stdbool.h>
+#include <stdint.h>
+#include "platform.h"
+#include "primitives.h"
+#include "internals.h"
+#include "specialize.h"
+#include "softfloat.h"
+
+float32_t f32_sqrt( float32_t a )
+{
+ union ui32_f32 uA;
+ uint_fast32_t uiA;
+ bool signA;
+ int_fast16_t expA;
+ uint_fast32_t sigA, uiZ;
+ struct exp16_sig32 normExpSig;
+ int_fast16_t expZ;
+ uint_fast32_t sigZ;
+ uint_fast64_t term, rem;
+ union ui32_f32 uZ;
+
+ uA.f = a;
+ uiA = uA.ui;
+ signA = signF32UI( uiA );
+ expA = expF32UI( uiA );
+ sigA = fracF32UI( uiA );
+ if ( expA == 0xFF ) {
+ if ( sigA ) {
+ uiZ = softfloat_propagateNaNF32UI( uiA, 0 );
+ goto uiZ;
+ }
+ if ( ! signA ) return a;
+ goto invalid;
+ }
+ if ( signA ) {
+ if ( ! ( expA | sigA ) ) return a;
+ goto invalid;
+ }
+ if ( ! expA ) {
+ if ( ! sigA ) return a;
+ normExpSig = softfloat_normSubnormalF32Sig( sigA );
+ expA = normExpSig.exp;
+ sigA = normExpSig.sig;
+ }
+ expZ = ( ( expA - 0x7F )>>1 ) + 0x7E;
+ sigA = ( sigA | 0x00800000 )<<8;
+ sigZ = softfloat_estimateSqrt32( expA, sigA ) + 2;
+ if ( ( sigZ & 0x7F ) <= 5 ) {
+ if ( sigZ < 2 ) {
+ sigZ = 0x7FFFFFFF;
+ goto roundPack;
+ }
+ sigA >>= expA & 1;
+ term = (uint_fast64_t) sigZ * sigZ;
+ rem = ( (uint_fast64_t) sigA<<32 ) - term;
+ while ( UINT64_C( 0x8000000000000000 ) <= rem ) {
+ --sigZ;
+ rem += ( (uint_fast64_t) sigZ<<1 ) | 1;
+ }
+ sigZ |= ( rem != 0 );
+ }
+ sigZ = softfloat_shortShift32Right1Jam( sigZ );
+ roundPack:
+ return softfloat_roundPackToF32( 0, expZ, sigZ );
+ invalid:
+ softfloat_raiseFlags( softfloat_flag_invalid );
+ uiZ = defaultNaNF32UI;
+ uiZ:
+ uZ.ui = uiZ;
+ return uZ.f;
+
+}
+