VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/source/s_subMagsF128.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: 4.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
44float128_t
45 softfloat_subMagsF128(
46 uint_fast64_t uiA64,
47 uint_fast64_t uiA0,
48 uint_fast64_t uiB64,
49 uint_fast64_t uiB0,
50 bool signZ
51 SOFTFLOAT_STATE_DECL_COMMA
52 )
53{
54 int_fast32_t expA;
55 struct uint128 sigA;
56 int_fast32_t expB;
57 struct uint128 sigB, sigZ;
58 int_fast32_t expDiff, expZ;
59 struct uint128 uiZ;
60 union ui128_f128 uZ;
61
62 expA = expF128UI64( uiA64 );
63 sigA.v64 = fracF128UI64( uiA64 );
64 sigA.v0 = uiA0;
65 expB = expF128UI64( uiB64 );
66 sigB.v64 = fracF128UI64( uiB64 );
67 sigB.v0 = uiB0;
68 sigA = softfloat_shortShiftLeft128( sigA.v64, sigA.v0, 4 );
69 sigB = softfloat_shortShiftLeft128( sigB.v64, sigB.v0, 4 );
70 expDiff = expA - expB;
71 if ( 0 < expDiff ) goto expABigger;
72 if ( expDiff < 0 ) goto expBBigger;
73 if ( expA == 0x7FFF ) {
74 if ( sigA.v64 | sigA.v0 | sigB.v64 | sigB.v0 ) goto propagateNaN;
75 softfloat_raiseFlags( softfloat_flag_invalid SOFTFLOAT_STATE_ARG_COMMA );
76 uiZ.v64 = defaultNaNF128UI64;
77 uiZ.v0 = defaultNaNF128UI0;
78 goto uiZ;
79 }
80 expZ = expA;
81 if ( ! expZ ) expZ = 1;
82 if ( sigB.v64 < sigA.v64 ) goto aBigger;
83 if ( sigA.v64 < sigB.v64 ) goto bBigger;
84 if ( sigB.v0 < sigA.v0 ) goto aBigger;
85 if ( sigA.v0 < sigB.v0 ) goto bBigger;
86 uiZ.v64 =
87 packToF128UI64(
88 (softfloat_roundingMode == softfloat_round_min), 0, 0 );
89 uiZ.v0 = 0;
90 goto uiZ;
91 expBBigger:
92 if ( expB == 0x7FFF ) {
93 if ( sigB.v64 | sigB.v0 ) goto propagateNaN;
94 uiZ.v64 = packToF128UI64( signZ ^ 1, 0x7FFF, 0 );
95 uiZ.v0 = 0;
96 goto uiZ;
97 }
98 if ( expA ) {
99 sigA.v64 |= UINT64_C( 0x0010000000000000 );
100 } else {
101 ++expDiff;
102 if ( ! expDiff ) goto newlyAlignedBBigger;
103 }
104 sigA = softfloat_shiftRightJam128( sigA.v64, sigA.v0, -expDiff );
105 newlyAlignedBBigger:
106 expZ = expB;
107 sigB.v64 |= UINT64_C( 0x0010000000000000 );
108 bBigger:
109 signZ = ! signZ;
110 sigZ = softfloat_sub128( sigB.v64, sigB.v0, sigA.v64, sigA.v0 );
111 goto normRoundPack;
112 expABigger:
113 if ( expA == 0x7FFF ) {
114 if ( sigA.v64 | sigA.v0 ) goto propagateNaN;
115 uiZ.v64 = uiA64;
116 uiZ.v0 = uiA0;
117 goto uiZ;
118 }
119 if ( expB ) {
120 sigB.v64 |= UINT64_C( 0x0010000000000000 );
121 } else {
122 --expDiff;
123 if ( ! expDiff ) goto newlyAlignedABigger;
124 }
125 sigB = softfloat_shiftRightJam128( sigB.v64, sigB.v0, expDiff );
126 newlyAlignedABigger:
127 expZ = expA;
128 sigA.v64 |= UINT64_C( 0x0010000000000000 );
129 aBigger:
130 sigZ = softfloat_sub128( sigA.v64, sigA.v0, sigB.v64, sigB.v0 );
131 normRoundPack:
132 return softfloat_normRoundPackToF128( signZ, expZ - 5, sigZ.v64, sigZ.v0 SOFTFLOAT_STATE_ARG_COMMA );
133 propagateNaN:
134 uiZ = softfloat_propagateNaNF128UI( uiA64, uiA0, uiB64, uiB0 SOFTFLOAT_STATE_ARG_COMMA );
135 uiZ:
136 uZ.ui = uiZ;
137 return uZ.f;
138
139}
140
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