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 uint32_t *aWPtr
,
47 const uint32_t *bWPtr
,
58 const uint32_t *tempPtr
;
59 uint32_t sig96A
, sig96B
;
62 (*addCarryMRoutinePtr
)(
69 uint32_t extSigZ
[5], wordSigZ
;
71 void (*roundPackRoutinePtr
)( bool, int32_t, uint32_t *, uint32_t * );
73 /*------------------------------------------------------------------------
74 *------------------------------------------------------------------------*/
75 uiA96
= aWPtr
[indexWordHi( 4 )];
76 expA
= expF128UI96( uiA96
);
77 uiB96
= bWPtr
[indexWordHi( 4 )];
78 expB
= expF128UI96( uiB96
);
79 /*------------------------------------------------------------------------
80 *------------------------------------------------------------------------*/
81 if ( (expA
== 0x7FFF) || (expB
== 0x7FFF) ) {
82 if ( softfloat_tryPropagateNaNF128M( aWPtr
, bWPtr
, zWPtr
) ) return;
84 if ( expB
== 0x7FFF ) {
85 uiZ96
= uiB96
^ packToF128UI96( negateB
, 0, 0 );
86 if ( (expA
== 0x7FFF) && (uiZ96
!= uiA96
) ) {
87 softfloat_invalidF128M( zWPtr
);
91 zWPtr
[indexWordHi( 4 )] = uiZ96
;
92 zWPtr
[indexWord( 4, 2 )] = 0;
93 zWPtr
[indexWord( 4, 1 )] = 0;
94 zWPtr
[indexWord( 4, 0 )] = 0;
97 /*------------------------------------------------------------------------
98 *------------------------------------------------------------------------*/
99 signZ
= signF128UI96( uiA96
);
100 signB
= signF128UI96( uiB96
) ^ negateB
;
101 negateB
= (signZ
!= signB
);
102 if ( (uint32_t) (uiA96
<<1) < (uint32_t) (uiB96
<<1) ) {
105 expB
= expF128UI96( uiA96
);
110 uiB96
= bWPtr
[indexWordHi( 4 )];
112 sig96A
= fracF128UI96( uiA96
);
113 sig96B
= fracF128UI96( uiB96
);
116 sig96A
|= 0x00010000;
119 sig96B
|= 0x00010000;
122 /*------------------------------------------------------------------------
123 *------------------------------------------------------------------------*/
124 addCarryMRoutinePtr
=
125 negateB
? softfloat_addComplCarryM
: softfloat_addCarryM
;
126 expDiff
= expA
- expB
;
128 /*--------------------------------------------------------------------
129 *--------------------------------------------------------------------*/
130 extSigZ
[indexWordHi( 5 )] = sig96B
;
131 extSigZ
[indexWord( 5, 3 )] = bWPtr
[indexWord( 4, 2 )];
132 extSigZ
[indexWord( 5, 2 )] = bWPtr
[indexWord( 4, 1 )];
133 extSigZ
[indexWord( 5, 1 )] = bWPtr
[indexWord( 4, 0 )];
134 extSigZ
[indexWord( 5, 0 )] = 0;
135 softfloat_shiftRightJam160M( extSigZ
, expDiff
, extSigZ
);
136 sig96B
= extSigZ
[indexWordHi( 5 )];
140 wordSigZ
= extSigZ
[indexWordLo( 5 )];
141 extSigZ
[indexWordLo( 5 )] = -wordSigZ
;
145 (*addCarryMRoutinePtr
)(
147 &aWPtr
[indexMultiwordLo( 4, 3 )],
148 &extSigZ
[indexMultiword( 5, 3, 1 )],
150 &extSigZ
[indexMultiword( 5, 3, 1 )]
152 wordSigZ
= sig96A
+ sig96B
+ carry
;
154 /*--------------------------------------------------------------------
155 *--------------------------------------------------------------------*/
156 extSigZ
[indexWordLo( 5 )] = 0;
158 (*addCarryMRoutinePtr
)(
160 &aWPtr
[indexMultiwordLo( 4, 3 )],
161 &bWPtr
[indexMultiwordLo( 4, 3 )],
163 &extSigZ
[indexMultiword( 5, 3, 1 )]
166 wordSigZ
= sig96A
+ ~sig96B
+ carry
;
167 if ( wordSigZ
& 0x80000000 ) {
170 softfloat_addComplCarry96M(
171 &bWPtr
[indexMultiwordLo( 4, 3 )],
172 &aWPtr
[indexMultiwordLo( 4, 3 )],
174 &extSigZ
[indexMultiword( 5, 3, 1 )]
176 wordSigZ
= sig96B
+ ~sig96A
+ carry
;
179 ! wordSigZ
&& ! extSigZ
[indexWord( 5, 3 )]
180 && ! ( extSigZ
[indexWord( 5, 2 )]
181 | extSigZ
[indexWord( 5, 1 )]
182 | extSigZ
[indexWord( 5, 0 )]
185 signZ
= (softfloat_roundingMode
== softfloat_round_min
);
186 zWPtr
[indexWordHi( 4 )] = packToF128UI96( signZ
, 0, 0 );
187 zWPtr
[indexWord( 4, 2 )] = 0;
188 zWPtr
[indexWord( 4, 1 )] = 0;
189 zWPtr
[indexWord( 4, 0 )] = 0;
194 wordSigZ
= sig96A
+ sig96B
+ carry
;
197 extSigZ
[indexWordHi( 5 )] = wordSigZ
;
198 /*------------------------------------------------------------------------
199 *------------------------------------------------------------------------*/
200 roundPackRoutinePtr
= softfloat_normRoundPackMToF128M
;
201 if ( 0x00010000 <= wordSigZ
) {
202 if ( 0x00020000 <= wordSigZ
) {
204 softfloat_shortShiftRightJam160M( extSigZ
, 1, extSigZ
);
206 roundPackRoutinePtr
= softfloat_roundPackMToF128M
;
208 (*roundPackRoutinePtr
)( signZ
, expA
, extSigZ
, zWPtr
);