2 /*============================================================================
4 This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
5 Package, Release 3e, 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 const struct extFloat80M
*aSPtr
,
47 const struct extFloat80M
*bSPtr
,
48 struct extFloat80M
*zSPtr
,
58 const struct extFloat80M
*tempSPtr
;
61 (*roundPackRoutinePtr
)(
62 bool, int32_t, uint32_t *, uint_fast8_t, struct extFloat80M
* );
64 uint32_t extSigX
[3], sigZExtra
;
66 /*------------------------------------------------------------------------
67 *------------------------------------------------------------------------*/
68 uiA64
= aSPtr
->signExp
;
69 expA
= expExtF80UI64( uiA64
);
70 uiB64
= bSPtr
->signExp
;
71 expB
= expExtF80UI64( uiB64
);
72 /*------------------------------------------------------------------------
73 *------------------------------------------------------------------------*/
74 if ( (expA
== 0x7FFF) || (expB
== 0x7FFF) ) {
75 if ( softfloat_tryPropagateNaNExtF80M( aSPtr
, bSPtr
, zSPtr
) ) return;
77 if ( expB
== 0x7FFF ) {
78 uiZ64
= uiB64
^ packToExtF80UI64( negateB
, 0 );
79 if ( (expA
== 0x7FFF) && (uiZ64
!= uiA64
) ) {
80 softfloat_invalidExtF80M( zSPtr
);
84 zSPtr
->signExp
= uiZ64
;
85 zSPtr
->signif
= UINT64_C( 0x8000000000000000 );
88 /*------------------------------------------------------------------------
89 *------------------------------------------------------------------------*/
90 signZ
= signExtF80UI64( uiA64
);
91 signB
= signExtF80UI64( uiB64
) ^ negateB
;
92 negateB
= (signZ
!= signB
);
96 expB
= expExtF80UI64( uiA64
);
103 if ( ! expA
) expA
= 1;
105 sigZ
= aSPtr
->signif
;
106 sigB
= bSPtr
->signif
;
107 /*------------------------------------------------------------------------
108 *------------------------------------------------------------------------*/
109 roundPackRoutinePtr
= softfloat_roundPackMToExtF80M
;
110 expDiff
= expA
- expB
;
112 /*--------------------------------------------------------------------
113 *--------------------------------------------------------------------*/
114 extSigX
[indexWord( 3, 2 )] = sigB
>>32;
115 extSigX
[indexWord( 3, 1 )] = sigB
;
116 extSigX
[indexWord( 3, 0 )] = 0;
117 softfloat_shiftRightJam96M( extSigX
, expDiff
, extSigX
);
119 (uint64_t) extSigX
[indexWord( 3, 2 )]<<32
120 | extSigX
[indexWord( 3, 1 )];
123 sigZExtra
= extSigX
[indexWordLo( 3 )];
126 sigZExtra
= -sigZExtra
;
128 if ( ! (sigZ
& UINT64_C( 0x8000000000000000 )) ) {
129 if ( sigZ
& UINT64_C( 0x4000000000000000 ) ) {
131 sigZ
= sigZ
<<1 | sigZExtra
>>31;
134 roundPackRoutinePtr
= softfloat_normRoundPackMToExtF80M
;
139 if ( sigZ
& UINT64_C( 0x8000000000000000 ) ) goto sigZ
;
140 sigZExtra
= (uint32_t) sigZ
<<31 | (extSigX
[indexWordLo( 3 )] != 0);
141 goto completeNormAfterAdd
;
144 /*--------------------------------------------------------------------
145 *--------------------------------------------------------------------*/
154 signZ
= (softfloat_roundingMode
== softfloat_round_min
);
155 zSPtr
->signExp
= packToExtF80UI64( signZ
, 0 );
160 roundPackRoutinePtr
= softfloat_normRoundPackMToExtF80M
;
164 sigZExtra
= (uint32_t) sigZ
<<31;
165 completeNormAfterAdd
:
167 sigZ
= UINT64_C( 0x8000000000000000 ) | sigZ
>>1;
169 if ( ! (sigZ
& UINT64_C( 0x8000000000000000 )) ) {
170 roundPackRoutinePtr
= softfloat_normRoundPackMToExtF80M
;
175 extSigX
[indexWord( 3, 0 )] = sigZExtra
;
177 extSigX
[indexWord( 3, 2 )] = sigZ
>>32;
178 extSigX
[indexWord( 3, 1 )] = sigZ
;
179 /*------------------------------------------------------------------------
180 *------------------------------------------------------------------------*/
182 (*roundPackRoutinePtr
)(
183 signZ
, expA
, extSigX
, extF80_roundingPrecision
, zSPtr
);