Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
f32_div.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 f32_div.c:

Go to the source code of this file.

Functions

float32_t f32_div (float32_t a, float32_t b)
 

Function Documentation

◆ f32_div()

float32_t f32_div ( float32_t a,
float32_t b )

Definition at line 44 of file f32_div.c.

45{
46 union ui32_f32 uA;
47 uint_fast32_t uiA;
48 bool signA;
49 int_fast16_t expA;
50 uint_fast32_t sigA;
51 union ui32_f32 uB;
52 uint_fast32_t uiB;
53 bool signB;
54 int_fast16_t expB;
55 uint_fast32_t sigB;
56 bool signZ;
57 struct exp16_sig32 normExpSig;
58 int_fast16_t expZ;
59#ifdef SOFTFLOAT_FAST_DIV64TO32
60 uint_fast64_t sig64A;
61 uint_fast32_t sigZ;
62#else
63 uint_fast32_t sigZ;
64 uint_fast64_t rem;
65#endif
66 uint_fast32_t uiZ;
67 union ui32_f32 uZ;
68
69 /*------------------------------------------------------------------------
70 *------------------------------------------------------------------------*/
71 uA.f = a;
72 uiA = uA.ui;
73 signA = signF32UI( uiA );
74 expA = expF32UI( uiA );
75 sigA = fracF32UI( uiA );
76 uB.f = b;
77 uiB = uB.ui;
78 signB = signF32UI( uiB );
79 expB = expF32UI( uiB );
80 sigB = fracF32UI( uiB );
81 signZ = signA ^ signB;
82 /*------------------------------------------------------------------------
83 *------------------------------------------------------------------------*/
84 if ( expA == 0xFF ) {
85 if ( sigA ) goto propagateNaN;
86 if ( expB == 0xFF ) {
87 if ( sigB ) goto propagateNaN;
88 goto invalid;
89 }
90 goto infinity;
91 }
92 if ( expB == 0xFF ) {
93 if ( sigB ) goto propagateNaN;
94 goto zero;
95 }
96 /*------------------------------------------------------------------------
97 *------------------------------------------------------------------------*/
98 if ( ! expB ) {
99 if ( ! sigB ) {
100 if ( ! (expA | sigA) ) goto invalid;
102 goto infinity;
103 }
104 normExpSig = softfloat_normSubnormalF32Sig( sigB );
105 expB = normExpSig.exp;
106 sigB = normExpSig.sig;
107 }
108 if ( ! expA ) {
109 if ( ! sigA ) goto zero;
110 normExpSig = softfloat_normSubnormalF32Sig( sigA );
111 expA = normExpSig.exp;
112 sigA = normExpSig.sig;
113 }
114 /*------------------------------------------------------------------------
115 *------------------------------------------------------------------------*/
116 expZ = expA - expB + 0x7E;
117 sigA |= 0x00800000;
118 sigB |= 0x00800000;
119#ifdef SOFTFLOAT_FAST_DIV64TO32
120 if ( sigA < sigB ) {
121 --expZ;
122 sig64A = (uint_fast64_t) sigA<<31;
123 } else {
124 sig64A = (uint_fast64_t) sigA<<30;
125 }
126 sigZ = sig64A / sigB;
127 if ( ! (sigZ & 0x3F) ) sigZ |= ((uint_fast64_t) sigB * sigZ != sig64A);
128#else
129 if ( sigA < sigB ) {
130 --expZ;
131 sigA <<= 8;
132 } else {
133 sigA <<= 7;
134 }
135 sigB <<= 8;
136 sigZ = ((uint_fast64_t) sigA * softfloat_approxRecip32_1( sigB ))>>32;
137 /*------------------------------------------------------------------------
138 *------------------------------------------------------------------------*/
139 sigZ += 2;
140 if ( (sigZ & 0x3F) < 2 ) {
141 sigZ &= ~3;
142#ifdef SOFTFLOAT_FAST_INT64
143 rem = ((uint_fast64_t) sigA<<31) - (uint_fast64_t) sigZ * sigB;
144#else
145 rem = ((uint_fast64_t) sigA<<32) - (uint_fast64_t) (sigZ<<1) * sigB;
146#endif
147 if ( rem & UINT64_C( 0x8000000000000000 ) ) {
148 sigZ -= 4;
149 } else {
150 if ( rem ) sigZ |= 1;
151 }
152 }
153#endif
154 return softfloat_roundPackToF32( signZ, expZ, sigZ );
155 /*------------------------------------------------------------------------
156 *------------------------------------------------------------------------*/
157 propagateNaN:
158 uiZ = softfloat_propagateNaNF32UI( uiA, uiB );
159 goto uiZ;
160 /*------------------------------------------------------------------------
161 *------------------------------------------------------------------------*/
162 invalid:
164 uiZ = defaultNaNF32UI;
165 goto uiZ;
166 /*------------------------------------------------------------------------
167 *------------------------------------------------------------------------*/
168 infinity:
169 uiZ = packToF32UI( signZ, 0xFF, 0 );
170 goto uiZ;
171 /*------------------------------------------------------------------------
172 *------------------------------------------------------------------------*/
173 zero:
174 uiZ = packToF32UI( signZ, 0, 0 );
175 uiZ:
176 uZ.ui = uiZ;
177 return uZ.f;
178
179}
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
uint_fast32_t softfloat_propagateNaNF32UI(uint_fast32_t uiA, uint_fast32_t uiB)
void softfloat_raiseFlags(uint_fast8_t flags)
#define defaultNaNF32UI
Definition specialize.h:123
#define expF32UI(a)
Definition internals.h:105
float32_t softfloat_roundPackToF32(bool, int_fast16_t, uint_fast32_t)
struct exp16_sig32 softfloat_normSubnormalF32Sig(uint_fast32_t)
#define fracF32UI(a)
Definition internals.h:106
#define signF32UI(a)
Definition internals.h:104
#define packToF32UI(sign, exp, sig)
Definition internals.h:107
uint32_t softfloat_approxRecip32_1(uint32_t a)
@ softfloat_flag_invalid
Definition softfloat.h:89
@ softfloat_flag_infinite
Definition softfloat.h:88
uint64_t uint_fast64_t
Definition stdint.h:157
#define UINT64_C(val)
Definition stdint.h:284
uint32_t uint_fast32_t
Definition stdint.h:156
int16_t int_fast16_t
Definition stdint.h:151
float32_t f
Definition internals.h:46
Here is the call graph for this function:
Here is the caller graph for this function: