2 /*============================================================================
4 This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
5 Package, Release 3a, 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"
46 uint_fast32_t uiA
, uint_fast32_t uiB
, uint_fast32_t uiC
, uint_fast8_t op
)
58 uint_fast32_t magBits
, uiZ
;
59 struct exp16_sig32 normExpSig
;
61 uint_fast64_t sigProd
;
66 uint_fast64_t sig64Z
, sig64C
;
67 int_fast8_t shiftCount
;
70 signA
= signF32UI( uiA
);
71 expA
= expF32UI( uiA
);
72 sigA
= fracF32UI( uiA
);
73 signB
= signF32UI( uiB
);
74 expB
= expF32UI( uiB
);
75 sigB
= fracF32UI( uiB
);
76 signC
= signF32UI( uiC
) ^ (op
== softfloat_mulAdd_subC
);
77 expC
= expF32UI( uiC
);
78 sigC
= fracF32UI( uiC
);
79 signProd
= signA
^ signB
^ (op
== softfloat_mulAdd_subProd
);
81 if ( sigA
|| ((expB
== 0xFF) && sigB
) ) goto propagateNaN_ABC
;
82 magBits
= expB
| sigB
;
86 if ( sigB
) goto propagateNaN_ABC
;
87 magBits
= expA
| sigA
;
99 if ( ! sigA
) goto zeroProd
;
100 normExpSig
= softfloat_normSubnormalF32Sig( sigA
);
101 expA
= normExpSig
.exp
;
102 sigA
= normExpSig
.sig
;
105 if ( ! sigB
) goto zeroProd
;
106 normExpSig
= softfloat_normSubnormalF32Sig( sigB
);
107 expB
= normExpSig
.exp
;
108 sigB
= normExpSig
.sig
;
110 expProd
= expA
+ expB
- 0x7E;
111 sigA
= (sigA
| 0x00800000)<<7;
112 sigB
= (sigB
| 0x00800000)<<7;
113 sigProd
= (uint_fast64_t) sigA
* sigB
;
114 if ( sigProd
< UINT64_C( 0x2000000000000000 ) ) {
122 sigZ
= softfloat_shortShiftRightJam64( sigProd
, 31 );
125 normExpSig
= softfloat_normSubnormalF32Sig( sigC
);
126 expC
= normExpSig
.exp
;
127 sigC
= normExpSig
.sig
;
129 sigC
= (sigC
| 0x00800000)<<6;
130 expDiff
= expProd
- expC
;
131 if ( signProd
== signC
) {
132 if ( expDiff
<= 0 ) {
134 sigZ
= sigC
+ softfloat_shiftRightJam64( sigProd
, 32 - expDiff
);
139 + softfloat_shiftRightJam64(
140 (uint_fast64_t) sigC
<<32, expDiff
);
141 sigZ
= softfloat_shortShiftRightJam64( sig64Z
, 32 );
143 if ( sigZ
< 0x40000000 ) {
148 sig64C
= (uint_fast64_t) sigC
<<32;
152 sig64Z
= sig64C
- softfloat_shiftRightJam64( sigProd
, -expDiff
);
153 } else if ( ! expDiff
) {
155 sig64Z
= sigProd
- sig64C
;
156 if ( ! sig64Z
) goto completeCancellation
;
157 if ( sig64Z
& UINT64_C( 0x8000000000000000 ) ) {
163 sig64Z
= sigProd
- softfloat_shiftRightJam64( sig64C
, expDiff
);
165 shiftCount
= softfloat_countLeadingZeros64( sig64Z
) - 1;
168 if ( shiftCount
< 0 ) {
169 sigZ
= softfloat_shortShiftRightJam64( sig64Z
, -shiftCount
);
171 sigZ
= (uint_fast32_t) sig64Z
<<shiftCount
;
175 return softfloat_roundPackToF32( signZ
, expZ
, sigZ
);
177 uiZ
= softfloat_propagateNaNF32UI( uiA
, uiB
);
178 goto propagateNaN_ZC
;
181 uiZ
= packToF32UI( signProd
, 0xFF, 0 );
182 if ( expC
!= 0xFF ) goto uiZ
;
183 if ( sigC
) goto propagateNaN_ZC
;
184 if ( signProd
== signC
) goto uiZ
;
187 softfloat_raiseFlags( softfloat_flag_invalid
);
188 uiZ
= defaultNaNF32UI
;
190 uiZ
= softfloat_propagateNaNF32UI( uiZ
, uiC
);
194 if ( ! (expC
| sigC
) && (signProd
!= signC
) ) {
195 completeCancellation
:
197 packToF32UI( softfloat_roundingMode
== softfloat_round_min
, 0, 0 );