VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/source/s_subMagsExtF80.c@ 98478

Last change on this file since 98478 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.7 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, 2015 The Regents of the University of
8California. All 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
44extFloat80_t
45 softfloat_subMagsExtF80(
46 uint_fast16_t uiA64,
47 uint_fast64_t uiA0,
48 uint_fast16_t uiB64,
49 uint_fast64_t uiB0,
50 bool signZ
51 SOFTFLOAT_STATE_DECL_COMMA
52 )
53{
54 int_fast32_t expA;
55 uint_fast64_t sigA;
56 int_fast32_t expB;
57 uint_fast64_t sigB;
58 int_fast32_t expDiff;
59 uint_fast16_t uiZ64;
60 uint_fast64_t uiZ0;
61 int_fast32_t expZ;
62 uint_fast64_t sigExtra;
63 struct uint128 sig128, uiZ;
64 union { struct extFloat80M s; extFloat80_t f; } uZ;
65
66 /*------------------------------------------------------------------------
67 *------------------------------------------------------------------------*/
68 expA = expExtF80UI64( uiA64 );
69 sigA = uiA0;
70 expB = expExtF80UI64( uiB64 );
71 sigB = uiB0;
72 /*------------------------------------------------------------------------
73 *------------------------------------------------------------------------*/
74 expDiff = expA - expB;
75 if ( 0 < expDiff ) goto expABigger;
76 if ( expDiff < 0 ) goto expBBigger;
77 if ( expA == 0x7FFF ) {
78 if ( (sigA | sigB) & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) {
79 goto propagateNaN;
80 }
81 softfloat_raiseFlags( softfloat_flag_invalid SOFTFLOAT_STATE_ARG_COMMA );
82 uiZ64 = defaultNaNExtF80UI64;
83 uiZ0 = defaultNaNExtF80UI0;
84 goto uiZ;
85 }
86 /*------------------------------------------------------------------------
87 *------------------------------------------------------------------------*/
88 expZ = expA;
89 if ( ! expZ ) expZ = 1;
90 sigExtra = 0;
91 if ( sigB < sigA ) goto aBigger;
92 if ( sigA < sigB ) goto bBigger;
93 uiZ64 =
94 packToExtF80UI64( (softfloat_roundingMode == softfloat_round_min), 0 );
95 uiZ0 = 0;
96 goto uiZ;
97 /*------------------------------------------------------------------------
98 *------------------------------------------------------------------------*/
99 expBBigger:
100 if ( expB == 0x7FFF ) {
101 if ( sigB & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) goto propagateNaN;
102 uiZ64 = packToExtF80UI64( signZ ^ 1, 0x7FFF );
103 uiZ0 = UINT64_C( 0x8000000000000000 );
104 goto uiZ;
105 }
106 if ( ! expA ) {
107 ++expDiff;
108 sigExtra = 0;
109 if ( ! expDiff ) goto newlyAlignedBBigger;
110 }
111 sig128 = softfloat_shiftRightJam128( sigA, 0, -expDiff );
112 sigA = sig128.v64;
113 sigExtra = sig128.v0;
114 newlyAlignedBBigger:
115 expZ = expB;
116 bBigger:
117 signZ = ! signZ;
118 sig128 = softfloat_sub128( sigB, 0, sigA, sigExtra );
119 goto normRoundPack;
120 /*------------------------------------------------------------------------
121 *------------------------------------------------------------------------*/
122 expABigger:
123 if ( expA == 0x7FFF ) {
124 if ( sigA & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) goto propagateNaN;
125 uiZ64 = uiA64;
126 uiZ0 = uiA0;
127 goto uiZ;
128 }
129 if ( ! expB ) {
130 --expDiff;
131 sigExtra = 0;
132 if ( ! expDiff ) goto newlyAlignedABigger;
133 }
134 sig128 = softfloat_shiftRightJam128( sigB, 0, expDiff );
135 sigB = sig128.v64;
136 sigExtra = sig128.v0;
137 newlyAlignedABigger:
138 expZ = expA;
139 aBigger:
140 sig128 = softfloat_sub128( sigA, 0, sigB, sigExtra );
141 /*------------------------------------------------------------------------
142 *------------------------------------------------------------------------*/
143 normRoundPack:
144 return
145 softfloat_normRoundPackToExtF80(
146 signZ, expZ, sig128.v64, sig128.v0, extF80_roundingPrecision SOFTFLOAT_STATE_ARG_COMMA );
147 /*------------------------------------------------------------------------
148 *------------------------------------------------------------------------*/
149 propagateNaN:
150 uiZ = softfloat_propagateNaNExtF80UI( uiA64, uiA0, uiB64, uiB0 SOFTFLOAT_STATE_ARG_COMMA );
151 uiZ64 = uiZ.v64;
152 uiZ0 = uiZ.v0;
153 uiZ:
154 uZ.s.signExp = uiZ64;
155 uZ.s.signif = uiZ0;
156 return uZ.f;
157
158}
159
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