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 float32_t
f32_div( float32_t a
, float32_t b
)
57 struct exp16_sig32 normExpSig
;
59 #ifdef SOFTFLOAT_FAST_DIV64TO32
69 /*------------------------------------------------------------------------
70 *------------------------------------------------------------------------*/
73 signA
= signF32UI( uiA
);
74 expA
= expF32UI( uiA
);
75 sigA
= fracF32UI( uiA
);
78 signB
= signF32UI( uiB
);
79 expB
= expF32UI( uiB
);
80 sigB
= fracF32UI( uiB
);
81 signZ
= signA
^ signB
;
82 /*------------------------------------------------------------------------
83 *------------------------------------------------------------------------*/
85 if ( sigA
) goto propagateNaN
;
87 if ( sigB
) goto propagateNaN
;
93 if ( sigB
) goto propagateNaN
;
96 /*------------------------------------------------------------------------
97 *------------------------------------------------------------------------*/
100 if ( ! (expA
| sigA
) ) goto invalid
;
101 softfloat_raiseFlags( softfloat_flag_infinite
);
104 normExpSig
= softfloat_normSubnormalF32Sig( sigB
);
105 expB
= normExpSig
.exp
;
106 sigB
= normExpSig
.sig
;
109 if ( ! sigA
) goto zero
;
110 normExpSig
= softfloat_normSubnormalF32Sig( sigA
);
111 expA
= normExpSig
.exp
;
112 sigA
= normExpSig
.sig
;
114 /*------------------------------------------------------------------------
115 *------------------------------------------------------------------------*/
116 expZ
= expA
- expB
+ 0x7E;
119 #ifdef SOFTFLOAT_FAST_DIV64TO32
122 sig64A
= (uint_fast64_t) sigA
<<31;
124 sig64A
= (uint_fast64_t) sigA
<<30;
126 sigZ
= sig64A
/ sigB
;
127 if ( ! (sigZ
& 0x3F) ) sigZ
|= ((uint_fast64_t) sigB
* sigZ
!= sig64A
);
136 sigZ
= ((uint_fast64_t) sigA
* softfloat_approxRecip32_1( sigB
))>>32;
137 /*------------------------------------------------------------------------
138 *------------------------------------------------------------------------*/
140 if ( (sigZ
& 0x3F) < 2 ) {
142 #ifdef SOFTFLOAT_FAST_INT64
143 rem
= ((uint_fast64_t) sigA
<<31) - (uint_fast64_t) sigZ
* sigB
;
145 rem
= ((uint_fast64_t) sigA
<<32) - (uint_fast64_t) (sigZ
<<1) * sigB
;
147 if ( rem
& UINT64_C( 0x8000000000000000 ) ) {
150 if ( rem
) sigZ
|= 1;
154 return softfloat_roundPackToF32( signZ
, expZ
, sigZ
);
155 /*------------------------------------------------------------------------
156 *------------------------------------------------------------------------*/
158 uiZ
= softfloat_propagateNaNF32UI( uiA
, uiB
);
160 /*------------------------------------------------------------------------
161 *------------------------------------------------------------------------*/
163 softfloat_raiseFlags( softfloat_flag_invalid
);
164 uiZ
= defaultNaNF32UI
;
166 /*------------------------------------------------------------------------
167 *------------------------------------------------------------------------*/
169 uiZ
= packToF32UI( signZ
, 0xFF, 0 );
171 /*------------------------------------------------------------------------
172 *------------------------------------------------------------------------*/
174 uiZ
= packToF32UI( signZ
, 0, 0 );