Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
extF80M_div.c
Go to the documentation of this file.
1
2/*============================================================================
3
4This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
5Package, Release 3e, by John R. Hauser.
6
7Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
8California. All rights reserved.
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are met:
12
13 1. Redistributions of source code must retain the above copyright notice,
14 this list of conditions, and the following disclaimer.
15
16 2. Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
19
20 3. Neither the name of the University nor the names of its contributors may
21 be used to endorse or promote products derived from this software without
22 specific prior written permission.
23
24THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
25EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
27DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
28DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35=============================================================================*/
36
37#include <stdbool.h>
38#include <stdint.h>
39#include "platform.h"
40#include "internals.h"
41#include "specialize.h"
42#include "softfloat.h"
43
44#ifdef SOFTFLOAT_FAST_INT64
45
46void
48 const extFloat80_t *aPtr, const extFloat80_t *bPtr, extFloat80_t *zPtr )
49{
50
51 *zPtr = extF80_div( *aPtr, *bPtr );
52
53}
54
55#else
56
57void
59 const extFloat80_t *aPtr, const extFloat80_t *bPtr, extFloat80_t *zPtr )
60{
61 const struct extFloat80M *aSPtr, *bSPtr;
62 struct extFloat80M *zSPtr;
63 uint_fast16_t uiA64;
64 int32_t expA;
65 uint_fast16_t uiB64;
66 int32_t expB;
67 bool signZ;
68 uint64_t sigA, x64;
69 int32_t expZ;
70 int shiftDist;
71 uint32_t y[3], recip32, sigB[3];
72 int ix;
73 uint32_t q, qs[2];
74 uint_fast16_t uiZ64;
75 uint64_t uiZ0;
76
77 /*------------------------------------------------------------------------
78 *------------------------------------------------------------------------*/
79 aSPtr = (const struct extFloat80M *) aPtr;
80 bSPtr = (const struct extFloat80M *) bPtr;
81 zSPtr = (struct extFloat80M *) zPtr;
82 /*------------------------------------------------------------------------
83 *------------------------------------------------------------------------*/
84 uiA64 = aSPtr->signExp;
85 expA = expExtF80UI64( uiA64 );
86 uiB64 = bSPtr->signExp;
87 expB = expExtF80UI64( uiB64 );
88 signZ = signExtF80UI64( uiA64 ) ^ signExtF80UI64( uiB64 );
89 /*------------------------------------------------------------------------
90 *------------------------------------------------------------------------*/
91 if ( (expA == 0x7FFF) || (expB == 0x7FFF) ) {
92 if ( softfloat_tryPropagateNaNExtF80M( aSPtr, bSPtr, zSPtr ) ) return;
93 if ( expA == 0x7FFF ) {
94 if ( expB == 0x7FFF ) goto invalid;
95 goto infinity;
96 }
97 goto zero;
98 }
99 /*------------------------------------------------------------------------
100 *------------------------------------------------------------------------*/
101 sigA = aSPtr->signif;
102 x64 = bSPtr->signif;
103 if ( ! expB ) expB = 1;
104 if ( ! (x64 & UINT64_C( 0x8000000000000000 )) ) {
105 if ( ! x64 ) {
106 if ( ! sigA ) goto invalid;
108 goto infinity;
109 }
110 expB += softfloat_normExtF80SigM( &x64 );
111 }
112 if ( ! expA ) expA = 1;
113 if ( ! (sigA & UINT64_C( 0x8000000000000000 )) ) {
114 if ( ! sigA ) goto zero;
115 expA += softfloat_normExtF80SigM( &sigA );
116 }
117 /*------------------------------------------------------------------------
118 *------------------------------------------------------------------------*/
119 expZ = expA - expB + 0x3FFF;
120 shiftDist = 29;
121 if ( sigA < x64 ) {
122 --expZ;
123 shiftDist = 30;
124 }
125 softfloat_shortShiftLeft64To96M( sigA, shiftDist, y );
126 recip32 = softfloat_approxRecip32_1( x64>>32 );
127 sigB[indexWord( 3, 0 )] = (uint32_t) x64<<30;
128 x64 >>= 2;
129 sigB[indexWord( 3, 2 )] = x64>>32;
130 sigB[indexWord( 3, 1 )] = x64;
131 ix = 2;
132 for (;;) {
133 x64 = (uint64_t) y[indexWordHi( 3 )] * recip32;
134 q = (x64 + 0x80000000)>>32;
135 --ix;
136 if ( ix < 0 ) break;
137 softfloat_remStep96MBy32( y, 29, sigB, q, y );
138 if ( y[indexWordHi( 3 )] & 0x80000000 ) {
139 --q;
140 softfloat_add96M( y, sigB, y );
141 }
142 qs[ix] = q;
143 }
144 /*------------------------------------------------------------------------
145 *------------------------------------------------------------------------*/
146 if ( ((q + 1) & 0x3FFFFF) < 2 ) {
147 softfloat_remStep96MBy32( y, 29, sigB, q, y );
148 if ( y[indexWordHi( 3 )] & 0x80000000 ) {
149 --q;
150 softfloat_add96M( y, sigB, y );
151 } else if ( softfloat_compare96M( sigB, y ) <= 0 ) {
152 ++q;
153 softfloat_sub96M( y, sigB, y );
154 }
155 if (
156 y[indexWordLo( 3 )] || y[indexWord( 3, 1 )] || y[indexWord( 3, 2 )]
157 ) {
158 q |= 1;
159 }
160 }
161 /*------------------------------------------------------------------------
162 *------------------------------------------------------------------------*/
163 x64 = (uint64_t) q<<9;
164 y[indexWord( 3, 0 )] = x64;
165 x64 = ((uint64_t) qs[0]<<6) + (x64>>32);
166 y[indexWord( 3, 1 )] = x64;
167 y[indexWord( 3, 2 )] = (qs[1]<<3) + (x64>>32);
169 signZ, expZ, y, extF80_roundingPrecision, zSPtr );
170 return;
171 /*------------------------------------------------------------------------
172 *------------------------------------------------------------------------*/
173 invalid:
175 return;
176 /*------------------------------------------------------------------------
177 *------------------------------------------------------------------------*/
178 infinity:
179 uiZ64 = packToExtF80UI64( signZ, 0x7FFF );
180 uiZ0 = UINT64_C( 0x8000000000000000 );
181 goto uiZ;
182 /*------------------------------------------------------------------------
183 *------------------------------------------------------------------------*/
184 zero:
185 uiZ64 = packToExtF80UI64( signZ, 0 );
186 uiZ0 = 0;
187 uiZ:
188 zSPtr->signExp = uiZ64;
189 zSPtr->signif = uiZ0;
190
191}
192
193#endif
194
void softfloat_raiseFlags(uint_fast8_t flags)
extFloat80_t extF80_div(extFloat80_t a, extFloat80_t b)
Definition extF80_div.c:44
void extF80M_div(const extFloat80_t *aPtr, const extFloat80_t *bPtr, extFloat80_t *zPtr)
Definition extF80M_div.c:58
#define packToExtF80UI64(sign, exp)
Definition internals.h:148
#define expExtF80UI64(a64)
Definition internals.h:147
void softfloat_invalidExtF80M(struct extFloat80M *)
void softfloat_roundPackMToExtF80M(bool, int32_t, uint32_t *, uint_fast8_t, struct extFloat80M *)
#define signExtF80UI64(a64)
Definition internals.h:146
bool softfloat_tryPropagateNaNExtF80M(const struct extFloat80M *, const struct extFloat80M *, struct extFloat80M *)
int softfloat_normExtF80SigM(uint64_t *)
#define indexWordLo(total)
#define indexWord(total, n)
#define indexWordHi(total)
int_fast8_t softfloat_compare96M(const uint32_t *aPtr, const uint32_t *bPtr)
#define softfloat_add96M(aPtr, bPtr, zPtr)
Definition primitives.h:915
#define softfloat_sub96M(aPtr, bPtr, zPtr)
#define softfloat_remStep96MBy32(remPtr, dist, bPtr, q, zPtr)
void softfloat_shortShiftLeft64To96M(uint64_t a, uint_fast8_t dist, uint32_t *zPtr)
uint32_t softfloat_approxRecip32_1(uint32_t a)
THREAD_LOCAL uint_fast8_t extF80_roundingPrecision
@ softfloat_flag_infinite
Definition softfloat.h:88
unsigned int uint32_t
Definition stdint.h:126
uint16_t uint_fast16_t
Definition stdint.h:155
#define UINT64_C(val)
Definition stdint.h:284
signed int int32_t
Definition stdint.h:123
unsigned __int64 uint64_t
Definition stdint.h:136
uint64_t signif
uint16_t signExp