VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/source/s_addMagsF128.c@ 96666

Last change on this file since 96666 was 94558, checked in by vboxsync, 3 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: 5.0 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
43float128_t
44 softfloat_addMagsF128(
45 uint_fast64_t uiA64,
46 uint_fast64_t uiA0,
47 uint_fast64_t uiB64,
48 uint_fast64_t uiB0,
49 bool signZ
50 SOFTFLOAT_STATE_DECL_COMMA
51 )
52{
53 int_fast32_t expA;
54 struct uint128 sigA;
55 int_fast32_t expB;
56 struct uint128 sigB;
57 int_fast32_t expDiff;
58 struct uint128 uiZ, sigZ;
59 int_fast32_t expZ;
60 uint_fast64_t sigZExtra;
61 struct uint128_extra sig128Extra;
62 union ui128_f128 uZ;
63
64 expA = expF128UI64( uiA64 );
65 sigA.v64 = fracF128UI64( uiA64 );
66 sigA.v0 = uiA0;
67 expB = expF128UI64( uiB64 );
68 sigB.v64 = fracF128UI64( uiB64 );
69 sigB.v0 = uiB0;
70 expDiff = expA - expB;
71 if ( ! expDiff ) {
72 if ( expA == 0x7FFF ) {
73 if ( sigA.v64 | sigA.v0 | sigB.v64 | sigB.v0 ) goto propagateNaN;
74 uiZ.v64 = uiA64;
75 uiZ.v0 = uiA0;
76 goto uiZ;
77 }
78 sigZ = softfloat_add128( sigA.v64, sigA.v0, sigB.v64, sigB.v0 );
79 if ( ! expA ) {
80 uiZ.v64 = packToF128UI64( signZ, 0, sigZ.v64 );
81 uiZ.v0 = sigZ.v0;
82 goto uiZ;
83 }
84 expZ = expA;
85 sigZ.v64 |= UINT64_C( 0x0002000000000000 );
86 sigZExtra = 0;
87 goto shiftRight1;
88 }
89 if ( expDiff < 0 ) {
90 if ( expB == 0x7FFF ) {
91 if ( sigB.v64 | sigB.v0 ) goto propagateNaN;
92 uiZ.v64 = packToF128UI64( signZ, 0x7FFF, 0 );
93 uiZ.v0 = 0;
94 goto uiZ;
95 }
96 expZ = expB;
97 if ( expA ) {
98 sigA.v64 |= UINT64_C( 0x0001000000000000 );
99 } else {
100 ++expDiff;
101 sigZExtra = 0;
102 if ( ! expDiff ) goto newlyAligned;
103 }
104 sig128Extra =
105 softfloat_shiftRightJam128Extra( sigA.v64, sigA.v0, 0, -expDiff );
106 sigA = sig128Extra.v;
107 sigZExtra = sig128Extra.extra;
108 } else {
109 if ( expA == 0x7FFF ) {
110 if ( sigA.v64 | sigA.v0 ) goto propagateNaN;
111 uiZ.v64 = uiA64;
112 uiZ.v0 = uiA0;
113 goto uiZ;
114 }
115 expZ = expA;
116 if ( expB ) {
117 sigB.v64 |= UINT64_C( 0x0001000000000000 );
118 } else {
119 --expDiff;
120 sigZExtra = 0;
121 if ( ! expDiff ) goto newlyAligned;
122 }
123 sig128Extra =
124 softfloat_shiftRightJam128Extra( sigB.v64, sigB.v0, 0, expDiff );
125 sigB = sig128Extra.v;
126 sigZExtra = sig128Extra.extra;
127 }
128 newlyAligned:
129 sigZ =
130 softfloat_add128(
131 sigA.v64 | UINT64_C( 0x0001000000000000 ),
132 sigA.v0,
133 sigB.v64,
134 sigB.v0
135 );
136 --expZ;
137 if ( sigZ.v64 < UINT64_C( 0x0002000000000000 ) ) goto roundAndPack;
138 ++expZ;
139 shiftRight1:
140 sig128Extra =
141 softfloat_shortShiftRightJam128Extra(
142 sigZ.v64, sigZ.v0, sigZExtra, 1 );
143 sigZ = sig128Extra.v;
144 sigZExtra = sig128Extra.extra;
145 roundAndPack:
146 return
147 softfloat_roundPackToF128( signZ, expZ, sigZ.v64, sigZ.v0, sigZExtra SOFTFLOAT_STATE_ARG_COMMA );
148 propagateNaN:
149 uiZ = softfloat_propagateNaNF128UI( uiA64, uiA0, uiB64, uiB0 SOFTFLOAT_STATE_ARG_COMMA );
150 uiZ:
151 uZ.ui = uiZ;
152 return uZ.f;
153
154}
155
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