Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
f16_sqrt.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "internals.h"
#include "specialize.h"
#include "softfloat.h"
Include dependency graph for f16_sqrt.c:

Go to the source code of this file.

Functions

float16_t f16_sqrt (float16_t a)
 

Variables

const uint16_t softfloat_approxRecipSqrt_1k0s []
 
const uint16_t softfloat_approxRecipSqrt_1k1s []
 

Function Documentation

◆ f16_sqrt()

float16_t f16_sqrt ( float16_t a)

Definition at line 47 of file f16_sqrt.c.

48{
49 union ui16_f16 uA;
50 uint_fast16_t uiA;
51 bool signA;
52 int_fast8_t expA;
53 uint_fast16_t sigA, uiZ;
54 struct exp8_sig16 normExpSig;
55 int_fast8_t expZ;
56 int index;
58 uint_fast32_t ESqrR0;
60 uint_fast16_t recipSqrt16, sigZ, shiftedSigZ;
61 uint16_t negRem;
62 union ui16_f16 uZ;
63
64 /*------------------------------------------------------------------------
65 *------------------------------------------------------------------------*/
66 uA.f = a;
67 uiA = uA.ui;
68 signA = signF16UI( uiA );
69 expA = expF16UI( uiA );
70 sigA = fracF16UI( uiA );
71 /*------------------------------------------------------------------------
72 *------------------------------------------------------------------------*/
73 if ( expA == 0x1F ) {
74 if ( sigA ) {
75 uiZ = softfloat_propagateNaNF16UI( uiA, 0 );
76 goto uiZ;
77 }
78 if ( ! signA ) return a;
79 goto invalid;
80 }
81 /*------------------------------------------------------------------------
82 *------------------------------------------------------------------------*/
83 if ( signA ) {
84 if ( ! (expA | sigA) ) return a;
85 goto invalid;
86 }
87 /*------------------------------------------------------------------------
88 *------------------------------------------------------------------------*/
89 if ( ! expA ) {
90 if ( ! sigA ) return a;
91 normExpSig = softfloat_normSubnormalF16Sig( sigA );
92 expA = normExpSig.exp;
93 sigA = normExpSig.sig;
94 }
95 /*------------------------------------------------------------------------
96 *------------------------------------------------------------------------*/
97 expZ = ((expA - 0xF)>>1) + 0xE;
98 expA &= 1;
99 sigA |= 0x0400;
100 index = (sigA>>6 & 0xE) + expA;
103 * (sigA & 0x7F))
104 >>11);
105 ESqrR0 = ((uint_fast32_t) r0 * r0)>>1;
106 if ( expA ) ESqrR0 >>= 1;
107 sigma0 = ~(uint_fast16_t) ((ESqrR0 * sigA)>>16);
108 recipSqrt16 = r0 + (((uint_fast32_t) r0 * sigma0)>>25);
109 if ( ! (recipSqrt16 & 0x8000) ) recipSqrt16 = 0x8000;
110 sigZ = ((uint_fast32_t) (sigA<<5) * recipSqrt16)>>16;
111 if ( expA ) sigZ >>= 1;
112 /*------------------------------------------------------------------------
113 *------------------------------------------------------------------------*/
114 ++sigZ;
115 if ( ! (sigZ & 7) ) {
116 shiftedSigZ = sigZ>>1;
117 negRem = shiftedSigZ * shiftedSigZ;
118 sigZ &= ~1;
119 if ( negRem & 0x8000 ) {
120 sigZ |= 1;
121 } else {
122 if ( negRem ) --sigZ;
123 }
124 }
125 return softfloat_roundPackToF16( 0, expZ, sigZ );
126 /*------------------------------------------------------------------------
127 *------------------------------------------------------------------------*/
128 invalid:
130 uiZ = defaultNaNF16UI;
131 uiZ:
132 uZ.ui = uiZ;
133 return uZ.f;
134
135}
#define sigma0(x)
Definition hash_impl.h:21
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
uint_fast16_t softfloat_propagateNaNF16UI(uint_fast16_t uiA, uint_fast16_t uiB)
void softfloat_raiseFlags(uint_fast8_t flags)
#define defaultNaNF16UI
Definition specialize.h:88
const uint16_t softfloat_approxRecipSqrt_1k0s[]
const uint16_t softfloat_approxRecipSqrt_1k1s[]
#define expF16UI(a)
Definition internals.h:84
#define signF16UI(a)
Definition internals.h:83
float16_t softfloat_roundPackToF16(bool, int_fast16_t, uint_fast16_t)
#define fracF16UI(a)
Definition internals.h:85
struct exp8_sig16 softfloat_normSubnormalF16Sig(uint_fast16_t)
@ softfloat_flag_invalid
Definition softfloat.h:89
unsigned short uint16_t
Definition stdint.h:125
uint16_t uint_fast16_t
Definition stdint.h:155
int8_t int_fast8_t
Definition stdint.h:150
uint32_t uint_fast32_t
Definition stdint.h:156
float16_t f
Definition internals.h:45
Here is the call graph for this function:

Variable Documentation

◆ softfloat_approxRecipSqrt_1k0s

const uint16_t softfloat_approxRecipSqrt_1k0s[]
extern

Definition at line 41 of file s_approxRecipSqrt_1Ks.c.

41 {
42 0xB4C9, 0xFFAB, 0xAA7D, 0xF11C, 0xA1C5, 0xE4C7, 0x9A43, 0xDA29,
43 0x93B5, 0xD0E5, 0x8DED, 0xC8B7, 0x88C6, 0xC16D, 0x8424, 0xBAE1
44};

◆ softfloat_approxRecipSqrt_1k1s

const uint16_t softfloat_approxRecipSqrt_1k1s[]
extern

Definition at line 45 of file s_approxRecipSqrt_1Ks.c.

45 {
46 0xA5A5, 0xEA42, 0x8C21, 0xC62D, 0x788F, 0xAA7F, 0x6928, 0x94B6,
47 0x5CC7, 0x8335, 0x52A6, 0x74E2, 0x4A3E, 0x68FE, 0x432B, 0x5EFD
48};