2 /*============================================================================
4 This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
5 Package, Release 3d, by John R. Hauser.
7 Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
13 1. Redistributions of source code must retain the above copyright notice,
14 this list of conditions, and the following disclaimer.
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.
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.
24 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
27 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 ON 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
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 =============================================================================*/
40 #include "internals.h"
41 #include "specialize.h"
42 #include "softfloat.h"
44 float64_t
f64_div( float64_t a
, float64_t b
)
57 struct exp16_sig64 normExpSig
;
59 uint32_t recip32
, sig32Z
, doubleTerm
;
66 /*------------------------------------------------------------------------
67 *------------------------------------------------------------------------*/
70 signA
= signF64UI( uiA
);
71 expA
= expF64UI( uiA
);
72 sigA
= fracF64UI( uiA
);
75 signB
= signF64UI( uiB
);
76 expB
= expF64UI( uiB
);
77 sigB
= fracF64UI( uiB
);
78 signZ
= signA
^ signB
;
79 /*------------------------------------------------------------------------
80 *------------------------------------------------------------------------*/
81 if ( expA
== 0x7FF ) {
82 if ( sigA
) goto propagateNaN
;
83 if ( expB
== 0x7FF ) {
84 if ( sigB
) goto propagateNaN
;
89 if ( expB
== 0x7FF ) {
90 if ( sigB
) goto propagateNaN
;
93 /*------------------------------------------------------------------------
94 *------------------------------------------------------------------------*/
97 if ( ! (expA
| sigA
) ) goto invalid
;
98 softfloat_raiseFlags( softfloat_flag_infinite
);
101 normExpSig
= softfloat_normSubnormalF64Sig( sigB
);
102 expB
= normExpSig
.exp
;
103 sigB
= normExpSig
.sig
;
106 if ( ! sigA
) goto zero
;
107 normExpSig
= softfloat_normSubnormalF64Sig( sigA
);
108 expA
= normExpSig
.exp
;
109 sigA
= normExpSig
.sig
;
111 /*------------------------------------------------------------------------
112 *------------------------------------------------------------------------*/
113 expZ
= expA
- expB
+ 0x3FE;
114 sigA
|= UINT64_C( 0x0010000000000000 );
115 sigB
|= UINT64_C( 0x0010000000000000 );
123 recip32
= softfloat_approxRecip32_1( sigB
>>32 ) - 2;
124 sig32Z
= ((uint32_t) (sigA
>>32) * (uint_fast64_t) recip32
)>>32;
125 doubleTerm
= sig32Z
<<1;
127 ((sigA
- (uint_fast64_t) doubleTerm
* (uint32_t) (sigB
>>32))<<28)
128 - (uint_fast64_t) doubleTerm
* ((uint32_t) sigB
>>4);
129 q
= (((uint32_t) (rem
>>32) * (uint_fast64_t) recip32
)>>32) + 4;
130 sigZ
= ((uint_fast64_t) sig32Z
<<32) + ((uint_fast64_t) q
<<4);
131 /*------------------------------------------------------------------------
132 *------------------------------------------------------------------------*/
133 if ( (sigZ
& 0x1FF) < 4<<4 ) {
135 sigZ
&= ~(uint_fast64_t) 0x7F;
138 ((rem
- (uint_fast64_t) doubleTerm
* (uint32_t) (sigB
>>32))<<28)
139 - (uint_fast64_t) doubleTerm
* ((uint32_t) sigB
>>4);
140 if ( rem
& UINT64_C( 0x8000000000000000 ) ) {
143 if ( rem
) sigZ
|= 1;
146 return softfloat_roundPackToF64( signZ
, expZ
, sigZ
);
147 /*------------------------------------------------------------------------
148 *------------------------------------------------------------------------*/
150 uiZ
= softfloat_propagateNaNF64UI( uiA
, uiB
);
152 /*------------------------------------------------------------------------
153 *------------------------------------------------------------------------*/
155 softfloat_raiseFlags( softfloat_flag_invalid
);
156 uiZ
= defaultNaNF64UI
;
158 /*------------------------------------------------------------------------
159 *------------------------------------------------------------------------*/
161 uiZ
= packToF64UI( signZ
, 0x7FF, 0 );
163 /*------------------------------------------------------------------------
164 *------------------------------------------------------------------------*/
166 uiZ
= packToF64UI( signZ
, 0, 0 );