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

Go to the source code of this file.

Functions

float16_t f16_div (float16_t a, float16_t b)
 

Variables

const uint16_t softfloat_approxRecip_1k0s []
 
const uint16_t softfloat_approxRecip_1k1s []
 

Function Documentation

◆ f16_div()

float16_t f16_div ( float16_t a,
float16_t b )

Definition at line 47 of file f16_div.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;
54 union ui16_f16 uB;
55 uint_fast16_t uiB;
56 bool signB;
57 int_fast8_t expB;
58 uint_fast16_t sigB;
59 bool signZ;
60 struct exp8_sig16 normExpSig;
61 int_fast8_t expZ;
62#ifdef SOFTFLOAT_FAST_DIV32TO16
63 uint_fast32_t sig32A;
64 uint_fast16_t sigZ;
65#else
66 int index;
67 uint16_t r0;
68 uint_fast16_t sigZ, rem;
69#endif
70 uint_fast16_t uiZ;
71 union ui16_f16 uZ;
72
73 /*------------------------------------------------------------------------
74 *------------------------------------------------------------------------*/
75 uA.f = a;
76 uiA = uA.ui;
77 signA = signF16UI( uiA );
78 expA = expF16UI( uiA );
79 sigA = fracF16UI( uiA );
80 uB.f = b;
81 uiB = uB.ui;
82 signB = signF16UI( uiB );
83 expB = expF16UI( uiB );
84 sigB = fracF16UI( uiB );
85 signZ = signA ^ signB;
86 /*------------------------------------------------------------------------
87 *------------------------------------------------------------------------*/
88 if ( expA == 0x1F ) {
89 if ( sigA ) goto propagateNaN;
90 if ( expB == 0x1F ) {
91 if ( sigB ) goto propagateNaN;
92 goto invalid;
93 }
94 goto infinity;
95 }
96 if ( expB == 0x1F ) {
97 if ( sigB ) goto propagateNaN;
98 goto zero;
99 }
100 /*------------------------------------------------------------------------
101 *------------------------------------------------------------------------*/
102 if ( ! expB ) {
103 if ( ! sigB ) {
104 if ( ! (expA | sigA) ) goto invalid;
106 goto infinity;
107 }
108 normExpSig = softfloat_normSubnormalF16Sig( sigB );
109 expB = normExpSig.exp;
110 sigB = normExpSig.sig;
111 }
112 if ( ! expA ) {
113 if ( ! sigA ) goto zero;
114 normExpSig = softfloat_normSubnormalF16Sig( sigA );
115 expA = normExpSig.exp;
116 sigA = normExpSig.sig;
117 }
118 /*------------------------------------------------------------------------
119 *------------------------------------------------------------------------*/
120 expZ = expA - expB + 0xE;
121 sigA |= 0x0400;
122 sigB |= 0x0400;
123#ifdef SOFTFLOAT_FAST_DIV32TO16
124 if ( sigA < sigB ) {
125 --expZ;
126 sig32A = (uint_fast32_t) sigA<<15;
127 } else {
128 sig32A = (uint_fast32_t) sigA<<14;
129 }
130 sigZ = sig32A / sigB;
131 if ( ! (sigZ & 7) ) sigZ |= ((uint_fast32_t) sigB * sigZ != sig32A);
132#else
133 if ( sigA < sigB ) {
134 --expZ;
135 sigA <<= 5;
136 } else {
137 sigA <<= 4;
138 }
139 index = sigB>>6 & 0xF;
142 * (sigB & 0x3F))
143 >>10);
144 sigZ = ((uint_fast32_t) sigA * r0)>>16;
145 rem = (sigA<<10) - sigZ * sigB;
146 sigZ += (rem * (uint_fast32_t) r0)>>26;
147 /*------------------------------------------------------------------------
148 *------------------------------------------------------------------------*/
149 ++sigZ;
150 if ( ! (sigZ & 7) ) {
151 sigZ &= ~1;
152 rem = (sigA<<10) - sigZ * sigB;
153 if ( rem & 0x8000 ) {
154 sigZ -= 2;
155 } else {
156 if ( rem ) sigZ |= 1;
157 }
158 }
159#endif
160 return softfloat_roundPackToF16( signZ, expZ, sigZ );
161 /*------------------------------------------------------------------------
162 *------------------------------------------------------------------------*/
163 propagateNaN:
164 uiZ = softfloat_propagateNaNF16UI( uiA, uiB );
165 goto uiZ;
166 /*------------------------------------------------------------------------
167 *------------------------------------------------------------------------*/
168 invalid:
170 uiZ = defaultNaNF16UI;
171 goto uiZ;
172 /*------------------------------------------------------------------------
173 *------------------------------------------------------------------------*/
174 infinity:
175 uiZ = packToF16UI( signZ, 0x1F, 0 );
176 goto uiZ;
177 /*------------------------------------------------------------------------
178 *------------------------------------------------------------------------*/
179 zero:
180 uiZ = packToF16UI( signZ, 0, 0 );
181 uiZ:
182 uZ.ui = uiZ;
183 return uZ.f;
184
185}
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_approxRecip_1k0s[]
const uint16_t softfloat_approxRecip_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)
#define packToF16UI(sign, exp, sig)
Definition internals.h:86
@ softfloat_flag_invalid
Definition softfloat.h:89
@ softfloat_flag_infinite
Definition softfloat.h:88
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_approxRecip_1k0s

const uint16_t softfloat_approxRecip_1k0s[]
extern

Definition at line 41 of file s_approxRecip_1Ks.c.

41 {
42 0xFFC4, 0xF0BE, 0xE363, 0xD76F, 0xCCAD, 0xC2F0, 0xBA16, 0xB201,
43 0xAA97, 0xA3C6, 0x9D7A, 0x97A6, 0x923C, 0x8D32, 0x887E, 0x8417
44};

◆ softfloat_approxRecip_1k1s

const uint16_t softfloat_approxRecip_1k1s[]
extern

Definition at line 45 of file s_approxRecip_1Ks.c.

45 {
46 0xF0F1, 0xD62C, 0xBFA1, 0xAC77, 0x9C0A, 0x8DDB, 0x8185, 0x76BA,
47 0x6D3B, 0x64D4, 0x5D5C, 0x56B1, 0x50B6, 0x4B55, 0x4679, 0x4211
48};