aboutsummaryrefslogtreecommitdiff
path: root/softfloat/f32_sqrt.c
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@s141.Millennium.Berkeley.EDU>2011-06-19 21:45:58 -0700
committerAndrew Waterman <waterman@s141.Millennium.Berkeley.EDU>2011-06-19 21:45:58 -0700
commit1e163c715550e20e239976a22e00869884713e54 (patch)
treedbcf7b10e35421c72758df098057014fef7ffff7 /softfloat/f32_sqrt.c
parent0edaecc54329048eb91ad6a45338265ef1a4569c (diff)
downloadpk-1e163c715550e20e239976a22e00869884713e54.zip
pk-1e163c715550e20e239976a22e00869884713e54.tar.gz
pk-1e163c715550e20e239976a22e00869884713e54.tar.bz2
fixed build after repo split
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;
+
+}
+