VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/source/s_addExtF80M.c@ 104389

Last change on this file since 104389 was 94558, checked in by vboxsync, 2 years ago

VMM/IEM,libs/softfloat: Don't use global variables in SoftFloat, pass in a state pointer to (almost) all functions instead. Started on fsqrt instruction implementation. bugref:9898

  • Property svn:eol-style set to native
File size: 7.1 KB
Line 
1
2/*============================================================================
3
4This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
5Package, Release 3e, by John R. Hauser.
6
7Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
8All rights reserved.
9
10Redistribution and use in source and binary forms, with or without
11modification, are permitted provided that the following conditions are met:
12
13 1. Redistributions of source code must retain the above copyright notice,
14 this list of conditions, and the following disclaimer.
15
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.
19
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.
23
24THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
25EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
27DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
28DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31ON 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
33SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35=============================================================================*/
36
37#include <stdbool.h>
38#include <stdint.h>
39#include "platform.h"
40#include "internals.h"
41#include "specialize.h"
42#include "softfloat.h"
43
44void
45 softfloat_addExtF80M(
46 const struct extFloat80M *aSPtr,
47 const struct extFloat80M *bSPtr,
48 struct extFloat80M *zSPtr,
49 bool negateB
50 SOFTFLOAT_STATE_DECL_COMMA
51 )
52{
53 uint32_t uiA64;
54 int32_t expA;
55 uint32_t uiB64;
56 int32_t expB;
57 uint32_t uiZ64;
58 bool signZ, signB;
59 const struct extFloat80M *tempSPtr;
60 uint64_t sigZ, sigB;
61 void
62 (*roundPackRoutinePtr)(
63 bool, int32_t, uint32_t *, uint_fast8_t, struct extFloat80M * SOFTFLOAT_STATE_DECL_COMMA );
64 int32_t expDiff;
65 uint32_t extSigX[3], sigZExtra;
66
67 /*------------------------------------------------------------------------
68 *------------------------------------------------------------------------*/
69 uiA64 = aSPtr->signExp;
70 expA = expExtF80UI64( uiA64 );
71 uiB64 = bSPtr->signExp;
72 expB = expExtF80UI64( uiB64 );
73 /*------------------------------------------------------------------------
74 *------------------------------------------------------------------------*/
75 if ( (expA == 0x7FFF) || (expB == 0x7FFF) ) {
76 if ( softfloat_tryPropagateNaNExtF80M( aSPtr, bSPtr, zSPtr SOFTFLOAT_STATE_ARG_COMMA ) ) return;
77 uiZ64 = uiA64;
78 if ( expB == 0x7FFF ) {
79 uiZ64 = uiB64 ^ packToExtF80UI64( negateB, 0 );
80 if ( (expA == 0x7FFF) && (uiZ64 != uiA64) ) {
81 softfloat_invalidExtF80M( zSPtr SOFTFLOAT_STATE_ARG_COMMA );
82 return;
83 }
84 }
85 zSPtr->signExp = uiZ64;
86 zSPtr->signif = UINT64_C( 0x8000000000000000 );
87 return;
88 }
89 /*------------------------------------------------------------------------
90 *------------------------------------------------------------------------*/
91 signZ = signExtF80UI64( uiA64 );
92 signB = signExtF80UI64( uiB64 ) ^ negateB;
93 negateB = (signZ != signB);
94 if ( expA < expB ) {
95 signZ = signB;
96 expA = expB;
97 expB = expExtF80UI64( uiA64 );
98 tempSPtr = aSPtr;
99 aSPtr = bSPtr;
100 bSPtr = tempSPtr;
101 }
102 if ( ! expB ) {
103 expB = 1;
104 if ( ! expA ) expA = 1;
105 }
106 sigZ = aSPtr->signif;
107 sigB = bSPtr->signif;
108 /*------------------------------------------------------------------------
109 *------------------------------------------------------------------------*/
110 roundPackRoutinePtr = softfloat_roundPackMToExtF80M;
111 expDiff = expA - expB;
112 if ( expDiff ) {
113 /*--------------------------------------------------------------------
114 *--------------------------------------------------------------------*/
115 extSigX[indexWord( 3, 2 )] = sigB>>32;
116 extSigX[indexWord( 3, 1 )] = sigB;
117 extSigX[indexWord( 3, 0 )] = 0;
118 softfloat_shiftRightJam96M( extSigX, expDiff, extSigX );
119 sigB =
120 (uint64_t) extSigX[indexWord( 3, 2 )]<<32
121 | extSigX[indexWord( 3, 1 )];
122 if ( negateB ) {
123 sigZ -= sigB;
124 sigZExtra = extSigX[indexWordLo( 3 )];
125 if ( sigZExtra ) {
126 --sigZ;
127 sigZExtra = -sigZExtra;
128 }
129 if ( ! (sigZ & UINT64_C( 0x8000000000000000 )) ) {
130 if ( sigZ & UINT64_C( 0x4000000000000000 ) ) {
131 --expA;
132 sigZ = sigZ<<1 | sigZExtra>>31;
133 sigZExtra <<= 1;
134 } else {
135 roundPackRoutinePtr = softfloat_normRoundPackMToExtF80M;
136 }
137 }
138 } else {
139 sigZ += sigB;
140 if ( sigZ & UINT64_C( 0x8000000000000000 ) ) goto sigZ;
141 sigZExtra = (uint32_t) sigZ<<31 | (extSigX[indexWordLo( 3 )] != 0);
142 goto completeNormAfterAdd;
143 }
144 } else {
145 /*--------------------------------------------------------------------
146 *--------------------------------------------------------------------*/
147 sigZExtra = 0;
148 if ( negateB ) {
149 if ( sigZ < sigB ) {
150 signZ = ! signZ;
151 sigZ = sigB - sigZ;
152 } else {
153 sigZ -= sigB;
154 if ( ! sigZ ) {
155 signZ = (softfloat_roundingMode == softfloat_round_min);
156 zSPtr->signExp = packToExtF80UI64( signZ, 0 );
157 zSPtr->signif = 0;
158 return;
159 }
160 }
161 roundPackRoutinePtr = softfloat_normRoundPackMToExtF80M;
162 } else {
163 sigZ += sigB;
164 if ( sigZ < sigB ) {
165 sigZExtra = (uint32_t) sigZ<<31;
166 completeNormAfterAdd:
167 ++expA;
168 sigZ = UINT64_C( 0x8000000000000000 ) | sigZ>>1;
169 } else {
170 if ( ! (sigZ & UINT64_C( 0x8000000000000000 )) ) {
171 roundPackRoutinePtr = softfloat_normRoundPackMToExtF80M;
172 }
173 }
174 }
175 }
176 extSigX[indexWord( 3, 0 )] = sigZExtra;
177 sigZ:
178 extSigX[indexWord( 3, 2 )] = sigZ>>32;
179 extSigX[indexWord( 3, 1 )] = sigZ;
180 /*------------------------------------------------------------------------
181 *------------------------------------------------------------------------*/
182 roundPack:
183 (*roundPackRoutinePtr)(
184 signZ, expA, extSigX, extF80_roundingPrecision, zSPtr SOFTFLOAT_STATE_ARG_COMMA );
185
186}
187
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette